aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/block/biodoc.txt20
-rw-r--r--Documentation/block/ioprio.txt11
-rw-r--r--Documentation/dvb/faq.txt2
-rw-r--r--Documentation/feature-removal-schedule.txt8
-rw-r--r--Documentation/kernel-parameters.txt3
-rw-r--r--Documentation/lguest/lguest.c2
-rw-r--r--Documentation/video4linux/CARDLIST.bttv1
-rw-r--r--Documentation/video4linux/CARDLIST.cx238855
-rw-r--r--Documentation/video4linux/CARDLIST.saa71345
-rw-r--r--Kbuild8
-rw-r--r--MAINTAINERS41
-rw-r--r--Makefile39
-rw-r--r--arch/arm/mach-imx/mx1ads.c2
-rw-r--r--arch/avr32/boards/atngw100/flash.c5
-rw-r--r--arch/avr32/boards/atngw100/setup.c14
-rw-r--r--arch/avr32/boards/atstk1000/atstk1002.c1
-rw-r--r--arch/avr32/boards/atstk1000/flash.c5
-rw-r--r--arch/avr32/kernel/Makefile5
-rw-r--r--arch/avr32/kernel/entry-avr32b.S26
-rw-r--r--arch/avr32/kernel/setup.c2
-rw-r--r--arch/avr32/kernel/vmlinux.lds.S143
-rw-r--r--arch/avr32/kernel/vmlinux.lds.c142
-rw-r--r--arch/avr32/mach-at32ap/at32ap7000.c74
-rw-r--r--arch/avr32/mach-at32ap/clock.c116
-rw-r--r--arch/avr32/mach-at32ap/hsmc.c129
-rw-r--r--arch/avr32/mach-at32ap/pio.c4
-rw-r--r--arch/avr32/mach-at32ap/pm.h8
-rw-r--r--arch/avr32/mm/init.c12
-rw-r--r--arch/blackfin/Kconfig365
-rw-r--r--arch/blackfin/configs/BF533-EZKIT_defconfig243
-rw-r--r--arch/blackfin/configs/BF533-STAMP_defconfig280
-rw-r--r--arch/blackfin/configs/BF537-STAMP_defconfig296
-rw-r--r--arch/blackfin/configs/BF548-EZKIT_defconfig480
-rw-r--r--arch/blackfin/configs/BF561-EZKIT_defconfig223
-rw-r--r--arch/blackfin/configs/PNAV-10_defconfig296
-rw-r--r--arch/blackfin/kernel/Makefile5
-rw-r--r--arch/blackfin/kernel/bfin_dma_5xx.c81
-rw-r--r--arch/blackfin/kernel/bfin_gpio.c549
-rw-r--r--arch/blackfin/kernel/bfin_ksyms.c1
-rw-r--r--arch/blackfin/kernel/cacheinit.c5
-rw-r--r--arch/blackfin/kernel/cplbinit.c7
-rw-r--r--arch/blackfin/kernel/early_printk.c214
-rw-r--r--arch/blackfin/kernel/irqchip.c12
-rw-r--r--arch/blackfin/kernel/process.c28
-rw-r--r--arch/blackfin/kernel/ptrace.c24
-rw-r--r--arch/blackfin/kernel/reboot.c78
-rw-r--r--arch/blackfin/kernel/setup.c90
-rw-r--r--arch/blackfin/kernel/traps.c110
-rw-r--r--arch/blackfin/kernel/vmlinux.lds.S48
-rw-r--r--arch/blackfin/lib/memcmp.S2
-rw-r--r--arch/blackfin/lib/memcpy.S2
-rw-r--r--arch/blackfin/lib/memmove.S4
-rw-r--r--arch/blackfin/mach-bf533/boards/cm_bf533.c81
-rw-r--r--arch/blackfin/mach-bf533/boards/ezkit.c91
-rw-r--r--arch/blackfin/mach-bf533/boards/stamp.c119
-rw-r--r--arch/blackfin/mach-bf533/head.S344
-rw-r--r--arch/blackfin/mach-bf537/Kconfig27
-rw-r--r--arch/blackfin/mach-bf537/boards/cm_bf537.c87
-rw-r--r--arch/blackfin/mach-bf537/boards/generic_board.c397
-rw-r--r--arch/blackfin/mach-bf537/boards/pnav10.c53
-rw-r--r--arch/blackfin/mach-bf537/boards/stamp.c142
-rw-r--r--arch/blackfin/mach-bf537/head.S128
-rw-r--r--arch/blackfin/mach-bf548/Kconfig11
-rw-r--r--arch/blackfin/mach-bf548/Makefile2
-rw-r--r--arch/blackfin/mach-bf548/boards/ezkit.c477
-rw-r--r--arch/blackfin/mach-bf548/gpio.c323
-rw-r--r--arch/blackfin/mach-bf548/head.S156
-rw-r--r--arch/blackfin/mach-bf561/boards/cm_bf561.c84
-rw-r--r--arch/blackfin/mach-bf561/boards/ezkit.c82
-rw-r--r--arch/blackfin/mach-bf561/head.S102
-rw-r--r--arch/blackfin/mach-common/Makefile2
-rw-r--r--arch/blackfin/mach-common/arch_checks.c60
-rw-r--r--arch/blackfin/mach-common/cache.S8
-rw-r--r--arch/blackfin/mach-common/cacheinit.S14
-rw-r--r--arch/blackfin/mach-common/cplbhdlr.S8
-rw-r--r--arch/blackfin/mach-common/cplbmgr.S56
-rw-r--r--arch/blackfin/mach-common/dpmc.S54
-rw-r--r--arch/blackfin/mach-common/entry.S268
-rw-r--r--arch/blackfin/mach-common/interrupt.S56
-rw-r--r--arch/blackfin/mach-common/ints-priority-dc.c13
-rw-r--r--arch/blackfin/mach-common/ints-priority-sc.c17
-rw-r--r--arch/blackfin/mach-common/lock.S24
-rw-r--r--arch/blackfin/mm/init.c2
-rw-r--r--arch/blackfin/oprofile/op_blackfin.h8
-rw-r--r--arch/i386/Kconfig8
-rw-r--r--arch/i386/Makefile72
-rw-r--r--arch/i386/boot/Makefile171
-rw-r--r--arch/i386/boot/compressed/Makefile50
-rw-r--r--arch/i386/crypto/Makefile12
-rw-r--r--arch/i386/kernel/Makefile88
-rw-r--r--arch/i386/kernel/acpi/Makefile10
-rw-r--r--arch/i386/kernel/asm-offsets.c147
-rw-r--r--arch/i386/kernel/cpu/mtrr/state.c79
-rw-r--r--arch/i386/kernel/early_printk.c2
-rw-r--r--arch/i386/kernel/entry.S1112
-rw-r--r--arch/i386/kernel/head.S578
-rw-r--r--arch/i386/kernel/signal.c667
-rw-r--r--arch/i386/kernel/tsc_sync.c1
-rw-r--r--arch/i386/kernel/vsyscall-int80.S53
-rw-r--r--arch/i386/kernel/vsyscall-note.S45
-rw-r--r--arch/i386/kernel/vsyscall-sysenter.S122
-rw-r--r--arch/i386/kernel/vsyscall.S15
-rw-r--r--arch/i386/lib/Makefile11
-rw-r--r--arch/i386/mach-generic/Makefile7
-rw-r--r--arch/i386/mach-voyager/Makefile8
-rw-r--r--arch/i386/mm/Makefile10
-rw-r--r--arch/i386/pci/Makefile14
-rw-r--r--arch/ia64/ia32/audit.c2
-rw-r--r--arch/um/sys-i386/sys_call_table.S2
-rw-r--r--arch/um/sys-x86_64/syscall_table.c4
-rw-r--r--arch/x86/boot/.gitignore (renamed from arch/i386/boot/.gitignore)0
-rw-r--r--arch/x86/boot/Makefile171
-rw-r--r--arch/x86/boot/a20.c (renamed from arch/i386/boot/a20.c)0
-rw-r--r--arch/x86/boot/apm.c (renamed from arch/i386/boot/apm.c)0
-rw-r--r--arch/x86/boot/bitops.h (renamed from arch/i386/boot/bitops.h)0
-rw-r--r--arch/x86/boot/boot.h (renamed from arch/i386/boot/boot.h)0
-rw-r--r--arch/x86/boot/cmdline.c (renamed from arch/i386/boot/cmdline.c)0
-rw-r--r--arch/x86/boot/code16gcc.h (renamed from arch/i386/boot/code16gcc.h)0
-rw-r--r--arch/x86/boot/compressed/.gitignore (renamed from arch/i386/boot/compressed/.gitignore)0
-rw-r--r--arch/x86/boot/compressed/Makefile5
-rw-r--r--arch/x86/boot/compressed/Makefile_3250
-rw-r--r--arch/x86/boot/compressed/Makefile_6430
-rw-r--r--arch/x86/boot/compressed/head_32.S (renamed from arch/i386/boot/compressed/head.S)0
-rw-r--r--arch/x86/boot/compressed/head_64.S311
-rw-r--r--arch/x86/boot/compressed/misc_32.c (renamed from arch/i386/boot/compressed/misc.c)0
-rw-r--r--arch/x86/boot/compressed/misc_64.c (renamed from arch/x86_64/boot/compressed/misc.c)0
-rw-r--r--arch/x86/boot/compressed/relocs.c (renamed from arch/i386/boot/compressed/relocs.c)0
-rw-r--r--arch/x86/boot/compressed/vmlinux_32.lds (renamed from arch/i386/boot/compressed/vmlinux.lds)0
-rw-r--r--arch/x86/boot/compressed/vmlinux_32.scr (renamed from arch/i386/boot/compressed/vmlinux.scr)0
-rw-r--r--arch/x86/boot/compressed/vmlinux_64.lds (renamed from arch/x86_64/boot/compressed/vmlinux.lds)0
-rw-r--r--arch/x86/boot/compressed/vmlinux_64.scr (renamed from arch/x86_64/boot/compressed/vmlinux.scr)0
-rw-r--r--arch/x86/boot/copy.S (renamed from arch/i386/boot/copy.S)0
-rw-r--r--arch/x86/boot/cpu.c (renamed from arch/i386/boot/cpu.c)0
-rw-r--r--arch/x86/boot/cpucheck.c (renamed from arch/i386/boot/cpucheck.c)0
-rw-r--r--arch/x86/boot/edd.c (renamed from arch/i386/boot/edd.c)0
-rw-r--r--arch/x86/boot/header.S (renamed from arch/i386/boot/header.S)0
-rw-r--r--arch/x86/boot/install.sh (renamed from arch/i386/boot/install.sh)0
-rw-r--r--arch/x86/boot/main.c (renamed from arch/i386/boot/main.c)0
-rw-r--r--arch/x86/boot/mca.c (renamed from arch/i386/boot/mca.c)0
-rw-r--r--arch/x86/boot/memory.c (renamed from arch/i386/boot/memory.c)0
-rw-r--r--arch/x86/boot/mtools.conf.in (renamed from arch/i386/boot/mtools.conf.in)0
-rw-r--r--arch/x86/boot/pm.c (renamed from arch/i386/boot/pm.c)0
-rw-r--r--arch/x86/boot/pmjump.S (renamed from arch/i386/boot/pmjump.S)0
-rw-r--r--arch/x86/boot/printf.c (renamed from arch/i386/boot/printf.c)0
-rw-r--r--arch/x86/boot/setup.ld (renamed from arch/i386/boot/setup.ld)0
-rw-r--r--arch/x86/boot/string.c (renamed from arch/i386/boot/string.c)0
-rw-r--r--arch/x86/boot/tools/.gitignore (renamed from arch/i386/boot/tools/.gitignore)0
-rw-r--r--arch/x86/boot/tools/build.c (renamed from arch/i386/boot/tools/build.c)0
-rw-r--r--arch/x86/boot/tty.c (renamed from arch/i386/boot/tty.c)0
-rw-r--r--arch/x86/boot/version.c (renamed from arch/i386/boot/version.c)0
-rw-r--r--arch/x86/boot/vesa.h (renamed from arch/i386/boot/vesa.h)0
-rw-r--r--arch/x86/boot/video-bios.c (renamed from arch/i386/boot/video-bios.c)0
-rw-r--r--arch/x86/boot/video-vesa.c (renamed from arch/i386/boot/video-vesa.c)0
-rw-r--r--arch/x86/boot/video-vga.c (renamed from arch/i386/boot/video-vga.c)0
-rw-r--r--arch/x86/boot/video.c (renamed from arch/i386/boot/video.c)0
-rw-r--r--arch/x86/boot/video.h (renamed from arch/i386/boot/video.h)0
-rw-r--r--arch/x86/boot/voyager.c (renamed from arch/i386/boot/voyager.c)0
-rw-r--r--arch/x86/crypto/Makefile5
-rw-r--r--arch/x86/crypto/Makefile_3212
-rw-r--r--arch/x86/crypto/Makefile_6412
-rw-r--r--arch/x86/crypto/aes-i586-asm_32.S (renamed from arch/i386/crypto/aes-i586-asm.S)0
-rw-r--r--arch/x86/crypto/aes-x86_64-asm_64.S (renamed from arch/x86_64/crypto/aes-x86_64-asm.S)0
-rw-r--r--arch/x86/crypto/aes_32.c (renamed from arch/i386/crypto/aes.c)0
-rw-r--r--arch/x86/crypto/aes_64.c (renamed from arch/x86_64/crypto/aes.c)0
-rw-r--r--arch/x86/crypto/twofish-i586-asm_32.S (renamed from arch/i386/crypto/twofish-i586-asm.S)0
-rw-r--r--arch/x86/crypto/twofish-x86_64-asm_64.S (renamed from arch/x86_64/crypto/twofish-x86_64-asm.S)0
-rw-r--r--arch/x86/crypto/twofish_32.c (renamed from arch/i386/crypto/twofish.c)0
-rw-r--r--arch/x86/crypto/twofish_64.c (renamed from arch/x86_64/crypto/twofish.c)0
-rw-r--r--arch/x86/ia32/Makefile (renamed from arch/x86_64/ia32/Makefile)0
-rw-r--r--arch/x86/ia32/audit.c42
-rw-r--r--arch/x86/ia32/fpu32.c (renamed from arch/x86_64/ia32/fpu32.c)0
-rw-r--r--arch/x86/ia32/ia32_aout.c (renamed from arch/x86_64/ia32/ia32_aout.c)0
-rw-r--r--arch/x86/ia32/ia32_binfmt.c (renamed from arch/x86_64/ia32/ia32_binfmt.c)0
-rw-r--r--arch/x86/ia32/ia32_signal.c (renamed from arch/x86_64/ia32/ia32_signal.c)0
-rw-r--r--arch/x86/ia32/ia32entry.S (renamed from arch/x86_64/ia32/ia32entry.S)0
-rw-r--r--arch/x86/ia32/ipc32.c57
-rw-r--r--arch/x86/ia32/mmap32.c (renamed from arch/x86_64/ia32/mmap32.c)0
-rw-r--r--arch/x86/ia32/ptrace32.c (renamed from arch/x86_64/ia32/ptrace32.c)0
-rw-r--r--arch/x86/ia32/sys_ia32.c (renamed from arch/x86_64/ia32/sys_ia32.c)0
-rw-r--r--arch/x86/ia32/syscall32.c (renamed from arch/x86_64/ia32/syscall32.c)0
-rw-r--r--arch/x86/ia32/syscall32_syscall.S17
-rw-r--r--arch/x86/ia32/tls32.c (renamed from arch/x86_64/ia32/tls32.c)0
-rw-r--r--arch/x86/ia32/vsyscall-sigreturn.S143
-rw-r--r--arch/x86/ia32/vsyscall-syscall.S (renamed from arch/x86_64/ia32/vsyscall-syscall.S)0
-rw-r--r--arch/x86/ia32/vsyscall-sysenter.S (renamed from arch/x86_64/ia32/vsyscall-sysenter.S)0
-rw-r--r--arch/x86/ia32/vsyscall.lds (renamed from arch/x86_64/ia32/vsyscall.lds)0
-rw-r--r--arch/x86/kernel/.gitignore (renamed from arch/i386/kernel/.gitignore)0
-rw-r--r--arch/x86/kernel/Makefile5
-rw-r--r--arch/x86/kernel/Makefile_3286
-rw-r--r--arch/x86/kernel/Makefile_6454
-rw-r--r--arch/x86/kernel/acpi/Makefile5
-rw-r--r--arch/x86/kernel/acpi/Makefile_3210
-rw-r--r--arch/x86/kernel/acpi/Makefile_647
-rw-r--r--arch/x86/kernel/acpi/boot.c (renamed from arch/i386/kernel/acpi/boot.c)0
-rw-r--r--arch/x86/kernel/acpi/cstate.c (renamed from arch/i386/kernel/acpi/cstate.c)0
-rw-r--r--arch/x86/kernel/acpi/earlyquirk_32.c (renamed from arch/i386/kernel/acpi/earlyquirk.c)0
-rw-r--r--arch/x86/kernel/acpi/processor.c (renamed from arch/i386/kernel/acpi/processor.c)0
-rw-r--r--arch/x86/kernel/acpi/sleep_32.c (renamed from arch/i386/kernel/acpi/sleep.c)0
-rw-r--r--arch/x86/kernel/acpi/sleep_64.c (renamed from arch/x86_64/kernel/acpi/sleep.c)0
-rw-r--r--arch/x86/kernel/acpi/wakeup_32.S (renamed from arch/i386/kernel/acpi/wakeup.S)0
-rw-r--r--arch/x86/kernel/acpi/wakeup_64.S456
-rw-r--r--arch/x86/kernel/alternative.c (renamed from arch/i386/kernel/alternative.c)0
-rw-r--r--arch/x86/kernel/aperture_64.c (renamed from arch/x86_64/kernel/aperture.c)0
-rw-r--r--arch/x86/kernel/apic_32.c (renamed from arch/i386/kernel/apic.c)0
-rw-r--r--arch/x86/kernel/apic_64.c (renamed from arch/x86_64/kernel/apic.c)0
-rw-r--r--arch/x86/kernel/apm_32.c (renamed from arch/i386/kernel/apm.c)0
-rw-r--r--arch/x86/kernel/asm-offsets.c5
-rw-r--r--arch/x86/kernel/asm-offsets_32.c147
-rw-r--r--arch/x86/kernel/asm-offsets_64.c (renamed from arch/x86_64/kernel/asm-offsets.c)0
-rw-r--r--arch/x86/kernel/audit_64.c (renamed from arch/x86_64/kernel/audit.c)0
-rw-r--r--arch/x86/kernel/bootflag.c (renamed from arch/i386/kernel/bootflag.c)0
-rw-r--r--arch/x86/kernel/bugs_64.c (renamed from arch/x86_64/kernel/bugs.c)0
-rw-r--r--arch/x86/kernel/cpu/Makefile (renamed from arch/i386/kernel/cpu/Makefile)0
-rw-r--r--arch/x86/kernel/cpu/addon_cpuid_features.c (renamed from arch/i386/kernel/cpu/addon_cpuid_features.c)0
-rw-r--r--arch/x86/kernel/cpu/amd.c (renamed from arch/i386/kernel/cpu/amd.c)0
-rw-r--r--arch/x86/kernel/cpu/bugs.c (renamed from arch/i386/kernel/cpu/bugs.c)0
-rw-r--r--arch/x86/kernel/cpu/centaur.c (renamed from arch/i386/kernel/cpu/centaur.c)0
-rw-r--r--arch/x86/kernel/cpu/common.c (renamed from arch/i386/kernel/cpu/common.c)0
-rw-r--r--arch/x86/kernel/cpu/cpu.h (renamed from arch/i386/kernel/cpu/cpu.h)0
-rw-r--r--arch/x86/kernel/cpu/cpufreq/Kconfig (renamed from arch/i386/kernel/cpu/cpufreq/Kconfig)0
-rw-r--r--arch/x86/kernel/cpu/cpufreq/Makefile (renamed from arch/i386/kernel/cpu/cpufreq/Makefile)0
-rw-r--r--arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c (renamed from arch/i386/kernel/cpu/cpufreq/acpi-cpufreq.c)0
-rw-r--r--arch/x86/kernel/cpu/cpufreq/cpufreq-nforce2.c (renamed from arch/i386/kernel/cpu/cpufreq/cpufreq-nforce2.c)0
-rw-r--r--arch/x86/kernel/cpu/cpufreq/e_powersaver.c (renamed from arch/i386/kernel/cpu/cpufreq/e_powersaver.c)0
-rw-r--r--arch/x86/kernel/cpu/cpufreq/elanfreq.c (renamed from arch/i386/kernel/cpu/cpufreq/elanfreq.c)0
-rw-r--r--arch/x86/kernel/cpu/cpufreq/gx-suspmod.c (renamed from arch/i386/kernel/cpu/cpufreq/gx-suspmod.c)0
-rw-r--r--arch/x86/kernel/cpu/cpufreq/longhaul.c (renamed from arch/i386/kernel/cpu/cpufreq/longhaul.c)0
-rw-r--r--arch/x86/kernel/cpu/cpufreq/longhaul.h (renamed from arch/i386/kernel/cpu/cpufreq/longhaul.h)0
-rw-r--r--arch/x86/kernel/cpu/cpufreq/longrun.c (renamed from arch/i386/kernel/cpu/cpufreq/longrun.c)0
-rw-r--r--arch/x86/kernel/cpu/cpufreq/p4-clockmod.c (renamed from arch/i386/kernel/cpu/cpufreq/p4-clockmod.c)0
-rw-r--r--arch/x86/kernel/cpu/cpufreq/powernow-k6.c (renamed from arch/i386/kernel/cpu/cpufreq/powernow-k6.c)0
-rw-r--r--arch/x86/kernel/cpu/cpufreq/powernow-k7.c (renamed from arch/i386/kernel/cpu/cpufreq/powernow-k7.c)0
-rw-r--r--arch/x86/kernel/cpu/cpufreq/powernow-k7.h (renamed from arch/i386/kernel/cpu/cpufreq/powernow-k7.h)0
-rw-r--r--arch/x86/kernel/cpu/cpufreq/powernow-k8.c (renamed from arch/i386/kernel/cpu/cpufreq/powernow-k8.c)0
-rw-r--r--arch/x86/kernel/cpu/cpufreq/powernow-k8.h (renamed from arch/i386/kernel/cpu/cpufreq/powernow-k8.h)0
-rw-r--r--arch/x86/kernel/cpu/cpufreq/sc520_freq.c (renamed from arch/i386/kernel/cpu/cpufreq/sc520_freq.c)0
-rw-r--r--arch/x86/kernel/cpu/cpufreq/speedstep-centrino.c (renamed from arch/i386/kernel/cpu/cpufreq/speedstep-centrino.c)0
-rw-r--r--arch/x86/kernel/cpu/cpufreq/speedstep-ich.c (renamed from arch/i386/kernel/cpu/cpufreq/speedstep-ich.c)0
-rw-r--r--arch/x86/kernel/cpu/cpufreq/speedstep-lib.c (renamed from arch/i386/kernel/cpu/cpufreq/speedstep-lib.c)0
-rw-r--r--arch/x86/kernel/cpu/cpufreq/speedstep-lib.h (renamed from arch/i386/kernel/cpu/cpufreq/speedstep-lib.h)0
-rw-r--r--arch/x86/kernel/cpu/cpufreq/speedstep-smi.c (renamed from arch/i386/kernel/cpu/cpufreq/speedstep-smi.c)0
-rw-r--r--arch/x86/kernel/cpu/cyrix.c (renamed from arch/i386/kernel/cpu/cyrix.c)0
-rw-r--r--arch/x86/kernel/cpu/intel.c (renamed from arch/i386/kernel/cpu/intel.c)0
-rw-r--r--arch/x86/kernel/cpu/intel_cacheinfo.c (renamed from arch/i386/kernel/cpu/intel_cacheinfo.c)0
-rw-r--r--arch/x86/kernel/cpu/mcheck/Makefile (renamed from arch/i386/kernel/cpu/mcheck/Makefile)0
-rw-r--r--arch/x86/kernel/cpu/mcheck/k7.c (renamed from arch/i386/kernel/cpu/mcheck/k7.c)0
-rw-r--r--arch/x86/kernel/cpu/mcheck/mce.c (renamed from arch/i386/kernel/cpu/mcheck/mce.c)0
-rw-r--r--arch/x86/kernel/cpu/mcheck/mce.h (renamed from arch/i386/kernel/cpu/mcheck/mce.h)0
-rw-r--r--arch/x86/kernel/cpu/mcheck/non-fatal.c (renamed from arch/i386/kernel/cpu/mcheck/non-fatal.c)0
-rw-r--r--arch/x86/kernel/cpu/mcheck/p4.c (renamed from arch/i386/kernel/cpu/mcheck/p4.c)0
-rw-r--r--arch/x86/kernel/cpu/mcheck/p5.c (renamed from arch/i386/kernel/cpu/mcheck/p5.c)0
-rw-r--r--arch/x86/kernel/cpu/mcheck/p6.c (renamed from arch/i386/kernel/cpu/mcheck/p6.c)0
-rw-r--r--arch/x86/kernel/cpu/mcheck/therm_throt.c (renamed from arch/i386/kernel/cpu/mcheck/therm_throt.c)0
-rw-r--r--arch/x86/kernel/cpu/mcheck/winchip.c (renamed from arch/i386/kernel/cpu/mcheck/winchip.c)0
-rw-r--r--arch/x86/kernel/cpu/mtrr/Makefile (renamed from arch/i386/kernel/cpu/mtrr/Makefile)0
-rw-r--r--arch/x86/kernel/cpu/mtrr/amd.c (renamed from arch/i386/kernel/cpu/mtrr/amd.c)0
-rw-r--r--arch/x86/kernel/cpu/mtrr/centaur.c (renamed from arch/i386/kernel/cpu/mtrr/centaur.c)0
-rw-r--r--arch/x86/kernel/cpu/mtrr/cyrix.c (renamed from arch/i386/kernel/cpu/mtrr/cyrix.c)0
-rw-r--r--arch/x86/kernel/cpu/mtrr/generic.c (renamed from arch/i386/kernel/cpu/mtrr/generic.c)0
-rw-r--r--arch/x86/kernel/cpu/mtrr/if.c (renamed from arch/i386/kernel/cpu/mtrr/if.c)0
-rw-r--r--arch/x86/kernel/cpu/mtrr/main.c (renamed from arch/i386/kernel/cpu/mtrr/main.c)0
-rw-r--r--arch/x86/kernel/cpu/mtrr/mtrr.h (renamed from arch/i386/kernel/cpu/mtrr/mtrr.h)0
-rw-r--r--arch/x86/kernel/cpu/mtrr/state.c79
-rw-r--r--arch/x86/kernel/cpu/nexgen.c (renamed from arch/i386/kernel/cpu/nexgen.c)0
-rw-r--r--arch/x86/kernel/cpu/perfctr-watchdog.c (renamed from arch/i386/kernel/cpu/perfctr-watchdog.c)0
-rw-r--r--arch/x86/kernel/cpu/proc.c (renamed from arch/i386/kernel/cpu/proc.c)0
-rw-r--r--arch/x86/kernel/cpu/transmeta.c (renamed from arch/i386/kernel/cpu/transmeta.c)0
-rw-r--r--arch/x86/kernel/cpu/umc.c (renamed from arch/i386/kernel/cpu/umc.c)0
-rw-r--r--arch/x86/kernel/cpufreq/Kconfig (renamed from arch/x86_64/kernel/cpufreq/Kconfig)0
-rw-r--r--arch/x86/kernel/cpuid.c (renamed from arch/i386/kernel/cpuid.c)0
-rw-r--r--arch/x86/kernel/crash_32.c (renamed from arch/i386/kernel/crash.c)0
-rw-r--r--arch/x86/kernel/crash_64.c (renamed from arch/x86_64/kernel/crash.c)0
-rw-r--r--arch/x86/kernel/crash_dump_32.c (renamed from arch/i386/kernel/crash_dump.c)0
-rw-r--r--arch/x86/kernel/crash_dump_64.c (renamed from arch/x86_64/kernel/crash_dump.c)0
-rw-r--r--arch/x86/kernel/doublefault_32.c (renamed from arch/i386/kernel/doublefault.c)0
-rw-r--r--arch/x86/kernel/e820_32.c (renamed from arch/i386/kernel/e820.c)0
-rw-r--r--arch/x86/kernel/e820_64.c (renamed from arch/x86_64/kernel/e820.c)0
-rw-r--r--arch/x86/kernel/early-quirks_64.c (renamed from arch/x86_64/kernel/early-quirks.c)0
-rw-r--r--arch/x86/kernel/early_printk.c (renamed from arch/x86_64/kernel/early_printk.c)0
-rw-r--r--arch/x86/kernel/efi_32.c (renamed from arch/i386/kernel/efi.c)0
-rw-r--r--arch/x86/kernel/efi_stub_32.S (renamed from arch/i386/kernel/efi_stub.S)0
-rw-r--r--arch/x86/kernel/entry_32.S1112
-rw-r--r--arch/x86/kernel/entry_64.S (renamed from arch/x86_64/kernel/entry.S)0
-rw-r--r--arch/x86/kernel/genapic_64.c (renamed from arch/x86_64/kernel/genapic.c)0
-rw-r--r--arch/x86/kernel/genapic_flat_64.c (renamed from arch/x86_64/kernel/genapic_flat.c)0
-rw-r--r--arch/x86/kernel/geode_32.c (renamed from arch/i386/kernel/geode.c)0
-rw-r--r--arch/x86/kernel/head64.c (renamed from arch/x86_64/kernel/head64.c)0
-rw-r--r--arch/x86/kernel/head_32.S578
-rw-r--r--arch/x86/kernel/head_64.S (renamed from arch/x86_64/kernel/head.S)0
-rw-r--r--arch/x86/kernel/hpet_32.c (renamed from arch/i386/kernel/hpet.c)0
-rw-r--r--arch/x86/kernel/hpet_64.c (renamed from arch/x86_64/kernel/hpet.c)0
-rw-r--r--arch/x86/kernel/i386_ksyms_32.c (renamed from arch/i386/kernel/i386_ksyms.c)0
-rw-r--r--arch/x86/kernel/i387_32.c (renamed from arch/i386/kernel/i387.c)0
-rw-r--r--arch/x86/kernel/i387_64.c (renamed from arch/x86_64/kernel/i387.c)0
-rw-r--r--arch/x86/kernel/i8237.c (renamed from arch/i386/kernel/i8237.c)0
-rw-r--r--arch/x86/kernel/i8253_32.c (renamed from arch/i386/kernel/i8253.c)0
-rw-r--r--arch/x86/kernel/i8259_32.c (renamed from arch/i386/kernel/i8259.c)0
-rw-r--r--arch/x86/kernel/i8259_64.c (renamed from arch/x86_64/kernel/i8259.c)0
-rw-r--r--arch/x86/kernel/init_task_32.c (renamed from arch/i386/kernel/init_task.c)0
-rw-r--r--arch/x86/kernel/init_task_64.c (renamed from arch/x86_64/kernel/init_task.c)0
-rw-r--r--arch/x86/kernel/io_apic_32.c (renamed from arch/i386/kernel/io_apic.c)0
-rw-r--r--arch/x86/kernel/io_apic_64.c (renamed from arch/x86_64/kernel/io_apic.c)0
-rw-r--r--arch/x86/kernel/ioport_32.c (renamed from arch/i386/kernel/ioport.c)0
-rw-r--r--arch/x86/kernel/ioport_64.c (renamed from arch/x86_64/kernel/ioport.c)0
-rw-r--r--arch/x86/kernel/irq_32.c (renamed from arch/i386/kernel/irq.c)0
-rw-r--r--arch/x86/kernel/irq_64.c (renamed from arch/x86_64/kernel/irq.c)0
-rw-r--r--arch/x86/kernel/k8.c (renamed from arch/x86_64/kernel/k8.c)0
-rw-r--r--arch/x86/kernel/kprobes_32.c (renamed from arch/i386/kernel/kprobes.c)0
-rw-r--r--arch/x86/kernel/kprobes_64.c (renamed from arch/x86_64/kernel/kprobes.c)0
-rw-r--r--arch/x86/kernel/ldt_32.c (renamed from arch/i386/kernel/ldt.c)0
-rw-r--r--arch/x86/kernel/ldt_64.c (renamed from arch/x86_64/kernel/ldt.c)0
-rw-r--r--arch/x86/kernel/machine_kexec_32.c (renamed from arch/i386/kernel/machine_kexec.c)0
-rw-r--r--arch/x86/kernel/machine_kexec_64.c (renamed from arch/x86_64/kernel/machine_kexec.c)0
-rw-r--r--arch/x86/kernel/mca_32.c (renamed from arch/i386/kernel/mca.c)0
-rw-r--r--arch/x86/kernel/mce_64.c (renamed from arch/x86_64/kernel/mce.c)0
-rw-r--r--arch/x86/kernel/mce_amd_64.c (renamed from arch/x86_64/kernel/mce_amd.c)0
-rw-r--r--arch/x86/kernel/mce_intel_64.c (renamed from arch/x86_64/kernel/mce_intel.c)0
-rw-r--r--arch/x86/kernel/microcode.c (renamed from arch/i386/kernel/microcode.c)0
-rw-r--r--arch/x86/kernel/module_32.c (renamed from arch/i386/kernel/module.c)0
-rw-r--r--arch/x86/kernel/module_64.c (renamed from arch/x86_64/kernel/module.c)0
-rw-r--r--arch/x86/kernel/mpparse_32.c (renamed from arch/i386/kernel/mpparse.c)0
-rw-r--r--arch/x86/kernel/mpparse_64.c (renamed from arch/x86_64/kernel/mpparse.c)0
-rw-r--r--arch/x86/kernel/msr.c (renamed from arch/i386/kernel/msr.c)0
-rw-r--r--arch/x86/kernel/nmi_32.c (renamed from arch/i386/kernel/nmi.c)0
-rw-r--r--arch/x86/kernel/nmi_64.c (renamed from arch/x86_64/kernel/nmi.c)0
-rw-r--r--arch/x86/kernel/numaq_32.c (renamed from arch/i386/kernel/numaq.c)0
-rw-r--r--arch/x86/kernel/paravirt_32.c (renamed from arch/i386/kernel/paravirt.c)0
-rw-r--r--arch/x86/kernel/pci-calgary_64.c (renamed from arch/x86_64/kernel/pci-calgary.c)0
-rw-r--r--arch/x86/kernel/pci-dma_32.c (renamed from arch/i386/kernel/pci-dma.c)0
-rw-r--r--arch/x86/kernel/pci-dma_64.c (renamed from arch/x86_64/kernel/pci-dma.c)0
-rw-r--r--arch/x86/kernel/pci-gart_64.c (renamed from arch/x86_64/kernel/pci-gart.c)0
-rw-r--r--arch/x86/kernel/pci-nommu_64.c (renamed from arch/x86_64/kernel/pci-nommu.c)0
-rw-r--r--arch/x86/kernel/pci-swiotlb_64.c (renamed from arch/x86_64/kernel/pci-swiotlb.c)0
-rw-r--r--arch/x86/kernel/pcspeaker.c (renamed from arch/i386/kernel/pcspeaker.c)0
-rw-r--r--arch/x86/kernel/pmtimer_64.c (renamed from arch/x86_64/kernel/pmtimer.c)0
-rw-r--r--arch/x86/kernel/process_32.c (renamed from arch/i386/kernel/process.c)0
-rw-r--r--arch/x86/kernel/process_64.c (renamed from arch/x86_64/kernel/process.c)0
-rw-r--r--arch/x86/kernel/ptrace_32.c (renamed from arch/i386/kernel/ptrace.c)0
-rw-r--r--arch/x86/kernel/ptrace_64.c (renamed from arch/x86_64/kernel/ptrace.c)0
-rw-r--r--arch/x86/kernel/quirks.c (renamed from arch/i386/kernel/quirks.c)0
-rw-r--r--arch/x86/kernel/reboot_32.c (renamed from arch/i386/kernel/reboot.c)0
-rw-r--r--arch/x86/kernel/reboot_64.c (renamed from arch/x86_64/kernel/reboot.c)0
-rw-r--r--arch/x86/kernel/reboot_fixups_32.c (renamed from arch/i386/kernel/reboot_fixups.c)0
-rw-r--r--arch/x86/kernel/relocate_kernel_32.S (renamed from arch/i386/kernel/relocate_kernel.S)0
-rw-r--r--arch/x86/kernel/relocate_kernel_64.S (renamed from arch/x86_64/kernel/relocate_kernel.S)0
-rw-r--r--arch/x86/kernel/scx200_32.c (renamed from arch/i386/kernel/scx200.c)0
-rw-r--r--arch/x86/kernel/setup64.c (renamed from arch/x86_64/kernel/setup64.c)0
-rw-r--r--arch/x86/kernel/setup_32.c (renamed from arch/i386/kernel/setup.c)0
-rw-r--r--arch/x86/kernel/setup_64.c (renamed from arch/x86_64/kernel/setup.c)0
-rw-r--r--arch/x86/kernel/sigframe_32.h (renamed from arch/i386/kernel/sigframe.h)0
-rw-r--r--arch/x86/kernel/signal_32.c667
-rw-r--r--arch/x86/kernel/signal_64.c (renamed from arch/x86_64/kernel/signal.c)0
-rw-r--r--arch/x86/kernel/smp_32.c (renamed from arch/i386/kernel/smp.c)0
-rw-r--r--arch/x86/kernel/smp_64.c (renamed from arch/x86_64/kernel/smp.c)0
-rw-r--r--arch/x86/kernel/smpboot_32.c (renamed from arch/i386/kernel/smpboot.c)0
-rw-r--r--arch/x86/kernel/smpboot_64.c (renamed from arch/x86_64/kernel/smpboot.c)0
-rw-r--r--arch/x86/kernel/smpcommon_32.c (renamed from arch/i386/kernel/smpcommon.c)0
-rw-r--r--arch/x86/kernel/srat_32.c (renamed from arch/i386/kernel/srat.c)0
-rw-r--r--arch/x86/kernel/stacktrace.c (renamed from arch/x86_64/kernel/stacktrace.c)0
-rw-r--r--arch/x86/kernel/summit_32.c (renamed from arch/i386/kernel/summit.c)0
-rw-r--r--arch/x86/kernel/suspend_64.c (renamed from arch/x86_64/kernel/suspend.c)0
-rw-r--r--arch/x86/kernel/suspend_asm_64.S (renamed from arch/x86_64/kernel/suspend_asm.S)0
-rw-r--r--arch/x86/kernel/sys_i386_32.c (renamed from arch/i386/kernel/sys_i386.c)0
-rw-r--r--arch/x86/kernel/sys_x86_64.c (renamed from arch/x86_64/kernel/sys_x86_64.c)0
-rw-r--r--arch/x86/kernel/syscall_64.c26
-rw-r--r--arch/x86/kernel/syscall_table_32.S (renamed from arch/i386/kernel/syscall_table.S)0
-rw-r--r--arch/x86/kernel/sysenter_32.c (renamed from arch/i386/kernel/sysenter.c)0
-rw-r--r--arch/x86/kernel/tce_64.c (renamed from arch/x86_64/kernel/tce.c)0
-rw-r--r--arch/x86/kernel/time_32.c (renamed from arch/i386/kernel/time.c)0
-rw-r--r--arch/x86/kernel/time_64.c (renamed from arch/x86_64/kernel/time.c)0
-rw-r--r--arch/x86/kernel/topology.c (renamed from arch/i386/kernel/topology.c)0
-rw-r--r--arch/x86/kernel/trampoline_32.S (renamed from arch/i386/kernel/trampoline.S)0
-rw-r--r--arch/x86/kernel/trampoline_64.S166
-rw-r--r--arch/x86/kernel/traps_32.c (renamed from arch/i386/kernel/traps.c)0
-rw-r--r--arch/x86/kernel/traps_64.c (renamed from arch/x86_64/kernel/traps.c)0
-rw-r--r--arch/x86/kernel/tsc_32.c (renamed from arch/i386/kernel/tsc.c)0
-rw-r--r--arch/x86/kernel/tsc_64.c (renamed from arch/x86_64/kernel/tsc.c)0
-rw-r--r--arch/x86/kernel/tsc_sync.c (renamed from arch/x86_64/kernel/tsc_sync.c)0
-rw-r--r--arch/x86/kernel/verify_cpu_64.S (renamed from arch/x86_64/kernel/verify_cpu.S)0
-rw-r--r--arch/x86/kernel/vm86_32.c (renamed from arch/i386/kernel/vm86.c)0
-rw-r--r--arch/x86/kernel/vmi_32.c (renamed from arch/i386/kernel/vmi.c)0
-rw-r--r--arch/x86/kernel/vmiclock_32.c (renamed from arch/i386/kernel/vmiclock.c)0
-rw-r--r--arch/x86/kernel/vmlinux.lds.S5
-rw-r--r--arch/x86/kernel/vmlinux_32.lds.S (renamed from arch/i386/kernel/vmlinux.lds.S)0
-rw-r--r--arch/x86/kernel/vmlinux_64.lds.S (renamed from arch/x86_64/kernel/vmlinux.lds.S)0
-rw-r--r--arch/x86/kernel/vsmp_64.c (renamed from arch/x86_64/kernel/vsmp.c)0
-rw-r--r--arch/x86/kernel/vsyscall-int80_32.S53
-rw-r--r--arch/x86/kernel/vsyscall-note_32.S45
-rw-r--r--arch/x86/kernel/vsyscall-sigreturn_32.S (renamed from arch/i386/kernel/vsyscall-sigreturn.S)0
-rw-r--r--arch/x86/kernel/vsyscall-sysenter_32.S122
-rw-r--r--arch/x86/kernel/vsyscall_32.S15
-rw-r--r--arch/x86/kernel/vsyscall_32.lds.S (renamed from arch/i386/kernel/vsyscall.lds.S)0
-rw-r--r--arch/x86/kernel/vsyscall_64.c (renamed from arch/x86_64/kernel/vsyscall.c)0
-rw-r--r--arch/x86/kernel/x8664_ksyms_64.c (renamed from arch/x86_64/kernel/x8664_ksyms.c)0
-rw-r--r--arch/x86/lib/Makefile5
-rw-r--r--arch/x86/lib/Makefile_3211
-rw-r--r--arch/x86/lib/Makefile_6413
-rw-r--r--arch/x86/lib/bitops_32.c (renamed from arch/i386/lib/bitops.c)0
-rw-r--r--arch/x86/lib/bitops_64.c (renamed from arch/x86_64/lib/bitops.c)0
-rw-r--r--arch/x86/lib/bitstr_64.c (renamed from arch/x86_64/lib/bitstr.c)0
-rw-r--r--arch/x86/lib/checksum_32.S (renamed from arch/i386/lib/checksum.S)0
-rw-r--r--arch/x86/lib/clear_page_64.S (renamed from arch/x86_64/lib/clear_page.S)0
-rw-r--r--arch/x86/lib/copy_page_64.S (renamed from arch/x86_64/lib/copy_page.S)0
-rw-r--r--arch/x86/lib/copy_user_64.S (renamed from arch/x86_64/lib/copy_user.S)0
-rw-r--r--arch/x86/lib/copy_user_nocache_64.S (renamed from arch/x86_64/lib/copy_user_nocache.S)0
-rw-r--r--arch/x86/lib/csum-copy_64.S (renamed from arch/x86_64/lib/csum-copy.S)0
-rw-r--r--arch/x86/lib/csum-partial_64.c (renamed from arch/x86_64/lib/csum-partial.c)0
-rw-r--r--arch/x86/lib/csum-wrappers_64.c (renamed from arch/x86_64/lib/csum-wrappers.c)0
-rw-r--r--arch/x86/lib/delay_32.c (renamed from arch/i386/lib/delay.c)0
-rw-r--r--arch/x86/lib/delay_64.c (renamed from arch/x86_64/lib/delay.c)0
-rw-r--r--arch/x86/lib/getuser_32.S (renamed from arch/i386/lib/getuser.S)0
-rw-r--r--arch/x86/lib/getuser_64.S (renamed from arch/x86_64/lib/getuser.S)0
-rw-r--r--arch/x86/lib/io_64.c (renamed from arch/x86_64/lib/io.c)0
-rw-r--r--arch/x86/lib/iomap_copy_64.S (renamed from arch/x86_64/lib/iomap_copy.S)0
-rw-r--r--arch/x86/lib/memcpy_32.c (renamed from arch/i386/lib/memcpy.c)0
-rw-r--r--arch/x86/lib/memcpy_64.S (renamed from arch/x86_64/lib/memcpy.S)0
-rw-r--r--arch/x86/lib/memmove_64.c (renamed from arch/x86_64/lib/memmove.c)0
-rw-r--r--arch/x86/lib/memset_64.S (renamed from arch/x86_64/lib/memset.S)0
-rw-r--r--arch/x86/lib/mmx_32.c (renamed from arch/i386/lib/mmx.c)0
-rw-r--r--arch/x86/lib/msr-on-cpu.c (renamed from arch/i386/lib/msr-on-cpu.c)0
-rw-r--r--arch/x86/lib/putuser_32.S (renamed from arch/i386/lib/putuser.S)0
-rw-r--r--arch/x86/lib/putuser_64.S (renamed from arch/x86_64/lib/putuser.S)0
-rw-r--r--arch/x86/lib/rwlock_64.S (renamed from arch/x86_64/lib/rwlock.S)0
-rw-r--r--arch/x86/lib/semaphore_32.S (renamed from arch/i386/lib/semaphore.S)0
-rw-r--r--arch/x86/lib/string_32.c (renamed from arch/i386/lib/string.c)0
-rw-r--r--arch/x86/lib/strstr_32.c (renamed from arch/i386/lib/strstr.c)0
-rw-r--r--arch/x86/lib/thunk_64.S (renamed from arch/x86_64/lib/thunk.S)0
-rw-r--r--arch/x86/lib/usercopy_32.c (renamed from arch/i386/lib/usercopy.c)0
-rw-r--r--arch/x86/lib/usercopy_64.c (renamed from arch/x86_64/lib/usercopy.c)0
-rw-r--r--arch/x86/mach-default/Makefile (renamed from arch/i386/mach-default/Makefile)0
-rw-r--r--arch/x86/mach-default/setup.c (renamed from arch/i386/mach-default/setup.c)0
-rw-r--r--arch/x86/mach-es7000/Makefile (renamed from arch/i386/mach-es7000/Makefile)0
-rw-r--r--arch/x86/mach-es7000/es7000.h (renamed from arch/i386/mach-es7000/es7000.h)0
-rw-r--r--arch/x86/mach-es7000/es7000plat.c (renamed from arch/i386/mach-es7000/es7000plat.c)0
-rw-r--r--arch/x86/mach-generic/Makefile8
-rw-r--r--arch/x86/mach-generic/bigsmp.c (renamed from arch/i386/mach-generic/bigsmp.c)0
-rw-r--r--arch/x86/mach-generic/default.c (renamed from arch/i386/mach-generic/default.c)0
-rw-r--r--arch/x86/mach-generic/es7000.c (renamed from arch/i386/mach-generic/es7000.c)0
-rw-r--r--arch/x86/mach-generic/probe.c (renamed from arch/i386/mach-generic/probe.c)0
-rw-r--r--arch/x86/mach-generic/summit.c (renamed from arch/i386/mach-generic/summit.c)0
-rw-r--r--arch/x86/mach-visws/Makefile (renamed from arch/i386/mach-visws/Makefile)0
-rw-r--r--arch/x86/mach-visws/mpparse.c (renamed from arch/i386/mach-visws/mpparse.c)0
-rw-r--r--arch/x86/mach-visws/reboot.c (renamed from arch/i386/mach-visws/reboot.c)0
-rw-r--r--arch/x86/mach-visws/setup.c (renamed from arch/i386/mach-visws/setup.c)0
-rw-r--r--arch/x86/mach-visws/traps.c (renamed from arch/i386/mach-visws/traps.c)0
-rw-r--r--arch/x86/mach-visws/visws_apic.c (renamed from arch/i386/mach-visws/visws_apic.c)0
-rw-r--r--arch/x86/mach-voyager/Makefile8
-rw-r--r--arch/x86/mach-voyager/setup.c (renamed from arch/i386/mach-voyager/setup.c)0
-rw-r--r--arch/x86/mach-voyager/voyager_basic.c (renamed from arch/i386/mach-voyager/voyager_basic.c)0
-rw-r--r--arch/x86/mach-voyager/voyager_cat.c (renamed from arch/i386/mach-voyager/voyager_cat.c)0
-rw-r--r--arch/x86/mach-voyager/voyager_smp.c (renamed from arch/i386/mach-voyager/voyager_smp.c)0
-rw-r--r--arch/x86/mach-voyager/voyager_thread.c (renamed from arch/i386/mach-voyager/voyager_thread.c)0
-rw-r--r--arch/x86/math-emu/Makefile (renamed from arch/i386/math-emu/Makefile)0
-rw-r--r--arch/x86/math-emu/README (renamed from arch/i386/math-emu/README)0
-rw-r--r--arch/x86/math-emu/control_w.h (renamed from arch/i386/math-emu/control_w.h)0
-rw-r--r--arch/x86/math-emu/div_Xsig.S (renamed from arch/i386/math-emu/div_Xsig.S)0
-rw-r--r--arch/x86/math-emu/div_small.S (renamed from arch/i386/math-emu/div_small.S)0
-rw-r--r--arch/x86/math-emu/errors.c (renamed from arch/i386/math-emu/errors.c)0
-rw-r--r--arch/x86/math-emu/exception.h (renamed from arch/i386/math-emu/exception.h)0
-rw-r--r--arch/x86/math-emu/fpu_arith.c (renamed from arch/i386/math-emu/fpu_arith.c)0
-rw-r--r--arch/x86/math-emu/fpu_asm.h (renamed from arch/i386/math-emu/fpu_asm.h)0
-rw-r--r--arch/x86/math-emu/fpu_aux.c (renamed from arch/i386/math-emu/fpu_aux.c)0
-rw-r--r--arch/x86/math-emu/fpu_emu.h (renamed from arch/i386/math-emu/fpu_emu.h)0
-rw-r--r--arch/x86/math-emu/fpu_entry.c (renamed from arch/i386/math-emu/fpu_entry.c)0
-rw-r--r--arch/x86/math-emu/fpu_etc.c (renamed from arch/i386/math-emu/fpu_etc.c)0
-rw-r--r--arch/x86/math-emu/fpu_proto.h (renamed from arch/i386/math-emu/fpu_proto.h)0
-rw-r--r--arch/x86/math-emu/fpu_system.h (renamed from arch/i386/math-emu/fpu_system.h)0
-rw-r--r--arch/x86/math-emu/fpu_tags.c (renamed from arch/i386/math-emu/fpu_tags.c)0
-rw-r--r--arch/x86/math-emu/fpu_trig.c (renamed from arch/i386/math-emu/fpu_trig.c)0
-rw-r--r--arch/x86/math-emu/get_address.c (renamed from arch/i386/math-emu/get_address.c)0
-rw-r--r--arch/x86/math-emu/load_store.c (renamed from arch/i386/math-emu/load_store.c)0
-rw-r--r--arch/x86/math-emu/mul_Xsig.S (renamed from arch/i386/math-emu/mul_Xsig.S)0
-rw-r--r--arch/x86/math-emu/poly.h (renamed from arch/i386/math-emu/poly.h)0
-rw-r--r--arch/x86/math-emu/poly_2xm1.c (renamed from arch/i386/math-emu/poly_2xm1.c)0
-rw-r--r--arch/x86/math-emu/poly_atan.c (renamed from arch/i386/math-emu/poly_atan.c)0
-rw-r--r--arch/x86/math-emu/poly_l2.c (renamed from arch/i386/math-emu/poly_l2.c)0
-rw-r--r--arch/x86/math-emu/poly_sin.c (renamed from arch/i386/math-emu/poly_sin.c)0
-rw-r--r--arch/x86/math-emu/poly_tan.c (renamed from arch/i386/math-emu/poly_tan.c)0
-rw-r--r--arch/x86/math-emu/polynom_Xsig.S (renamed from arch/i386/math-emu/polynom_Xsig.S)0
-rw-r--r--arch/x86/math-emu/reg_add_sub.c (renamed from arch/i386/math-emu/reg_add_sub.c)0
-rw-r--r--arch/x86/math-emu/reg_compare.c (renamed from arch/i386/math-emu/reg_compare.c)0
-rw-r--r--arch/x86/math-emu/reg_constant.c (renamed from arch/i386/math-emu/reg_constant.c)0
-rw-r--r--arch/x86/math-emu/reg_constant.h (renamed from arch/i386/math-emu/reg_constant.h)0
-rw-r--r--arch/x86/math-emu/reg_convert.c (renamed from arch/i386/math-emu/reg_convert.c)0
-rw-r--r--arch/x86/math-emu/reg_divide.c (renamed from arch/i386/math-emu/reg_divide.c)0
-rw-r--r--arch/x86/math-emu/reg_ld_str.c (renamed from arch/i386/math-emu/reg_ld_str.c)0
-rw-r--r--arch/x86/math-emu/reg_mul.c (renamed from arch/i386/math-emu/reg_mul.c)0
-rw-r--r--arch/x86/math-emu/reg_norm.S (renamed from arch/i386/math-emu/reg_norm.S)0
-rw-r--r--arch/x86/math-emu/reg_round.S (renamed from arch/i386/math-emu/reg_round.S)0
-rw-r--r--arch/x86/math-emu/reg_u_add.S (renamed from arch/i386/math-emu/reg_u_add.S)0
-rw-r--r--arch/x86/math-emu/reg_u_div.S (renamed from arch/i386/math-emu/reg_u_div.S)0
-rw-r--r--arch/x86/math-emu/reg_u_mul.S (renamed from arch/i386/math-emu/reg_u_mul.S)0
-rw-r--r--arch/x86/math-emu/reg_u_sub.S (renamed from arch/i386/math-emu/reg_u_sub.S)0
-rw-r--r--arch/x86/math-emu/round_Xsig.S (renamed from arch/i386/math-emu/round_Xsig.S)0
-rw-r--r--arch/x86/math-emu/shr_Xsig.S (renamed from arch/i386/math-emu/shr_Xsig.S)0
-rw-r--r--arch/x86/math-emu/status_w.h (renamed from arch/i386/math-emu/status_w.h)0
-rw-r--r--arch/x86/math-emu/version.h (renamed from arch/i386/math-emu/version.h)0
-rw-r--r--arch/x86/math-emu/wm_shrx.S (renamed from arch/i386/math-emu/wm_shrx.S)0
-rw-r--r--arch/x86/math-emu/wm_sqrt.S (renamed from arch/i386/math-emu/wm_sqrt.S)0
-rw-r--r--arch/x86/mm/Makefile5
-rw-r--r--arch/x86/mm/Makefile_3210
-rw-r--r--arch/x86/mm/Makefile_6410
-rw-r--r--arch/x86/mm/boot_ioremap_32.c (renamed from arch/i386/mm/boot_ioremap.c)0
-rw-r--r--arch/x86/mm/discontig_32.c (renamed from arch/i386/mm/discontig.c)0
-rw-r--r--arch/x86/mm/extable_32.c (renamed from arch/i386/mm/extable.c)0
-rw-r--r--arch/x86/mm/extable_64.c (renamed from arch/x86_64/mm/extable.c)0
-rw-r--r--arch/x86/mm/fault_32.c (renamed from arch/i386/mm/fault.c)0
-rw-r--r--arch/x86/mm/fault_64.c (renamed from arch/x86_64/mm/fault.c)0
-rw-r--r--arch/x86/mm/highmem_32.c (renamed from arch/i386/mm/highmem.c)0
-rw-r--r--arch/x86/mm/hugetlbpage.c (renamed from arch/i386/mm/hugetlbpage.c)0
-rw-r--r--arch/x86/mm/init_32.c (renamed from arch/i386/mm/init.c)0
-rw-r--r--arch/x86/mm/init_64.c (renamed from arch/x86_64/mm/init.c)0
-rw-r--r--arch/x86/mm/ioremap_32.c (renamed from arch/i386/mm/ioremap.c)0
-rw-r--r--arch/x86/mm/ioremap_64.c (renamed from arch/x86_64/mm/ioremap.c)0
-rw-r--r--arch/x86/mm/k8topology_64.c (renamed from arch/x86_64/mm/k8topology.c)0
-rw-r--r--arch/x86/mm/mmap_32.c (renamed from arch/i386/mm/mmap.c)0
-rw-r--r--arch/x86/mm/mmap_64.c (renamed from arch/x86_64/mm/mmap.c)0
-rw-r--r--arch/x86/mm/numa_64.c (renamed from arch/x86_64/mm/numa.c)0
-rw-r--r--arch/x86/mm/pageattr_32.c (renamed from arch/i386/mm/pageattr.c)0
-rw-r--r--arch/x86/mm/pageattr_64.c (renamed from arch/x86_64/mm/pageattr.c)0
-rw-r--r--arch/x86/mm/pgtable_32.c (renamed from arch/i386/mm/pgtable.c)0
-rw-r--r--arch/x86/mm/srat_64.c (renamed from arch/x86_64/mm/srat.c)0
-rw-r--r--arch/x86/oprofile/Kconfig (renamed from arch/i386/oprofile/Kconfig)0
-rw-r--r--arch/x86/oprofile/Makefile (renamed from arch/i386/oprofile/Makefile)0
-rw-r--r--arch/x86/oprofile/backtrace.c (renamed from arch/i386/oprofile/backtrace.c)0
-rw-r--r--arch/x86/oprofile/init.c (renamed from arch/i386/oprofile/init.c)0
-rw-r--r--arch/x86/oprofile/nmi_int.c (renamed from arch/i386/oprofile/nmi_int.c)0
-rw-r--r--arch/x86/oprofile/nmi_timer_int.c (renamed from arch/i386/oprofile/nmi_timer_int.c)0
-rw-r--r--arch/x86/oprofile/op_counter.h (renamed from arch/i386/oprofile/op_counter.h)0
-rw-r--r--arch/x86/oprofile/op_model_athlon.c (renamed from arch/i386/oprofile/op_model_athlon.c)0
-rw-r--r--arch/x86/oprofile/op_model_p4.c (renamed from arch/i386/oprofile/op_model_p4.c)0
-rw-r--r--arch/x86/oprofile/op_model_ppro.c (renamed from arch/i386/oprofile/op_model_ppro.c)0
-rw-r--r--arch/x86/oprofile/op_x86_model.h (renamed from arch/i386/oprofile/op_x86_model.h)0
-rw-r--r--arch/x86/pci/Makefile5
-rw-r--r--arch/x86/pci/Makefile_3214
-rw-r--r--arch/x86/pci/Makefile_6417
-rw-r--r--arch/x86/pci/acpi.c (renamed from arch/i386/pci/acpi.c)0
-rw-r--r--arch/x86/pci/common.c (renamed from arch/i386/pci/common.c)0
-rw-r--r--arch/x86/pci/direct.c (renamed from arch/i386/pci/direct.c)0
-rw-r--r--arch/x86/pci/early.c (renamed from arch/i386/pci/early.c)0
-rw-r--r--arch/x86/pci/fixup.c (renamed from arch/i386/pci/fixup.c)0
-rw-r--r--arch/x86/pci/i386.c (renamed from arch/i386/pci/i386.c)0
-rw-r--r--arch/x86/pci/init.c (renamed from arch/i386/pci/init.c)0
-rw-r--r--arch/x86/pci/irq.c (renamed from arch/i386/pci/irq.c)0
-rw-r--r--arch/x86/pci/k8-bus_64.c (renamed from arch/x86_64/pci/k8-bus.c)0
-rw-r--r--arch/x86/pci/legacy.c (renamed from arch/i386/pci/legacy.c)0
-rw-r--r--arch/x86/pci/mmconfig-shared.c (renamed from arch/i386/pci/mmconfig-shared.c)0
-rw-r--r--arch/x86/pci/mmconfig_32.c (renamed from arch/i386/pci/mmconfig.c)0
-rw-r--r--arch/x86/pci/mmconfig_64.c (renamed from arch/x86_64/pci/mmconfig.c)0
-rw-r--r--arch/x86/pci/numa.c (renamed from arch/i386/pci/numa.c)0
-rw-r--r--arch/x86/pci/pcbios.c (renamed from arch/i386/pci/pcbios.c)0
-rw-r--r--arch/x86/pci/pci.h (renamed from arch/i386/pci/pci.h)0
-rw-r--r--arch/x86/pci/visws.c (renamed from arch/i386/pci/visws.c)0
-rw-r--r--arch/x86/power/Makefile (renamed from arch/i386/power/Makefile)0
-rw-r--r--arch/x86/power/cpu.c (renamed from arch/i386/power/cpu.c)0
-rw-r--r--arch/x86/power/suspend.c (renamed from arch/i386/power/suspend.c)0
-rw-r--r--arch/x86/power/swsusp.S (renamed from arch/i386/power/swsusp.S)0
-rw-r--r--arch/x86/vdso/.gitignore (renamed from arch/x86_64/vdso/.gitignore)0
-rw-r--r--arch/x86/vdso/Makefile (renamed from arch/x86_64/vdso/Makefile)0
-rw-r--r--arch/x86/vdso/vclock_gettime.c (renamed from arch/x86_64/vdso/vclock_gettime.c)0
-rw-r--r--arch/x86/vdso/vdso-note.S (renamed from arch/x86_64/vdso/vdso-note.S)0
-rw-r--r--arch/x86/vdso/vdso-start.S (renamed from arch/x86_64/vdso/vdso-start.S)0
-rw-r--r--arch/x86/vdso/vdso.S2
-rw-r--r--arch/x86/vdso/vdso.lds.S (renamed from arch/x86_64/vdso/vdso.lds.S)0
-rw-r--r--arch/x86/vdso/vextern.h (renamed from arch/x86_64/vdso/vextern.h)0
-rw-r--r--arch/x86/vdso/vgetcpu.c (renamed from arch/x86_64/vdso/vgetcpu.c)0
-rw-r--r--arch/x86/vdso/vma.c (renamed from arch/x86_64/vdso/vma.c)0
-rw-r--r--arch/x86/vdso/voffset.h (renamed from arch/x86_64/vdso/voffset.h)0
-rw-r--r--arch/x86/vdso/vvar.c (renamed from arch/x86_64/vdso/vvar.c)0
-rw-r--r--arch/x86/video/Makefile (renamed from arch/i386/video/Makefile)0
-rw-r--r--arch/x86/video/fbdev.c (renamed from arch/i386/video/fbdev.c)0
-rw-r--r--arch/x86/xen/Kconfig (renamed from arch/i386/xen/Kconfig)0
-rw-r--r--arch/x86/xen/Makefile (renamed from arch/i386/xen/Makefile)0
-rw-r--r--arch/x86/xen/enlighten.c (renamed from arch/i386/xen/enlighten.c)0
-rw-r--r--arch/x86/xen/events.c (renamed from arch/i386/xen/events.c)0
-rw-r--r--arch/x86/xen/features.c (renamed from arch/i386/xen/features.c)0
-rw-r--r--arch/x86/xen/manage.c (renamed from arch/i386/xen/manage.c)0
-rw-r--r--arch/x86/xen/mmu.c (renamed from arch/i386/xen/mmu.c)0
-rw-r--r--arch/x86/xen/mmu.h (renamed from arch/i386/xen/mmu.h)0
-rw-r--r--arch/x86/xen/multicalls.c (renamed from arch/i386/xen/multicalls.c)0
-rw-r--r--arch/x86/xen/multicalls.h (renamed from arch/i386/xen/multicalls.h)0
-rw-r--r--arch/x86/xen/setup.c (renamed from arch/i386/xen/setup.c)0
-rw-r--r--arch/x86/xen/smp.c (renamed from arch/i386/xen/smp.c)0
-rw-r--r--arch/x86/xen/time.c (renamed from arch/i386/xen/time.c)0
-rw-r--r--arch/x86/xen/vdso.h (renamed from arch/i386/xen/vdso.h)0
-rw-r--r--arch/x86/xen/xen-asm.S (renamed from arch/i386/xen/xen-asm.S)0
-rw-r--r--arch/x86/xen/xen-head.S (renamed from arch/i386/xen/xen-head.S)0
-rw-r--r--arch/x86/xen/xen-ops.h (renamed from arch/i386/xen/xen-ops.h)0
-rw-r--r--arch/x86_64/Kconfig4
-rw-r--r--arch/x86_64/Makefile28
-rw-r--r--arch/x86_64/boot/.gitignore5
-rw-r--r--arch/x86_64/boot/Makefile9
-rw-r--r--arch/x86_64/boot/compressed/Makefile30
-rw-r--r--arch/x86_64/boot/compressed/head.S311
-rw-r--r--arch/x86_64/boot/tools/.gitignore1
-rw-r--r--arch/x86_64/crypto/Makefile12
-rw-r--r--arch/x86_64/ia32/audit.c42
-rw-r--r--arch/x86_64/ia32/ipc32.c57
-rw-r--r--arch/x86_64/ia32/syscall32_syscall.S17
-rw-r--r--arch/x86_64/ia32/vsyscall-sigreturn.S143
-rw-r--r--arch/x86_64/kernel/Makefile63
-rw-r--r--arch/x86_64/kernel/acpi/Makefile9
-rw-r--r--arch/x86_64/kernel/acpi/wakeup.S456
-rw-r--r--arch/x86_64/kernel/cpufreq/Makefile17
-rw-r--r--arch/x86_64/kernel/syscall.c26
-rw-r--r--arch/x86_64/kernel/trampoline.S166
-rw-r--r--arch/x86_64/lib/Makefile13
-rw-r--r--arch/x86_64/lib/msr-on-cpu.c1
-rw-r--r--arch/x86_64/mm/Makefile11
-rw-r--r--arch/x86_64/oprofile/Kconfig17
-rw-r--r--arch/x86_64/oprofile/Makefile19
-rw-r--r--arch/x86_64/pci/Makefile27
-rw-r--r--arch/x86_64/vdso/vdso.S2
-rw-r--r--block/Makefile1
-rw-r--r--block/blktrace.c54
-rw-r--r--block/compat_ioctl.c814
-rw-r--r--block/ioctl.c21
-rw-r--r--block/ll_rw_blk.c291
-rw-r--r--drivers/block/aoe/aoeblk.c4
-rw-r--r--drivers/block/aoe/aoecmd.c2
-rw-r--r--drivers/block/aoe/aoedev.c4
-rw-r--r--drivers/block/cciss.c2
-rw-r--r--drivers/block/cpqarray.c2
-rw-r--r--drivers/block/floppy.c87
-rw-r--r--drivers/block/lguest_blk.c36
-rw-r--r--drivers/block/loop.c4
-rw-r--r--drivers/block/nbd.c59
-rw-r--r--drivers/block/pktcdvd.c25
-rw-r--r--drivers/block/ps3disk.c42
-rw-r--r--drivers/block/rd.c4
-rw-r--r--drivers/block/umem.c238
-rw-r--r--drivers/block/umem.h133
-rw-r--r--drivers/block/xen-blkfront.c32
-rw-r--r--drivers/block/xsysace.c274
-rw-r--r--drivers/ide/ide-floppy.c52
-rw-r--r--drivers/md/dm-crypt.c21
-rw-r--r--drivers/md/dm-emc.c15
-rw-r--r--drivers/md/dm-io.c8
-rw-r--r--drivers/md/dm-mpath.c4
-rw-r--r--drivers/md/dm-raid1.c4
-rw-r--r--drivers/md/dm-snap.c2
-rw-r--r--drivers/md/dm-zero.c2
-rw-r--r--drivers/md/dm.c18
-rw-r--r--drivers/md/faulty.c10
-rw-r--r--drivers/md/linear.c4
-rw-r--r--drivers/md/md.c25
-rw-r--r--drivers/md/multipath.c13
-rw-r--r--drivers/md/raid0.c4
-rw-r--r--drivers/md/raid1.c30
-rw-r--r--drivers/md/raid10.c31
-rw-r--r--drivers/md/raid5.c48
-rw-r--r--drivers/media/Kconfig70
-rw-r--r--drivers/media/common/Kconfig2
-rw-r--r--drivers/media/common/ir-functions.c1
-rw-r--r--drivers/media/common/ir-keymaps.c62
-rw-r--r--drivers/media/common/saa7146_core.c34
-rw-r--r--drivers/media/common/saa7146_fops.c5
-rw-r--r--drivers/media/common/saa7146_i2c.c23
-rw-r--r--drivers/media/common/saa7146_vbi.c9
-rw-r--r--drivers/media/common/saa7146_video.c11
-rw-r--r--drivers/media/dvb/bt8xx/bt878.c1
-rw-r--r--drivers/media/dvb/bt8xx/bt878.h7
-rw-r--r--drivers/media/dvb/bt8xx/dvb-bt8xx.c1
-rw-r--r--drivers/media/dvb/cinergyT2/cinergyT2.c8
-rw-r--r--drivers/media/dvb/dvb-core/dmxdev.c1
-rw-r--r--drivers/media/dvb/dvb-core/dvb_ca_en50221.c93
-rw-r--r--drivers/media/dvb/dvb-core/dvb_demux.c5
-rw-r--r--drivers/media/dvb/dvb-core/dvb_frontend.c125
-rw-r--r--drivers/media/dvb/dvb-core/dvb_frontend.h13
-rw-r--r--drivers/media/dvb/dvb-core/dvb_net.c22
-rw-r--r--drivers/media/dvb/dvb-core/dvbdev.c41
-rw-r--r--drivers/media/dvb/dvb-usb/Kconfig2
-rw-r--r--drivers/media/dvb/dvb-usb/dib0700.h5
-rw-r--r--drivers/media/dvb/dvb-usb/dib0700_core.c23
-rw-r--r--drivers/media/dvb/dvb-usb/dib0700_devices.c676
-rw-r--r--drivers/media/dvb/dvb-usb/dtt200u.c28
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-ids.h26
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-init.c2
-rw-r--r--drivers/media/dvb/dvb-usb/gp8psk-fe.c84
-rw-r--r--drivers/media/dvb/dvb-usb/gp8psk.c93
-rw-r--r--drivers/media/dvb/dvb-usb/gp8psk.h32
-rw-r--r--drivers/media/dvb/dvb-usb/vp7045.c2
-rw-r--r--drivers/media/dvb/frontends/Kconfig33
-rw-r--r--drivers/media/dvb/frontends/Makefile4
-rw-r--r--drivers/media/dvb/frontends/bcm3510.c1
-rw-r--r--drivers/media/dvb/frontends/cx22700.c1
-rw-r--r--drivers/media/dvb/frontends/cx24110.c1
-rw-r--r--drivers/media/dvb/frontends/cx24123.c1
-rw-r--r--drivers/media/dvb/frontends/dib0070.c580
-rw-r--r--drivers/media/dvb/frontends/dib0070.h44
-rw-r--r--drivers/media/dvb/frontends/dib3000mb.c1
-rw-r--r--drivers/media/dvb/frontends/dib3000mc.c192
-rw-r--r--drivers/media/dvb/frontends/dib7000m.c727
-rw-r--r--drivers/media/dvb/frontends/dib7000p.c908
-rw-r--r--drivers/media/dvb/frontends/dib7000p.h14
-rw-r--r--drivers/media/dvb/frontends/dibx000_common.h57
-rw-r--r--drivers/media/dvb/frontends/dvb-pll.c147
-rw-r--r--drivers/media/dvb/frontends/dvb_dummy_fe.c1
-rw-r--r--drivers/media/dvb/frontends/isl6421.c1
-rw-r--r--drivers/media/dvb/frontends/l64781.c1
-rw-r--r--drivers/media/dvb/frontends/lgdt330x.c1
-rw-r--r--drivers/media/dvb/frontends/lnbp21.c1
-rw-r--r--drivers/media/dvb/frontends/mt2060.c1
-rw-r--r--drivers/media/dvb/frontends/mt2131.c314
-rw-r--r--drivers/media/dvb/frontends/mt2131.h54
-rw-r--r--drivers/media/dvb/frontends/mt2131_priv.h49
-rw-r--r--drivers/media/dvb/frontends/mt2266.c287
-rw-r--r--drivers/media/dvb/frontends/mt2266.h37
-rw-r--r--drivers/media/dvb/frontends/mt312.c1
-rw-r--r--drivers/media/dvb/frontends/mt352.c1
-rw-r--r--drivers/media/dvb/frontends/nxt200x.c1
-rw-r--r--drivers/media/dvb/frontends/or51132.c1
-rw-r--r--drivers/media/dvb/frontends/or51211.c1
-rw-r--r--drivers/media/dvb/frontends/s5h1409.c729
-rw-r--r--drivers/media/dvb/frontends/s5h1409.h73
-rw-r--r--drivers/media/dvb/frontends/sp8870.c1
-rw-r--r--drivers/media/dvb/frontends/sp887x.c1
-rw-r--r--drivers/media/dvb/frontends/stv0297.c4
-rw-r--r--drivers/media/dvb/frontends/stv0299.c1
-rw-r--r--drivers/media/dvb/frontends/tda10021.c4
-rw-r--r--drivers/media/dvb/frontends/tda10023.c10
-rw-r--r--drivers/media/dvb/frontends/tda1004x.c1
-rw-r--r--drivers/media/dvb/frontends/tda10086.c1
-rw-r--r--drivers/media/dvb/frontends/tda8083.c9
-rw-r--r--drivers/media/dvb/frontends/ves1820.c4
-rw-r--r--drivers/media/dvb/frontends/zl10353.c1
-rw-r--r--drivers/media/dvb/ttpci/av7110.c3
-rw-r--r--drivers/media/dvb/ttpci/av7110_hw.c28
-rw-r--r--drivers/media/dvb/ttpci/av7110_ir.c3
-rw-r--r--drivers/media/dvb/ttpci/av7110_v4l.c6
-rw-r--r--drivers/media/dvb/ttpci/budget-av.c2
-rw-r--r--drivers/media/dvb/ttpci/budget-ci.c2
-rw-r--r--drivers/media/dvb/ttpci/budget-core.c1
-rw-r--r--drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c1
-rw-r--r--drivers/media/dvb/ttusb-dec/ttusb_dec.c1
-rw-r--r--drivers/media/radio/Kconfig24
-rw-r--r--drivers/media/radio/radio-gemtek.c618
-rw-r--r--drivers/media/radio/radio-terratec.c2
-rw-r--r--drivers/media/video/Kconfig29
-rw-r--r--drivers/media/video/Makefile28
-rw-r--r--drivers/media/video/arv.c3
-rw-r--r--drivers/media/video/bt8xx/Kconfig2
-rw-r--r--drivers/media/video/bt8xx/bttv-cards.c38
-rw-r--r--drivers/media/video/bt8xx/bttv-driver.c31
-rw-r--r--drivers/media/video/bt8xx/bttv-gpio.c6
-rw-r--r--drivers/media/video/bt8xx/bttv-i2c.c1
-rw-r--r--drivers/media/video/bt8xx/bttv-input.c1
-rw-r--r--drivers/media/video/bt8xx/bttv-risc.c35
-rw-r--r--drivers/media/video/bt8xx/bttv-vbi.c6
-rw-r--r--drivers/media/video/bt8xx/bttv.h2
-rw-r--r--drivers/media/video/bt8xx/bttvp.h2
-rw-r--r--drivers/media/video/btcx-risc.c1
-rw-r--r--drivers/media/video/bw-qcam.c18
-rw-r--r--drivers/media/video/cafe_ccic.c21
-rw-r--r--drivers/media/video/compat_ioctl32.c5
-rw-r--r--drivers/media/video/cpia.c1
-rw-r--r--drivers/media/video/cpia2/cpia2_v4l.c1
-rw-r--r--drivers/media/video/cx2341x.c19
-rw-r--r--drivers/media/video/cx23885/Kconfig20
-rw-r--r--drivers/media/video/cx23885/Makefile9
-rw-r--r--drivers/media/video/cx23885/cx23885-cards.c280
-rw-r--r--drivers/media/video/cx23885/cx23885-core.c1530
-rw-r--r--drivers/media/video/cx23885/cx23885-dvb.c213
-rw-r--r--drivers/media/video/cx23885/cx23885-i2c.c382
-rw-r--r--drivers/media/video/cx23885/cx23885-reg.h431
-rw-r--r--drivers/media/video/cx23885/cx23885.h301
-rw-r--r--drivers/media/video/cx25840/cx25840-audio.c75
-rw-r--r--drivers/media/video/cx25840/cx25840-core.c98
-rw-r--r--drivers/media/video/cx25840/cx25840-core.h6
-rw-r--r--drivers/media/video/cx88/Kconfig4
-rw-r--r--drivers/media/video/cx88/cx88-alsa.c315
-rw-r--r--drivers/media/video/cx88/cx88-blackbird.c31
-rw-r--r--drivers/media/video/cx88/cx88-cards.c219
-rw-r--r--drivers/media/video/cx88/cx88-core.c222
-rw-r--r--drivers/media/video/cx88/cx88-dvb.c25
-rw-r--r--drivers/media/video/cx88/cx88-i2c.c27
-rw-r--r--drivers/media/video/cx88/cx88-input.c20
-rw-r--r--drivers/media/video/cx88/cx88-mpeg.c142
-rw-r--r--drivers/media/video/cx88/cx88-reg.h35
-rw-r--r--drivers/media/video/cx88/cx88-tvaudio.c22
-rw-r--r--drivers/media/video/cx88/cx88-vbi.c13
-rw-r--r--drivers/media/video/cx88/cx88-video.c169
-rw-r--r--drivers/media/video/cx88/cx88-vp3054-i2c.c5
-rw-r--r--drivers/media/video/cx88/cx88.h39
-rw-r--r--drivers/media/video/dpc7146.c5
-rw-r--r--drivers/media/video/em28xx/em28xx-core.c1
-rw-r--r--drivers/media/video/em28xx/em28xx-input.c1
-rw-r--r--drivers/media/video/em28xx/em28xx-video.c6
-rw-r--r--drivers/media/video/et61x251/et61x251_core.c59
-rw-r--r--drivers/media/video/ir-kbd-i2c.c38
-rw-r--r--drivers/media/video/ivtv/Kconfig17
-rw-r--r--drivers/media/video/ivtv/Makefile5
-rw-r--r--drivers/media/video/ivtv/ivtv-audio.c74
-rw-r--r--drivers/media/video/ivtv/ivtv-audio.h23
-rw-r--r--drivers/media/video/ivtv/ivtv-cards.c84
-rw-r--r--drivers/media/video/ivtv/ivtv-cards.h67
-rw-r--r--drivers/media/video/ivtv/ivtv-controls.c16
-rw-r--r--drivers/media/video/ivtv/ivtv-controls.h5
-rw-r--r--drivers/media/video/ivtv/ivtv-driver.c332
-rw-r--r--drivers/media/video/ivtv/ivtv-driver.h691
-rw-r--r--drivers/media/video/ivtv/ivtv-fileops.c199
-rw-r--r--drivers/media/video/ivtv/ivtv-fileops.h5
-rw-r--r--drivers/media/video/ivtv/ivtv-firmware.h5
-rw-r--r--drivers/media/video/ivtv/ivtv-gpio.c24
-rw-r--r--drivers/media/video/ivtv/ivtv-gpio.h7
-rw-r--r--drivers/media/video/ivtv/ivtv-i2c.c17
-rw-r--r--drivers/media/video/ivtv/ivtv-i2c.h5
-rw-r--r--drivers/media/video/ivtv/ivtv-ioctl.c191
-rw-r--r--drivers/media/video/ivtv/ivtv-ioctl.h5
-rw-r--r--drivers/media/video/ivtv/ivtv-irq.c321
-rw-r--r--drivers/media/video/ivtv/ivtv-irq.h27
-rw-r--r--drivers/media/video/ivtv/ivtv-mailbox.c6
-rw-r--r--drivers/media/video/ivtv/ivtv-mailbox.h8
-rw-r--r--drivers/media/video/ivtv/ivtv-queue.c119
-rw-r--r--drivers/media/video/ivtv/ivtv-queue.h13
-rw-r--r--drivers/media/video/ivtv/ivtv-routing.c116
-rw-r--r--drivers/media/video/ivtv/ivtv-routing.h27
-rw-r--r--drivers/media/video/ivtv/ivtv-streams.c131
-rw-r--r--drivers/media/video/ivtv/ivtv-streams.h5
-rw-r--r--drivers/media/video/ivtv/ivtv-udma.c46
-rw-r--r--drivers/media/video/ivtv/ivtv-udma.h5
-rw-r--r--drivers/media/video/ivtv/ivtv-vbi.c283
-rw-r--r--drivers/media/video/ivtv/ivtv-vbi.h9
-rw-r--r--drivers/media/video/ivtv/ivtv-version.h7
-rw-r--r--drivers/media/video/ivtv/ivtv-video.c142
-rw-r--r--drivers/media/video/ivtv/ivtv-video.h24
-rw-r--r--drivers/media/video/ivtv/ivtv-yuv.c55
-rw-r--r--drivers/media/video/ivtv/ivtv-yuv.h21
-rw-r--r--drivers/media/video/ivtv/ivtvfb.c1190
-rw-r--r--drivers/media/video/msp3400-driver.c19
-rw-r--r--drivers/media/video/mt20xx.c311
-rw-r--r--drivers/media/video/mt20xx.h37
-rw-r--r--drivers/media/video/mxb.c4
-rw-r--r--drivers/media/video/ov511.c81
-rw-r--r--drivers/media/video/ov7670.c1
-rw-r--r--drivers/media/video/ovcamchip/ovcamchip_core.c1
-rw-r--r--drivers/media/video/planb.c30
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-context.c6
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-debug.h53
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-debugifc.c16
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h1
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-hdw.c310
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-hdw.h12
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-i2c-core.c63
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-main.c2
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-std.c8
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-sysfs.c216
-rw-r--r--drivers/media/video/pwc/pwc-ctrl.c2
-rw-r--r--drivers/media/video/pwc/pwc-if.c132
-rw-r--r--drivers/media/video/saa6588.c1
-rw-r--r--drivers/media/video/saa7127.c10
-rw-r--r--drivers/media/video/saa7134/Kconfig4
-rw-r--r--drivers/media/video/saa7134/saa7134-alsa.c3
-rw-r--r--drivers/media/video/saa7134/saa7134-cards.c57
-rw-r--r--drivers/media/video/saa7134/saa7134-core.c214
-rw-r--r--drivers/media/video/saa7134/saa7134-dvb.c23
-rw-r--r--drivers/media/video/saa7134/saa7134-empress.c18
-rw-r--r--drivers/media/video/saa7134/saa7134-i2c.c1
-rw-r--r--drivers/media/video/saa7134/saa7134-input.c1
-rw-r--r--drivers/media/video/saa7134/saa7134-oss.c43
-rw-r--r--drivers/media/video/saa7134/saa7134-ts.c30
-rw-r--r--drivers/media/video/saa7134/saa7134-tvaudio.c5
-rw-r--r--drivers/media/video/saa7134/saa7134-vbi.c7
-rw-r--r--drivers/media/video/saa7134/saa7134-video.c210
-rw-r--r--drivers/media/video/saa7134/saa7134.h23
-rw-r--r--drivers/media/video/sn9c102/sn9c102_core.c113
-rw-r--r--drivers/media/video/stv680.c51
-rw-r--r--drivers/media/video/tcm825x.c928
-rw-r--r--drivers/media/video/tcm825x.h199
-rw-r--r--drivers/media/video/tda8290.c517
-rw-r--r--drivers/media/video/tda8290.h54
-rw-r--r--drivers/media/video/tda9887.c62
-rw-r--r--drivers/media/video/tea5761.c187
-rw-r--r--drivers/media/video/tea5761.h47
-rw-r--r--drivers/media/video/tea5767.c203
-rw-r--r--drivers/media/video/tea5767.h47
-rw-r--r--drivers/media/video/tuner-core.c256
-rw-r--r--drivers/media/video/tuner-driver.h44
-rw-r--r--drivers/media/video/tuner-i2c.h70
-rw-r--r--drivers/media/video/tuner-simple.c397
-rw-r--r--drivers/media/video/tuner-simple.h46
-rw-r--r--drivers/media/video/tuner-types.c8
-rw-r--r--drivers/media/video/tvaudio.c1
-rw-r--r--drivers/media/video/tveeprom.c1
-rw-r--r--drivers/media/video/tvmixer.c6
-rw-r--r--drivers/media/video/usbvision/usbvision-core.c1
-rw-r--r--drivers/media/video/usbvision/usbvision-i2c.c4
-rw-r--r--drivers/media/video/usbvision/usbvision-video.c120
-rw-r--r--drivers/media/video/v4l1-compat.c1
-rw-r--r--drivers/media/video/v4l2-common.c6
-rw-r--r--drivers/media/video/v4l2-int-device.c158
-rw-r--r--drivers/media/video/video-buf-dvb.c255
-rw-r--r--drivers/media/video/video-buf.c1425
-rw-r--r--drivers/media/video/videobuf-core.c1006
-rw-r--r--drivers/media/video/videobuf-dma-sg.c726
-rw-r--r--drivers/media/video/videobuf-dvb.c256
-rw-r--r--drivers/media/video/videobuf-vmalloc.c370
-rw-r--r--drivers/media/video/videodev.c39
-rw-r--r--drivers/media/video/vino.c1
-rw-r--r--drivers/media/video/vivi.c185
-rw-r--r--drivers/media/video/vp27smpx.c212
-rw-r--r--drivers/media/video/w9968cf.c3
-rw-r--r--drivers/media/video/zc0301/zc0301_core.c3
-rw-r--r--drivers/media/video/zoran_card.c64
-rw-r--r--drivers/media/video/zoran_card.h8
-rw-r--r--drivers/media/video/zoran_device.c19
-rw-r--r--drivers/media/video/zoran_driver.c31
-rw-r--r--drivers/media/video/zoran_procfs.c9
-rw-r--r--drivers/media/video/zr36016.c4
-rw-r--r--drivers/media/video/zr36050.c6
-rw-r--r--drivers/media/video/zr36060.c6
-rw-r--r--drivers/mmc/card/Kconfig7
-rw-r--r--drivers/mmc/card/Makefile2
-rw-r--r--drivers/mmc/card/block.c30
-rw-r--r--drivers/mmc/card/sdio_uart.c1158
-rw-r--r--drivers/mmc/core/Makefile4
-rw-r--r--drivers/mmc/core/bus.c67
-rw-r--r--drivers/mmc/core/core.c167
-rw-r--r--drivers/mmc/core/core.h2
-rw-r--r--drivers/mmc/core/host.c8
-rw-r--r--drivers/mmc/core/mmc.c134
-rw-r--r--drivers/mmc/core/mmc_ops.c200
-rw-r--r--drivers/mmc/core/mmc_ops.h3
-rw-r--r--drivers/mmc/core/sd.c126
-rw-r--r--drivers/mmc/core/sd_ops.c107
-rw-r--r--drivers/mmc/core/sdio.c395
-rw-r--r--drivers/mmc/core/sdio_bus.c270
-rw-r--r--drivers/mmc/core/sdio_bus.h22
-rw-r--r--drivers/mmc/core/sdio_cis.c346
-rw-r--r--drivers/mmc/core/sdio_cis.h23
-rw-r--r--drivers/mmc/core/sdio_io.c548
-rw-r--r--drivers/mmc/core/sdio_irq.c267
-rw-r--r--drivers/mmc/core/sdio_ops.c176
-rw-r--r--drivers/mmc/core/sdio_ops.h22
-rw-r--r--drivers/mmc/host/Kconfig30
-rw-r--r--drivers/mmc/host/Makefile2
-rw-r--r--drivers/mmc/host/at91_mci.c25
-rw-r--r--drivers/mmc/host/au1xmmc.c58
-rw-r--r--drivers/mmc/host/imxmmc.c32
-rw-r--r--drivers/mmc/host/mmc_spi.c1408
-rw-r--r--drivers/mmc/host/mmci.c21
-rw-r--r--drivers/mmc/host/omap.c12
-rw-r--r--drivers/mmc/host/pxamci.c71
-rw-r--r--drivers/mmc/host/pxamci.h2
-rw-r--r--drivers/mmc/host/ricoh_mmc.c151
-rw-r--r--drivers/mmc/host/sdhci.c127
-rw-r--r--drivers/mmc/host/sdhci.h2
-rw-r--r--drivers/mmc/host/tifm_sd.c32
-rw-r--r--drivers/mmc/host/wbsd.c43
-rw-r--r--drivers/pci/hotplug/cpqphp_core.c2
-rw-r--r--drivers/pci/hotplug/cpqphp_pci.c2
-rw-r--r--drivers/pci/hotplug/ibmphp_core.c2
-rw-r--r--drivers/s390/block/dasd_diag.c37
-rw-r--r--drivers/s390/block/dasd_eckd.c28
-rw-r--r--drivers/s390/block/dasd_fba.c28
-rw-r--r--drivers/s390/block/dcssblk.c4
-rw-r--r--drivers/s390/block/xpram.c6
-rw-r--r--drivers/s390/char/tape_34xx.c32
-rw-r--r--drivers/s390/char/tape_3590.c37
-rw-r--r--drivers/scsi/scsi_lib.c21
-rw-r--r--drivers/serial/bfin_5xx.c222
-rw-r--r--fs/bio.c50
-rw-r--r--fs/block_dev.c2
-rw-r--r--fs/buffer.c6
-rw-r--r--fs/compat_ioctl.c671
-rw-r--r--fs/direct-io.c13
-rw-r--r--fs/fs-writeback.c1
-rw-r--r--fs/gfs2/super.c4
-rw-r--r--fs/jfs/jfs_logmgr.c5
-rw-r--r--fs/jfs/jfs_metapage.c12
-rw-r--r--fs/mpage.c12
-rw-r--r--fs/ocfs2/cluster/heartbeat.c4
-rw-r--r--fs/xfs/linux-2.6/xfs_aops.c4
-rw-r--r--fs/xfs/linux-2.6/xfs_buf.c4
-rw-r--r--include/asm-arm/arch-imx/mmc.h5
-rw-r--r--include/asm-avr32/arch-at32ap/board.h8
-rw-r--r--include/asm-avr32/arch-at32ap/portmux.h1
-rw-r--r--include/asm-avr32/arch-at32ap/smc.h51
-rw-r--r--include/asm-avr32/dma-mapping.h17
-rw-r--r--include/asm-avr32/system.h13
-rw-r--r--include/asm-avr32/unistd.h13
-rw-r--r--include/asm-blackfin/bfin5xx_spi.h2
-rw-r--r--include/asm-blackfin/blackfin.h112
-rw-r--r--include/asm-blackfin/cacheflush.h14
-rw-r--r--include/asm-blackfin/cplb.h99
-rw-r--r--include/asm-blackfin/dma.h2
-rw-r--r--include/asm-blackfin/early_printk.h28
-rw-r--r--include/asm-blackfin/gpio.h31
-rw-r--r--include/asm-blackfin/io.h24
-rw-r--r--include/asm-blackfin/ioctls.h9
-rw-r--r--include/asm-blackfin/irq_handler.h15
-rw-r--r--include/asm-blackfin/kgdb.h1
-rw-r--r--include/asm-blackfin/mach-bf527/anomaly.h41
-rw-r--r--include/asm-blackfin/mach-bf527/defBF52x_base.h2
-rw-r--r--include/asm-blackfin/mach-bf533/anomaly.h468
-rw-r--r--include/asm-blackfin/mach-bf533/bf533.h157
-rw-r--r--include/asm-blackfin/mach-bf533/blackfin.h2
-rw-r--r--include/asm-blackfin/mach-bf533/cdefBF532.h62
-rw-r--r--include/asm-blackfin/mach-bf533/defBF532.h3
-rw-r--r--include/asm-blackfin/mach-bf533/irq.h2
-rw-r--r--include/asm-blackfin/mach-bf533/mem_map.h56
-rw-r--r--include/asm-blackfin/mach-bf537/anomaly.h249
-rw-r--r--include/asm-blackfin/mach-bf537/bf537.h158
-rw-r--r--include/asm-blackfin/mach-bf537/blackfin.h280
-rw-r--r--include/asm-blackfin/mach-bf537/cdefBF534.h4
-rw-r--r--include/asm-blackfin/mach-bf537/defBF534.h4
-rw-r--r--include/asm-blackfin/mach-bf537/irq.h2
-rw-r--r--include/asm-blackfin/mach-bf537/mem_map.h60
-rw-r--r--include/asm-blackfin/mach-bf537/portmux.h2
-rw-r--r--include/asm-blackfin/mach-bf548/anomaly.h145
-rw-r--r--include/asm-blackfin/mach-bf548/bf548.h154
-rw-r--r--include/asm-blackfin/mach-bf548/bfin_serial_5xx.h39
-rw-r--r--include/asm-blackfin/mach-bf548/blackfin.h2
-rw-r--r--include/asm-blackfin/mach-bf548/cdefBF54x_base.h4
-rw-r--r--include/asm-blackfin/mach-bf548/defBF544.h1
-rw-r--r--include/asm-blackfin/mach-bf548/defBF548.h2
-rw-r--r--include/asm-blackfin/mach-bf548/defBF549.h2
-rw-r--r--include/asm-blackfin/mach-bf548/defBF54x_base.h3
-rw-r--r--include/asm-blackfin/mach-bf548/gpio.h5
-rw-r--r--include/asm-blackfin/mach-bf548/irq.h591
-rw-r--r--include/asm-blackfin/mach-bf548/mem_map.h24
-rw-r--r--include/asm-blackfin/mach-bf561/anomaly.h410
-rw-r--r--include/asm-blackfin/mach-bf561/bf561.h178
-rw-r--r--include/asm-blackfin/mach-bf561/blackfin.h2
-rw-r--r--include/asm-blackfin/mach-bf561/cdefBF561.h9
-rw-r--r--include/asm-blackfin/mach-bf561/defBF561.h1
-rw-r--r--include/asm-blackfin/mach-bf561/irq.h2
-rw-r--r--include/asm-blackfin/mach-bf561/mem_map.h24
-rw-r--r--include/asm-blackfin/mach-bf561/portmux.h2
-rw-r--r--include/asm-blackfin/mach-common/cdef_LPBlackfin.h4
-rw-r--r--include/asm-blackfin/mach-common/clocks.h70
-rw-r--r--include/asm-blackfin/mach-common/def_LPBlackfin.h135
-rw-r--r--include/asm-blackfin/pgtable.h2
-rw-r--r--include/asm-blackfin/reboot.h20
-rw-r--r--include/asm-blackfin/system.h93
-rw-r--r--include/asm-blackfin/termbits.h5
-rw-r--r--include/asm-blackfin/termios.h10
-rw-r--r--include/asm-blackfin/trace.h55
-rw-r--r--include/asm-i386/Kbuild12
-rw-r--r--include/asm-i386/k8.h1
-rw-r--r--include/asm-i386/pci-direct.h1
-rw-r--r--include/asm-i386/stacktrace.h1
-rw-r--r--include/asm-i386/termios.h91
-rw-r--r--include/asm-sh/mpc1211/mc146818rtc.h2
-rw-r--r--include/asm-x86/8253pit.h5
-rw-r--r--include/asm-x86/8253pit_32.h (renamed from include/asm-i386/8253pit.h)0
-rw-r--r--include/asm-x86/8253pit_64.h (renamed from include/asm-x86_64/8253pit.h)0
-rw-r--r--include/asm-x86/Kbuild88
-rw-r--r--include/asm-x86/a.out.h13
-rw-r--r--include/asm-x86/a.out_32.h (renamed from include/asm-i386/a.out.h)0
-rw-r--r--include/asm-x86/a.out_64.h (renamed from include/asm-x86_64/a.out.h)0
-rw-r--r--include/asm-x86/acpi.h5
-rw-r--r--include/asm-x86/acpi_32.h (renamed from include/asm-i386/acpi.h)0
-rw-r--r--include/asm-x86/acpi_64.h (renamed from include/asm-x86_64/acpi.h)0
-rw-r--r--include/asm-x86/agp.h5
-rw-r--r--include/asm-x86/agp_32.h (renamed from include/asm-i386/agp.h)0
-rw-r--r--include/asm-x86/agp_64.h (renamed from include/asm-x86_64/agp.h)0
-rw-r--r--include/asm-x86/alternative-asm.i5
-rw-r--r--include/asm-x86/alternative-asm_32.i (renamed from include/asm-i386/alternative-asm.i)0
-rw-r--r--include/asm-x86/alternative-asm_64.i (renamed from include/asm-x86_64/alternative-asm.i)0
-rw-r--r--include/asm-x86/alternative.h5
-rw-r--r--include/asm-x86/alternative_32.h (renamed from include/asm-i386/alternative.h)0
-rw-r--r--include/asm-x86/alternative_64.h (renamed from include/asm-x86_64/alternative.h)0
-rw-r--r--include/asm-x86/apic.h5
-rw-r--r--include/asm-x86/apic_32.h (renamed from include/asm-i386/apic.h)0
-rw-r--r--include/asm-x86/apic_64.h (renamed from include/asm-x86_64/apic.h)0
-rw-r--r--include/asm-x86/apicdef.h5
-rw-r--r--include/asm-x86/apicdef_32.h (renamed from include/asm-i386/apicdef.h)0
-rw-r--r--include/asm-x86/apicdef_64.h (renamed from include/asm-x86_64/apicdef.h)0
-rw-r--r--include/asm-x86/arch_hooks.h (renamed from include/asm-i386/arch_hooks.h)0
-rw-r--r--include/asm-x86/atomic.h5
-rw-r--r--include/asm-x86/atomic_32.h (renamed from include/asm-i386/atomic.h)0
-rw-r--r--include/asm-x86/atomic_64.h (renamed from include/asm-x86_64/atomic.h)0
-rw-r--r--include/asm-x86/auxvec.h13
-rw-r--r--include/asm-x86/auxvec_32.h (renamed from include/asm-i386/auxvec.h)0
-rw-r--r--include/asm-x86/auxvec_64.h (renamed from include/asm-x86_64/auxvec.h)0
-rw-r--r--include/asm-x86/bitops.h5
-rw-r--r--include/asm-x86/bitops_32.h (renamed from include/asm-i386/bitops.h)0
-rw-r--r--include/asm-x86/bitops_64.h (renamed from include/asm-x86_64/bitops.h)0
-rw-r--r--include/asm-x86/boot.h (renamed from include/asm-i386/boot.h)0
-rw-r--r--include/asm-x86/bootparam.h (renamed from include/asm-i386/bootparam.h)0
-rw-r--r--include/asm-x86/bootsetup.h (renamed from include/asm-x86_64/bootsetup.h)0
-rw-r--r--include/asm-x86/bug.h5
-rw-r--r--include/asm-x86/bug_32.h (renamed from include/asm-i386/bug.h)0
-rw-r--r--include/asm-x86/bug_64.h (renamed from include/asm-x86_64/bug.h)0
-rw-r--r--include/asm-x86/bugs.h5
-rw-r--r--include/asm-x86/bugs_32.h (renamed from include/asm-i386/bugs.h)0
-rw-r--r--include/asm-x86/bugs_64.h (renamed from include/asm-x86_64/bugs.h)0
-rw-r--r--include/asm-x86/byteorder.h13
-rw-r--r--include/asm-x86/byteorder_32.h (renamed from include/asm-i386/byteorder.h)0
-rw-r--r--include/asm-x86/byteorder_64.h (renamed from include/asm-x86_64/byteorder.h)0
-rw-r--r--include/asm-x86/cache.h5
-rw-r--r--include/asm-x86/cache_32.h (renamed from include/asm-i386/cache.h)0
-rw-r--r--include/asm-x86/cache_64.h (renamed from include/asm-x86_64/cache.h)0
-rw-r--r--include/asm-x86/cacheflush.h5
-rw-r--r--include/asm-x86/cacheflush_32.h (renamed from include/asm-i386/cacheflush.h)0
-rw-r--r--include/asm-x86/cacheflush_64.h (renamed from include/asm-x86_64/cacheflush.h)0
-rw-r--r--include/asm-x86/calgary.h (renamed from include/asm-x86_64/calgary.h)0
-rw-r--r--include/asm-x86/calling.h (renamed from include/asm-x86_64/calling.h)0
-rw-r--r--include/asm-x86/checksum.h5
-rw-r--r--include/asm-x86/checksum_32.h (renamed from include/asm-i386/checksum.h)0
-rw-r--r--include/asm-x86/checksum_64.h (renamed from include/asm-x86_64/checksum.h)0
-rw-r--r--include/asm-x86/cmpxchg.h5
-rw-r--r--include/asm-x86/cmpxchg_32.h (renamed from include/asm-i386/cmpxchg.h)0
-rw-r--r--include/asm-x86/cmpxchg_64.h (renamed from include/asm-x86_64/cmpxchg.h)0
-rw-r--r--include/asm-x86/compat.h (renamed from include/asm-x86_64/compat.h)0
-rw-r--r--include/asm-x86/cpu.h (renamed from include/asm-i386/cpu.h)0
-rw-r--r--include/asm-x86/cpufeature.h5
-rw-r--r--include/asm-x86/cpufeature_32.h (renamed from include/asm-i386/cpufeature.h)0
-rw-r--r--include/asm-x86/cpufeature_64.h30
-rw-r--r--include/asm-x86/cputime.h5
-rw-r--r--include/asm-x86/cputime_32.h (renamed from include/asm-i386/cputime.h)0
-rw-r--r--include/asm-x86/cputime_64.h (renamed from include/asm-x86_64/cputime.h)0
-rw-r--r--include/asm-x86/current.h5
-rw-r--r--include/asm-x86/current_32.h (renamed from include/asm-i386/current.h)0
-rw-r--r--include/asm-x86/current_64.h (renamed from include/asm-x86_64/current.h)0
-rw-r--r--include/asm-x86/debugreg.h13
-rw-r--r--include/asm-x86/debugreg_32.h (renamed from include/asm-i386/debugreg.h)0
-rw-r--r--include/asm-x86/debugreg_64.h (renamed from include/asm-x86_64/debugreg.h)0
-rw-r--r--include/asm-x86/delay.h5
-rw-r--r--include/asm-x86/delay_32.h (renamed from include/asm-i386/delay.h)0
-rw-r--r--include/asm-x86/delay_64.h (renamed from include/asm-x86_64/delay.h)0
-rw-r--r--include/asm-x86/desc.h5
-rw-r--r--include/asm-x86/desc_32.h (renamed from include/asm-i386/desc.h)0
-rw-r--r--include/asm-x86/desc_64.h (renamed from include/asm-x86_64/desc.h)0
-rw-r--r--include/asm-x86/desc_defs.h (renamed from include/asm-x86_64/desc_defs.h)0
-rw-r--r--include/asm-x86/device.h5
-rw-r--r--include/asm-x86/device_32.h (renamed from include/asm-i386/device.h)0
-rw-r--r--include/asm-x86/device_64.h (renamed from include/asm-x86_64/device.h)0
-rw-r--r--include/asm-x86/div64.h5
-rw-r--r--include/asm-x86/div64_32.h (renamed from include/asm-i386/div64.h)0
-rw-r--r--include/asm-x86/div64_64.h (renamed from include/asm-x86_64/div64.h)0
-rw-r--r--include/asm-x86/dma-mapping.h5
-rw-r--r--include/asm-x86/dma-mapping_32.h (renamed from include/asm-i386/dma-mapping.h)0
-rw-r--r--include/asm-x86/dma-mapping_64.h (renamed from include/asm-x86_64/dma-mapping.h)0
-rw-r--r--include/asm-x86/dma.h5
-rw-r--r--include/asm-x86/dma_32.h (renamed from include/asm-i386/dma.h)0
-rw-r--r--include/asm-x86/dma_64.h (renamed from include/asm-x86_64/dma.h)0
-rw-r--r--include/asm-x86/dmi.h5
-rw-r--r--include/asm-x86/dmi_32.h (renamed from include/asm-i386/dmi.h)0
-rw-r--r--include/asm-x86/dmi_64.h (renamed from include/asm-x86_64/dmi.h)0
-rw-r--r--include/asm-x86/dwarf2.h5
-rw-r--r--include/asm-x86/dwarf2_32.h (renamed from include/asm-i386/dwarf2.h)0
-rw-r--r--include/asm-x86/dwarf2_64.h (renamed from include/asm-x86_64/dwarf2.h)0
-rw-r--r--include/asm-x86/e820.h5
-rw-r--r--include/asm-x86/e820_32.h (renamed from include/asm-i386/e820.h)0
-rw-r--r--include/asm-x86/e820_64.h (renamed from include/asm-x86_64/e820.h)0
-rw-r--r--include/asm-x86/edac.h5
-rw-r--r--include/asm-x86/edac_32.h (renamed from include/asm-i386/edac.h)0
-rw-r--r--include/asm-x86/edac_64.h (renamed from include/asm-x86_64/edac.h)0
-rw-r--r--include/asm-x86/elf.h13
-rw-r--r--include/asm-x86/elf_32.h (renamed from include/asm-i386/elf.h)0
-rw-r--r--include/asm-x86/elf_64.h (renamed from include/asm-x86_64/elf.h)0
-rw-r--r--include/asm-x86/emergency-restart.h (renamed from include/asm-i386/emergency-restart.h)0
-rw-r--r--include/asm-x86/errno.h13
-rw-r--r--include/asm-x86/errno_32.h (renamed from include/asm-i386/errno.h)0
-rw-r--r--include/asm-x86/errno_64.h (renamed from include/asm-x86_64/errno.h)0
-rw-r--r--include/asm-x86/fb.h5
-rw-r--r--include/asm-x86/fb_32.h (renamed from include/asm-i386/fb.h)0
-rw-r--r--include/asm-x86/fb_64.h (renamed from include/asm-x86_64/fb.h)0
-rw-r--r--include/asm-x86/fcntl.h (renamed from include/asm-i386/fcntl.h)0
-rw-r--r--include/asm-x86/fixmap.h5
-rw-r--r--include/asm-x86/fixmap_32.h (renamed from include/asm-i386/fixmap.h)0
-rw-r--r--include/asm-x86/fixmap_64.h (renamed from include/asm-x86_64/fixmap.h)0
-rw-r--r--include/asm-x86/floppy.h5
-rw-r--r--include/asm-x86/floppy_32.h (renamed from include/asm-i386/floppy.h)0
-rw-r--r--include/asm-x86/floppy_64.h (renamed from include/asm-x86_64/floppy.h)0
-rw-r--r--include/asm-x86/fpu32.h (renamed from include/asm-x86_64/fpu32.h)0
-rw-r--r--include/asm-x86/frame.i (renamed from include/asm-i386/frame.i)0
-rw-r--r--include/asm-x86/futex.h5
-rw-r--r--include/asm-x86/futex_32.h (renamed from include/asm-i386/futex.h)0
-rw-r--r--include/asm-x86/futex_64.h (renamed from include/asm-x86_64/futex.h)0
-rw-r--r--include/asm-x86/genapic.h5
-rw-r--r--include/asm-x86/genapic_32.h (renamed from include/asm-i386/genapic.h)0
-rw-r--r--include/asm-x86/genapic_64.h (renamed from include/asm-x86_64/genapic.h)0
-rw-r--r--include/asm-x86/geode.h (renamed from include/asm-i386/geode.h)0
-rw-r--r--include/asm-x86/hardirq.h5
-rw-r--r--include/asm-x86/hardirq_32.h (renamed from include/asm-i386/hardirq.h)0
-rw-r--r--include/asm-x86/hardirq_64.h (renamed from include/asm-x86_64/hardirq.h)0
-rw-r--r--include/asm-x86/highmem.h (renamed from include/asm-i386/highmem.h)0
-rw-r--r--include/asm-x86/hpet.h5
-rw-r--r--include/asm-x86/hpet_32.h (renamed from include/asm-i386/hpet.h)0
-rw-r--r--include/asm-x86/hpet_64.h18
-rw-r--r--include/asm-x86/hw_irq.h5
-rw-r--r--include/asm-x86/hw_irq_32.h (renamed from include/asm-i386/hw_irq.h)0
-rw-r--r--include/asm-x86/hw_irq_64.h (renamed from include/asm-x86_64/hw_irq.h)0
-rw-r--r--include/asm-x86/hypertransport.h (renamed from include/asm-i386/hypertransport.h)0
-rw-r--r--include/asm-x86/i387.h5
-rw-r--r--include/asm-x86/i387_32.h (renamed from include/asm-i386/i387.h)0
-rw-r--r--include/asm-x86/i387_64.h (renamed from include/asm-x86_64/i387.h)0
-rw-r--r--include/asm-x86/i8253.h5
-rw-r--r--include/asm-x86/i8253_32.h (renamed from include/asm-i386/i8253.h)0
-rw-r--r--include/asm-x86/i8253_64.h (renamed from include/asm-x86_64/i8253.h)0
-rw-r--r--include/asm-x86/i8259.h (renamed from include/asm-i386/i8259.h)0
-rw-r--r--include/asm-x86/ia32.h (renamed from include/asm-x86_64/ia32.h)0
-rw-r--r--include/asm-x86/ia32_unistd.h (renamed from include/asm-x86_64/ia32_unistd.h)0
-rw-r--r--include/asm-x86/ide.h (renamed from include/asm-i386/ide.h)0
-rw-r--r--include/asm-x86/idle.h (renamed from include/asm-x86_64/idle.h)0
-rw-r--r--include/asm-x86/intel_arch_perfmon.h5
-rw-r--r--include/asm-x86/intel_arch_perfmon_32.h (renamed from include/asm-i386/intel_arch_perfmon.h)0
-rw-r--r--include/asm-x86/intel_arch_perfmon_64.h (renamed from include/asm-x86_64/intel_arch_perfmon.h)0
-rw-r--r--include/asm-x86/io.h5
-rw-r--r--include/asm-x86/io_32.h (renamed from include/asm-i386/io.h)0
-rw-r--r--include/asm-x86/io_64.h (renamed from include/asm-x86_64/io.h)0
-rw-r--r--include/asm-x86/io_apic.h5
-rw-r--r--include/asm-x86/io_apic_32.h (renamed from include/asm-i386/io_apic.h)0
-rw-r--r--include/asm-x86/io_apic_64.h (renamed from include/asm-x86_64/io_apic.h)0
-rw-r--r--include/asm-x86/ioctl.h (renamed from include/asm-i386/ioctl.h)0
-rw-r--r--include/asm-x86/ioctls.h13
-rw-r--r--include/asm-x86/ioctls_32.h (renamed from include/asm-i386/ioctls.h)0
-rw-r--r--include/asm-x86/ioctls_64.h (renamed from include/asm-x86_64/ioctls.h)0
-rw-r--r--include/asm-x86/iommu.h (renamed from include/asm-x86_64/iommu.h)0
-rw-r--r--include/asm-x86/ipc.h (renamed from include/asm-i386/ipc.h)0
-rw-r--r--include/asm-x86/ipcbuf.h13
-rw-r--r--include/asm-x86/ipcbuf_32.h (renamed from include/asm-i386/ipcbuf.h)0
-rw-r--r--include/asm-x86/ipcbuf_64.h (renamed from include/asm-x86_64/ipcbuf.h)0
-rw-r--r--include/asm-x86/ipi.h (renamed from include/asm-x86_64/ipi.h)0
-rw-r--r--include/asm-x86/irq.h5
-rw-r--r--include/asm-x86/irq_32.h (renamed from include/asm-i386/irq.h)0
-rw-r--r--include/asm-x86/irq_64.h (renamed from include/asm-x86_64/irq.h)0
-rw-r--r--include/asm-x86/irq_regs.h5
-rw-r--r--include/asm-x86/irq_regs_32.h (renamed from include/asm-i386/irq_regs.h)0
-rw-r--r--include/asm-x86/irq_regs_64.h (renamed from include/asm-x86_64/irq_regs.h)0
-rw-r--r--include/asm-x86/irqflags.h5
-rw-r--r--include/asm-x86/irqflags_32.h (renamed from include/asm-i386/irqflags.h)0
-rw-r--r--include/asm-x86/irqflags_64.h (renamed from include/asm-x86_64/irqflags.h)0
-rw-r--r--include/asm-x86/ist.h (renamed from include/asm-i386/ist.h)0
-rw-r--r--include/asm-x86/k8.h (renamed from include/asm-x86_64/k8.h)0
-rw-r--r--include/asm-x86/kdebug.h5
-rw-r--r--include/asm-x86/kdebug_32.h (renamed from include/asm-i386/kdebug.h)0
-rw-r--r--include/asm-x86/kdebug_64.h (renamed from include/asm-x86_64/kdebug.h)0
-rw-r--r--include/asm-x86/kexec.h5
-rw-r--r--include/asm-x86/kexec_32.h (renamed from include/asm-i386/kexec.h)0
-rw-r--r--include/asm-x86/kexec_64.h (renamed from include/asm-x86_64/kexec.h)0
-rw-r--r--include/asm-x86/kmap_types.h5
-rw-r--r--include/asm-x86/kmap_types_32.h (renamed from include/asm-i386/kmap_types.h)0
-rw-r--r--include/asm-x86/kmap_types_64.h (renamed from include/asm-x86_64/kmap_types.h)0
-rw-r--r--include/asm-x86/kprobes.h5
-rw-r--r--include/asm-x86/kprobes_32.h (renamed from include/asm-i386/kprobes.h)0
-rw-r--r--include/asm-x86/kprobes_64.h (renamed from include/asm-x86_64/kprobes.h)0
-rw-r--r--include/asm-x86/ldt.h13
-rw-r--r--include/asm-x86/ldt_32.h (renamed from include/asm-i386/ldt.h)0
-rw-r--r--include/asm-x86/ldt_64.h (renamed from include/asm-x86_64/ldt.h)0
-rw-r--r--include/asm-x86/linkage.h5
-rw-r--r--include/asm-x86/linkage_32.h (renamed from include/asm-i386/linkage.h)0
-rw-r--r--include/asm-x86/linkage_64.h (renamed from include/asm-x86_64/linkage.h)0
-rw-r--r--include/asm-x86/local.h5
-rw-r--r--include/asm-x86/local_32.h (renamed from include/asm-i386/local.h)0
-rw-r--r--include/asm-x86/local_64.h (renamed from include/asm-x86_64/local.h)0
-rw-r--r--include/asm-x86/mach-bigsmp/mach_apic.h (renamed from include/asm-i386/mach-bigsmp/mach_apic.h)0
-rw-r--r--include/asm-x86/mach-bigsmp/mach_apicdef.h (renamed from include/asm-i386/mach-bigsmp/mach_apicdef.h)0
-rw-r--r--include/asm-x86/mach-bigsmp/mach_ipi.h (renamed from include/asm-i386/mach-bigsmp/mach_ipi.h)0
-rw-r--r--include/asm-x86/mach-bigsmp/mach_mpspec.h (renamed from include/asm-i386/mach-bigsmp/mach_mpspec.h)0
-rw-r--r--include/asm-x86/mach-default/apm.h (renamed from include/asm-i386/mach-default/apm.h)0
-rw-r--r--include/asm-x86/mach-default/bios_ebda.h (renamed from include/asm-i386/mach-default/bios_ebda.h)0
-rw-r--r--include/asm-x86/mach-default/do_timer.h (renamed from include/asm-i386/mach-default/do_timer.h)0
-rw-r--r--include/asm-x86/mach-default/entry_arch.h (renamed from include/asm-i386/mach-default/entry_arch.h)0
-rw-r--r--include/asm-x86/mach-default/io_ports.h (renamed from include/asm-i386/mach-default/io_ports.h)0
-rw-r--r--include/asm-x86/mach-default/irq_vectors.h (renamed from include/asm-i386/mach-default/irq_vectors.h)0
-rw-r--r--include/asm-x86/mach-default/irq_vectors_limits.h (renamed from include/asm-i386/mach-default/irq_vectors_limits.h)0
-rw-r--r--include/asm-x86/mach-default/mach_apic.h (renamed from include/asm-i386/mach-default/mach_apic.h)0
-rw-r--r--include/asm-x86/mach-default/mach_apicdef.h (renamed from include/asm-i386/mach-default/mach_apicdef.h)0
-rw-r--r--include/asm-x86/mach-default/mach_ipi.h (renamed from include/asm-i386/mach-default/mach_ipi.h)0
-rw-r--r--include/asm-x86/mach-default/mach_mpparse.h (renamed from include/asm-i386/mach-default/mach_mpparse.h)0
-rw-r--r--include/asm-x86/mach-default/mach_mpspec.h (renamed from include/asm-i386/mach-default/mach_mpspec.h)0
-rw-r--r--include/asm-x86/mach-default/mach_reboot.h (renamed from include/asm-i386/mach-default/mach_reboot.h)0
-rw-r--r--include/asm-x86/mach-default/mach_time.h (renamed from include/asm-i386/mach-default/mach_time.h)0
-rw-r--r--include/asm-x86/mach-default/mach_timer.h (renamed from include/asm-i386/mach-default/mach_timer.h)0
-rw-r--r--include/asm-x86/mach-default/mach_traps.h (renamed from include/asm-i386/mach-default/mach_traps.h)0
-rw-r--r--include/asm-x86/mach-default/mach_wakecpu.h (renamed from include/asm-i386/mach-default/mach_wakecpu.h)0
-rw-r--r--include/asm-x86/mach-default/pci-functions.h (renamed from include/asm-i386/mach-default/pci-functions.h)0
-rw-r--r--include/asm-x86/mach-default/setup_arch.h (renamed from include/asm-i386/mach-default/setup_arch.h)0
-rw-r--r--include/asm-x86/mach-default/smpboot_hooks.h (renamed from include/asm-i386/mach-default/smpboot_hooks.h)0
-rw-r--r--include/asm-x86/mach-es7000/mach_apic.h (renamed from include/asm-i386/mach-es7000/mach_apic.h)0
-rw-r--r--include/asm-x86/mach-es7000/mach_apicdef.h (renamed from include/asm-i386/mach-es7000/mach_apicdef.h)0
-rw-r--r--include/asm-x86/mach-es7000/mach_ipi.h (renamed from include/asm-i386/mach-es7000/mach_ipi.h)0
-rw-r--r--include/asm-x86/mach-es7000/mach_mpparse.h (renamed from include/asm-i386/mach-es7000/mach_mpparse.h)0
-rw-r--r--include/asm-x86/mach-es7000/mach_mpspec.h (renamed from include/asm-i386/mach-es7000/mach_mpspec.h)0
-rw-r--r--include/asm-x86/mach-es7000/mach_wakecpu.h (renamed from include/asm-i386/mach-es7000/mach_wakecpu.h)0
-rw-r--r--include/asm-x86/mach-generic/irq_vectors_limits.h (renamed from include/asm-i386/mach-generic/irq_vectors_limits.h)0
-rw-r--r--include/asm-x86/mach-generic/mach_apic.h (renamed from include/asm-i386/mach-generic/mach_apic.h)0
-rw-r--r--include/asm-x86/mach-generic/mach_apicdef.h (renamed from include/asm-i386/mach-generic/mach_apicdef.h)0
-rw-r--r--include/asm-x86/mach-generic/mach_ipi.h (renamed from include/asm-i386/mach-generic/mach_ipi.h)0
-rw-r--r--include/asm-x86/mach-generic/mach_mpparse.h (renamed from include/asm-i386/mach-generic/mach_mpparse.h)0
-rw-r--r--include/asm-x86/mach-generic/mach_mpspec.h (renamed from include/asm-i386/mach-generic/mach_mpspec.h)0
-rw-r--r--include/asm-x86/mach-numaq/mach_apic.h (renamed from include/asm-i386/mach-numaq/mach_apic.h)0
-rw-r--r--include/asm-x86/mach-numaq/mach_apicdef.h (renamed from include/asm-i386/mach-numaq/mach_apicdef.h)0
-rw-r--r--include/asm-x86/mach-numaq/mach_ipi.h (renamed from include/asm-i386/mach-numaq/mach_ipi.h)0
-rw-r--r--include/asm-x86/mach-numaq/mach_mpparse.h (renamed from include/asm-i386/mach-numaq/mach_mpparse.h)0
-rw-r--r--include/asm-x86/mach-numaq/mach_mpspec.h (renamed from include/asm-i386/mach-numaq/mach_mpspec.h)0
-rw-r--r--include/asm-x86/mach-numaq/mach_wakecpu.h (renamed from include/asm-i386/mach-numaq/mach_wakecpu.h)0
-rw-r--r--include/asm-x86/mach-summit/irq_vectors_limits.h (renamed from include/asm-i386/mach-summit/irq_vectors_limits.h)0
-rw-r--r--include/asm-x86/mach-summit/mach_apic.h (renamed from include/asm-i386/mach-summit/mach_apic.h)0
-rw-r--r--include/asm-x86/mach-summit/mach_apicdef.h (renamed from include/asm-i386/mach-summit/mach_apicdef.h)0
-rw-r--r--include/asm-x86/mach-summit/mach_ipi.h (renamed from include/asm-i386/mach-summit/mach_ipi.h)0
-rw-r--r--include/asm-x86/mach-summit/mach_mpparse.h (renamed from include/asm-i386/mach-summit/mach_mpparse.h)0
-rw-r--r--include/asm-x86/mach-summit/mach_mpspec.h (renamed from include/asm-i386/mach-summit/mach_mpspec.h)0
-rw-r--r--include/asm-x86/mach-visws/cobalt.h (renamed from include/asm-i386/mach-visws/cobalt.h)0
-rw-r--r--include/asm-x86/mach-visws/entry_arch.h (renamed from include/asm-i386/mach-visws/entry_arch.h)0
-rw-r--r--include/asm-x86/mach-visws/irq_vectors.h (renamed from include/asm-i386/mach-visws/irq_vectors.h)0
-rw-r--r--include/asm-x86/mach-visws/lithium.h (renamed from include/asm-i386/mach-visws/lithium.h)0
-rw-r--r--include/asm-x86/mach-visws/mach_apic.h (renamed from include/asm-i386/mach-visws/mach_apic.h)0
-rw-r--r--include/asm-x86/mach-visws/mach_apicdef.h (renamed from include/asm-i386/mach-visws/mach_apicdef.h)0
-rw-r--r--include/asm-x86/mach-visws/piix4.h (renamed from include/asm-i386/mach-visws/piix4.h)0
-rw-r--r--include/asm-x86/mach-visws/setup_arch.h (renamed from include/asm-i386/mach-visws/setup_arch.h)0
-rw-r--r--include/asm-x86/mach-visws/smpboot_hooks.h (renamed from include/asm-i386/mach-visws/smpboot_hooks.h)0
-rw-r--r--include/asm-x86/mach-voyager/do_timer.h (renamed from include/asm-i386/mach-voyager/do_timer.h)0
-rw-r--r--include/asm-x86/mach-voyager/entry_arch.h (renamed from include/asm-i386/mach-voyager/entry_arch.h)0
-rw-r--r--include/asm-x86/mach-voyager/irq_vectors.h (renamed from include/asm-i386/mach-voyager/irq_vectors.h)0
-rw-r--r--include/asm-x86/mach-voyager/setup_arch.h (renamed from include/asm-i386/mach-voyager/setup_arch.h)0
-rw-r--r--include/asm-x86/mach_apic.h (renamed from include/asm-x86_64/mach_apic.h)0
-rw-r--r--include/asm-x86/math_emu.h (renamed from include/asm-i386/math_emu.h)0
-rw-r--r--include/asm-x86/mc146818rtc.h5
-rw-r--r--include/asm-x86/mc146818rtc_32.h (renamed from include/asm-i386/mc146818rtc.h)0
-rw-r--r--include/asm-x86/mc146818rtc_64.h (renamed from include/asm-x86_64/mc146818rtc.h)0
-rw-r--r--include/asm-x86/mca.h (renamed from include/asm-i386/mca.h)0
-rw-r--r--include/asm-x86/mca_dma.h (renamed from include/asm-i386/mca_dma.h)0
-rw-r--r--include/asm-x86/mce.h5
-rw-r--r--include/asm-x86/mce_32.h (renamed from include/asm-i386/mce.h)0
-rw-r--r--include/asm-x86/mce_64.h (renamed from include/asm-x86_64/mce.h)0
-rw-r--r--include/asm-x86/mman.h13
-rw-r--r--include/asm-x86/mman_32.h (renamed from include/asm-i386/mman.h)0
-rw-r--r--include/asm-x86/mman_64.h (renamed from include/asm-x86_64/mman.h)0
-rw-r--r--include/asm-x86/mmsegment.h (renamed from include/asm-x86_64/mmsegment.h)0
-rw-r--r--include/asm-x86/mmu.h5
-rw-r--r--include/asm-x86/mmu_32.h (renamed from include/asm-i386/mmu.h)0
-rw-r--r--include/asm-x86/mmu_64.h (renamed from include/asm-x86_64/mmu.h)0
-rw-r--r--include/asm-x86/mmu_context.h5
-rw-r--r--include/asm-x86/mmu_context_32.h (renamed from include/asm-i386/mmu_context.h)0
-rw-r--r--include/asm-x86/mmu_context_64.h (renamed from include/asm-x86_64/mmu_context.h)0
-rw-r--r--include/asm-x86/mmx.h (renamed from include/asm-i386/mmx.h)0
-rw-r--r--include/asm-x86/mmzone.h5
-rw-r--r--include/asm-x86/mmzone_32.h (renamed from include/asm-i386/mmzone.h)0
-rw-r--r--include/asm-x86/mmzone_64.h (renamed from include/asm-x86_64/mmzone.h)0
-rw-r--r--include/asm-x86/module.h5
-rw-r--r--include/asm-x86/module_32.h (renamed from include/asm-i386/module.h)0
-rw-r--r--include/asm-x86/module_64.h (renamed from include/asm-x86_64/module.h)0
-rw-r--r--include/asm-x86/mpspec.h5
-rw-r--r--include/asm-x86/mpspec_32.h (renamed from include/asm-i386/mpspec.h)0
-rw-r--r--include/asm-x86/mpspec_64.h (renamed from include/asm-x86_64/mpspec.h)0
-rw-r--r--include/asm-x86/mpspec_def.h (renamed from include/asm-i386/mpspec_def.h)0
-rw-r--r--include/asm-x86/msgbuf.h13
-rw-r--r--include/asm-x86/msgbuf_32.h (renamed from include/asm-i386/msgbuf.h)0
-rw-r--r--include/asm-x86/msgbuf_64.h (renamed from include/asm-x86_64/msgbuf.h)0
-rw-r--r--include/asm-x86/msidef.h (renamed from include/asm-i386/msidef.h)0
-rw-r--r--include/asm-x86/msr-index.h (renamed from include/asm-i386/msr-index.h)0
-rw-r--r--include/asm-x86/msr.h13
-rw-r--r--include/asm-x86/msr_32.h (renamed from include/asm-i386/msr.h)0
-rw-r--r--include/asm-x86/msr_64.h (renamed from include/asm-x86_64/msr.h)0
-rw-r--r--include/asm-x86/mtrr.h13
-rw-r--r--include/asm-x86/mtrr_32.h (renamed from include/asm-i386/mtrr.h)0
-rw-r--r--include/asm-x86/mtrr_64.h (renamed from include/asm-x86_64/mtrr.h)0
-rw-r--r--include/asm-x86/mutex.h5
-rw-r--r--include/asm-x86/mutex_32.h (renamed from include/asm-i386/mutex.h)0
-rw-r--r--include/asm-x86/mutex_64.h (renamed from include/asm-x86_64/mutex.h)0
-rw-r--r--include/asm-x86/namei.h5
-rw-r--r--include/asm-x86/namei_32.h (renamed from include/asm-i386/namei.h)0
-rw-r--r--include/asm-x86/namei_64.h (renamed from include/asm-x86_64/namei.h)0
-rw-r--r--include/asm-x86/nmi.h5
-rw-r--r--include/asm-x86/nmi_32.h (renamed from include/asm-i386/nmi.h)0
-rw-r--r--include/asm-x86/nmi_64.h (renamed from include/asm-x86_64/nmi.h)0
-rw-r--r--include/asm-x86/numa.h5
-rw-r--r--include/asm-x86/numa_32.h (renamed from include/asm-i386/numa.h)0
-rw-r--r--include/asm-x86/numa_64.h (renamed from include/asm-x86_64/numa.h)0
-rw-r--r--include/asm-x86/numaq.h (renamed from include/asm-i386/numaq.h)0
-rw-r--r--include/asm-x86/page.h13
-rw-r--r--include/asm-x86/page_32.h (renamed from include/asm-i386/page.h)0
-rw-r--r--include/asm-x86/page_64.h (renamed from include/asm-x86_64/page.h)0
-rw-r--r--include/asm-x86/param.h13
-rw-r--r--include/asm-x86/param_32.h (renamed from include/asm-i386/param.h)0
-rw-r--r--include/asm-x86/param_64.h (renamed from include/asm-x86_64/param.h)0
-rw-r--r--include/asm-x86/paravirt.h (renamed from include/asm-i386/paravirt.h)0
-rw-r--r--include/asm-x86/parport.h5
-rw-r--r--include/asm-x86/parport_32.h (renamed from include/asm-i386/parport.h)0
-rw-r--r--include/asm-x86/parport_64.h (renamed from include/asm-x86_64/parport.h)0
-rw-r--r--include/asm-x86/pci-direct.h (renamed from include/asm-x86_64/pci-direct.h)0
-rw-r--r--include/asm-x86/pci.h5
-rw-r--r--include/asm-x86/pci_32.h (renamed from include/asm-i386/pci.h)0
-rw-r--r--include/asm-x86/pci_64.h (renamed from include/asm-x86_64/pci.h)0
-rw-r--r--include/asm-x86/pda.h (renamed from include/asm-x86_64/pda.h)0
-rw-r--r--include/asm-x86/percpu.h5
-rw-r--r--include/asm-x86/percpu_32.h (renamed from include/asm-i386/percpu.h)0
-rw-r--r--include/asm-x86/percpu_64.h (renamed from include/asm-x86_64/percpu.h)0
-rw-r--r--include/asm-x86/pgalloc.h5
-rw-r--r--include/asm-x86/pgalloc_32.h (renamed from include/asm-i386/pgalloc.h)0
-rw-r--r--include/asm-x86/pgalloc_64.h (renamed from include/asm-x86_64/pgalloc.h)0
-rw-r--r--include/asm-x86/pgtable-2level-defs.h (renamed from include/asm-i386/pgtable-2level-defs.h)0
-rw-r--r--include/asm-x86/pgtable-2level.h (renamed from include/asm-i386/pgtable-2level.h)0
-rw-r--r--include/asm-x86/pgtable-3level-defs.h (renamed from include/asm-i386/pgtable-3level-defs.h)0
-rw-r--r--include/asm-x86/pgtable-3level.h (renamed from include/asm-i386/pgtable-3level.h)0
-rw-r--r--include/asm-x86/pgtable.h5
-rw-r--r--include/asm-x86/pgtable_32.h (renamed from include/asm-i386/pgtable.h)0
-rw-r--r--include/asm-x86/pgtable_64.h (renamed from include/asm-x86_64/pgtable.h)0
-rw-r--r--include/asm-x86/poll.h (renamed from include/asm-i386/poll.h)0
-rw-r--r--include/asm-x86/posix_types.h13
-rw-r--r--include/asm-x86/posix_types_32.h (renamed from include/asm-i386/posix_types.h)0
-rw-r--r--include/asm-x86/posix_types_64.h (renamed from include/asm-x86_64/posix_types.h)0
-rw-r--r--include/asm-x86/prctl.h (renamed from include/asm-x86_64/prctl.h)0
-rw-r--r--include/asm-x86/processor-cyrix.h (renamed from include/asm-i386/processor-cyrix.h)0
-rw-r--r--include/asm-x86/processor-flags.h (renamed from include/asm-i386/processor-flags.h)0
-rw-r--r--include/asm-x86/processor.h5
-rw-r--r--include/asm-x86/processor_32.h (renamed from include/asm-i386/processor.h)0
-rw-r--r--include/asm-x86/processor_64.h (renamed from include/asm-x86_64/processor.h)0
-rw-r--r--include/asm-x86/proto.h (renamed from include/asm-x86_64/proto.h)0
-rw-r--r--include/asm-x86/ptrace-abi.h13
-rw-r--r--include/asm-x86/ptrace-abi_32.h (renamed from include/asm-i386/ptrace-abi.h)0
-rw-r--r--include/asm-x86/ptrace-abi_64.h (renamed from include/asm-x86_64/ptrace-abi.h)0
-rw-r--r--include/asm-x86/ptrace.h13
-rw-r--r--include/asm-x86/ptrace_32.h (renamed from include/asm-i386/ptrace.h)0
-rw-r--r--include/asm-x86/ptrace_64.h (renamed from include/asm-x86_64/ptrace.h)0
-rw-r--r--include/asm-x86/reboot.h (renamed from include/asm-i386/reboot.h)0
-rw-r--r--include/asm-x86/reboot_fixups.h (renamed from include/asm-i386/reboot_fixups.h)0
-rw-r--r--include/asm-x86/required-features.h5
-rw-r--r--include/asm-x86/required-features_32.h (renamed from include/asm-i386/required-features.h)0
-rw-r--r--include/asm-x86/required-features_64.h (renamed from include/asm-x86_64/required-features.h)0
-rw-r--r--include/asm-x86/resource.h13
-rw-r--r--include/asm-x86/resource_32.h (renamed from include/asm-i386/resource.h)0
-rw-r--r--include/asm-x86/resource_64.h (renamed from include/asm-x86_64/resource.h)0
-rw-r--r--include/asm-x86/resume-trace.h5
-rw-r--r--include/asm-x86/resume-trace_32.h (renamed from include/asm-i386/resume-trace.h)0
-rw-r--r--include/asm-x86/resume-trace_64.h (renamed from include/asm-x86_64/resume-trace.h)0
-rw-r--r--include/asm-x86/rio.h (renamed from include/asm-x86_64/rio.h)0
-rw-r--r--include/asm-x86/rtc.h5
-rw-r--r--include/asm-x86/rtc_32.h (renamed from include/asm-i386/rtc.h)0
-rw-r--r--include/asm-x86/rtc_64.h (renamed from include/asm-x86_64/rtc.h)0
-rw-r--r--include/asm-x86/rwlock.h5
-rw-r--r--include/asm-x86/rwlock_32.h (renamed from include/asm-i386/rwlock.h)0
-rw-r--r--include/asm-x86/rwlock_64.h (renamed from include/asm-x86_64/rwlock.h)0
-rw-r--r--include/asm-x86/rwsem.h (renamed from include/asm-i386/rwsem.h)0
-rw-r--r--include/asm-x86/scatterlist.h5
-rw-r--r--include/asm-x86/scatterlist_32.h (renamed from include/asm-i386/scatterlist.h)0
-rw-r--r--include/asm-x86/scatterlist_64.h (renamed from include/asm-x86_64/scatterlist.h)0
-rw-r--r--include/asm-x86/seccomp.h5
-rw-r--r--include/asm-x86/seccomp_32.h (renamed from include/asm-i386/seccomp.h)0
-rw-r--r--include/asm-x86/seccomp_64.h (renamed from include/asm-x86_64/seccomp.h)0
-rw-r--r--include/asm-x86/sections.h5
-rw-r--r--include/asm-x86/sections_32.h (renamed from include/asm-i386/sections.h)0
-rw-r--r--include/asm-x86/sections_64.h (renamed from include/asm-x86_64/sections.h)0
-rw-r--r--include/asm-x86/segment.h5
-rw-r--r--include/asm-x86/segment_32.h (renamed from include/asm-i386/segment.h)0
-rw-r--r--include/asm-x86/segment_64.h (renamed from include/asm-x86_64/segment.h)0
-rw-r--r--include/asm-x86/semaphore.h5
-rw-r--r--include/asm-x86/semaphore_32.h (renamed from include/asm-i386/semaphore.h)0
-rw-r--r--include/asm-x86/semaphore_64.h (renamed from include/asm-x86_64/semaphore.h)0
-rw-r--r--include/asm-x86/sembuf.h13
-rw-r--r--include/asm-x86/sembuf_32.h (renamed from include/asm-i386/sembuf.h)0
-rw-r--r--include/asm-x86/sembuf_64.h (renamed from include/asm-x86_64/sembuf.h)0
-rw-r--r--include/asm-x86/serial.h5
-rw-r--r--include/asm-x86/serial_32.h (renamed from include/asm-i386/serial.h)0
-rw-r--r--include/asm-x86/serial_64.h (renamed from include/asm-x86_64/serial.h)0
-rw-r--r--include/asm-x86/setup.h13
-rw-r--r--include/asm-x86/setup_32.h (renamed from include/asm-i386/setup.h)0
-rw-r--r--include/asm-x86/setup_64.h (renamed from include/asm-x86_64/setup.h)0
-rw-r--r--include/asm-x86/shmbuf.h13
-rw-r--r--include/asm-x86/shmbuf_32.h (renamed from include/asm-i386/shmbuf.h)0
-rw-r--r--include/asm-x86/shmbuf_64.h (renamed from include/asm-x86_64/shmbuf.h)0
-rw-r--r--include/asm-x86/shmparam.h13
-rw-r--r--include/asm-x86/shmparam_32.h (renamed from include/asm-i386/shmparam.h)0
-rw-r--r--include/asm-x86/shmparam_64.h (renamed from include/asm-x86_64/shmparam.h)0
-rw-r--r--include/asm-x86/sigcontext.h13
-rw-r--r--include/asm-x86/sigcontext32.h (renamed from include/asm-x86_64/sigcontext32.h)0
-rw-r--r--include/asm-x86/sigcontext_32.h (renamed from include/asm-i386/sigcontext.h)0
-rw-r--r--include/asm-x86/sigcontext_64.h (renamed from include/asm-x86_64/sigcontext.h)0
-rw-r--r--include/asm-x86/siginfo.h13
-rw-r--r--include/asm-x86/siginfo_32.h (renamed from include/asm-i386/siginfo.h)0
-rw-r--r--include/asm-x86/siginfo_64.h (renamed from include/asm-x86_64/siginfo.h)0
-rw-r--r--include/asm-x86/signal.h13
-rw-r--r--include/asm-x86/signal_32.h (renamed from include/asm-i386/signal.h)0
-rw-r--r--include/asm-x86/signal_64.h (renamed from include/asm-x86_64/signal.h)0
-rw-r--r--include/asm-x86/smp.h5
-rw-r--r--include/asm-x86/smp_32.h (renamed from include/asm-i386/smp.h)0
-rw-r--r--include/asm-x86/smp_64.h (renamed from include/asm-x86_64/smp.h)0
-rw-r--r--include/asm-x86/socket.h (renamed from include/asm-i386/socket.h)0
-rw-r--r--include/asm-x86/sockios.h13
-rw-r--r--include/asm-x86/sockios_32.h (renamed from include/asm-i386/sockios.h)0
-rw-r--r--include/asm-x86/sockios_64.h (renamed from include/asm-x86_64/sockios.h)0
-rw-r--r--include/asm-x86/sparsemem.h5
-rw-r--r--include/asm-x86/sparsemem_32.h (renamed from include/asm-i386/sparsemem.h)0
-rw-r--r--include/asm-x86/sparsemem_64.h (renamed from include/asm-x86_64/sparsemem.h)0
-rw-r--r--include/asm-x86/spinlock.h5
-rw-r--r--include/asm-x86/spinlock_32.h (renamed from include/asm-i386/spinlock.h)0
-rw-r--r--include/asm-x86/spinlock_64.h (renamed from include/asm-x86_64/spinlock.h)0
-rw-r--r--include/asm-x86/spinlock_types.h (renamed from include/asm-i386/spinlock_types.h)0
-rw-r--r--include/asm-x86/srat.h (renamed from include/asm-i386/srat.h)0
-rw-r--r--include/asm-x86/stacktrace.h (renamed from include/asm-x86_64/stacktrace.h)0
-rw-r--r--include/asm-x86/stat.h13
-rw-r--r--include/asm-x86/stat_32.h (renamed from include/asm-i386/stat.h)0
-rw-r--r--include/asm-x86/stat_64.h (renamed from include/asm-x86_64/stat.h)0
-rw-r--r--include/asm-x86/statfs.h13
-rw-r--r--include/asm-x86/statfs_32.h (renamed from include/asm-i386/statfs.h)0
-rw-r--r--include/asm-x86/statfs_64.h (renamed from include/asm-x86_64/statfs.h)0
-rw-r--r--include/asm-x86/string.h5
-rw-r--r--include/asm-x86/string_32.h (renamed from include/asm-i386/string.h)0
-rw-r--r--include/asm-x86/string_64.h (renamed from include/asm-x86_64/string.h)0
-rw-r--r--include/asm-x86/suspend.h5
-rw-r--r--include/asm-x86/suspend_32.h (renamed from include/asm-i386/suspend.h)0
-rw-r--r--include/asm-x86/suspend_64.h (renamed from include/asm-x86_64/suspend.h)0
-rw-r--r--include/asm-x86/swiotlb.h (renamed from include/asm-x86_64/swiotlb.h)0
-rw-r--r--include/asm-x86/sync_bitops.h (renamed from include/asm-i386/sync_bitops.h)0
-rw-r--r--include/asm-x86/system.h5
-rw-r--r--include/asm-x86/system_32.h (renamed from include/asm-i386/system.h)0
-rw-r--r--include/asm-x86/system_64.h (renamed from include/asm-x86_64/system.h)0
-rw-r--r--include/asm-x86/tce.h (renamed from include/asm-x86_64/tce.h)0
-rw-r--r--include/asm-x86/termbits.h13
-rw-r--r--include/asm-x86/termbits_32.h (renamed from include/asm-i386/termbits.h)0
-rw-r--r--include/asm-x86/termbits_64.h (renamed from include/asm-x86_64/termbits.h)0
-rw-r--r--include/asm-x86/termios.h13
-rw-r--r--include/asm-x86/termios_32.h90
-rw-r--r--include/asm-x86/termios_64.h (renamed from include/asm-x86_64/termios.h)0
-rw-r--r--include/asm-x86/therm_throt.h (renamed from include/asm-i386/therm_throt.h)0
-rw-r--r--include/asm-x86/thread_info.h5
-rw-r--r--include/asm-x86/thread_info_32.h (renamed from include/asm-i386/thread_info.h)0
-rw-r--r--include/asm-x86/thread_info_64.h (renamed from include/asm-x86_64/thread_info.h)0
-rw-r--r--include/asm-x86/time.h (renamed from include/asm-i386/time.h)0
-rw-r--r--include/asm-x86/timer.h (renamed from include/asm-i386/timer.h)0
-rw-r--r--include/asm-x86/timex.h5
-rw-r--r--include/asm-x86/timex_32.h (renamed from include/asm-i386/timex.h)0
-rw-r--r--include/asm-x86/timex_64.h (renamed from include/asm-x86_64/timex.h)0
-rw-r--r--include/asm-x86/tlb.h5
-rw-r--r--include/asm-x86/tlb_32.h (renamed from include/asm-i386/tlb.h)0
-rw-r--r--include/asm-x86/tlb_64.h (renamed from include/asm-x86_64/tlb.h)0
-rw-r--r--include/asm-x86/tlbflush.h5
-rw-r--r--include/asm-x86/tlbflush_32.h (renamed from include/asm-i386/tlbflush.h)0
-rw-r--r--include/asm-x86/tlbflush_64.h (renamed from include/asm-x86_64/tlbflush.h)0
-rw-r--r--include/asm-x86/topology.h5
-rw-r--r--include/asm-x86/topology_32.h (renamed from include/asm-i386/topology.h)0
-rw-r--r--include/asm-x86/topology_64.h (renamed from include/asm-x86_64/topology.h)0
-rw-r--r--include/asm-x86/tsc.h (renamed from include/asm-i386/tsc.h)0
-rw-r--r--include/asm-x86/types.h13
-rw-r--r--include/asm-x86/types_32.h (renamed from include/asm-i386/types.h)0
-rw-r--r--include/asm-x86/types_64.h (renamed from include/asm-x86_64/types.h)0
-rw-r--r--include/asm-x86/uaccess.h5
-rw-r--r--include/asm-x86/uaccess_32.h (renamed from include/asm-i386/uaccess.h)0
-rw-r--r--include/asm-x86/uaccess_64.h (renamed from include/asm-x86_64/uaccess.h)0
-rw-r--r--include/asm-x86/ucontext.h13
-rw-r--r--include/asm-x86/ucontext_32.h (renamed from include/asm-i386/ucontext.h)0
-rw-r--r--include/asm-x86/ucontext_64.h (renamed from include/asm-x86_64/ucontext.h)0
-rw-r--r--include/asm-x86/unaligned.h5
-rw-r--r--include/asm-x86/unaligned_32.h (renamed from include/asm-i386/unaligned.h)0
-rw-r--r--include/asm-x86/unaligned_64.h (renamed from include/asm-x86_64/unaligned.h)0
-rw-r--r--include/asm-x86/unistd.h13
-rw-r--r--include/asm-x86/unistd_32.h (renamed from include/asm-i386/unistd.h)0
-rw-r--r--include/asm-x86/unistd_64.h (renamed from include/asm-x86_64/unistd.h)0
-rw-r--r--include/asm-x86/unwind.h5
-rw-r--r--include/asm-x86/unwind_32.h (renamed from include/asm-i386/unwind.h)0
-rw-r--r--include/asm-x86/unwind_64.h (renamed from include/asm-x86_64/unwind.h)0
-rw-r--r--include/asm-x86/user.h13
-rw-r--r--include/asm-x86/user32.h (renamed from include/asm-x86_64/user32.h)0
-rw-r--r--include/asm-x86/user_32.h (renamed from include/asm-i386/user.h)0
-rw-r--r--include/asm-x86/user_64.h (renamed from include/asm-x86_64/user.h)0
-rw-r--r--include/asm-x86/vga.h (renamed from include/asm-i386/vga.h)0
-rw-r--r--include/asm-x86/vgtod.h (renamed from include/asm-x86_64/vgtod.h)0
-rw-r--r--include/asm-x86/vic.h (renamed from include/asm-i386/vic.h)0
-rw-r--r--include/asm-x86/vm86.h (renamed from include/asm-i386/vm86.h)0
-rw-r--r--include/asm-x86/vmi.h (renamed from include/asm-i386/vmi.h)0
-rw-r--r--include/asm-x86/vmi_time.h (renamed from include/asm-i386/vmi_time.h)0
-rw-r--r--include/asm-x86/voyager.h (renamed from include/asm-i386/voyager.h)0
-rw-r--r--include/asm-x86/vsyscall.h (renamed from include/asm-x86_64/vsyscall.h)0
-rw-r--r--include/asm-x86/vsyscall32.h (renamed from include/asm-x86_64/vsyscall32.h)0
-rw-r--r--include/asm-x86/xen/hypercall.h (renamed from include/asm-i386/xen/hypercall.h)0
-rw-r--r--include/asm-x86/xen/hypervisor.h (renamed from include/asm-i386/xen/hypervisor.h)0
-rw-r--r--include/asm-x86/xen/interface.h (renamed from include/asm-i386/xen/interface.h)0
-rw-r--r--include/asm-x86/xor.h5
-rw-r--r--include/asm-x86/xor_32.h (renamed from include/asm-i386/xor.h)0
-rw-r--r--include/asm-x86/xor_64.h (renamed from include/asm-x86_64/xor.h)0
-rw-r--r--include/asm-x86_64/Kbuild21
-rw-r--r--include/asm-x86_64/boot.h1
-rw-r--r--include/asm-x86_64/bootparam.h1
-rw-r--r--include/asm-x86_64/cpu.h1
-rw-r--r--include/asm-x86_64/cpufeature.h30
-rw-r--r--include/asm-x86_64/emergency-restart.h6
-rw-r--r--include/asm-x86_64/fcntl.h1
-rw-r--r--include/asm-x86_64/hpet.h18
-rw-r--r--include/asm-x86_64/hypertransport.h1
-rw-r--r--include/asm-x86_64/ide.h1
-rw-r--r--include/asm-x86_64/ioctl.h1
-rw-r--r--include/asm-x86_64/ist.h1
-rw-r--r--include/asm-x86_64/msidef.h1
-rw-r--r--include/asm-x86_64/msr-index.h1
-rw-r--r--include/asm-x86_64/node.h1
-rw-r--r--include/asm-x86_64/poll.h1
-rw-r--r--include/asm-x86_64/processor-flags.h1
-rw-r--r--include/asm-x86_64/socket.h55
-rw-r--r--include/asm-x86_64/spinlock_types.h20
-rw-r--r--include/asm-x86_64/therm_throt.h1
-rw-r--r--include/asm-x86_64/tsc.h1
-rw-r--r--include/asm-x86_64/vga.h20
-rw-r--r--include/linux/bio.h6
-rw-r--r--include/linux/blkdev.h25
-rw-r--r--include/linux/blktrace_api.h12
-rw-r--r--include/linux/i2c-id.h2
-rw-r--r--include/linux/ivtv.h72
-rw-r--r--include/linux/ivtvfb.h42
-rw-r--r--include/linux/mmc/card.h32
-rw-r--r--include/linux/mmc/core.h63
-rw-r--r--include/linux/mmc/host.h39
-rw-r--r--include/linux/mmc/mmc.h39
-rw-r--r--include/linux/mmc/sdio.h159
-rw-r--r--include/linux/mmc/sdio_func.h153
-rw-r--r--include/linux/mmc/sdio_ids.h23
-rw-r--r--include/linux/mod_devicetable.h11
-rw-r--r--include/linux/pci_ids.h7
-rw-r--r--include/linux/spi/mmc_spi.h33
-rw-r--r--include/linux/swap.h2
-rw-r--r--include/linux/umem.h138
-rw-r--r--include/linux/videodev2.h7
-rw-r--r--include/linux/writeback.h1
-rw-r--r--include/media/cx2341x.h2
-rw-r--r--include/media/ir-common.h1
-rw-r--r--include/media/ivtv.h65
-rw-r--r--include/media/saa7146.h1
-rw-r--r--include/media/saa7146_vv.h2
-rw-r--r--include/media/tuner-types.h4
-rw-r--r--include/media/tuner.h1
-rw-r--r--include/media/v4l2-chip-ident.h3
-rw-r--r--include/media/v4l2-dev.h16
-rw-r--r--include/media/v4l2-int-device.h278
-rw-r--r--include/media/video-buf.h289
-rw-r--r--include/media/videobuf-core.h236
-rw-r--r--include/media/videobuf-dma-sg.h122
-rw-r--r--include/media/videobuf-dvb.h (renamed from include/media/video-buf-dvb.h)0
-rw-r--r--include/media/videobuf-vmalloc.h41
-rw-r--r--kernel/sched.c1
-rw-r--r--mm/bounce.c25
-rw-r--r--mm/page_io.c12
-rw-r--r--mm/readahead.c1
-rwxr-xr-xscripts/checkstack.pl5
-rwxr-xr-xscripts/checksyscalls.sh2
-rw-r--r--scripts/mod/file2alias.c20
-rwxr-xr-xscripts/namespace.pl8
1630 files changed, 40534 insertions, 19505 deletions
diff --git a/Documentation/block/biodoc.txt b/Documentation/block/biodoc.txt
index 8af392fc6ef0..dc3f49e3e539 100644
--- a/Documentation/block/biodoc.txt
+++ b/Documentation/block/biodoc.txt
@@ -477,9 +477,9 @@ With this multipage bio design:
477 the same bi_io_vec array, but with the index and size accordingly modified) 477 the same bi_io_vec array, but with the index and size accordingly modified)
478- A linked list of bios is used as before for unrelated merges (*) - this 478- A linked list of bios is used as before for unrelated merges (*) - this
479 avoids reallocs and makes independent completions easier to handle. 479 avoids reallocs and makes independent completions easier to handle.
480- Code that traverses the req list needs to make a distinction between 480- Code that traverses the req list can find all the segments of a bio
481 segments of a request (bio_for_each_segment) and the distinct completion 481 by using rq_for_each_segment. This handles the fact that a request
482 units/bios (rq_for_each_bio). 482 has multiple bios, each of which can have multiple segments.
483- Drivers which can't process a large bio in one shot can use the bi_idx 483- Drivers which can't process a large bio in one shot can use the bi_idx
484 field to keep track of the next bio_vec entry to process. 484 field to keep track of the next bio_vec entry to process.
485 (e.g a 1MB bio_vec needs to be handled in max 128kB chunks for IDE) 485 (e.g a 1MB bio_vec needs to be handled in max 128kB chunks for IDE)
@@ -664,14 +664,14 @@ in lvm or md.
664 664
6653.2.1 Traversing segments and completion units in a request 6653.2.1 Traversing segments and completion units in a request
666 666
667The macros bio_for_each_segment() and rq_for_each_bio() should be used for 667The macro rq_for_each_segment() should be used for traversing the bios
668traversing the bios in the request list (drivers should avoid directly 668in the request list (drivers should avoid directly trying to do it
669trying to do it themselves). Using these helpers should also make it easier 669themselves). Using these helpers should also make it easier to cope
670to cope with block changes in the future. 670with block changes in the future.
671 671
672 rq_for_each_bio(bio, rq) 672 struct req_iterator iter;
673 bio_for_each_segment(bio_vec, bio, i) 673 rq_for_each_segment(bio_vec, rq, iter)
674 /* bio_vec is now current segment */ 674 /* bio_vec is now current segment */
675 675
676I/O completion callbacks are per-bio rather than per-segment, so drivers 676I/O completion callbacks are per-bio rather than per-segment, so drivers
677that traverse bio chains on completion need to keep that in mind. Drivers 677that traverse bio chains on completion need to keep that in mind. Drivers
diff --git a/Documentation/block/ioprio.txt b/Documentation/block/ioprio.txt
index 1b930ef5a079..35e516b0b8a9 100644
--- a/Documentation/block/ioprio.txt
+++ b/Documentation/block/ioprio.txt
@@ -86,8 +86,15 @@ extern int sys_ioprio_get(int, int);
86#error "Unsupported arch" 86#error "Unsupported arch"
87#endif 87#endif
88 88
89_syscall3(int, ioprio_set, int, which, int, who, int, ioprio); 89static inline int ioprio_set(int which, int who, int ioprio)
90_syscall2(int, ioprio_get, int, which, int, who); 90{
91 return syscall(__NR_ioprio_set, which, who, ioprio);
92}
93
94static inline int ioprio_get(int which, int who)
95{
96 return syscall(__NR_ioprio_get, which, who);
97}
91 98
92enum { 99enum {
93 IOPRIO_CLASS_NONE, 100 IOPRIO_CLASS_NONE,
diff --git a/Documentation/dvb/faq.txt b/Documentation/dvb/faq.txt
index dbcedf5833ee..2511a335abd6 100644
--- a/Documentation/dvb/faq.txt
+++ b/Documentation/dvb/faq.txt
@@ -150,7 +150,7 @@ Some very frequently asked questions about linuxtv-dvb
150 - saa7146_vv: SAA7146 video and vbi functions. These are only needed 150 - saa7146_vv: SAA7146 video and vbi functions. These are only needed
151 for full-featured cards. 151 for full-featured cards.
152 152
153 - video-buf: capture helper module for the saa7146_vv driver. This 153 - videobuf-dma-sg: capture helper module for the saa7146_vv driver. This
154 one is responsible to handle capture buffers. 154 one is responsible to handle capture buffers.
155 155
156 - dvb-ttpci: The main driver for AV7110 based, full-featured 156 - dvb-ttpci: The main driver for AV7110 based, full-featured
diff --git a/Documentation/feature-removal-schedule.txt b/Documentation/feature-removal-schedule.txt
index 00928d2ecfb2..675f75601ae6 100644
--- a/Documentation/feature-removal-schedule.txt
+++ b/Documentation/feature-removal-schedule.txt
@@ -306,3 +306,11 @@ Why: In kernel tree version of driver is unmaintained. Sk98lin driver
306Who: Stephen Hemminger <shemminger@linux-foundation.org> 306Who: Stephen Hemminger <shemminger@linux-foundation.org>
307 307
308--------------------------- 308---------------------------
309
310What: i386/x86_64 bzImage symlinks
311When: April 2008
312
313Why: The i386/x86_64 merge provides a symlink to the old bzImage
314 location so not yet updated user space tools, e.g. package
315 scripts, do not break.
316Who: Thomas Gleixner <tglx@linutronix.de>
diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index 4d175c751246..a57c1f216b21 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -35,6 +35,7 @@ parameter is applicable:
35 APIC APIC support is enabled. 35 APIC APIC support is enabled.
36 APM Advanced Power Management support is enabled. 36 APM Advanced Power Management support is enabled.
37 AX25 Appropriate AX.25 support is enabled. 37 AX25 Appropriate AX.25 support is enabled.
38 BLACKFIN Blackfin architecture is enabled.
38 DRM Direct Rendering Management support is enabled. 39 DRM Direct Rendering Management support is enabled.
39 EDD BIOS Enhanced Disk Drive Services (EDD) is enabled 40 EDD BIOS Enhanced Disk Drive Services (EDD) is enabled
40 EFI EFI Partitioning (GPT) is enabled 41 EFI EFI Partitioning (GPT) is enabled
@@ -550,7 +551,7 @@ and is between 256 and 4096 characters. It is defined in the file
550 551
551 dtc3181e= [HW,SCSI] 552 dtc3181e= [HW,SCSI]
552 553
553 earlyprintk= [X86-32,X86-64,SH] 554 earlyprintk= [X86-32,X86-64,SH,BLACKFIN]
554 earlyprintk=vga 555 earlyprintk=vga
555 earlyprintk=serial[,ttySn[,baudrate]] 556 earlyprintk=serial[,ttySn[,baudrate]]
556 557
diff --git a/Documentation/lguest/lguest.c b/Documentation/lguest/lguest.c
index 73c5f1f3d5d2..103e346c8b6a 100644
--- a/Documentation/lguest/lguest.c
+++ b/Documentation/lguest/lguest.c
@@ -46,7 +46,7 @@ typedef uint32_t u32;
46typedef uint16_t u16; 46typedef uint16_t u16;
47typedef uint8_t u8; 47typedef uint8_t u8;
48#include "../../include/linux/lguest_launcher.h" 48#include "../../include/linux/lguest_launcher.h"
49#include "../../include/asm-i386/e820.h" 49#include "../../include/asm-x86/e820_32.h"
50/*:*/ 50/*:*/
51 51
52#define PAGE_PRESENT 0x7 /* Present, RW, Execute */ 52#define PAGE_PRESENT 0x7 /* Present, RW, Execute */
diff --git a/Documentation/video4linux/CARDLIST.bttv b/Documentation/video4linux/CARDLIST.bttv
index 177159c5f4c4..d97cf7cc6088 100644
--- a/Documentation/video4linux/CARDLIST.bttv
+++ b/Documentation/video4linux/CARDLIST.bttv
@@ -147,3 +147,4 @@
147146 -> SSAI Ultrasound Video Interface [414a:5353] 147146 -> SSAI Ultrasound Video Interface [414a:5353]
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)
diff --git a/Documentation/video4linux/CARDLIST.cx23885 b/Documentation/video4linux/CARDLIST.cx23885
new file mode 100644
index 000000000000..00cb646a4bde
--- /dev/null
+++ b/Documentation/video4linux/CARDLIST.cx23885
@@ -0,0 +1,5 @@
1 0 -> UNKNOWN/GENERIC [0070:3400]
2 1 -> Hauppauge WinTV-HVR1800lp [0070:7600]
3 2 -> Hauppauge WinTV-HVR1800 [0070:7800,0070:7801]
4 3 -> Hauppauge WinTV-HVR1250 [0070:7911]
5 4 -> DViCO FusionHDTV5 Express [18ac:d500]
diff --git a/Documentation/video4linux/CARDLIST.saa7134 b/Documentation/video4linux/CARDLIST.saa7134
index 3f8aeab50a10..a14545300e4c 100644
--- a/Documentation/video4linux/CARDLIST.saa7134
+++ b/Documentation/video4linux/CARDLIST.saa7134
@@ -88,11 +88,11 @@
88 87 -> ADS Instant TV Duo Cardbus PTV331 [0331:1421] 88 87 -> ADS Instant TV Duo Cardbus PTV331 [0331:1421]
89 88 -> Tevion/KWorld DVB-T 220RF [17de:7201] 89 88 -> Tevion/KWorld DVB-T 220RF [17de:7201]
90 89 -> ELSA EX-VISION 700TV [1048:226c] 90 89 -> ELSA EX-VISION 700TV [1048:226c]
91 90 -> Kworld ATSC110 [17de:7350] 91 90 -> Kworld ATSC110/115 [17de:7350,17de:7352]
92 91 -> AVerMedia A169 B [1461:7360] 92 91 -> AVerMedia A169 B [1461:7360]
93 92 -> AVerMedia A169 B1 [1461:6360] 93 92 -> AVerMedia A169 B1 [1461:6360]
94 93 -> Medion 7134 Bridge #2 [16be:0005] 94 93 -> Medion 7134 Bridge #2 [16be:0005]
95 94 -> LifeView FlyDVB-T Hybrid Cardbus [5168:3306,5168:3502] 95 94 -> LifeView FlyDVB-T Hybrid Cardbus/MSI TV @nywhere A/D NB [5168:3306,5168:3502,4e42:3502]
96 95 -> LifeView FlyVIDEO3000 (NTSC) [5169:0138] 96 95 -> LifeView FlyVIDEO3000 (NTSC) [5169:0138]
97 96 -> Medion Md8800 Quadro [16be:0007,16be:0008] 97 96 -> Medion Md8800 Quadro [16be:0007,16be:0008]
98 97 -> LifeView FlyDVB-S /Acorp TV134DS [5168:0300,4e42:0300] 98 97 -> LifeView FlyDVB-S /Acorp TV134DS [5168:0300,4e42:0300]
@@ -115,3 +115,4 @@
115114 -> KWorld DVB-T 210 [17de:7250] 115114 -> KWorld DVB-T 210 [17de:7250]
116115 -> Sabrent PCMCIA TV-PCB05 [0919:2003] 116115 -> Sabrent PCMCIA TV-PCB05 [0919:2003]
117116 -> 10MOONS TM300 TV Card [1131:2304] 117116 -> 10MOONS TM300 TV Card [1131:2304]
118117 -> Avermedia Super 007 [1461:f01d]
diff --git a/Kbuild b/Kbuild
index 56b8edf6a3bc..1570d248ad92 100644
--- a/Kbuild
+++ b/Kbuild
@@ -8,11 +8,11 @@
8# 1) Generate asm-offsets.h 8# 1) Generate asm-offsets.h
9# 9#
10 10
11offsets-file := include/asm-$(ARCH)/asm-offsets.h 11offsets-file := include/asm-$(SRCARCH)/asm-offsets.h
12 12
13always := $(offsets-file) 13always := $(offsets-file)
14targets := $(offsets-file) 14targets := $(offsets-file)
15targets += arch/$(ARCH)/kernel/asm-offsets.s 15targets += arch/$(SRCARCH)/kernel/asm-offsets.s
16clean-files := $(addprefix $(objtree)/,$(targets)) 16clean-files := $(addprefix $(objtree)/,$(targets))
17 17
18# Default sed regexp - multiline due to syntax constraints 18# Default sed regexp - multiline due to syntax constraints
@@ -40,11 +40,11 @@ define cmd_offsets
40endef 40endef
41 41
42# We use internal kbuild rules to avoid the "is up to date" message from make 42# We use internal kbuild rules to avoid the "is up to date" message from make
43arch/$(ARCH)/kernel/asm-offsets.s: arch/$(ARCH)/kernel/asm-offsets.c FORCE 43arch/$(SRCARCH)/kernel/asm-offsets.s: arch/$(SRCARCH)/kernel/asm-offsets.c FORCE
44 $(Q)mkdir -p $(dir $@) 44 $(Q)mkdir -p $(dir $@)
45 $(call if_changed_dep,cc_s_c) 45 $(call if_changed_dep,cc_s_c)
46 46
47$(obj)/$(offsets-file): arch/$(ARCH)/kernel/asm-offsets.s Kbuild 47$(obj)/$(offsets-file): arch/$(SRCARCH)/kernel/asm-offsets.s Kbuild
48 $(Q)mkdir -p $(dir $@) 48 $(Q)mkdir -p $(dir $@)
49 $(call cmd,offsets) 49 $(call cmd,offsets)
50 50
diff --git a/MAINTAINERS b/MAINTAINERS
index 9a91d9e3f1f2..60162706716f 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -718,34 +718,8 @@ M: rpurdie@rpsys.net
718S: Maintained 718S: Maintained
719 719
720BLACKFIN ARCHITECTURE 720BLACKFIN ARCHITECTURE
721P: Aubrey Li
722M: aubrey.li@analog.com
723P: Bernd Schmidt
724M: bernd.schmidt@analog.com
725P: Bryan Wu 721P: Bryan Wu
726M: bryan.wu@analog.com 722M: bryan.wu@analog.com
727P: Grace Pan
728M: grace.pan@analog.com
729P: Marc Hoffman
730M: marc.hoffman@analog.com
731P: Michael Hennerich
732M: michael.hennerich@analog.com
733P: Mike Frysinger
734M: michael.frysinger@analog.com
735P: Jerry Zeng
736M: jerry.zeng@analog.com
737P: Jie Zhang
738M: jie.zhang@analog.com
739P: Robin Getz
740M: robin.getz@analog.com
741P: Roy Huang
742M: roy.huang@analog.com
743P: Sonic Zhang
744M: sonic.zhang@analog.com
745P: Vivi Li
746M: vivi.li@analog.com
747P: Yi Li
748M: yi.li@analog.com
749L: uclinux-dist-devel@blackfin.uclinux.org (subscribers-only) 723L: uclinux-dist-devel@blackfin.uclinux.org (subscribers-only)
750W: http://blackfin.uclinux.org 724W: http://blackfin.uclinux.org
751S: Supported 725S: Supported
@@ -2561,12 +2535,18 @@ L: linux-kernel@vger.kernel.org
2561W: http://www.atnf.csiro.au/~rgooch/linux/kernel-patches.html 2535W: http://www.atnf.csiro.au/~rgooch/linux/kernel-patches.html
2562S: Maintained 2536S: Maintained
2563 2537
2564MULTIMEDIA CARD (MMC) AND SECURE DIGITAL (SD) SUBSYSTEM 2538MULTIMEDIA CARD (MMC), SECURE DIGITAL (SD) AND SDIO SUBSYSTEM
2565P: Pierre Ossman 2539P: Pierre Ossman
2566M: drzeus-mmc@drzeus.cx 2540M: drzeus-mmc@drzeus.cx
2567L: linux-kernel@vger.kernel.org 2541L: linux-kernel@vger.kernel.org
2568S: Maintained 2542S: Maintained
2569 2543
2544MULTIMEDIA CARD (MMC) ETC. OVER SPI
2545P: David Brownell
2546M: dbrownell@users.sourceforge.net
2547L: linux-kernel@vger.kernel.org
2548S: Odd fixes
2549
2570MULTISOUND SOUND DRIVER 2550MULTISOUND SOUND DRIVER
2571P: Andrew Veliath 2551P: Andrew Veliath
2572M: andrewtv@usa.net 2552M: andrewtv@usa.net
@@ -4176,6 +4156,13 @@ W: http://oss.sgi.com/projects/xfs
4176T: git git://oss.sgi.com:8090/xfs/xfs-2.6.git 4156T: git git://oss.sgi.com:8090/xfs/xfs-2.6.git
4177S: Supported 4157S: Supported
4178 4158
4159XILINX SYSTEMACE DRIVER
4160P: Grant Likely
4161M: grant.likely@secretlab.ca
4162W: http://www.secretlab.ca/
4163L: linux-kernel@vger.kernel.org
4164S: Maintained
4165
4179XILINX UARTLITE SERIAL DRIVER 4166XILINX UARTLITE SERIAL DRIVER
4180P: Peter Korsgaard 4167P: Peter Korsgaard
4181M: jacmet@sunsite.dk 4168M: jacmet@sunsite.dk
diff --git a/Makefile b/Makefile
index 4635a64da36c..1274084c9090 100644
--- a/Makefile
+++ b/Makefile
@@ -186,7 +186,8 @@ ARCH ?= $(SUBARCH)
186CROSS_COMPILE ?= 186CROSS_COMPILE ?=
187 187
188# Architecture as present in compile.h 188# Architecture as present in compile.h
189UTS_MACHINE := $(ARCH) 189UTS_MACHINE := $(ARCH)
190SRCARCH := $(ARCH)
190 191
191KCONFIG_CONFIG ?= .config 192KCONFIG_CONFIG ?= .config
192 193
@@ -322,7 +323,7 @@ KERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null)
322KERNELVERSION = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION) 323KERNELVERSION = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
323 324
324export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION 325export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION
325export ARCH CONFIG_SHELL HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC 326export ARCH SRCARCH CONFIG_SHELL HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC
326export CPP AR NM STRIP OBJCOPY OBJDUMP MAKE AWK GENKSYMS PERL UTS_MACHINE 327export CPP AR NM STRIP OBJCOPY OBJDUMP MAKE AWK GENKSYMS PERL UTS_MACHINE
327export HOSTCXX HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS 328export HOSTCXX HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS
328 329
@@ -609,7 +610,7 @@ libs-y := $(libs-y1) $(libs-y2)
609vmlinux-init := $(head-y) $(init-y) 610vmlinux-init := $(head-y) $(init-y)
610vmlinux-main := $(core-y) $(libs-y) $(drivers-y) $(net-y) 611vmlinux-main := $(core-y) $(libs-y) $(drivers-y) $(net-y)
611vmlinux-all := $(vmlinux-init) $(vmlinux-main) 612vmlinux-all := $(vmlinux-init) $(vmlinux-main)
612vmlinux-lds := arch/$(ARCH)/kernel/vmlinux.lds 613vmlinux-lds := arch/$(SRCARCH)/kernel/vmlinux.lds
613export KBUILD_VMLINUX_OBJS := $(vmlinux-all) 614export KBUILD_VMLINUX_OBJS := $(vmlinux-all)
614 615
615# Rule to link vmlinux - also used during CONFIG_KALLSYMS 616# Rule to link vmlinux - also used during CONFIG_KALLSYMS
@@ -862,7 +863,7 @@ ifneq ($(KBUILD_SRC),)
862 /bin/false; \ 863 /bin/false; \
863 fi; 864 fi;
864 $(Q)if [ ! -d include2 ]; then mkdir -p include2; fi; 865 $(Q)if [ ! -d include2 ]; then mkdir -p include2; fi;
865 $(Q)ln -fsn $(srctree)/include/asm-$(ARCH) include2/asm 866 $(Q)ln -fsn $(srctree)/include/asm-$(SRCARCH) include2/asm
866endif 867endif
867 868
868# prepare2 creates a makefile if using a separate output directory 869# prepare2 creates a makefile if using a separate output directory
@@ -894,9 +895,9 @@ export CPPFLAGS_vmlinux.lds += -P -C -U$(ARCH)
894# before switching between archs anyway. 895# before switching between archs anyway.
895 896
896include/asm: 897include/asm:
897 @echo ' SYMLINK $@ -> include/asm-$(ARCH)' 898 @echo ' SYMLINK $@ -> include/asm-$(SRCARCH)'
898 $(Q)if [ ! -d include ]; then mkdir -p include; fi; 899 $(Q)if [ ! -d include ]; then mkdir -p include; fi;
899 @ln -fsn asm-$(ARCH) $@ 900 @ln -fsn asm-$(SRCARCH) $@
900 901
901# Generate some files 902# Generate some files
902# --------------------------------------------------------------------------- 903# ---------------------------------------------------------------------------
@@ -936,7 +937,8 @@ depend dep:
936INSTALL_HDR_PATH=$(objtree)/usr 937INSTALL_HDR_PATH=$(objtree)/usr
937export INSTALL_HDR_PATH 938export INSTALL_HDR_PATH
938 939
939HDRARCHES=$(filter-out generic,$(patsubst $(srctree)/include/asm-%/Kbuild,%,$(wildcard $(srctree)/include/asm-*/Kbuild))) 940HDRFILTER=generic i386 x86_64
941HDRARCHES=$(filter-out $(HDRFILTER),$(patsubst $(srctree)/include/asm-%/Kbuild,%,$(wildcard $(srctree)/include/asm-*/Kbuild)))
940 942
941PHONY += headers_install_all 943PHONY += headers_install_all
942headers_install_all: include/linux/version.h scripts_basic FORCE 944headers_install_all: include/linux/version.h scripts_basic FORCE
@@ -947,11 +949,11 @@ headers_install_all: include/linux/version.h scripts_basic FORCE
947 949
948PHONY += headers_install 950PHONY += headers_install
949headers_install: include/linux/version.h scripts_basic FORCE 951headers_install: include/linux/version.h scripts_basic FORCE
950 @if [ ! -r $(srctree)/include/asm-$(ARCH)/Kbuild ]; then \ 952 @if [ ! -r $(srctree)/include/asm-$(SRCARCH)/Kbuild ]; then \
951 echo '*** Error: Headers not exportable for this architecture ($(ARCH))'; \ 953 echo '*** Error: Headers not exportable for this architecture ($(SRCARCH))'; \
952 exit 1 ; fi 954 exit 1 ; fi
953 $(Q)$(MAKE) $(build)=scripts scripts/unifdef 955 $(Q)$(MAKE) $(build)=scripts scripts/unifdef
954 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.headersinst obj=include 956 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.headersinst ARCH=$(SRCARCH) obj=include
955 957
956PHONY += headers_check_all 958PHONY += headers_check_all
957headers_check_all: headers_install_all 959headers_check_all: headers_install_all
@@ -961,7 +963,7 @@ headers_check_all: headers_install_all
961 963
962PHONY += headers_check 964PHONY += headers_check
963headers_check: headers_install 965headers_check: headers_install
964 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.headersinst obj=include HDRCHECK=1 966 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.headersinst ARCH=$(SRCARCH) obj=include HDRCHECK=1
965 967
966# --------------------------------------------------------------------------- 968# ---------------------------------------------------------------------------
967# Modules 969# Modules
@@ -1139,7 +1141,7 @@ help:
1139 @echo ' cscope - Generate cscope index' 1141 @echo ' cscope - Generate cscope index'
1140 @echo ' kernelrelease - Output the release version string' 1142 @echo ' kernelrelease - Output the release version string'
1141 @echo ' kernelversion - Output the version stored in Makefile' 1143 @echo ' kernelversion - Output the version stored in Makefile'
1142 @if [ -r $(srctree)/include/asm-$(ARCH)/Kbuild ]; then \ 1144 @if [ -r $(srctree)/include/asm-$(SRCARCH)/Kbuild ]; then \
1143 echo ' headers_install - Install sanitised kernel headers to INSTALL_HDR_PATH'; \ 1145 echo ' headers_install - Install sanitised kernel headers to INSTALL_HDR_PATH'; \
1144 echo ' (default: $(INSTALL_HDR_PATH))'; \ 1146 echo ' (default: $(INSTALL_HDR_PATH))'; \
1145 fi 1147 fi
@@ -1147,7 +1149,7 @@ help:
1147 @echo 'Static analysers' 1149 @echo 'Static analysers'
1148 @echo ' checkstack - Generate a list of stack hogs' 1150 @echo ' checkstack - Generate a list of stack hogs'
1149 @echo ' namespacecheck - Name space analysis on compiled kernel' 1151 @echo ' namespacecheck - Name space analysis on compiled kernel'
1150 @if [ -r $(srctree)/include/asm-$(ARCH)/Kbuild ]; then \ 1152 @if [ -r $(srctree)/include/asm-$(SRCARCH)/Kbuild ]; then \
1151 echo ' headers_check - Sanity check on exported headers'; \ 1153 echo ' headers_check - Sanity check on exported headers'; \
1152 fi 1154 fi
1153 @echo '' 1155 @echo ''
@@ -1292,18 +1294,23 @@ ifeq ($(ALLSOURCE_ARCHS),)
1292ifeq ($(ARCH),um) 1294ifeq ($(ARCH),um)
1293ALLINCLUDE_ARCHS := $(ARCH) $(SUBARCH) 1295ALLINCLUDE_ARCHS := $(ARCH) $(SUBARCH)
1294else 1296else
1295ALLINCLUDE_ARCHS := $(ARCH) 1297ALLINCLUDE_ARCHS := $(SRCARCH)
1296endif 1298endif
1297else 1299else
1298#Allow user to specify only ALLSOURCE_PATHS on the command line, keeping existing behavour. 1300#Allow user to specify only ALLSOURCE_PATHS on the command line, keeping existing behavour.
1299ALLINCLUDE_ARCHS := $(ALLSOURCE_ARCHS) 1301ALLINCLUDE_ARCHS := $(ALLSOURCE_ARCHS)
1300endif 1302endif
1301 1303
1304# Take care of arch/x86
1305ifeq ($(ARCH), $(SRCARCH))
1302ALLSOURCE_ARCHS := $(ARCH) 1306ALLSOURCE_ARCHS := $(ARCH)
1307else
1308ALLSOURCE_ARCHS := $(ARCH) $(SRCARCH)
1309endif
1303 1310
1304define find-sources 1311define find-sources
1305 ( for ARCH in $(ALLSOURCE_ARCHS) ; do \ 1312 ( for ARCH in $(ALLSOURCE_ARCHS) ; do \
1306 find $(__srctree)arch/$${ARCH} $(RCS_FIND_IGNORE) \ 1313 find $(__srctree)arch/$${SRCARCH} $(RCS_FIND_IGNORE) \
1307 -name $1 -print; \ 1314 -name $1 -print; \
1308 done ; \ 1315 done ; \
1309 find $(__srctree)security/selinux/include $(RCS_FIND_IGNORE) \ 1316 find $(__srctree)security/selinux/include $(RCS_FIND_IGNORE) \
@@ -1312,7 +1319,7 @@ define find-sources
1312 \( -name config -o -name 'asm-*' \) -prune \ 1319 \( -name config -o -name 'asm-*' \) -prune \
1313 -o -name $1 -print; \ 1320 -o -name $1 -print; \
1314 for ARCH in $(ALLINCLUDE_ARCHS) ; do \ 1321 for ARCH in $(ALLINCLUDE_ARCHS) ; do \
1315 find $(__srctree)include/asm-$${ARCH} $(RCS_FIND_IGNORE) \ 1322 find $(__srctree)include/asm-$${SRCARCH} $(RCS_FIND_IGNORE) \
1316 -name $1 -print; \ 1323 -name $1 -print; \
1317 done ; \ 1324 done ; \
1318 find $(__srctree)include/asm-generic $(RCS_FIND_IGNORE) \ 1325 find $(__srctree)include/asm-generic $(RCS_FIND_IGNORE) \
diff --git a/arch/arm/mach-imx/mx1ads.c b/arch/arm/mach-imx/mx1ads.c
index da893c80d471..a9778c1587ab 100644
--- a/arch/arm/mach-imx/mx1ads.c
+++ b/arch/arm/mach-imx/mx1ads.c
@@ -116,7 +116,7 @@ static struct platform_device *devices[] __initdata = {
116}; 116};
117 117
118#ifdef CONFIG_MMC_IMX 118#ifdef CONFIG_MMC_IMX
119static int mx1ads_mmc_card_present(void) 119static int mx1ads_mmc_card_present(struct device *dev)
120{ 120{
121 /* MMC/SD Card Detect is PB 20 on MX1ADS V1.0.7 */ 121 /* MMC/SD Card Detect is PB 20 on MX1ADS V1.0.7 */
122 return (SSR(1) & (1 << 20) ? 0 : 1); 122 return (SSR(1) & (1 << 20) ? 0 : 1);
diff --git a/arch/avr32/boards/atngw100/flash.c b/arch/avr32/boards/atngw100/flash.c
index f9b32a8eab9b..b07ae63aa548 100644
--- a/arch/avr32/boards/atngw100/flash.c
+++ b/arch/avr32/boards/atngw100/flash.c
@@ -15,7 +15,7 @@
15 15
16#include <asm/arch/smc.h> 16#include <asm/arch/smc.h>
17 17
18static struct smc_config flash_config __initdata = { 18static struct smc_timing flash_timing __initdata = {
19 .ncs_read_setup = 0, 19 .ncs_read_setup = 0,
20 .nrd_setup = 40, 20 .nrd_setup = 40,
21 .ncs_write_setup = 0, 21 .ncs_write_setup = 0,
@@ -28,7 +28,9 @@ static struct smc_config flash_config __initdata = {
28 28
29 .read_cycle = 120, 29 .read_cycle = 120,
30 .write_cycle = 120, 30 .write_cycle = 120,
31};
31 32
33static struct smc_config flash_config __initdata = {
32 .bus_width = 2, 34 .bus_width = 2,
33 .nrd_controlled = 1, 35 .nrd_controlled = 1,
34 .nwe_controlled = 1, 36 .nwe_controlled = 1,
@@ -82,6 +84,7 @@ static int __init atngw100_flash_init(void)
82{ 84{
83 int ret; 85 int ret;
84 86
87 smc_set_timing(&flash_config, &flash_timing);
85 ret = smc_set_configuration(0, &flash_config); 88 ret = smc_set_configuration(0, &flash_config);
86 if (ret < 0) { 89 if (ret < 0) {
87 printk(KERN_ERR "atngw100: failed to set NOR flash timing\n"); 90 printk(KERN_ERR "atngw100: failed to set NOR flash timing\n");
diff --git a/arch/avr32/boards/atngw100/setup.c b/arch/avr32/boards/atngw100/setup.c
index ef801563bbf5..52987c81d668 100644
--- a/arch/avr32/boards/atngw100/setup.c
+++ b/arch/avr32/boards/atngw100/setup.c
@@ -125,8 +125,11 @@ static struct platform_device ngw_gpio_leds = {
125}; 125};
126 126
127static struct i2c_gpio_platform_data i2c_gpio_data = { 127static struct i2c_gpio_platform_data i2c_gpio_data = {
128 .sda_pin = GPIO_PIN_PA(6), 128 .sda_pin = GPIO_PIN_PA(6),
129 .scl_pin = GPIO_PIN_PA(7), 129 .scl_pin = GPIO_PIN_PA(7),
130 .sda_is_open_drain = 1,
131 .scl_is_open_drain = 1,
132 .udelay = 2, /* close to 100 kHz */
130}; 133};
131 134
132static struct platform_device i2c_gpio_device = { 135static struct platform_device i2c_gpio_device = {
@@ -154,6 +157,7 @@ static int __init atngw100_init(void)
154 set_hw_addr(at32_add_device_eth(1, &eth_data[1])); 157 set_hw_addr(at32_add_device_eth(1, &eth_data[1]));
155 158
156 at32_add_device_spi(0, spi0_board_info, ARRAY_SIZE(spi0_board_info)); 159 at32_add_device_spi(0, spi0_board_info, ARRAY_SIZE(spi0_board_info));
160 at32_add_device_usba(0, NULL);
157 161
158 for (i = 0; i < ARRAY_SIZE(ngw_leds); i++) { 162 for (i = 0; i < ARRAY_SIZE(ngw_leds); i++) {
159 at32_select_gpio(ngw_leds[i].gpio, 163 at32_select_gpio(ngw_leds[i].gpio,
@@ -161,8 +165,10 @@ static int __init atngw100_init(void)
161 } 165 }
162 platform_device_register(&ngw_gpio_leds); 166 platform_device_register(&ngw_gpio_leds);
163 167
164 at32_select_gpio(i2c_gpio_data.sda_pin, 0); 168 at32_select_gpio(i2c_gpio_data.sda_pin,
165 at32_select_gpio(i2c_gpio_data.scl_pin, 0); 169 AT32_GPIOF_MULTIDRV | AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
170 at32_select_gpio(i2c_gpio_data.scl_pin,
171 AT32_GPIOF_MULTIDRV | AT32_GPIOF_OUTPUT | AT32_GPIOF_HIGH);
166 platform_device_register(&i2c_gpio_device); 172 platform_device_register(&i2c_gpio_device);
167 173
168 return 0; 174 return 0;
diff --git a/arch/avr32/boards/atstk1000/atstk1002.c b/arch/avr32/boards/atstk1000/atstk1002.c
index c9981b731efa..6b9e466104ad 100644
--- a/arch/avr32/boards/atstk1000/atstk1002.c
+++ b/arch/avr32/boards/atstk1000/atstk1002.c
@@ -241,6 +241,7 @@ static int __init atstk1002_init(void)
241 at32_add_device_lcdc(0, &atstk1000_lcdc_data, 241 at32_add_device_lcdc(0, &atstk1000_lcdc_data,
242 fbmem_start, fbmem_size); 242 fbmem_start, fbmem_size);
243#endif 243#endif
244 at32_add_device_usba(0, NULL);
244#ifndef CONFIG_BOARD_ATSTK1002_SW3_CUSTOM 245#ifndef CONFIG_BOARD_ATSTK1002_SW3_CUSTOM
245 at32_add_device_ssc(0, ATMEL_SSC_TX); 246 at32_add_device_ssc(0, ATMEL_SSC_TX);
246#endif 247#endif
diff --git a/arch/avr32/boards/atstk1000/flash.c b/arch/avr32/boards/atstk1000/flash.c
index aac4300cca12..3d0a102ad45e 100644
--- a/arch/avr32/boards/atstk1000/flash.c
+++ b/arch/avr32/boards/atstk1000/flash.c
@@ -15,7 +15,7 @@
15 15
16#include <asm/arch/smc.h> 16#include <asm/arch/smc.h>
17 17
18static struct smc_config flash_config __initdata = { 18static struct smc_timing flash_timing __initdata = {
19 .ncs_read_setup = 0, 19 .ncs_read_setup = 0,
20 .nrd_setup = 40, 20 .nrd_setup = 40,
21 .ncs_write_setup = 0, 21 .ncs_write_setup = 0,
@@ -28,7 +28,9 @@ static struct smc_config flash_config __initdata = {
28 28
29 .read_cycle = 120, 29 .read_cycle = 120,
30 .write_cycle = 120, 30 .write_cycle = 120,
31};
31 32
33static struct smc_config flash_config __initdata = {
32 .bus_width = 2, 34 .bus_width = 2,
33 .nrd_controlled = 1, 35 .nrd_controlled = 1,
34 .nwe_controlled = 1, 36 .nwe_controlled = 1,
@@ -82,6 +84,7 @@ static int __init atstk1000_flash_init(void)
82{ 84{
83 int ret; 85 int ret;
84 86
87 smc_set_timing(&flash_config, &flash_timing);
85 ret = smc_set_configuration(0, &flash_config); 88 ret = smc_set_configuration(0, &flash_config);
86 if (ret < 0) { 89 if (ret < 0) {
87 printk(KERN_ERR "atstk1000: failed to set NOR flash timing\n"); 90 printk(KERN_ERR "atstk1000: failed to set NOR flash timing\n");
diff --git a/arch/avr32/kernel/Makefile b/arch/avr32/kernel/Makefile
index 90e5afff54a2..989fcd1fef7e 100644
--- a/arch/avr32/kernel/Makefile
+++ b/arch/avr32/kernel/Makefile
@@ -11,8 +11,3 @@ obj-y += signal.o sys_avr32.o process.o time.o
11obj-y += init_task.o switch_to.o cpu.o 11obj-y += init_task.o switch_to.o cpu.o
12obj-$(CONFIG_MODULES) += module.o avr32_ksyms.o 12obj-$(CONFIG_MODULES) += module.o avr32_ksyms.o
13obj-$(CONFIG_KPROBES) += kprobes.o 13obj-$(CONFIG_KPROBES) += kprobes.o
14
15USE_STANDARD_AS_RULE := true
16
17%.lds: %.lds.c FORCE
18 $(call if_changed_dep,cpp_lds_S)
diff --git a/arch/avr32/kernel/entry-avr32b.S b/arch/avr32/kernel/entry-avr32b.S
index 42657f1703b2..ccadfd9b438d 100644
--- a/arch/avr32/kernel/entry-avr32b.S
+++ b/arch/avr32/kernel/entry-avr32b.S
@@ -159,11 +159,18 @@ handle_vmalloc_miss:
159 159
160 .section .scall.text,"ax",@progbits 160 .section .scall.text,"ax",@progbits
161system_call: 161system_call:
162#ifdef CONFIG_PREEMPT
163 mask_interrupts
164#endif
162 pushm r12 /* r12_orig */ 165 pushm r12 /* r12_orig */
163 stmts --sp, r0-lr 166 stmts --sp, r0-lr
164 zero_fp 167
165 mfsr r0, SYSREG_RAR_SUP 168 mfsr r0, SYSREG_RAR_SUP
166 mfsr r1, SYSREG_RSR_SUP 169 mfsr r1, SYSREG_RSR_SUP
170#ifdef CONFIG_PREEMPT
171 unmask_interrupts
172#endif
173 zero_fp
167 stm --sp, r0-r1 174 stm --sp, r0-r1
168 175
169 /* check for syscall tracing */ 176 /* check for syscall tracing */
@@ -638,6 +645,13 @@ irq_level\level:
638 stmts --sp,r0-lr 645 stmts --sp,r0-lr
639 mfsr r8, rar_int\level 646 mfsr r8, rar_int\level
640 mfsr r9, rsr_int\level 647 mfsr r9, rsr_int\level
648
649#ifdef CONFIG_PREEMPT
650 sub r11, pc, (. - system_call)
651 cp.w r11, r8
652 breq 4f
653#endif
654
641 pushm r8-r9 655 pushm r8-r9
642 656
643 mov r11, sp 657 mov r11, sp
@@ -668,6 +682,16 @@ irq_level\level:
668 sub sp, -4 /* ignore r12_orig */ 682 sub sp, -4 /* ignore r12_orig */
669 rete 683 rete
670 684
685#ifdef CONFIG_PREEMPT
6864: mask_interrupts
687 mfsr r8, rsr_int\level
688 sbr r8, 16
689 mtsr rsr_int\level, r8
690 ldmts sp++, r0-lr
691 sub sp, -4 /* ignore r12_orig */
692 rete
693#endif
694
6712: get_thread_info r0 6952: get_thread_info r0
672 ld.w r1, r0[TI_flags] 696 ld.w r1, r0[TI_flags]
673 bld r1, TIF_CPU_GOING_TO_SLEEP 697 bld r1, TIF_CPU_GOING_TO_SLEEP
diff --git a/arch/avr32/kernel/setup.c b/arch/avr32/kernel/setup.c
index d08b0bc6b2bb..4b4c1884e1c5 100644
--- a/arch/avr32/kernel/setup.c
+++ b/arch/avr32/kernel/setup.c
@@ -248,7 +248,7 @@ static int __init early_parse_fbmem(char *p)
248 248
249 fbmem_size = memparse(p, &p); 249 fbmem_size = memparse(p, &p);
250 if (*p == '@') { 250 if (*p == '@') {
251 fbmem_start = memparse(p, &p); 251 fbmem_start = memparse(p + 1, &p);
252 ret = add_reserved_region(fbmem_start, 252 ret = add_reserved_region(fbmem_start,
253 fbmem_start + fbmem_size - 1, 253 fbmem_start + fbmem_size - 1,
254 "Framebuffer"); 254 "Framebuffer");
diff --git a/arch/avr32/kernel/vmlinux.lds.S b/arch/avr32/kernel/vmlinux.lds.S
new file mode 100644
index 000000000000..ce9ac9659883
--- /dev/null
+++ b/arch/avr32/kernel/vmlinux.lds.S
@@ -0,0 +1,143 @@
1/*
2 * AVR32 linker script for the Linux kernel
3 *
4 * Copyright (C) 2004-2006 Atmel Corporation
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#define LOAD_OFFSET 0x00000000
11#include <asm-generic/vmlinux.lds.h>
12#include <asm/cache.h>
13#include <asm/thread_info.h>
14
15OUTPUT_FORMAT("elf32-avr32", "elf32-avr32", "elf32-avr32")
16OUTPUT_ARCH(avr32)
17ENTRY(_start)
18
19/* Big endian */
20jiffies = jiffies_64 + 4;
21
22SECTIONS
23{
24 . = CONFIG_ENTRY_ADDRESS;
25 .init : AT(ADDR(.init) - LOAD_OFFSET) {
26 _stext = .;
27 __init_begin = .;
28 _sinittext = .;
29 *(.text.reset)
30 *(.init.text)
31 /*
32 * .exit.text is discarded at runtime, not
33 * link time, to deal with references from
34 * __bug_table
35 */
36 *(.exit.text)
37 _einittext = .;
38 . = ALIGN(4);
39 __tagtable_begin = .;
40 *(.taglist.init)
41 __tagtable_end = .;
42 *(.init.data)
43 . = ALIGN(16);
44 __setup_start = .;
45 *(.init.setup)
46 __setup_end = .;
47 . = ALIGN(4);
48 __initcall_start = .;
49 INITCALLS
50 __initcall_end = .;
51 __con_initcall_start = .;
52 *(.con_initcall.init)
53 __con_initcall_end = .;
54 __security_initcall_start = .;
55 *(.security_initcall.init)
56 __security_initcall_end = .;
57#ifdef CONFIG_BLK_DEV_INITRD
58 . = ALIGN(32);
59 __initramfs_start = .;
60 *(.init.ramfs)
61 __initramfs_end = .;
62#endif
63 . = ALIGN(PAGE_SIZE);
64 __init_end = .;
65 }
66
67 .text : AT(ADDR(.text) - LOAD_OFFSET) {
68 _evba = .;
69 _text = .;
70 *(.ex.text)
71 . = 0x50;
72 *(.tlbx.ex.text)
73 . = 0x60;
74 *(.tlbr.ex.text)
75 . = 0x70;
76 *(.tlbw.ex.text)
77 . = 0x100;
78 *(.scall.text)
79 *(.irq.text)
80 TEXT_TEXT
81 SCHED_TEXT
82 LOCK_TEXT
83 KPROBES_TEXT
84 *(.fixup)
85 *(.gnu.warning)
86 _etext = .;
87 } = 0xd703d703
88
89 . = ALIGN(4);
90 __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
91 __start___ex_table = .;
92 *(__ex_table)
93 __stop___ex_table = .;
94 }
95
96 BUG_TABLE
97
98 RODATA
99
100 . = ALIGN(THREAD_SIZE);
101
102 .data : AT(ADDR(.data) - LOAD_OFFSET) {
103 _data = .;
104 _sdata = .;
105 /*
106 * First, the init task union, aligned to an 8K boundary.
107 */
108 *(.data.init_task)
109
110 /* Then, the cacheline aligned data */
111 . = ALIGN(L1_CACHE_BYTES);
112 *(.data.cacheline_aligned)
113
114 /* And the rest... */
115 *(.data.rel*)
116 DATA_DATA
117 CONSTRUCTORS
118
119 _edata = .;
120 }
121
122
123 . = ALIGN(8);
124 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
125 __bss_start = .;
126 *(.bss)
127 *(COMMON)
128 . = ALIGN(8);
129 __bss_stop = .;
130 _end = .;
131 }
132
133 /* When something in the kernel is NOT compiled as a module, the module
134 * cleanup code and data are put into these segments. Both can then be
135 * thrown away, as cleanup code is never called unless it's a module.
136 */
137 /DISCARD/ : {
138 *(.exit.data)
139 *(.exitcall.exit)
140 }
141
142 DWARF_DEBUG
143}
diff --git a/arch/avr32/kernel/vmlinux.lds.c b/arch/avr32/kernel/vmlinux.lds.c
deleted file mode 100644
index db0438f35c00..000000000000
--- a/arch/avr32/kernel/vmlinux.lds.c
+++ /dev/null
@@ -1,142 +0,0 @@
1/*
2 * AVR32 linker script for the Linux kernel
3 *
4 * Copyright (C) 2004-2006 Atmel Corporation
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#define LOAD_OFFSET 0x00000000
11#include <asm-generic/vmlinux.lds.h>
12
13OUTPUT_FORMAT("elf32-avr32", "elf32-avr32", "elf32-avr32")
14OUTPUT_ARCH(avr32)
15ENTRY(_start)
16
17/* Big endian */
18jiffies = jiffies_64 + 4;
19
20SECTIONS
21{
22 . = CONFIG_ENTRY_ADDRESS;
23 .init : AT(ADDR(.init) - LOAD_OFFSET) {
24 _stext = .;
25 __init_begin = .;
26 _sinittext = .;
27 *(.text.reset)
28 *(.init.text)
29 /*
30 * .exit.text is discarded at runtime, not
31 * link time, to deal with references from
32 * __bug_table
33 */
34 *(.exit.text)
35 _einittext = .;
36 . = ALIGN(4);
37 __tagtable_begin = .;
38 *(.taglist.init)
39 __tagtable_end = .;
40 *(.init.data)
41 . = ALIGN(16);
42 __setup_start = .;
43 *(.init.setup)
44 __setup_end = .;
45 . = ALIGN(4);
46 __initcall_start = .;
47 INITCALLS
48 __initcall_end = .;
49 __con_initcall_start = .;
50 *(.con_initcall.init)
51 __con_initcall_end = .;
52 __security_initcall_start = .;
53 *(.security_initcall.init)
54 __security_initcall_end = .;
55#ifdef CONFIG_BLK_DEV_INITRD
56 . = ALIGN(32);
57 __initramfs_start = .;
58 *(.init.ramfs)
59 __initramfs_end = .;
60#endif
61 . = ALIGN(4096);
62 __init_end = .;
63 }
64
65 . = ALIGN(8192);
66 .text : AT(ADDR(.text) - LOAD_OFFSET) {
67 _evba = .;
68 _text = .;
69 *(.ex.text)
70 . = 0x50;
71 *(.tlbx.ex.text)
72 . = 0x60;
73 *(.tlbr.ex.text)
74 . = 0x70;
75 *(.tlbw.ex.text)
76 . = 0x100;
77 *(.scall.text)
78 *(.irq.text)
79 TEXT_TEXT
80 SCHED_TEXT
81 LOCK_TEXT
82 KPROBES_TEXT
83 *(.fixup)
84 *(.gnu.warning)
85 _etext = .;
86 } = 0xd703d703
87
88 . = ALIGN(4);
89 __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
90 __start___ex_table = .;
91 *(__ex_table)
92 __stop___ex_table = .;
93 }
94
95 BUG_TABLE
96
97 RODATA
98
99 . = ALIGN(8192);
100
101 .data : AT(ADDR(.data) - LOAD_OFFSET) {
102 _data = .;
103 _sdata = .;
104 /*
105 * First, the init task union, aligned to an 8K boundary.
106 */
107 *(.data.init_task)
108
109 /* Then, the cacheline aligned data */
110 . = ALIGN(32);
111 *(.data.cacheline_aligned)
112
113 /* And the rest... */
114 *(.data.rel*)
115 DATA_DATA
116 CONSTRUCTORS
117
118 _edata = .;
119 }
120
121
122 . = ALIGN(8);
123 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
124 __bss_start = .;
125 *(.bss)
126 *(COMMON)
127 . = ALIGN(8);
128 __bss_stop = .;
129 _end = .;
130 }
131
132 /* When something in the kernel is NOT compiled as a module, the module
133 * cleanup code and data are put into these segments. Both can then be
134 * thrown away, as cleanup code is never called unless it's a module.
135 */
136 /DISCARD/ : {
137 *(.exit.data)
138 *(.exitcall.exit)
139 }
140
141 DWARF_DEBUG
142}
diff --git a/arch/avr32/mach-at32ap/at32ap7000.c b/arch/avr32/mach-at32ap/at32ap7000.c
index 64cc5583ddfb..f6d154ca4d24 100644
--- a/arch/avr32/mach-at32ap/at32ap7000.c
+++ b/arch/avr32/mach-at32ap/at32ap7000.c
@@ -25,12 +25,6 @@
25#include "pio.h" 25#include "pio.h"
26#include "pm.h" 26#include "pm.h"
27 27
28/*
29 * We can reduce the code size a bit by using a constant here. Since
30 * this file is completely chip-specific, it's safe to not use
31 * ioremap. Generic drivers should of course never do this.
32 */
33#define AT32_PM_BASE 0xfff00000
34 28
35#define PBMEM(base) \ 29#define PBMEM(base) \
36 { \ 30 { \
@@ -1168,6 +1162,72 @@ at32_add_device_ssc(unsigned int id, unsigned int flags)
1168} 1162}
1169 1163
1170/* -------------------------------------------------------------------- 1164/* --------------------------------------------------------------------
1165 * USB Device Controller
1166 * -------------------------------------------------------------------- */
1167static struct resource usba0_resource[] __initdata = {
1168 {
1169 .start = 0xff300000,
1170 .end = 0xff3fffff,
1171 .flags = IORESOURCE_MEM,
1172 }, {
1173 .start = 0xfff03000,
1174 .end = 0xfff033ff,
1175 .flags = IORESOURCE_MEM,
1176 },
1177 IRQ(31),
1178};
1179static struct clk usba0_pclk = {
1180 .name = "pclk",
1181 .parent = &pbb_clk,
1182 .mode = pbb_clk_mode,
1183 .get_rate = pbb_clk_get_rate,
1184 .index = 12,
1185};
1186static struct clk usba0_hclk = {
1187 .name = "hclk",
1188 .parent = &hsb_clk,
1189 .mode = hsb_clk_mode,
1190 .get_rate = hsb_clk_get_rate,
1191 .index = 6,
1192};
1193
1194struct platform_device *__init
1195at32_add_device_usba(unsigned int id, struct usba_platform_data *data)
1196{
1197 struct platform_device *pdev;
1198
1199 if (id != 0)
1200 return NULL;
1201
1202 pdev = platform_device_alloc("atmel_usba_udc", 0);
1203 if (!pdev)
1204 return NULL;
1205
1206 if (platform_device_add_resources(pdev, usba0_resource,
1207 ARRAY_SIZE(usba0_resource)))
1208 goto out_free_pdev;
1209
1210 if (data) {
1211 if (platform_device_add_data(pdev, data, sizeof(*data)))
1212 goto out_free_pdev;
1213
1214 if (data->vbus_pin != GPIO_PIN_NONE)
1215 at32_select_gpio(data->vbus_pin, 0);
1216 }
1217
1218 usba0_pclk.dev = &pdev->dev;
1219 usba0_hclk.dev = &pdev->dev;
1220
1221 platform_device_add(pdev);
1222
1223 return pdev;
1224
1225out_free_pdev:
1226 platform_device_put(pdev);
1227 return NULL;
1228}
1229
1230/* --------------------------------------------------------------------
1171 * GCLK 1231 * GCLK
1172 * -------------------------------------------------------------------- */ 1232 * -------------------------------------------------------------------- */
1173static struct clk gclk0 = { 1233static struct clk gclk0 = {
@@ -1252,6 +1312,8 @@ struct clk *at32_clock_list[] = {
1252 &ssc0_pclk, 1312 &ssc0_pclk,
1253 &ssc1_pclk, 1313 &ssc1_pclk,
1254 &ssc2_pclk, 1314 &ssc2_pclk,
1315 &usba0_hclk,
1316 &usba0_pclk,
1255 &gclk0, 1317 &gclk0,
1256 &gclk1, 1318 &gclk1,
1257 &gclk2, 1319 &gclk2,
diff --git a/arch/avr32/mach-at32ap/clock.c b/arch/avr32/mach-at32ap/clock.c
index 0f8c89c9f832..4642117cc9ab 100644
--- a/arch/avr32/mach-at32ap/clock.c
+++ b/arch/avr32/mach-at32ap/clock.c
@@ -150,3 +150,119 @@ struct clk *clk_get_parent(struct clk *clk)
150 return clk->parent; 150 return clk->parent;
151} 151}
152EXPORT_SYMBOL(clk_get_parent); 152EXPORT_SYMBOL(clk_get_parent);
153
154
155
156#ifdef CONFIG_DEBUG_FS
157
158/* /sys/kernel/debug/at32ap_clk */
159
160#include <linux/io.h>
161#include <linux/debugfs.h>
162#include <linux/seq_file.h>
163#include "pm.h"
164
165
166#define NEST_DELTA 2
167#define NEST_MAX 6
168
169struct clkinf {
170 struct seq_file *s;
171 unsigned nest;
172};
173
174static void
175dump_clock(struct clk *parent, struct clkinf *r)
176{
177 unsigned nest = r->nest;
178 char buf[16 + NEST_MAX];
179 struct clk *clk;
180 unsigned i;
181
182 /* skip clocks coupled to devices that aren't registered */
183 if (parent->dev && !parent->dev->bus_id[0] && !parent->users)
184 return;
185
186 /* <nest spaces> name <pad to end> */
187 memset(buf, ' ', sizeof(buf) - 1);
188 buf[sizeof(buf) - 1] = 0;
189 i = strlen(parent->name);
190 memcpy(buf + nest, parent->name,
191 min(i, (unsigned)(sizeof(buf) - 1 - nest)));
192
193 seq_printf(r->s, "%s%c users=%2d %-3s %9ld Hz",
194 buf, parent->set_parent ? '*' : ' ',
195 parent->users,
196 parent->users ? "on" : "off", /* NOTE: not-paranoid!! */
197 clk_get_rate(parent));
198 if (parent->dev)
199 seq_printf(r->s, ", for %s", parent->dev->bus_id);
200 seq_printf(r->s, "\n");
201
202 /* cost of this scan is small, but not linear... */
203 r->nest = nest + NEST_DELTA;
204 for (i = 3; i < at32_nr_clocks; i++) {
205 clk = at32_clock_list[i];
206 if (clk->parent == parent)
207 dump_clock(clk, r);
208 }
209 r->nest = nest;
210}
211
212static int clk_show(struct seq_file *s, void *unused)
213{
214 struct clkinf r;
215 int i;
216
217 /* show all the power manager registers */
218 seq_printf(s, "MCCTRL = %8x\n", pm_readl(MCCTRL));
219 seq_printf(s, "CKSEL = %8x\n", pm_readl(CKSEL));
220 seq_printf(s, "CPUMASK = %8x\n", pm_readl(CPU_MASK));
221 seq_printf(s, "HSBMASK = %8x\n", pm_readl(HSB_MASK));
222 seq_printf(s, "PBAMASK = %8x\n", pm_readl(PBA_MASK));
223 seq_printf(s, "PBBMASK = %8x\n", pm_readl(PBB_MASK));
224 seq_printf(s, "PLL0 = %8x\n", pm_readl(PLL0));
225 seq_printf(s, "PLL1 = %8x\n", pm_readl(PLL1));
226 seq_printf(s, "IMR = %8x\n", pm_readl(IMR));
227 for (i = 0; i < 8; i++) {
228 if (i == 5)
229 continue;
230 seq_printf(s, "GCCTRL%d = %8x\n", i, pm_readl(GCCTRL(i)));
231 }
232
233 seq_printf(s, "\n");
234
235 /* show clock tree as derived from the three oscillators
236 * we "know" are at the head of the list
237 */
238 r.s = s;
239 r.nest = 0;
240 dump_clock(at32_clock_list[0], &r);
241 dump_clock(at32_clock_list[1], &r);
242 dump_clock(at32_clock_list[2], &r);
243
244 return 0;
245}
246
247static int clk_open(struct inode *inode, struct file *file)
248{
249 return single_open(file, clk_show, NULL);
250}
251
252static const struct file_operations clk_operations = {
253 .open = clk_open,
254 .read = seq_read,
255 .llseek = seq_lseek,
256 .release = single_release,
257};
258
259static int __init clk_debugfs_init(void)
260{
261 (void) debugfs_create_file("at32ap_clk", S_IFREG | S_IRUGO,
262 NULL, NULL, &clk_operations);
263
264 return 0;
265}
266postcore_initcall(clk_debugfs_init);
267
268#endif
diff --git a/arch/avr32/mach-at32ap/hsmc.c b/arch/avr32/mach-at32ap/hsmc.c
index 5e22a750632b..704607fbcc69 100644
--- a/arch/avr32/mach-at32ap/hsmc.c
+++ b/arch/avr32/mach-at32ap/hsmc.c
@@ -29,16 +29,25 @@ struct hsmc {
29 29
30static struct hsmc *hsmc; 30static struct hsmc *hsmc;
31 31
32int smc_set_configuration(int cs, const struct smc_config *config) 32void smc_set_timing(struct smc_config *config,
33 const struct smc_timing *timing)
33{ 34{
35 int recover;
36 int cycle;
37
34 unsigned long mul; 38 unsigned long mul;
35 unsigned long offset;
36 u32 setup, pulse, cycle, mode;
37 39
38 if (!hsmc) 40 /* Reset all SMC timings */
39 return -ENODEV; 41 config->ncs_read_setup = 0;
40 if (cs >= NR_CHIP_SELECTS) 42 config->nrd_setup = 0;
41 return -EINVAL; 43 config->ncs_write_setup = 0;
44 config->nwe_setup = 0;
45 config->ncs_read_pulse = 0;
46 config->nrd_pulse = 0;
47 config->ncs_write_pulse = 0;
48 config->nwe_pulse = 0;
49 config->read_cycle = 0;
50 config->write_cycle = 0;
42 51
43 /* 52 /*
44 * cycles = x / T = x * f 53 * cycles = x / T = x * f
@@ -50,16 +59,102 @@ int smc_set_configuration(int cs, const struct smc_config *config)
50 59
51#define ns2cyc(x) ((((x) * mul) + 65535) >> 16) 60#define ns2cyc(x) ((((x) * mul) + 65535) >> 16)
52 61
53 setup = (HSMC_BF(NWE_SETUP, ns2cyc(config->nwe_setup)) 62 if (timing->ncs_read_setup > 0)
54 | HSMC_BF(NCS_WR_SETUP, ns2cyc(config->ncs_write_setup)) 63 config->ncs_read_setup = ns2cyc(timing->ncs_read_setup);
55 | HSMC_BF(NRD_SETUP, ns2cyc(config->nrd_setup)) 64
56 | HSMC_BF(NCS_RD_SETUP, ns2cyc(config->ncs_read_setup))); 65 if (timing->nrd_setup > 0)
57 pulse = (HSMC_BF(NWE_PULSE, ns2cyc(config->nwe_pulse)) 66 config->nrd_setup = ns2cyc(timing->nrd_setup);
58 | HSMC_BF(NCS_WR_PULSE, ns2cyc(config->ncs_write_pulse)) 67
59 | HSMC_BF(NRD_PULSE, ns2cyc(config->nrd_pulse)) 68 if (timing->ncs_write_setup > 0)
60 | HSMC_BF(NCS_RD_PULSE, ns2cyc(config->ncs_read_pulse))); 69 config->ncs_write_setup = ns2cyc(timing->ncs_write_setup);
61 cycle = (HSMC_BF(NWE_CYCLE, ns2cyc(config->write_cycle)) 70
62 | HSMC_BF(NRD_CYCLE, ns2cyc(config->read_cycle))); 71 if (timing->nwe_setup > 0)
72 config->nwe_setup = ns2cyc(timing->nwe_setup);
73
74 if (timing->ncs_read_pulse > 0)
75 config->ncs_read_pulse = ns2cyc(timing->ncs_read_pulse);
76
77 if (timing->nrd_pulse > 0)
78 config->nrd_pulse = ns2cyc(timing->nrd_pulse);
79
80 if (timing->ncs_write_pulse > 0)
81 config->ncs_write_pulse = ns2cyc(timing->ncs_write_pulse);
82
83 if (timing->nwe_pulse > 0)
84 config->nwe_pulse = ns2cyc(timing->nwe_pulse);
85
86 if (timing->read_cycle > 0)
87 config->read_cycle = ns2cyc(timing->read_cycle);
88
89 if (timing->write_cycle > 0)
90 config->write_cycle = ns2cyc(timing->write_cycle);
91
92 /* Extend read cycle in needed */
93 if (timing->ncs_read_recover > 0)
94 recover = ns2cyc(timing->ncs_read_recover);
95 else
96 recover = 1;
97
98 cycle = config->ncs_read_setup + config->ncs_read_pulse + recover;
99
100 if (config->read_cycle < cycle)
101 config->read_cycle = cycle;
102
103 /* Extend read cycle in needed */
104 if (timing->nrd_recover > 0)
105 recover = ns2cyc(timing->nrd_recover);
106 else
107 recover = 1;
108
109 cycle = config->nrd_setup + config->nrd_pulse + recover;
110
111 if (config->read_cycle < cycle)
112 config->read_cycle = cycle;
113
114 /* Extend write cycle in needed */
115 if (timing->ncs_write_recover > 0)
116 recover = ns2cyc(timing->ncs_write_recover);
117 else
118 recover = 1;
119
120 cycle = config->ncs_write_setup + config->ncs_write_pulse + recover;
121
122 if (config->write_cycle < cycle)
123 config->write_cycle = cycle;
124
125 /* Extend write cycle in needed */
126 if (timing->nwe_recover > 0)
127 recover = ns2cyc(timing->nwe_recover);
128 else
129 recover = 1;
130
131 cycle = config->nwe_setup + config->nwe_pulse + recover;
132
133 if (config->write_cycle < cycle)
134 config->write_cycle = cycle;
135}
136EXPORT_SYMBOL(smc_set_timing);
137
138int smc_set_configuration(int cs, const struct smc_config *config)
139{
140 unsigned long offset;
141 u32 setup, pulse, cycle, mode;
142
143 if (!hsmc)
144 return -ENODEV;
145 if (cs >= NR_CHIP_SELECTS)
146 return -EINVAL;
147
148 setup = (HSMC_BF(NWE_SETUP, config->nwe_setup)
149 | HSMC_BF(NCS_WR_SETUP, config->ncs_write_setup)
150 | HSMC_BF(NRD_SETUP, config->nrd_setup)
151 | HSMC_BF(NCS_RD_SETUP, config->ncs_read_setup));
152 pulse = (HSMC_BF(NWE_PULSE, config->nwe_pulse)
153 | HSMC_BF(NCS_WR_PULSE, config->ncs_write_pulse)
154 | HSMC_BF(NRD_PULSE, config->nrd_pulse)
155 | HSMC_BF(NCS_RD_PULSE, config->ncs_read_pulse));
156 cycle = (HSMC_BF(NWE_CYCLE, config->write_cycle)
157 | HSMC_BF(NRD_CYCLE, config->read_cycle));
63 158
64 switch (config->bus_width) { 159 switch (config->bus_width) {
65 case 1: 160 case 1:
diff --git a/arch/avr32/mach-at32ap/pio.c b/arch/avr32/mach-at32ap/pio.c
index 1eb99b814f5b..d61a02da898c 100644
--- a/arch/avr32/mach-at32ap/pio.c
+++ b/arch/avr32/mach-at32ap/pio.c
@@ -110,6 +110,10 @@ void __init at32_select_gpio(unsigned int pin, unsigned long flags)
110 pio_writel(pio, SODR, mask); 110 pio_writel(pio, SODR, mask);
111 else 111 else
112 pio_writel(pio, CODR, mask); 112 pio_writel(pio, CODR, mask);
113 if (flags & AT32_GPIOF_MULTIDRV)
114 pio_writel(pio, MDER, mask);
115 else
116 pio_writel(pio, MDDR, mask);
113 pio_writel(pio, PUDR, mask); 117 pio_writel(pio, PUDR, mask);
114 pio_writel(pio, OER, mask); 118 pio_writel(pio, OER, mask);
115 } else { 119 } else {
diff --git a/arch/avr32/mach-at32ap/pm.h b/arch/avr32/mach-at32ap/pm.h
index a1f8aced0a8c..47efd0d1951f 100644
--- a/arch/avr32/mach-at32ap/pm.h
+++ b/arch/avr32/mach-at32ap/pm.h
@@ -4,6 +4,14 @@
4#ifndef __ARCH_AVR32_MACH_AT32AP_PM_H__ 4#ifndef __ARCH_AVR32_MACH_AT32AP_PM_H__
5#define __ARCH_AVR32_MACH_AT32AP_PM_H__ 5#define __ARCH_AVR32_MACH_AT32AP_PM_H__
6 6
7/*
8 * We can reduce the code size a bit by using a constant here. Since
9 * this file is only used on AVR32 AP CPUs with segmentation enabled,
10 * it's safe to not use ioremap. Generic drivers should of course
11 * never do this.
12 */
13#define AT32_PM_BASE 0xfff00000
14
7/* PM register offsets */ 15/* PM register offsets */
8#define PM_MCCTRL 0x0000 16#define PM_MCCTRL 0x0000
9#define PM_CKSEL 0x0004 17#define PM_CKSEL 0x0004
diff --git a/arch/avr32/mm/init.c b/arch/avr32/mm/init.c
index 82cf70854b90..480760bde63f 100644
--- a/arch/avr32/mm/init.c
+++ b/arch/avr32/mm/init.c
@@ -224,19 +224,9 @@ void free_initmem(void)
224 224
225#ifdef CONFIG_BLK_DEV_INITRD 225#ifdef CONFIG_BLK_DEV_INITRD
226 226
227static int keep_initrd;
228
229void free_initrd_mem(unsigned long start, unsigned long end) 227void free_initrd_mem(unsigned long start, unsigned long end)
230{ 228{
231 if (!keep_initrd) 229 free_area(start, end, "initrd");
232 free_area(start, end, "initrd");
233}
234
235static int __init keepinitrd_setup(char *__unused)
236{
237 keep_initrd = 1;
238 return 1;
239} 230}
240 231
241__setup("keepinitrd", keepinitrd_setup);
242#endif 232#endif
diff --git a/arch/blackfin/Kconfig b/arch/blackfin/Kconfig
index 017defaa525b..b24f4535ffe0 100644
--- a/arch/blackfin/Kconfig
+++ b/arch/blackfin/Kconfig
@@ -57,7 +57,7 @@ config GENERIC_TIME
57 bool 57 bool
58 default n 58 default n
59 59
60config GENERIC_CALIBRATE_DELAY 60config GENERIC_GPIO
61 bool 61 bool
62 default y 62 default y
63 63
@@ -323,7 +323,7 @@ config CMDLINE
323 to the kernel, you may specify one here. As a minimum, you should specify 323 to the kernel, you may specify one here. As a minimum, you should specify
324 the memory size and the root device (e.g., mem=8M, root=/dev/nfs). 324 the memory size and the root device (e.g., mem=8M, root=/dev/nfs).
325 325
326comment "Board Setup" 326comment "Clock/PLL Setup"
327 327
328config CLKIN_HZ 328config CLKIN_HZ
329 int "Crystal Frequency in Hz" 329 int "Crystal Frequency in Hz"
@@ -335,6 +335,118 @@ config CLKIN_HZ
335 help 335 help
336 The frequency of CLKIN crystal oscillator on the board in Hz. 336 The frequency of CLKIN crystal oscillator on the board in Hz.
337 337
338config BFIN_KERNEL_CLOCK
339 bool "Re-program Clocks while Kernel boots?"
340 default n
341 help
342 This option decides if kernel clocks are re-programed from the
343 bootloader settings. If the clocks are not set, the SDRAM settings
344 are also not changed, and the Bootloader does 100% of the hardware
345 configuration.
346
347config PLL_BYPASS
348 bool "Bypass PLL"
349 depends on BFIN_KERNEL_CLOCK
350 default n
351
352config CLKIN_HALF
353 bool "Half Clock In"
354 depends on BFIN_KERNEL_CLOCK && (! PLL_BYPASS)
355 default n
356 help
357 If this is set the clock will be divided by 2, before it goes to the PLL.
358
359config VCO_MULT
360 int "VCO Multiplier"
361 depends on BFIN_KERNEL_CLOCK && (! PLL_BYPASS)
362 range 1 64
363 default "22" if BFIN533_EZKIT
364 default "45" if BFIN533_STAMP
365 default "20" if BFIN537_STAMP
366 default "22" if BFIN533_BLUETECHNIX_CM
367 default "20" if BFIN537_BLUETECHNIX_CM
368 default "20" if BFIN561_BLUETECHNIX_CM
369 default "20" if BFIN561_EZKIT
370 help
371 This controls the frequency of the on-chip PLL. This can be between 1 and 64.
372 PLL Frequency = (Crystal Frequency) * (this setting)
373
374choice
375 prompt "Core Clock Divider"
376 depends on BFIN_KERNEL_CLOCK
377 default CCLK_DIV_1
378 help
379 This sets the frequency of the core. It can be 1, 2, 4 or 8
380 Core Frequency = (PLL frequency) / (this setting)
381
382config CCLK_DIV_1
383 bool "1"
384
385config CCLK_DIV_2
386 bool "2"
387
388config CCLK_DIV_4
389 bool "4"
390
391config CCLK_DIV_8
392 bool "8"
393endchoice
394
395config SCLK_DIV
396 int "System Clock Divider"
397 depends on BFIN_KERNEL_CLOCK
398 range 1 15
399 default 5 if BFIN533_EZKIT
400 default 5 if BFIN533_STAMP
401 default 4 if BFIN537_STAMP
402 default 5 if BFIN533_BLUETECHNIX_CM
403 default 4 if BFIN537_BLUETECHNIX_CM
404 default 4 if BFIN561_BLUETECHNIX_CM
405 default 5 if BFIN561_EZKIT
406 help
407 This sets the frequency of the system clock (including SDRAM or DDR).
408 This can be between 1 and 15
409 System Clock = (PLL frequency) / (this setting)
410
411#
412# Max & Min Speeds for various Chips
413#
414config MAX_VCO_HZ
415 int
416 default 600000000 if BF522
417 default 600000000 if BF525
418 default 600000000 if BF527
419 default 400000000 if BF531
420 default 400000000 if BF532
421 default 750000000 if BF533
422 default 500000000 if BF534
423 default 400000000 if BF536
424 default 600000000 if BF537
425 default 533000000 if BF538
426 default 533000000 if BF539
427 default 600000000 if BF542
428 default 533000000 if BF544
429 default 533000000 if BF549
430 default 600000000 if BF561
431
432config MIN_VCO_HZ
433 int
434 default 50000000
435
436config MAX_SCLK_HZ
437 int
438 default 133000000
439
440config MIN_SCLK_HZ
441 int
442 default 27000000
443
444comment "Kernel Timer/Scheduler"
445
446source kernel/Kconfig.hz
447
448comment "Memory Setup"
449
338config MEM_SIZE 450config MEM_SIZE
339 int "SDRAM Memory Size in MBytes" 451 int "SDRAM Memory Size in MBytes"
340 default 32 if BFIN533_EZKIT 452 default 32 if BFIN533_EZKIT
@@ -364,15 +476,16 @@ config ENET_FLASH_PIN
364config BOOT_LOAD 476config BOOT_LOAD
365 hex "Kernel load address for booting" 477 hex "Kernel load address for booting"
366 default "0x1000" 478 default "0x1000"
479 range 0x1000 0x20000000
367 help 480 help
368 This option allows you to set the load address of the kernel. 481 This option allows you to set the load address of the kernel.
369 This can be useful if you are on a board which has a small amount 482 This can be useful if you are on a board which has a small amount
370 of memory or you wish to reserve some memory at the beginning of 483 of memory or you wish to reserve some memory at the beginning of
371 the address space. 484 the address space.
372 485
373 Note that you generally want to keep this value at or above 4k 486 Note that you need to keep this value above 4k (0x1000) as this
374 (0x1000) as this will allow the kernel to capture NULL pointer 487 memory region is used to capture NULL pointer references as well
375 references. 488 as some core kernel functions.
376 489
377comment "LED Status Indicators" 490comment "LED Status Indicators"
378 depends on (BFIN533_STAMP || BFIN533_BLUETECHNIX_CM) 491 depends on (BFIN533_STAMP || BFIN533_BLUETECHNIX_CM)
@@ -408,6 +521,52 @@ config BFIN_IDLE_LED_NUM
408 help 521 help
409 Select the LED (marked on the board) for you to blink. 522 Select the LED (marked on the board) for you to blink.
410 523
524choice
525 prompt "Blackfin Exception Scratch Register"
526 default BFIN_SCRATCH_REG_RETN
527 help
528 Select the resource to reserve for the Exception handler:
529 - RETN: Non-Maskable Interrupt (NMI)
530 - RETE: Exception Return (JTAG/ICE)
531 - CYCLES: Performance counter
532
533 If you are unsure, please select "RETN".
534
535config BFIN_SCRATCH_REG_RETN
536 bool "RETN"
537 help
538 Use the RETN register in the Blackfin exception handler
539 as a stack scratch register. This means you cannot
540 safely use NMI on the Blackfin while running Linux, but
541 you can debug the system with a JTAG ICE and use the
542 CYCLES performance registers.
543
544 If you are unsure, please select "RETN".
545
546config BFIN_SCRATCH_REG_RETE
547 bool "RETE"
548 help
549 Use the RETE register in the Blackfin exception handler
550 as a stack scratch register. This means you cannot
551 safely use a JTAG ICE while debugging a Blackfin board,
552 but you can safely use the CYCLES performance registers
553 and the NMI.
554
555 If you are unsure, please select "RETN".
556
557config BFIN_SCRATCH_REG_CYCLES
558 bool "CYCLES"
559 help
560 Use the CYCLES register in the Blackfin exception handler
561 as a stack scratch register. This means you cannot
562 safely use the CYCLES performance registers on a Blackfin
563 board at anytime, but you can debug the system with a JTAG
564 ICE and use the NMI.
565
566 If you are unsure, please select "RETN".
567
568endchoice
569
411# 570#
412# Sorry - but you need to put the hex address here - 571# Sorry - but you need to put the hex address here -
413# 572#
@@ -448,10 +607,6 @@ endmenu
448 607
449menu "Blackfin Kernel Optimizations" 608menu "Blackfin Kernel Optimizations"
450 609
451comment "Timer Tick"
452
453source kernel/Kconfig.hz
454
455comment "Memory Optimizations" 610comment "Memory Optimizations"
456 611
457config I_ENTRY_L1 612config I_ENTRY_L1
@@ -614,22 +769,22 @@ endchoice
614 769
615 770
616comment "Cache Support" 771comment "Cache Support"
617config BLKFIN_CACHE 772config BFIN_ICACHE
618 bool "Enable ICACHE" 773 bool "Enable ICACHE"
619config BLKFIN_DCACHE 774config BFIN_DCACHE
620 bool "Enable DCACHE" 775 bool "Enable DCACHE"
621config BLKFIN_DCACHE_BANKA 776config BFIN_DCACHE_BANKA
622 bool "Enable only 16k BankA DCACHE - BankB is SRAM" 777 bool "Enable only 16k BankA DCACHE - BankB is SRAM"
623 depends on BLKFIN_DCACHE && !BF531 778 depends on BFIN_DCACHE && !BF531
624 default n 779 default n
625config BLKFIN_CACHE_LOCK 780config BFIN_ICACHE_LOCK
626 bool "Enable Cache Locking" 781 bool "Enable Instruction Cache Locking"
627 782
628choice 783choice
629 prompt "Policy" 784 prompt "Policy"
630 depends on BLKFIN_DCACHE 785 depends on BFIN_DCACHE
631 default BLKFIN_WB 786 default BFIN_WB
632config BLKFIN_WB 787config BFIN_WB
633 bool "Write back" 788 bool "Write back"
634 help 789 help
635 Write Back Policy: 790 Write Back Policy:
@@ -646,7 +801,7 @@ config BLKFIN_WB
646 If you are unsure of the options and you want to be safe, 801 If you are unsure of the options and you want to be safe,
647 then go with Write Through. 802 then go with Write Through.
648 803
649config BLKFIN_WT 804config BFIN_WT
650 bool "Write through" 805 bool "Write through"
651 help 806 help
652 Write Back Policy: 807 Write Back Policy:
@@ -672,66 +827,9 @@ config L1_MAX_PIECE
672 Set the max memory pieces for the L1 SRAM allocation algorithm. 827 Set the max memory pieces for the L1 SRAM allocation algorithm.
673 Min value is 16. Max value is 1024. 828 Min value is 16. Max value is 1024.
674 829
675menu "Clock Settings"
676
677
678config BFIN_KERNEL_CLOCK
679 bool "Re-program Clocks while Kernel boots?"
680 default n
681 help
682 This option decides if kernel clocks are re-programed from the
683 bootloader settings. If the clocks are not set, the SDRAM settings
684 are also not changed, and the Bootloader does 100% of the hardware
685 configuration.
686
687config VCO_MULT
688 int "VCO Multiplier"
689 depends on BFIN_KERNEL_CLOCK
690 default "22" if BFIN533_EZKIT
691 default "45" if BFIN533_STAMP
692 default "20" if BFIN537_STAMP
693 default "22" if BFIN533_BLUETECHNIX_CM
694 default "20" if BFIN537_BLUETECHNIX_CM
695 default "20" if BFIN561_BLUETECHNIX_CM
696 default "20" if BFIN561_EZKIT
697
698config CCLK_DIV
699 int "Core Clock Divider"
700 depends on BFIN_KERNEL_CLOCK
701 default 1 if BFIN533_EZKIT
702 default 1 if BFIN533_STAMP
703 default 1 if BFIN537_STAMP
704 default 1 if BFIN533_BLUETECHNIX_CM
705 default 1 if BFIN537_BLUETECHNIX_CM
706 default 1 if BFIN561_BLUETECHNIX_CM
707 default 1 if BFIN561_EZKIT
708
709config SCLK_DIV
710 int "System Clock Divider"
711 depends on BFIN_KERNEL_CLOCK
712 default 5 if BFIN533_EZKIT
713 default 5 if BFIN533_STAMP
714 default 4 if BFIN537_STAMP
715 default 5 if BFIN533_BLUETECHNIX_CM
716 default 4 if BFIN537_BLUETECHNIX_CM
717 default 4 if BFIN561_BLUETECHNIX_CM
718 default 5 if BFIN561_EZKIT
719
720config CLKIN_HALF
721 bool "Half ClockIn"
722 depends on BFIN_KERNEL_CLOCK
723 default n
724
725config PLL_BYPASS
726 bool "Bypass PLL"
727 depends on BFIN_KERNEL_CLOCK
728 default n
729
730endmenu
731
732comment "Asynchonous Memory Configuration" 830comment "Asynchonous Memory Configuration"
733 831
734menu "EBIU_AMBCTL Global Control" 832menu "EBIU_AMGCTL Global Control"
735config C_AMCKEN 833config C_AMCKEN
736 bool "Enable CLKOUT" 834 bool "Enable CLKOUT"
737 default y 835 default y
@@ -941,24 +1039,6 @@ config DEBUG_ICACHE_CHECK
941 also relocates the irq_panic() function to L1 memory, (which is 1039 also relocates the irq_panic() function to L1 memory, (which is
942 un-cached). 1040 un-cached).
943 1041
944config DEBUG_KERNEL_START
945 bool "Debug Kernel Startup"
946 depends on DEBUG_KERNEL
947 help
948 Say Y here to put in an mini-execption handler before the kernel
949 replaces the bootloader exception handler. This will stop kernels
950 from dieing at startup with no visible error messages.
951
952config DEBUG_SERIAL_EARLY_INIT
953 bool "Initialize serial driver early"
954 default n
955 depends on SERIAL_BFIN
956 help
957 Say Y here if you want to get kernel output early when kernel
958 crashes before the normal console initialization. If this option
959 is enable, console output will always go to the ttyBF0, no matter
960 what kernel boot paramters you set.
961
962config DEBUG_HUNT_FOR_ZERO 1042config DEBUG_HUNT_FOR_ZERO
963 bool "Catch NULL pointer reads/writes" 1043 bool "Catch NULL pointer reads/writes"
964 default y 1044 default y
@@ -973,8 +1053,89 @@ config DEBUG_HUNT_FOR_ZERO
973 Enabling this option will take up an extra entry in CPLB table. 1053 Enabling this option will take up an extra entry in CPLB table.
974 Otherwise, there is no extra overhead. 1054 Otherwise, there is no extra overhead.
975 1055
1056config DEBUG_BFIN_HWTRACE_ON
1057 bool "Turn on Blackfin's Hardware Trace"
1058 default y
1059 help
1060 All Blackfins include a Trace Unit which stores a history of the last
1061 16 changes in program flow taken by the program sequencer. The history
1062 allows the user to recreate the program sequencer’s recent path. This
1063 can be handy when an application dies - we print out the execution
1064 path of how it got to the offending instruction.
1065
1066 By turning this off, you may save a tiny amount of power.
1067
1068choice
1069 prompt "Omit loop Tracing"
1070 default DEBUG_BFIN_HWTRACE_COMPRESSION_OFF
1071 depends on DEBUG_BFIN_HWTRACE_ON
1072 help
1073 The trace buffer can be configured to omit recording of changes in
1074 program flow that match either the last entry or one of the last
1075 two entries. Omitting one of these entries from the record prevents
1076 the trace buffer from overflowing because of any sort of loop (for, do
1077 while, etc) in the program.
1078
1079 Because zero-overhead Hardware loops are not recorded in the trace buffer,
1080 this feature can be used to prevent trace overflow from loops that
1081 are nested four deep.
1082
1083config DEBUG_BFIN_HWTRACE_COMPRESSION_OFF
1084 bool "Trace all Loops"
1085 help
1086 The trace buffer records all changes of flow
1087
1088config DEBUG_BFIN_HWTRACE_COMPRESSION_ONE
1089 bool "Compress single-level loops"
1090 help
1091 The trace buffer does not record single loops - helpful if trace
1092 is spinning on a while or do loop.
1093
1094config DEBUG_BFIN_HWTRACE_COMPRESSION_TWO
1095 bool "Compress two-level loops"
1096 help
1097 The trace buffer does not record loops two levels deep. Helpful if
1098 the trace is spinning in a nested loop
1099
1100endchoice
1101
1102config DEBUG_BFIN_HWTRACE_COMPRESSION
1103 int
1104 depends on DEBUG_BFIN_HWTRACE_ON
1105 default 0 if DEBUG_BFIN_HWTRACE_COMPRESSION_OFF
1106 default 1 if DEBUG_BFIN_HWTRACE_COMPRESSION_ONE
1107 default 2 if DEBUG_BFIN_HWTRACE_COMPRESSION_TWO
1108
1109
1110config DEBUG_BFIN_HWTRACE_EXPAND
1111 bool "Expand Trace Buffer greater than 16 entries"
1112 depends on DEBUG_BFIN_HWTRACE_ON
1113 default n
1114 help
1115 By selecting this option, every time the 16 hardware entries in
1116 the Blackfin's HW Trace buffer are full, the kernel will move them
1117 into a software buffer, for dumping when there is an issue. This
1118 has a great impact on performance, (an interrupt every 16 change of
1119 flows) and should normally be turned off, except in those nasty
1120 debugging sessions
1121
1122config DEBUG_BFIN_HWTRACE_EXPAND_LEN
1123 int "Size of Trace buffer (in power of 2k)"
1124 range 0 4
1125 depends on DEBUG_BFIN_HWTRACE_EXPAND
1126 default 1
1127 help
1128 This sets the size of the software buffer that the trace information
1129 is kept in.
1130 0 for (2^0) 1k, or 256 entries,
1131 1 for (2^1) 2k, or 512 entries,
1132 2 for (2^2) 4k, or 1024 entries,
1133 3 for (2^3) 8k, or 2048 entries,
1134 4 for (2^4) 16k, or 4096 entries
1135
976config DEBUG_BFIN_NO_KERN_HWTRACE 1136config DEBUG_BFIN_NO_KERN_HWTRACE
977 bool "Trace user apps (turn off hwtrace in kernel)" 1137 bool "Trace user apps (turn off hwtrace in kernel)"
1138 depends on DEBUG_BFIN_HWTRACE_ON
978 default n 1139 default n
979 help 1140 help
980 Some pieces of the kernel contain a lot of flow changes which can 1141 Some pieces of the kernel contain a lot of flow changes which can
@@ -985,6 +1146,20 @@ config DEBUG_BFIN_NO_KERN_HWTRACE
985 Say Y here to disable hardware tracing in some known "jumpy" pieces 1146 Say Y here to disable hardware tracing in some known "jumpy" pieces
986 of code so that the trace buffer will extend further back. 1147 of code so that the trace buffer will extend further back.
987 1148
1149config EARLY_PRINTK
1150 bool "Early printk"
1151 default n
1152 help
1153 This option enables special console drivers which allow the kernel
1154 to print messages very early in the bootup process.
1155
1156 This is useful for kernel debugging when your machine crashes very
1157 early before the console code is initialized. After enabling this
1158 feature, you must add "earlyprintk=serial,uart0,57600" to the
1159 command line (bootargs). It is safe to say Y here in all cases, as
1160 all of this lives in the init section and is thrown away after the
1161 kernel boots completely.
1162
988config DUAL_CORE_TEST_MODULE 1163config DUAL_CORE_TEST_MODULE
989 tristate "Dual Core Test Module" 1164 tristate "Dual Core Test Module"
990 depends on (BF561) 1165 depends on (BF561)
diff --git a/arch/blackfin/configs/BF533-EZKIT_defconfig b/arch/blackfin/configs/BF533-EZKIT_defconfig
index 1cf1ab28dc66..57f58d5cd47a 100644
--- a/arch/blackfin/configs/BF533-EZKIT_defconfig
+++ b/arch/blackfin/configs/BF533-EZKIT_defconfig
@@ -1,6 +1,6 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.21.5 3# Linux kernel version: 2.6.22.6
4# 4#
5# CONFIG_MMU is not set 5# CONFIG_MMU is not set
6# CONFIG_FPU is not set 6# CONFIG_FPU is not set
@@ -15,8 +15,9 @@ CONFIG_GENERIC_HWEIGHT=y
15CONFIG_GENERIC_HARDIRQS=y 15CONFIG_GENERIC_HARDIRQS=y
16CONFIG_GENERIC_IRQ_PROBE=y 16CONFIG_GENERIC_IRQ_PROBE=y
17# CONFIG_GENERIC_TIME is not set 17# CONFIG_GENERIC_TIME is not set
18CONFIG_GENERIC_CALIBRATE_DELAY=y 18CONFIG_GENERIC_GPIO=y
19CONFIG_FORCE_MAX_ZONEORDER=14 19CONFIG_FORCE_MAX_ZONEORDER=14
20CONFIG_GENERIC_CALIBRATE_DELAY=y
20CONFIG_IRQCHIP_DEMUX_GPIO=y 21CONFIG_IRQCHIP_DEMUX_GPIO=y
21CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config" 22CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
22 23
@@ -40,7 +41,9 @@ CONFIG_SYSVIPC_SYSCTL=y
40# CONFIG_TASKSTATS is not set 41# CONFIG_TASKSTATS is not set
41# CONFIG_UTS_NS is not set 42# CONFIG_UTS_NS is not set
42# CONFIG_AUDIT is not set 43# CONFIG_AUDIT is not set
43# CONFIG_IKCONFIG is not set 44CONFIG_IKCONFIG=y
45CONFIG_IKCONFIG_PROC=y
46CONFIG_LOG_BUF_SHIFT=14
44CONFIG_SYSFS_DEPRECATED=y 47CONFIG_SYSFS_DEPRECATED=y
45# CONFIG_RELAY is not set 48# CONFIG_RELAY is not set
46CONFIG_BLK_DEV_INITRD=y 49CONFIG_BLK_DEV_INITRD=y
@@ -58,15 +61,20 @@ CONFIG_BUG=y
58CONFIG_ELF_CORE=y 61CONFIG_ELF_CORE=y
59CONFIG_BASE_FULL=y 62CONFIG_BASE_FULL=y
60CONFIG_FUTEX=y 63CONFIG_FUTEX=y
64CONFIG_ANON_INODES=y
65CONFIG_EPOLL=y
66CONFIG_SIGNALFD=y
67CONFIG_TIMERFD=y
68CONFIG_EVENTFD=y
69CONFIG_VM_EVENT_COUNTERS=y
61CONFIG_BIG_ORDER_ALLOC_NOFAIL_MAGIC=3 70CONFIG_BIG_ORDER_ALLOC_NOFAIL_MAGIC=3
62CONFIG_BUDDY=y
63# CONFIG_NP2 is not set 71# CONFIG_NP2 is not set
64CONFIG_SLAB=y 72CONFIG_SLAB=y
65CONFIG_VM_EVENT_COUNTERS=y 73# CONFIG_SLUB is not set
74# CONFIG_SLOB is not set
66CONFIG_RT_MUTEXES=y 75CONFIG_RT_MUTEXES=y
67CONFIG_TINY_SHMEM=y 76CONFIG_TINY_SHMEM=y
68CONFIG_BASE_SMALL=0 77CONFIG_BASE_SMALL=0
69# CONFIG_SLOB is not set
70 78
71# 79#
72# Loadable module support 80# Loadable module support
@@ -184,19 +192,17 @@ CONFIG_WDTIMER=13
184# CONFIG_CMDLINE_BOOL is not set 192# CONFIG_CMDLINE_BOOL is not set
185 193
186# 194#
187# Board Setup 195# Clock/PLL Setup
188# 196#
189CONFIG_CLKIN_HZ=27000000 197CONFIG_CLKIN_HZ=27000000
190CONFIG_MEM_SIZE=32 198# CONFIG_BFIN_KERNEL_CLOCK is not set
191CONFIG_MEM_ADD_WIDTH=9 199CONFIG_MAX_VCO_HZ=750000000
192CONFIG_BOOT_LOAD=0x1000 200CONFIG_MIN_VCO_HZ=50000000
193 201CONFIG_MAX_SCLK_HZ=133000000
194# 202CONFIG_MIN_SCLK_HZ=27000000
195# Blackfin Kernel Optimizations
196#
197 203
198# 204#
199# Timer Tick 205# Kernel Timer/Scheduler
200# 206#
201# CONFIG_HZ_100 is not set 207# CONFIG_HZ_100 is not set
202CONFIG_HZ_250=y 208CONFIG_HZ_250=y
@@ -205,6 +211,20 @@ CONFIG_HZ_250=y
205CONFIG_HZ=250 211CONFIG_HZ=250
206 212
207# 213#
214# Memory Setup
215#
216CONFIG_MEM_SIZE=32
217CONFIG_MEM_ADD_WIDTH=9
218CONFIG_BOOT_LOAD=0x1000
219CONFIG_BFIN_SCRATCH_REG_RETN=y
220# CONFIG_BFIN_SCRATCH_REG_RETE is not set
221# CONFIG_BFIN_SCRATCH_REG_CYCLES is not set
222
223#
224# Blackfin Kernel Optimizations
225#
226
227#
208# Memory Optimizations 228# Memory Optimizations
209# 229#
210CONFIG_I_ENTRY_L1=y 230CONFIG_I_ENTRY_L1=y
@@ -243,20 +263,15 @@ CONFIG_DMA_UNCACHED_1M=y
243# 263#
244# Cache Support 264# Cache Support
245# 265#
246CONFIG_BLKFIN_CACHE=y 266CONFIG_BFIN_ICACHE=y
247CONFIG_BLKFIN_DCACHE=y 267CONFIG_BFIN_DCACHE=y
248# CONFIG_BLKFIN_DCACHE_BANKA is not set 268# CONFIG_BFIN_DCACHE_BANKA is not set
249# CONFIG_BLKFIN_CACHE_LOCK is not set 269# CONFIG_BFIN_ICACHE_LOCK is not set
250# CONFIG_BLKFIN_WB is not set 270# CONFIG_BFIN_WB is not set
251CONFIG_BLKFIN_WT=y 271CONFIG_BFIN_WT=y
252CONFIG_L1_MAX_PIECE=16 272CONFIG_L1_MAX_PIECE=16
253 273
254# 274#
255# Clock Settings
256#
257# CONFIG_BFIN_KERNEL_CLOCK is not set
258
259#
260# Asynchonous Memory Configuration 275# Asynchonous Memory Configuration
261# 276#
262 277
@@ -277,12 +292,13 @@ CONFIG_C_AMBEN_ALL=y
277CONFIG_BANK_0=0x7BB0 292CONFIG_BANK_0=0x7BB0
278CONFIG_BANK_1=0x7BB0 293CONFIG_BANK_1=0x7BB0
279CONFIG_BANK_2=0x7BB0 294CONFIG_BANK_2=0x7BB0
280CONFIG_BANK_3=0x99B3 295CONFIG_BANK_3=0xAAC3
281 296
282# 297#
283# Bus options (PCI, PCMCIA, EISA, MCA, ISA) 298# Bus options (PCI, PCMCIA, EISA, MCA, ISA)
284# 299#
285# CONFIG_PCI is not set 300# CONFIG_PCI is not set
301# CONFIG_ARCH_SUPPORTS_MSI is not set
286 302
287# 303#
288# PCCARD (PCMCIA/CardBus) support 304# PCCARD (PCMCIA/CardBus) support
@@ -290,10 +306,6 @@ CONFIG_BANK_3=0x99B3
290# CONFIG_PCCARD is not set 306# CONFIG_PCCARD is not set
291 307
292# 308#
293# PCI Hotplug Support
294#
295
296#
297# Executable file formats 309# Executable file formats
298# 310#
299CONFIG_BINFMT_ELF_FDPIC=y 311CONFIG_BINFMT_ELF_FDPIC=y
@@ -327,7 +339,6 @@ CONFIG_NET=y
327# 339#
328# Networking options 340# Networking options
329# 341#
330# CONFIG_NETDEBUG is not set
331CONFIG_PACKET=y 342CONFIG_PACKET=y
332# CONFIG_PACKET_MMAP is not set 343# CONFIG_PACKET_MMAP is not set
333CONFIG_UNIX=y 344CONFIG_UNIX=y
@@ -368,20 +379,8 @@ CONFIG_DEFAULT_TCP_CONG="cubic"
368# CONFIG_NETLABEL is not set 379# CONFIG_NETLABEL is not set
369# CONFIG_NETWORK_SECMARK is not set 380# CONFIG_NETWORK_SECMARK is not set
370# CONFIG_NETFILTER is not set 381# CONFIG_NETFILTER is not set
371
372#
373# DCCP Configuration (EXPERIMENTAL)
374#
375# CONFIG_IP_DCCP is not set 382# CONFIG_IP_DCCP is not set
376
377#
378# SCTP Configuration (EXPERIMENTAL)
379#
380# CONFIG_IP_SCTP is not set 383# CONFIG_IP_SCTP is not set
381
382#
383# TIPC Configuration (EXPERIMENTAL)
384#
385# CONFIG_TIPC is not set 384# CONFIG_TIPC is not set
386# CONFIG_ATM is not set 385# CONFIG_ATM is not set
387# CONFIG_BRIDGE is not set 386# CONFIG_BRIDGE is not set
@@ -448,7 +447,16 @@ CONFIG_IRTTY_SIR=m
448# FIR device drivers 447# FIR device drivers
449# 448#
450# CONFIG_BT is not set 449# CONFIG_BT is not set
450# CONFIG_AF_RXRPC is not set
451
452#
453# Wireless
454#
455# CONFIG_CFG80211 is not set
456# CONFIG_WIRELESS_EXT is not set
457# CONFIG_MAC80211 is not set
451# CONFIG_IEEE80211 is not set 458# CONFIG_IEEE80211 is not set
459# CONFIG_RFKILL is not set
452 460
453# 461#
454# Device Drivers 462# Device Drivers
@@ -466,10 +474,6 @@ CONFIG_PREVENT_FIRMWARE_BUILD=y
466# Connector - unified userspace <-> kernelspace linker 474# Connector - unified userspace <-> kernelspace linker
467# 475#
468# CONFIG_CONNECTOR is not set 476# CONFIG_CONNECTOR is not set
469
470#
471# Memory Technology Devices (MTD)
472#
473CONFIG_MTD=y 477CONFIG_MTD=y
474# CONFIG_MTD_DEBUG is not set 478# CONFIG_MTD_DEBUG is not set
475# CONFIG_MTD_CONCAT is not set 479# CONFIG_MTD_CONCAT is not set
@@ -513,7 +517,6 @@ CONFIG_MTD_MW320D=m
513CONFIG_MTD_RAM=y 517CONFIG_MTD_RAM=y
514CONFIG_MTD_ROM=m 518CONFIG_MTD_ROM=m
515# CONFIG_MTD_ABSENT is not set 519# CONFIG_MTD_ABSENT is not set
516# CONFIG_MTD_OBSOLETE_CHIPS is not set
517 520
518# 521#
519# Mapping drivers for chip access 522# Mapping drivers for chip access
@@ -550,16 +553,13 @@ CONFIG_BFIN_FLASH_BANK_3=0x7BB0
550# CONFIG_MTD_DOC2000 is not set 553# CONFIG_MTD_DOC2000 is not set
551# CONFIG_MTD_DOC2001 is not set 554# CONFIG_MTD_DOC2001 is not set
552# CONFIG_MTD_DOC2001PLUS is not set 555# CONFIG_MTD_DOC2001PLUS is not set
553
554#
555# NAND Flash Device Drivers
556#
557# CONFIG_MTD_NAND is not set 556# CONFIG_MTD_NAND is not set
557# CONFIG_MTD_ONENAND is not set
558 558
559# 559#
560# OneNAND Flash Device Drivers 560# UBI - Unsorted block images
561# 561#
562# CONFIG_MTD_ONENAND is not set 562# CONFIG_MTD_UBI is not set
563 563
564# 564#
565# Parallel port support 565# Parallel port support
@@ -587,10 +587,6 @@ CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
587# 587#
588# Misc devices 588# Misc devices
589# 589#
590
591#
592# ATA/ATAPI/MFM/RLL support
593#
594# CONFIG_IDE is not set 590# CONFIG_IDE is not set
595 591
596# 592#
@@ -599,10 +595,6 @@ CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
599# CONFIG_RAID_ATTRS is not set 595# CONFIG_RAID_ATTRS is not set
600# CONFIG_SCSI is not set 596# CONFIG_SCSI is not set
601# CONFIG_SCSI_NETLINK is not set 597# CONFIG_SCSI_NETLINK is not set
602
603#
604# Serial ATA (prod) and Parallel ATA (experimental) drivers
605#
606# CONFIG_ATA is not set 598# CONFIG_ATA is not set
607 599
608# 600#
@@ -611,19 +603,6 @@ CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
611# CONFIG_MD is not set 603# CONFIG_MD is not set
612 604
613# 605#
614# Fusion MPT device support
615#
616# CONFIG_FUSION is not set
617
618#
619# IEEE 1394 (FireWire) support
620#
621
622#
623# I2O device support
624#
625
626#
627# Network device support 606# Network device support
628# 607#
629CONFIG_NETDEVICES=y 608CONFIG_NETDEVICES=y
@@ -631,10 +610,6 @@ CONFIG_NETDEVICES=y
631# CONFIG_BONDING is not set 610# CONFIG_BONDING is not set
632# CONFIG_EQUALIZER is not set 611# CONFIG_EQUALIZER is not set
633# CONFIG_TUN is not set 612# CONFIG_TUN is not set
634
635#
636# PHY device support
637#
638# CONFIG_PHYLIB is not set 613# CONFIG_PHYLIB is not set
639 614
640# 615#
@@ -644,27 +619,15 @@ CONFIG_NET_ETHERNET=y
644CONFIG_MII=y 619CONFIG_MII=y
645CONFIG_SMC91X=y 620CONFIG_SMC91X=y
646# CONFIG_SMSC911X is not set 621# CONFIG_SMSC911X is not set
622# CONFIG_DM9000 is not set
623CONFIG_NETDEV_1000=y
624CONFIG_NETDEV_10000=y
647 625
648# 626#
649# Ethernet (1000 Mbit) 627# Wireless LAN
650#
651
652#
653# Ethernet (10000 Mbit)
654#
655
656#
657# Token Ring devices
658#
659
660#
661# Wireless LAN (non-hamradio)
662#
663# CONFIG_NET_RADIO is not set
664
665#
666# Wan interfaces
667# 628#
629# CONFIG_WLAN_PRE80211 is not set
630# CONFIG_WLAN_80211 is not set
668# CONFIG_WAN is not set 631# CONFIG_WAN is not set
669# CONFIG_PPP is not set 632# CONFIG_PPP is not set
670# CONFIG_SLIP is not set 633# CONFIG_SLIP is not set
@@ -688,6 +651,7 @@ CONFIG_SMC91X=y
688# 651#
689CONFIG_INPUT=m 652CONFIG_INPUT=m
690# CONFIG_INPUT_FF_MEMLESS is not set 653# CONFIG_INPUT_FF_MEMLESS is not set
654# CONFIG_INPUT_POLLDEV is not set
691 655
692# 656#
693# Userland interfaces 657# Userland interfaces
@@ -704,6 +668,7 @@ CONFIG_INPUT_EVDEV=m
704# CONFIG_INPUT_KEYBOARD is not set 668# CONFIG_INPUT_KEYBOARD is not set
705# CONFIG_INPUT_MOUSE is not set 669# CONFIG_INPUT_MOUSE is not set
706# CONFIG_INPUT_JOYSTICK is not set 670# CONFIG_INPUT_JOYSTICK is not set
671# CONFIG_INPUT_TABLET is not set
707# CONFIG_INPUT_TOUCHSCREEN is not set 672# CONFIG_INPUT_TOUCHSCREEN is not set
708# CONFIG_INPUT_MISC is not set 673# CONFIG_INPUT_MISC is not set
709 674
@@ -718,7 +683,7 @@ CONFIG_INPUT_EVDEV=m
718# 683#
719# CONFIG_AD9960 is not set 684# CONFIG_AD9960 is not set
720# CONFIG_SPI_ADC_BF533 is not set 685# CONFIG_SPI_ADC_BF533 is not set
721# CONFIG_BF5xx_PFLAGS is not set 686# CONFIG_BFIN_PFLAGS is not set
722# CONFIG_BF5xx_PPIFCD is not set 687# CONFIG_BF5xx_PPIFCD is not set
723# CONFIG_BF5xx_TIMERS is not set 688# CONFIG_BF5xx_TIMERS is not set
724# CONFIG_BF5xx_PPI is not set 689# CONFIG_BF5xx_PPI is not set
@@ -758,10 +723,6 @@ CONFIG_UNIX98_PTYS=y
758# IPMI 723# IPMI
759# 724#
760# CONFIG_IPMI_HANDLER is not set 725# CONFIG_IPMI_HANDLER is not set
761
762#
763# Watchdog Cards
764#
765CONFIG_WATCHDOG=y 726CONFIG_WATCHDOG=y
766# CONFIG_WATCHDOG_NOWAYOUT is not set 727# CONFIG_WATCHDOG_NOWAYOUT is not set
767 728
@@ -773,7 +734,6 @@ CONFIG_BFIN_WDT=y
773CONFIG_HW_RANDOM=y 734CONFIG_HW_RANDOM=y
774# CONFIG_GEN_RTC is not set 735# CONFIG_GEN_RTC is not set
775CONFIG_BLACKFIN_DPMC=y 736CONFIG_BLACKFIN_DPMC=y
776# CONFIG_DTLK is not set
777# CONFIG_R3964 is not set 737# CONFIG_R3964 is not set
778# CONFIG_RAW_DRIVER is not set 738# CONFIG_RAW_DRIVER is not set
779 739
@@ -781,10 +741,6 @@ CONFIG_BLACKFIN_DPMC=y
781# TPM devices 741# TPM devices
782# 742#
783# CONFIG_TCG_TPM is not set 743# CONFIG_TCG_TPM is not set
784
785#
786# I2C support
787#
788# CONFIG_I2C is not set 744# CONFIG_I2C is not set
789 745
790# 746#
@@ -803,22 +759,22 @@ CONFIG_SPI_BFIN=y
803# SPI Protocol Masters 759# SPI Protocol Masters
804# 760#
805# CONFIG_SPI_AT25 is not set 761# CONFIG_SPI_AT25 is not set
762# CONFIG_SPI_SPIDEV is not set
806 763
807# 764#
808# Dallas's 1-wire bus 765# Dallas's 1-wire bus
809# 766#
810# CONFIG_W1 is not set 767# CONFIG_W1 is not set
811
812#
813# Hardware Monitoring support
814#
815CONFIG_HWMON=y 768CONFIG_HWMON=y
816# CONFIG_HWMON_VID is not set 769# CONFIG_HWMON_VID is not set
817# CONFIG_SENSORS_ABITUGURU is not set 770# CONFIG_SENSORS_ABITUGURU is not set
818# CONFIG_SENSORS_F71805F is not set 771# CONFIG_SENSORS_F71805F is not set
819# CONFIG_SENSORS_LM70 is not set 772# CONFIG_SENSORS_LM70 is not set
820# CONFIG_SENSORS_PC87427 is not set 773# CONFIG_SENSORS_PC87427 is not set
774# CONFIG_SENSORS_SMSC47M1 is not set
775# CONFIG_SENSORS_SMSC47B397 is not set
821# CONFIG_SENSORS_VT1211 is not set 776# CONFIG_SENSORS_VT1211 is not set
777# CONFIG_SENSORS_W83627HF is not set
822# CONFIG_HWMON_DEBUG_CHIP is not set 778# CONFIG_HWMON_DEBUG_CHIP is not set
823 779
824# 780#
@@ -830,16 +786,19 @@ CONFIG_HWMON=y
830# Multimedia devices 786# Multimedia devices
831# 787#
832# CONFIG_VIDEO_DEV is not set 788# CONFIG_VIDEO_DEV is not set
789# CONFIG_DVB_CORE is not set
790CONFIG_DAB=y
833 791
834# 792#
835# Digital Video Broadcasting Devices 793# Graphics support
836# 794#
837# CONFIG_DVB is not set 795# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
838 796
839# 797#
840# Graphics support 798# Display device support
841# 799#
842# CONFIG_BACKLIGHT_LCD_SUPPORT is not set 800# CONFIG_DISPLAY_SUPPORT is not set
801# CONFIG_VGASTATE is not set
843# CONFIG_FB is not set 802# CONFIG_FB is not set
844 803
845# 804#
@@ -862,18 +821,17 @@ CONFIG_USB_ARCH_HAS_HCD=y
862# CONFIG_USB is not set 821# CONFIG_USB is not set
863 822
864# 823#
865# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support' 824# Enable Host or Gadget support to see Inventra options
866# 825#
867 826
868# 827#
869# USB Gadget Support 828# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support'
870# 829#
871# CONFIG_USB_GADGET is not set
872 830
873# 831#
874# MMC/SD Card support 832# USB Gadget Support
875# 833#
876# CONFIG_SPI_MMC is not set 834# CONFIG_USB_GADGET is not set
877# CONFIG_MMC is not set 835# CONFIG_MMC is not set
878 836
879# 837#
@@ -913,17 +871,29 @@ CONFIG_RTC_INTF_SYSFS=y
913CONFIG_RTC_INTF_PROC=y 871CONFIG_RTC_INTF_PROC=y
914CONFIG_RTC_INTF_DEV=y 872CONFIG_RTC_INTF_DEV=y
915# CONFIG_RTC_INTF_DEV_UIE_EMUL is not set 873# CONFIG_RTC_INTF_DEV_UIE_EMUL is not set
874# CONFIG_RTC_DRV_TEST is not set
875
876#
877# I2C RTC drivers
878#
879
880#
881# SPI RTC drivers
882#
883# CONFIG_RTC_DRV_RS5C348 is not set
884# CONFIG_RTC_DRV_MAX6902 is not set
916 885
917# 886#
918# RTC drivers 887# Platform RTC drivers
919# 888#
920# CONFIG_RTC_DRV_DS1553 is not set 889# CONFIG_RTC_DRV_DS1553 is not set
921# CONFIG_RTC_DRV_DS1742 is not set 890# CONFIG_RTC_DRV_DS1742 is not set
922# CONFIG_RTC_DRV_RS5C348 is not set
923# CONFIG_RTC_DRV_M48T86 is not set 891# CONFIG_RTC_DRV_M48T86 is not set
924# CONFIG_RTC_DRV_TEST is not set
925# CONFIG_RTC_DRV_MAX6902 is not set
926# CONFIG_RTC_DRV_V3020 is not set 892# CONFIG_RTC_DRV_V3020 is not set
893
894#
895# on-CPU RTC drivers
896#
927CONFIG_RTC_DRV_BFIN=y 897CONFIG_RTC_DRV_BFIN=y
928 898
929# 899#
@@ -940,14 +910,6 @@ CONFIG_RTC_DRV_BFIN=y
940# 910#
941 911
942# 912#
943# Auxiliary Display support
944#
945
946#
947# Virtualization
948#
949
950#
951# PBX support 913# PBX support
952# 914#
953# CONFIG_PBX is not set 915# CONFIG_PBX is not set
@@ -1047,6 +1009,7 @@ CONFIG_LOCKD=m
1047CONFIG_LOCKD_V4=y 1009CONFIG_LOCKD_V4=y
1048CONFIG_NFS_COMMON=y 1010CONFIG_NFS_COMMON=y
1049CONFIG_SUNRPC=m 1011CONFIG_SUNRPC=m
1012# CONFIG_SUNRPC_BIND34 is not set
1050# CONFIG_RPCSEC_GSS_KRB5 is not set 1013# CONFIG_RPCSEC_GSS_KRB5 is not set
1051# CONFIG_RPCSEC_GSS_SPKM3 is not set 1014# CONFIG_RPCSEC_GSS_SPKM3 is not set
1052CONFIG_SMB_FS=m 1015CONFIG_SMB_FS=m
@@ -1124,14 +1087,20 @@ CONFIG_NLS_DEFAULT="iso8859-1"
1124CONFIG_ENABLE_MUST_CHECK=y 1087CONFIG_ENABLE_MUST_CHECK=y
1125# CONFIG_MAGIC_SYSRQ is not set 1088# CONFIG_MAGIC_SYSRQ is not set
1126# CONFIG_UNUSED_SYMBOLS is not set 1089# CONFIG_UNUSED_SYMBOLS is not set
1127# CONFIG_DEBUG_FS is not set 1090CONFIG_DEBUG_FS=y
1128# CONFIG_HEADERS_CHECK is not set 1091# CONFIG_HEADERS_CHECK is not set
1129# CONFIG_DEBUG_KERNEL is not set 1092# CONFIG_DEBUG_KERNEL is not set
1130CONFIG_LOG_BUF_SHIFT=14
1131# CONFIG_DEBUG_BUGVERBOSE is not set 1093# CONFIG_DEBUG_BUGVERBOSE is not set
1132# CONFIG_DEBUG_SERIAL_EARLY_INIT is not set 1094CONFIG_DEBUG_MMRS=y
1133CONFIG_DEBUG_HUNT_FOR_ZERO=y 1095CONFIG_DEBUG_HUNT_FOR_ZERO=y
1096CONFIG_DEBUG_BFIN_HWTRACE_ON=y
1097CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_OFF=y
1098# CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_ONE is not set
1099# CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_TWO is not set
1100CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION=0
1101# CONFIG_DEBUG_BFIN_HWTRACE_EXPAND is not set
1134# CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE is not set 1102# CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE is not set
1103CONFIG_EARLY_PRINTK=y
1135CONFIG_CPLB_INFO=y 1104CONFIG_CPLB_INFO=y
1136CONFIG_ACCESS_CHECK=y 1105CONFIG_ACCESS_CHECK=y
1137 1106
@@ -1154,6 +1123,7 @@ CONFIG_SECURITY_CAPABILITIES=m
1154CONFIG_BITREVERSE=y 1123CONFIG_BITREVERSE=y
1155CONFIG_CRC_CCITT=m 1124CONFIG_CRC_CCITT=m
1156# CONFIG_CRC16 is not set 1125# CONFIG_CRC16 is not set
1126# CONFIG_CRC_ITU_T is not set
1157CONFIG_CRC32=y 1127CONFIG_CRC32=y
1158# CONFIG_LIBCRC32C is not set 1128# CONFIG_LIBCRC32C is not set
1159CONFIG_ZLIB_INFLATE=y 1129CONFIG_ZLIB_INFLATE=y
@@ -1161,3 +1131,4 @@ CONFIG_ZLIB_DEFLATE=m
1161CONFIG_PLIST=y 1131CONFIG_PLIST=y
1162CONFIG_HAS_IOMEM=y 1132CONFIG_HAS_IOMEM=y
1163CONFIG_HAS_IOPORT=y 1133CONFIG_HAS_IOPORT=y
1134CONFIG_HAS_DMA=y
diff --git a/arch/blackfin/configs/BF533-STAMP_defconfig b/arch/blackfin/configs/BF533-STAMP_defconfig
index 64b7f1b3b2af..306302baff06 100644
--- a/arch/blackfin/configs/BF533-STAMP_defconfig
+++ b/arch/blackfin/configs/BF533-STAMP_defconfig
@@ -1,6 +1,6 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.21.5 3# Linux kernel version: 2.6.22.6
4# 4#
5# CONFIG_MMU is not set 5# CONFIG_MMU is not set
6# CONFIG_FPU is not set 6# CONFIG_FPU is not set
@@ -15,8 +15,9 @@ CONFIG_GENERIC_HWEIGHT=y
15CONFIG_GENERIC_HARDIRQS=y 15CONFIG_GENERIC_HARDIRQS=y
16CONFIG_GENERIC_IRQ_PROBE=y 16CONFIG_GENERIC_IRQ_PROBE=y
17# CONFIG_GENERIC_TIME is not set 17# CONFIG_GENERIC_TIME is not set
18CONFIG_GENERIC_CALIBRATE_DELAY=y 18CONFIG_GENERIC_GPIO=y
19CONFIG_FORCE_MAX_ZONEORDER=14 19CONFIG_FORCE_MAX_ZONEORDER=14
20CONFIG_GENERIC_CALIBRATE_DELAY=y
20CONFIG_IRQCHIP_DEMUX_GPIO=y 21CONFIG_IRQCHIP_DEMUX_GPIO=y
21CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config" 22CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
22 23
@@ -40,7 +41,9 @@ CONFIG_SYSVIPC_SYSCTL=y
40# CONFIG_TASKSTATS is not set 41# CONFIG_TASKSTATS is not set
41# CONFIG_UTS_NS is not set 42# CONFIG_UTS_NS is not set
42# CONFIG_AUDIT is not set 43# CONFIG_AUDIT is not set
43# CONFIG_IKCONFIG is not set 44CONFIG_IKCONFIG=y
45CONFIG_IKCONFIG_PROC=y
46CONFIG_LOG_BUF_SHIFT=14
44CONFIG_SYSFS_DEPRECATED=y 47CONFIG_SYSFS_DEPRECATED=y
45# CONFIG_RELAY is not set 48# CONFIG_RELAY is not set
46CONFIG_BLK_DEV_INITRD=y 49CONFIG_BLK_DEV_INITRD=y
@@ -58,15 +61,20 @@ CONFIG_BUG=y
58CONFIG_ELF_CORE=y 61CONFIG_ELF_CORE=y
59CONFIG_BASE_FULL=y 62CONFIG_BASE_FULL=y
60CONFIG_FUTEX=y 63CONFIG_FUTEX=y
64CONFIG_ANON_INODES=y
65CONFIG_EPOLL=y
66CONFIG_SIGNALFD=y
67CONFIG_TIMERFD=y
68CONFIG_EVENTFD=y
69CONFIG_VM_EVENT_COUNTERS=y
61CONFIG_BIG_ORDER_ALLOC_NOFAIL_MAGIC=3 70CONFIG_BIG_ORDER_ALLOC_NOFAIL_MAGIC=3
62CONFIG_BUDDY=y
63# CONFIG_NP2 is not set 71# CONFIG_NP2 is not set
64CONFIG_SLAB=y 72CONFIG_SLAB=y
65CONFIG_VM_EVENT_COUNTERS=y 73# CONFIG_SLUB is not set
74# CONFIG_SLOB is not set
66CONFIG_RT_MUTEXES=y 75CONFIG_RT_MUTEXES=y
67CONFIG_TINY_SHMEM=y 76CONFIG_TINY_SHMEM=y
68CONFIG_BASE_SMALL=0 77CONFIG_BASE_SMALL=0
69# CONFIG_SLOB is not set
70 78
71# 79#
72# Loadable module support 80# Loadable module support
@@ -185,9 +193,27 @@ CONFIG_WDTIMER=13
185# CONFIG_CMDLINE_BOOL is not set 193# CONFIG_CMDLINE_BOOL is not set
186 194
187# 195#
188# Board Setup 196# Clock/PLL Setup
189# 197#
190CONFIG_CLKIN_HZ=11059200 198CONFIG_CLKIN_HZ=11059200
199# CONFIG_BFIN_KERNEL_CLOCK is not set
200CONFIG_MAX_VCO_HZ=750000000
201CONFIG_MIN_VCO_HZ=50000000
202CONFIG_MAX_SCLK_HZ=133000000
203CONFIG_MIN_SCLK_HZ=27000000
204
205#
206# Kernel Timer/Scheduler
207#
208# CONFIG_HZ_100 is not set
209CONFIG_HZ_250=y
210# CONFIG_HZ_300 is not set
211# CONFIG_HZ_1000 is not set
212CONFIG_HZ=250
213
214#
215# Memory Setup
216#
191CONFIG_MEM_SIZE=128 217CONFIG_MEM_SIZE=128
192CONFIG_MEM_ADD_WIDTH=11 218CONFIG_MEM_ADD_WIDTH=11
193CONFIG_ENET_FLASH_PIN=0 219CONFIG_ENET_FLASH_PIN=0
@@ -198,6 +224,9 @@ CONFIG_BOOT_LOAD=0x1000
198# 224#
199# CONFIG_BFIN_ALIVE_LED is not set 225# CONFIG_BFIN_ALIVE_LED is not set
200# CONFIG_BFIN_IDLE_LED is not set 226# CONFIG_BFIN_IDLE_LED is not set
227CONFIG_BFIN_SCRATCH_REG_RETN=y
228# CONFIG_BFIN_SCRATCH_REG_RETE is not set
229# CONFIG_BFIN_SCRATCH_REG_CYCLES is not set
201CONFIG_BFIN_ALIVE_LED_PORT=0xFFC00700 230CONFIG_BFIN_ALIVE_LED_PORT=0xFFC00700
202CONFIG_BFIN_ALIVE_LED_DPORT=0xFFC00730 231CONFIG_BFIN_ALIVE_LED_DPORT=0xFFC00730
203CONFIG_BFIN_IDLE_LED_PORT=0xFFC00700 232CONFIG_BFIN_IDLE_LED_PORT=0xFFC00700
@@ -208,15 +237,6 @@ CONFIG_BFIN_IDLE_LED_DPORT=0xFFC00730
208# 237#
209 238
210# 239#
211# Timer Tick
212#
213# CONFIG_HZ_100 is not set
214CONFIG_HZ_250=y
215# CONFIG_HZ_300 is not set
216# CONFIG_HZ_1000 is not set
217CONFIG_HZ=250
218
219#
220# Memory Optimizations 240# Memory Optimizations
221# 241#
222CONFIG_I_ENTRY_L1=y 242CONFIG_I_ENTRY_L1=y
@@ -255,20 +275,15 @@ CONFIG_DMA_UNCACHED_1M=y
255# 275#
256# Cache Support 276# Cache Support
257# 277#
258CONFIG_BLKFIN_CACHE=y 278CONFIG_BFIN_ICACHE=y
259CONFIG_BLKFIN_DCACHE=y 279CONFIG_BFIN_DCACHE=y
260# CONFIG_BLKFIN_DCACHE_BANKA is not set 280# CONFIG_BFIN_DCACHE_BANKA is not set
261# CONFIG_BLKFIN_CACHE_LOCK is not set 281# CONFIG_BFIN_ICACHE_LOCK is not set
262# CONFIG_BLKFIN_WB is not set 282# CONFIG_BFIN_WB is not set
263CONFIG_BLKFIN_WT=y 283CONFIG_BFIN_WT=y
264CONFIG_L1_MAX_PIECE=16 284CONFIG_L1_MAX_PIECE=16
265 285
266# 286#
267# Clock Settings
268#
269# CONFIG_BFIN_KERNEL_CLOCK is not set
270
271#
272# Asynchonous Memory Configuration 287# Asynchonous Memory Configuration
273# 288#
274 289
@@ -289,12 +304,13 @@ CONFIG_C_AMBEN_ALL=y
289CONFIG_BANK_0=0x7BB0 304CONFIG_BANK_0=0x7BB0
290CONFIG_BANK_1=0x7BB0 305CONFIG_BANK_1=0x7BB0
291CONFIG_BANK_2=0x7BB0 306CONFIG_BANK_2=0x7BB0
292CONFIG_BANK_3=0x99B3 307CONFIG_BANK_3=0xAAC3
293 308
294# 309#
295# Bus options (PCI, PCMCIA, EISA, MCA, ISA) 310# Bus options (PCI, PCMCIA, EISA, MCA, ISA)
296# 311#
297# CONFIG_PCI is not set 312# CONFIG_PCI is not set
313# CONFIG_ARCH_SUPPORTS_MSI is not set
298 314
299# 315#
300# PCCARD (PCMCIA/CardBus) support 316# PCCARD (PCMCIA/CardBus) support
@@ -302,10 +318,6 @@ CONFIG_BANK_3=0x99B3
302# CONFIG_PCCARD is not set 318# CONFIG_PCCARD is not set
303 319
304# 320#
305# PCI Hotplug Support
306#
307
308#
309# Executable file formats 321# Executable file formats
310# 322#
311CONFIG_BINFMT_ELF_FDPIC=y 323CONFIG_BINFMT_ELF_FDPIC=y
@@ -339,7 +351,6 @@ CONFIG_NET=y
339# 351#
340# Networking options 352# Networking options
341# 353#
342# CONFIG_NETDEBUG is not set
343CONFIG_PACKET=y 354CONFIG_PACKET=y
344# CONFIG_PACKET_MMAP is not set 355# CONFIG_PACKET_MMAP is not set
345CONFIG_UNIX=y 356CONFIG_UNIX=y
@@ -380,20 +391,8 @@ CONFIG_DEFAULT_TCP_CONG="cubic"
380# CONFIG_NETLABEL is not set 391# CONFIG_NETLABEL is not set
381# CONFIG_NETWORK_SECMARK is not set 392# CONFIG_NETWORK_SECMARK is not set
382# CONFIG_NETFILTER is not set 393# CONFIG_NETFILTER is not set
383
384#
385# DCCP Configuration (EXPERIMENTAL)
386#
387# CONFIG_IP_DCCP is not set 394# CONFIG_IP_DCCP is not set
388
389#
390# SCTP Configuration (EXPERIMENTAL)
391#
392# CONFIG_IP_SCTP is not set 395# CONFIG_IP_SCTP is not set
393
394#
395# TIPC Configuration (EXPERIMENTAL)
396#
397# CONFIG_TIPC is not set 396# CONFIG_TIPC is not set
398# CONFIG_ATM is not set 397# CONFIG_ATM is not set
399# CONFIG_BRIDGE is not set 398# CONFIG_BRIDGE is not set
@@ -460,7 +459,16 @@ CONFIG_IRTTY_SIR=m
460# FIR device drivers 459# FIR device drivers
461# 460#
462# CONFIG_BT is not set 461# CONFIG_BT is not set
462# CONFIG_AF_RXRPC is not set
463
464#
465# Wireless
466#
467# CONFIG_CFG80211 is not set
468# CONFIG_WIRELESS_EXT is not set
469# CONFIG_MAC80211 is not set
463# CONFIG_IEEE80211 is not set 470# CONFIG_IEEE80211 is not set
471# CONFIG_RFKILL is not set
464 472
465# 473#
466# Device Drivers 474# Device Drivers
@@ -478,10 +486,6 @@ CONFIG_PREVENT_FIRMWARE_BUILD=y
478# Connector - unified userspace <-> kernelspace linker 486# Connector - unified userspace <-> kernelspace linker
479# 487#
480# CONFIG_CONNECTOR is not set 488# CONFIG_CONNECTOR is not set
481
482#
483# Memory Technology Devices (MTD)
484#
485CONFIG_MTD=y 489CONFIG_MTD=y
486# CONFIG_MTD_DEBUG is not set 490# CONFIG_MTD_DEBUG is not set
487# CONFIG_MTD_CONCAT is not set 491# CONFIG_MTD_CONCAT is not set
@@ -525,7 +529,6 @@ CONFIG_MTD_MW320D=m
525CONFIG_MTD_RAM=y 529CONFIG_MTD_RAM=y
526CONFIG_MTD_ROM=m 530CONFIG_MTD_ROM=m
527# CONFIG_MTD_ABSENT is not set 531# CONFIG_MTD_ABSENT is not set
528# CONFIG_MTD_OBSOLETE_CHIPS is not set
529 532
530# 533#
531# Mapping drivers for chip access 534# Mapping drivers for chip access
@@ -562,16 +565,13 @@ CONFIG_BFIN_FLASH_BANK_3=0x7BB0
562# CONFIG_MTD_DOC2000 is not set 565# CONFIG_MTD_DOC2000 is not set
563# CONFIG_MTD_DOC2001 is not set 566# CONFIG_MTD_DOC2001 is not set
564# CONFIG_MTD_DOC2001PLUS is not set 567# CONFIG_MTD_DOC2001PLUS is not set
565
566#
567# NAND Flash Device Drivers
568#
569# CONFIG_MTD_NAND is not set 568# CONFIG_MTD_NAND is not set
569# CONFIG_MTD_ONENAND is not set
570 570
571# 571#
572# OneNAND Flash Device Drivers 572# UBI - Unsorted block images
573# 573#
574# CONFIG_MTD_ONENAND is not set 574# CONFIG_MTD_UBI is not set
575 575
576# 576#
577# Parallel port support 577# Parallel port support
@@ -599,10 +599,6 @@ CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
599# 599#
600# Misc devices 600# Misc devices
601# 601#
602
603#
604# ATA/ATAPI/MFM/RLL support
605#
606# CONFIG_IDE is not set 602# CONFIG_IDE is not set
607 603
608# 604#
@@ -611,10 +607,6 @@ CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
611# CONFIG_RAID_ATTRS is not set 607# CONFIG_RAID_ATTRS is not set
612# CONFIG_SCSI is not set 608# CONFIG_SCSI is not set
613# CONFIG_SCSI_NETLINK is not set 609# CONFIG_SCSI_NETLINK is not set
614
615#
616# Serial ATA (prod) and Parallel ATA (experimental) drivers
617#
618# CONFIG_ATA is not set 610# CONFIG_ATA is not set
619 611
620# 612#
@@ -623,19 +615,6 @@ CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
623# CONFIG_MD is not set 615# CONFIG_MD is not set
624 616
625# 617#
626# Fusion MPT device support
627#
628# CONFIG_FUSION is not set
629
630#
631# IEEE 1394 (FireWire) support
632#
633
634#
635# I2O device support
636#
637
638#
639# Network device support 618# Network device support
640# 619#
641CONFIG_NETDEVICES=y 620CONFIG_NETDEVICES=y
@@ -643,10 +622,6 @@ CONFIG_NETDEVICES=y
643# CONFIG_BONDING is not set 622# CONFIG_BONDING is not set
644# CONFIG_EQUALIZER is not set 623# CONFIG_EQUALIZER is not set
645# CONFIG_TUN is not set 624# CONFIG_TUN is not set
646
647#
648# PHY device support
649#
650# CONFIG_PHYLIB is not set 625# CONFIG_PHYLIB is not set
651 626
652# 627#
@@ -656,27 +631,15 @@ CONFIG_NET_ETHERNET=y
656CONFIG_MII=y 631CONFIG_MII=y
657CONFIG_SMC91X=y 632CONFIG_SMC91X=y
658# CONFIG_SMSC911X is not set 633# CONFIG_SMSC911X is not set
634# CONFIG_DM9000 is not set
635CONFIG_NETDEV_1000=y
636CONFIG_NETDEV_10000=y
659 637
660# 638#
661# Ethernet (1000 Mbit) 639# Wireless LAN
662#
663
664#
665# Ethernet (10000 Mbit)
666#
667
668#
669# Token Ring devices
670#
671
672#
673# Wireless LAN (non-hamradio)
674#
675# CONFIG_NET_RADIO is not set
676
677#
678# Wan interfaces
679# 640#
641# CONFIG_WLAN_PRE80211 is not set
642# CONFIG_WLAN_80211 is not set
680# CONFIG_WAN is not set 643# CONFIG_WAN is not set
681# CONFIG_PPP is not set 644# CONFIG_PPP is not set
682# CONFIG_SLIP is not set 645# CONFIG_SLIP is not set
@@ -700,6 +663,7 @@ CONFIG_SMC91X=y
700# 663#
701CONFIG_INPUT=y 664CONFIG_INPUT=y
702# CONFIG_INPUT_FF_MEMLESS is not set 665# CONFIG_INPUT_FF_MEMLESS is not set
666# CONFIG_INPUT_POLLDEV is not set
703 667
704# 668#
705# Userland interfaces 669# Userland interfaces
@@ -716,8 +680,14 @@ CONFIG_INPUT_EVDEV=m
716# CONFIG_INPUT_KEYBOARD is not set 680# CONFIG_INPUT_KEYBOARD is not set
717# CONFIG_INPUT_MOUSE is not set 681# CONFIG_INPUT_MOUSE is not set
718# CONFIG_INPUT_JOYSTICK is not set 682# CONFIG_INPUT_JOYSTICK is not set
683# CONFIG_INPUT_TABLET is not set
719# CONFIG_INPUT_TOUCHSCREEN is not set 684# CONFIG_INPUT_TOUCHSCREEN is not set
720CONFIG_INPUT_MISC=y 685CONFIG_INPUT_MISC=y
686# CONFIG_INPUT_ATI_REMOTE is not set
687# CONFIG_INPUT_ATI_REMOTE2 is not set
688# CONFIG_INPUT_KEYSPAN_REMOTE is not set
689# CONFIG_INPUT_POWERMATE is not set
690# CONFIG_INPUT_YEALINK is not set
721# CONFIG_INPUT_UINPUT is not set 691# CONFIG_INPUT_UINPUT is not set
722# CONFIG_BF53X_PFBUTTONS is not set 692# CONFIG_BF53X_PFBUTTONS is not set
723CONFIG_TWI_KEYPAD=m 693CONFIG_TWI_KEYPAD=m
@@ -734,7 +704,7 @@ CONFIG_BFIN_TWIKEYPAD_IRQ_PFX=39
734# 704#
735# CONFIG_AD9960 is not set 705# CONFIG_AD9960 is not set
736# CONFIG_SPI_ADC_BF533 is not set 706# CONFIG_SPI_ADC_BF533 is not set
737# CONFIG_BF5xx_PFLAGS is not set 707# CONFIG_BFIN_PFLAGS is not set
738# CONFIG_BF5xx_PPIFCD is not set 708# CONFIG_BF5xx_PPIFCD is not set
739# CONFIG_BF5xx_TIMERS is not set 709# CONFIG_BF5xx_TIMERS is not set
740# CONFIG_BF5xx_PPI is not set 710# CONFIG_BF5xx_PPI is not set
@@ -777,10 +747,6 @@ CONFIG_UNIX98_PTYS=y
777# IPMI 747# IPMI
778# 748#
779# CONFIG_IPMI_HANDLER is not set 749# CONFIG_IPMI_HANDLER is not set
780
781#
782# Watchdog Cards
783#
784CONFIG_WATCHDOG=y 750CONFIG_WATCHDOG=y
785# CONFIG_WATCHDOG_NOWAYOUT is not set 751# CONFIG_WATCHDOG_NOWAYOUT is not set
786 752
@@ -792,7 +758,6 @@ CONFIG_BFIN_WDT=y
792CONFIG_HW_RANDOM=y 758CONFIG_HW_RANDOM=y
793# CONFIG_GEN_RTC is not set 759# CONFIG_GEN_RTC is not set
794CONFIG_BLACKFIN_DPMC=y 760CONFIG_BLACKFIN_DPMC=y
795# CONFIG_DTLK is not set
796# CONFIG_R3964 is not set 761# CONFIG_R3964 is not set
797# CONFIG_RAW_DRIVER is not set 762# CONFIG_RAW_DRIVER is not set
798 763
@@ -800,11 +765,8 @@ CONFIG_BLACKFIN_DPMC=y
800# TPM devices 765# TPM devices
801# 766#
802# CONFIG_TCG_TPM is not set 767# CONFIG_TCG_TPM is not set
803
804#
805# I2C support
806#
807CONFIG_I2C=m 768CONFIG_I2C=m
769CONFIG_I2C_BOARDINFO=y
808CONFIG_I2C_CHARDEV=m 770CONFIG_I2C_CHARDEV=m
809 771
810# 772#
@@ -818,10 +780,11 @@ CONFIG_I2C_ALGOBIT=m
818# I2C Hardware Bus support 780# I2C Hardware Bus support
819# 781#
820# CONFIG_I2C_BLACKFIN_GPIO is not set 782# CONFIG_I2C_BLACKFIN_GPIO is not set
783# CONFIG_I2C_GPIO is not set
821# CONFIG_I2C_OCORES is not set 784# CONFIG_I2C_OCORES is not set
822# CONFIG_I2C_PARPORT_LIGHT is not set 785# CONFIG_I2C_PARPORT_LIGHT is not set
786# CONFIG_I2C_SIMTEC is not set
823# CONFIG_I2C_STUB is not set 787# CONFIG_I2C_STUB is not set
824# CONFIG_I2C_PCA_ISA is not set
825 788
826# 789#
827# Miscellaneous I2C Chip support 790# Miscellaneous I2C Chip support
@@ -857,18 +820,16 @@ CONFIG_SPI_BFIN=y
857# SPI Protocol Masters 820# SPI Protocol Masters
858# 821#
859# CONFIG_SPI_AT25 is not set 822# CONFIG_SPI_AT25 is not set
823# CONFIG_SPI_SPIDEV is not set
860 824
861# 825#
862# Dallas's 1-wire bus 826# Dallas's 1-wire bus
863# 827#
864# CONFIG_W1 is not set 828# CONFIG_W1 is not set
865
866#
867# Hardware Monitoring support
868#
869CONFIG_HWMON=y 829CONFIG_HWMON=y
870# CONFIG_HWMON_VID is not set 830# CONFIG_HWMON_VID is not set
871# CONFIG_SENSORS_ABITUGURU is not set 831# CONFIG_SENSORS_ABITUGURU is not set
832# CONFIG_SENSORS_AD7418 is not set
872# CONFIG_SENSORS_ADM1021 is not set 833# CONFIG_SENSORS_ADM1021 is not set
873# CONFIG_SENSORS_ADM1025 is not set 834# CONFIG_SENSORS_ADM1025 is not set
874# CONFIG_SENSORS_ADM1026 is not set 835# CONFIG_SENSORS_ADM1026 is not set
@@ -896,6 +857,7 @@ CONFIG_HWMON=y
896# CONFIG_SENSORS_LM90 is not set 857# CONFIG_SENSORS_LM90 is not set
897# CONFIG_SENSORS_LM92 is not set 858# CONFIG_SENSORS_LM92 is not set
898# CONFIG_SENSORS_MAX1619 is not set 859# CONFIG_SENSORS_MAX1619 is not set
860# CONFIG_SENSORS_MAX6650 is not set
899# CONFIG_SENSORS_PC87360 is not set 861# CONFIG_SENSORS_PC87360 is not set
900# CONFIG_SENSORS_PC87427 is not set 862# CONFIG_SENSORS_PC87427 is not set
901# CONFIG_SENSORS_SMSC47M1 is not set 863# CONFIG_SENSORS_SMSC47M1 is not set
@@ -920,22 +882,30 @@ CONFIG_HWMON=y
920# Multimedia devices 882# Multimedia devices
921# 883#
922# CONFIG_VIDEO_DEV is not set 884# CONFIG_VIDEO_DEV is not set
885# CONFIG_DVB_CORE is not set
886CONFIG_DAB=y
923 887
924# 888#
925# Digital Video Broadcasting Devices 889# Graphics support
926# 890#
927# CONFIG_DVB is not set 891# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
928 892
929# 893#
930# Graphics support 894# Display device support
931# 895#
932# CONFIG_BACKLIGHT_LCD_SUPPORT is not set 896# CONFIG_DISPLAY_SUPPORT is not set
897# CONFIG_VGASTATE is not set
933CONFIG_FB=m 898CONFIG_FB=m
934CONFIG_FIRMWARE_EDID=y 899CONFIG_FIRMWARE_EDID=y
935# CONFIG_FB_DDC is not set 900# CONFIG_FB_DDC is not set
936CONFIG_FB_CFB_FILLRECT=m 901CONFIG_FB_CFB_FILLRECT=m
937CONFIG_FB_CFB_COPYAREA=m 902CONFIG_FB_CFB_COPYAREA=m
938CONFIG_FB_CFB_IMAGEBLIT=m 903CONFIG_FB_CFB_IMAGEBLIT=m
904# CONFIG_FB_SYS_FILLRECT is not set
905# CONFIG_FB_SYS_COPYAREA is not set
906# CONFIG_FB_SYS_IMAGEBLIT is not set
907# CONFIG_FB_SYS_FOPS is not set
908CONFIG_FB_DEFERRED_IO=y
939# CONFIG_FB_SVGALIB is not set 909# CONFIG_FB_SVGALIB is not set
940# CONFIG_FB_MACMODES is not set 910# CONFIG_FB_MACMODES is not set
941# CONFIG_FB_BACKLIGHT is not set 911# CONFIG_FB_BACKLIGHT is not set
@@ -957,10 +927,6 @@ CONFIG_ADV7393_1XMEM=y
957# CONFIG_ADV7393_2XMEM is not set 927# CONFIG_ADV7393_2XMEM is not set
958# CONFIG_FB_S1D13XXX is not set 928# CONFIG_FB_S1D13XXX is not set
959# CONFIG_FB_VIRTUAL is not set 929# CONFIG_FB_VIRTUAL is not set
960
961#
962# Logo configuration
963#
964# CONFIG_LOGO is not set 930# CONFIG_LOGO is not set
965 931
966# 932#
@@ -1001,7 +967,6 @@ CONFIG_SND_BLACKFIN_AD1836_TDM=y
1001# CONFIG_SND_BLACKFIN_AD1836_I2S is not set 967# CONFIG_SND_BLACKFIN_AD1836_I2S is not set
1002CONFIG_SND_BLACKFIN_AD1836_MULSUB=y 968CONFIG_SND_BLACKFIN_AD1836_MULSUB=y
1003# CONFIG_SND_BLACKFIN_AD1836_5P1 is not set 969# CONFIG_SND_BLACKFIN_AD1836_5P1 is not set
1004CONFIG_SND_BLACKFIN_AD1981B=m
1005CONFIG_SND_BLACKFIN_SPORT=0 970CONFIG_SND_BLACKFIN_SPORT=0
1006CONFIG_SND_BLACKFIN_SPI_PFBIT=4 971CONFIG_SND_BLACKFIN_SPI_PFBIT=4
1007CONFIG_SND_BFIN_AD73311=m 972CONFIG_SND_BFIN_AD73311=m
@@ -1009,11 +974,16 @@ CONFIG_SND_BFIN_SPORT=0
1009CONFIG_SND_BFIN_AD73311_SE=4 974CONFIG_SND_BFIN_AD73311_SE=4
1010 975
1011# 976#
1012# SoC audio support 977# System on Chip audio support
1013# 978#
1014# CONFIG_SND_SOC is not set 979# CONFIG_SND_SOC is not set
1015 980
1016# 981#
982# SoC Audio for the ADI Blackfin
983#
984# CONFIG_SND_BF5XX_HAVE_COLD_RESET is not set
985
986#
1017# Open Sound System 987# Open Sound System
1018# 988#
1019# CONFIG_SOUND_PRIME is not set 989# CONFIG_SOUND_PRIME is not set
@@ -1033,18 +1003,17 @@ CONFIG_USB_ARCH_HAS_HCD=y
1033# CONFIG_USB is not set 1003# CONFIG_USB is not set
1034 1004
1035# 1005#
1036# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support' 1006# Enable Host or Gadget support to see Inventra options
1037# 1007#
1038 1008
1039# 1009#
1040# USB Gadget Support 1010# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support'
1041# 1011#
1042# CONFIG_USB_GADGET is not set
1043 1012
1044# 1013#
1045# MMC/SD Card support 1014# USB Gadget Support
1046# 1015#
1047# CONFIG_SPI_MMC is not set 1016# CONFIG_USB_GADGET is not set
1048# CONFIG_MMC is not set 1017# CONFIG_MMC is not set
1049 1018
1050# 1019#
@@ -1084,44 +1053,50 @@ CONFIG_RTC_INTF_SYSFS=y
1084CONFIG_RTC_INTF_PROC=y 1053CONFIG_RTC_INTF_PROC=y
1085CONFIG_RTC_INTF_DEV=y 1054CONFIG_RTC_INTF_DEV=y
1086# CONFIG_RTC_INTF_DEV_UIE_EMUL is not set 1055# CONFIG_RTC_INTF_DEV_UIE_EMUL is not set
1056# CONFIG_RTC_DRV_TEST is not set
1087 1057
1088# 1058#
1089# RTC drivers 1059# I2C RTC drivers
1090# 1060#
1091# CONFIG_RTC_DRV_X1205 is not set
1092# CONFIG_RTC_DRV_DS1307 is not set 1061# CONFIG_RTC_DRV_DS1307 is not set
1093# CONFIG_RTC_DRV_DS1553 is not set
1094# CONFIG_RTC_DRV_ISL1208 is not set
1095# CONFIG_RTC_DRV_DS1672 is not set 1062# CONFIG_RTC_DRV_DS1672 is not set
1096# CONFIG_RTC_DRV_DS1742 is not set 1063# CONFIG_RTC_DRV_MAX6900 is not set
1064# CONFIG_RTC_DRV_RS5C372 is not set
1065# CONFIG_RTC_DRV_ISL1208 is not set
1066# CONFIG_RTC_DRV_X1205 is not set
1097# CONFIG_RTC_DRV_PCF8563 is not set 1067# CONFIG_RTC_DRV_PCF8563 is not set
1068# CONFIG_RTC_DRV_PCF8583 is not set
1069
1070#
1071# SPI RTC drivers
1072#
1098# CONFIG_RTC_DRV_RS5C348 is not set 1073# CONFIG_RTC_DRV_RS5C348 is not set
1099# CONFIG_RTC_DRV_RS5C372 is not set
1100# CONFIG_RTC_DRV_M48T86 is not set
1101# CONFIG_RTC_DRV_TEST is not set
1102# CONFIG_RTC_DRV_MAX6902 is not set 1074# CONFIG_RTC_DRV_MAX6902 is not set
1103# CONFIG_RTC_DRV_V3020 is not set
1104CONFIG_RTC_DRV_BFIN=y
1105 1075
1106# 1076#
1107# DMA Engine support 1077# Platform RTC drivers
1108# 1078#
1109# CONFIG_DMA_ENGINE is not set 1079# CONFIG_RTC_DRV_DS1553 is not set
1080# CONFIG_RTC_DRV_DS1742 is not set
1081# CONFIG_RTC_DRV_M48T86 is not set
1082# CONFIG_RTC_DRV_V3020 is not set
1110 1083
1111# 1084#
1112# DMA Clients 1085# on-CPU RTC drivers
1113# 1086#
1087CONFIG_RTC_DRV_BFIN=y
1114 1088
1115# 1089#
1116# DMA Devices 1090# DMA Engine support
1117# 1091#
1092# CONFIG_DMA_ENGINE is not set
1118 1093
1119# 1094#
1120# Auxiliary Display support 1095# DMA Clients
1121# 1096#
1122 1097
1123# 1098#
1124# Virtualization 1099# DMA Devices
1125# 1100#
1126 1101
1127# 1102#
@@ -1224,6 +1199,7 @@ CONFIG_LOCKD=m
1224CONFIG_LOCKD_V4=y 1199CONFIG_LOCKD_V4=y
1225CONFIG_NFS_COMMON=y 1200CONFIG_NFS_COMMON=y
1226CONFIG_SUNRPC=m 1201CONFIG_SUNRPC=m
1202# CONFIG_SUNRPC_BIND34 is not set
1227# CONFIG_RPCSEC_GSS_KRB5 is not set 1203# CONFIG_RPCSEC_GSS_KRB5 is not set
1228# CONFIG_RPCSEC_GSS_SPKM3 is not set 1204# CONFIG_RPCSEC_GSS_SPKM3 is not set
1229CONFIG_SMB_FS=m 1205CONFIG_SMB_FS=m
@@ -1301,14 +1277,20 @@ CONFIG_NLS_DEFAULT="iso8859-1"
1301CONFIG_ENABLE_MUST_CHECK=y 1277CONFIG_ENABLE_MUST_CHECK=y
1302# CONFIG_MAGIC_SYSRQ is not set 1278# CONFIG_MAGIC_SYSRQ is not set
1303# CONFIG_UNUSED_SYMBOLS is not set 1279# CONFIG_UNUSED_SYMBOLS is not set
1304# CONFIG_DEBUG_FS is not set 1280CONFIG_DEBUG_FS=y
1305# CONFIG_HEADERS_CHECK is not set 1281# CONFIG_HEADERS_CHECK is not set
1306# CONFIG_DEBUG_KERNEL is not set 1282# CONFIG_DEBUG_KERNEL is not set
1307CONFIG_LOG_BUF_SHIFT=14
1308# CONFIG_DEBUG_BUGVERBOSE is not set 1283# CONFIG_DEBUG_BUGVERBOSE is not set
1309# CONFIG_DEBUG_SERIAL_EARLY_INIT is not set 1284CONFIG_DEBUG_MMRS=y
1310CONFIG_DEBUG_HUNT_FOR_ZERO=y 1285CONFIG_DEBUG_HUNT_FOR_ZERO=y
1286CONFIG_DEBUG_BFIN_HWTRACE_ON=y
1287CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_OFF=y
1288# CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_ONE is not set
1289# CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_TWO is not set
1290CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION=0
1291# CONFIG_DEBUG_BFIN_HWTRACE_EXPAND is not set
1311# CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE is not set 1292# CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE is not set
1293CONFIG_EARLY_PRINTK=y
1312CONFIG_CPLB_INFO=y 1294CONFIG_CPLB_INFO=y
1313CONFIG_ACCESS_CHECK=y 1295CONFIG_ACCESS_CHECK=y
1314 1296
@@ -1331,6 +1313,7 @@ CONFIG_SECURITY_CAPABILITIES=m
1331CONFIG_BITREVERSE=y 1313CONFIG_BITREVERSE=y
1332CONFIG_CRC_CCITT=m 1314CONFIG_CRC_CCITT=m
1333# CONFIG_CRC16 is not set 1315# CONFIG_CRC16 is not set
1316# CONFIG_CRC_ITU_T is not set
1334CONFIG_CRC32=y 1317CONFIG_CRC32=y
1335# CONFIG_LIBCRC32C is not set 1318# CONFIG_LIBCRC32C is not set
1336CONFIG_ZLIB_INFLATE=y 1319CONFIG_ZLIB_INFLATE=y
@@ -1338,3 +1321,4 @@ CONFIG_ZLIB_DEFLATE=m
1338CONFIG_PLIST=y 1321CONFIG_PLIST=y
1339CONFIG_HAS_IOMEM=y 1322CONFIG_HAS_IOMEM=y
1340CONFIG_HAS_IOPORT=y 1323CONFIG_HAS_IOPORT=y
1324CONFIG_HAS_DMA=y
diff --git a/arch/blackfin/configs/BF537-STAMP_defconfig b/arch/blackfin/configs/BF537-STAMP_defconfig
index ccf09dc09a18..828b604438eb 100644
--- a/arch/blackfin/configs/BF537-STAMP_defconfig
+++ b/arch/blackfin/configs/BF537-STAMP_defconfig
@@ -1,6 +1,6 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.21.5 3# Linux kernel version: 2.6.22.6
4# 4#
5# CONFIG_MMU is not set 5# CONFIG_MMU is not set
6# CONFIG_FPU is not set 6# CONFIG_FPU is not set
@@ -15,8 +15,9 @@ CONFIG_GENERIC_HWEIGHT=y
15CONFIG_GENERIC_HARDIRQS=y 15CONFIG_GENERIC_HARDIRQS=y
16CONFIG_GENERIC_IRQ_PROBE=y 16CONFIG_GENERIC_IRQ_PROBE=y
17# CONFIG_GENERIC_TIME is not set 17# CONFIG_GENERIC_TIME is not set
18CONFIG_GENERIC_CALIBRATE_DELAY=y 18CONFIG_GENERIC_GPIO=y
19CONFIG_FORCE_MAX_ZONEORDER=14 19CONFIG_FORCE_MAX_ZONEORDER=14
20CONFIG_GENERIC_CALIBRATE_DELAY=y
20CONFIG_IRQCHIP_DEMUX_GPIO=y 21CONFIG_IRQCHIP_DEMUX_GPIO=y
21CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config" 22CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
22 23
@@ -40,7 +41,9 @@ CONFIG_SYSVIPC_SYSCTL=y
40# CONFIG_TASKSTATS is not set 41# CONFIG_TASKSTATS is not set
41# CONFIG_UTS_NS is not set 42# CONFIG_UTS_NS is not set
42# CONFIG_AUDIT is not set 43# CONFIG_AUDIT is not set
43# CONFIG_IKCONFIG is not set 44CONFIG_IKCONFIG=y
45CONFIG_IKCONFIG_PROC=y
46CONFIG_LOG_BUF_SHIFT=14
44CONFIG_SYSFS_DEPRECATED=y 47CONFIG_SYSFS_DEPRECATED=y
45# CONFIG_RELAY is not set 48# CONFIG_RELAY is not set
46CONFIG_BLK_DEV_INITRD=y 49CONFIG_BLK_DEV_INITRD=y
@@ -58,15 +61,20 @@ CONFIG_BUG=y
58CONFIG_ELF_CORE=y 61CONFIG_ELF_CORE=y
59CONFIG_BASE_FULL=y 62CONFIG_BASE_FULL=y
60CONFIG_FUTEX=y 63CONFIG_FUTEX=y
64CONFIG_ANON_INODES=y
65CONFIG_EPOLL=y
66CONFIG_SIGNALFD=y
67CONFIG_TIMERFD=y
68CONFIG_EVENTFD=y
69CONFIG_VM_EVENT_COUNTERS=y
61CONFIG_BIG_ORDER_ALLOC_NOFAIL_MAGIC=3 70CONFIG_BIG_ORDER_ALLOC_NOFAIL_MAGIC=3
62CONFIG_BUDDY=y
63# CONFIG_NP2 is not set 71# CONFIG_NP2 is not set
64CONFIG_SLAB=y 72CONFIG_SLAB=y
65CONFIG_VM_EVENT_COUNTERS=y 73# CONFIG_SLUB is not set
74# CONFIG_SLOB is not set
66CONFIG_RT_MUTEXES=y 75CONFIG_RT_MUTEXES=y
67CONFIG_TINY_SHMEM=y 76CONFIG_TINY_SHMEM=y
68CONFIG_BASE_SMALL=0 77CONFIG_BASE_SMALL=0
69# CONFIG_SLOB is not set
70 78
71# 79#
72# Loadable module support 80# Loadable module support
@@ -148,13 +156,6 @@ CONFIG_IRQ_PLL_WAKEUP=7
148# 156#
149 157
150# 158#
151# PORT F/G Selection
152#
153CONFIG_BF537_PORT_F=y
154# CONFIG_BF537_PORT_G is not set
155# CONFIG_BF537_PORT_H is not set
156
157#
158# Interrupt Priority Assignment 159# Interrupt Priority Assignment
159# 160#
160 161
@@ -199,19 +200,17 @@ CONFIG_IRQ_WATCH=13
199# CONFIG_CMDLINE_BOOL is not set 200# CONFIG_CMDLINE_BOOL is not set
200 201
201# 202#
202# Board Setup 203# Clock/PLL Setup
203# 204#
204CONFIG_CLKIN_HZ=25000000 205CONFIG_CLKIN_HZ=25000000
205CONFIG_MEM_SIZE=64 206# CONFIG_BFIN_KERNEL_CLOCK is not set
206CONFIG_MEM_ADD_WIDTH=10 207CONFIG_MAX_VCO_HZ=600000000
207CONFIG_BOOT_LOAD=0x1000 208CONFIG_MIN_VCO_HZ=50000000
208 209CONFIG_MAX_SCLK_HZ=133000000
209# 210CONFIG_MIN_SCLK_HZ=27000000
210# Blackfin Kernel Optimizations
211#
212 211
213# 212#
214# Timer Tick 213# Kernel Timer/Scheduler
215# 214#
216# CONFIG_HZ_100 is not set 215# CONFIG_HZ_100 is not set
217CONFIG_HZ_250=y 216CONFIG_HZ_250=y
@@ -220,6 +219,20 @@ CONFIG_HZ_250=y
220CONFIG_HZ=250 219CONFIG_HZ=250
221 220
222# 221#
222# Memory Setup
223#
224CONFIG_MEM_SIZE=64
225CONFIG_MEM_ADD_WIDTH=10
226CONFIG_BOOT_LOAD=0x1000
227CONFIG_BFIN_SCRATCH_REG_RETN=y
228# CONFIG_BFIN_SCRATCH_REG_RETE is not set
229# CONFIG_BFIN_SCRATCH_REG_CYCLES is not set
230
231#
232# Blackfin Kernel Optimizations
233#
234
235#
223# Memory Optimizations 236# Memory Optimizations
224# 237#
225CONFIG_I_ENTRY_L1=y 238CONFIG_I_ENTRY_L1=y
@@ -258,20 +271,15 @@ CONFIG_DMA_UNCACHED_1M=y
258# 271#
259# Cache Support 272# Cache Support
260# 273#
261CONFIG_BLKFIN_CACHE=y 274CONFIG_BFIN_ICACHE=y
262CONFIG_BLKFIN_DCACHE=y 275CONFIG_BFIN_DCACHE=y
263# CONFIG_BLKFIN_DCACHE_BANKA is not set 276# CONFIG_BFIN_DCACHE_BANKA is not set
264# CONFIG_BLKFIN_CACHE_LOCK is not set 277# CONFIG_BFIN_ICACHE_LOCK is not set
265# CONFIG_BLKFIN_WB is not set 278# CONFIG_BFIN_WB is not set
266CONFIG_BLKFIN_WT=y 279CONFIG_BFIN_WT=y
267CONFIG_L1_MAX_PIECE=16 280CONFIG_L1_MAX_PIECE=16
268 281
269# 282#
270# Clock Settings
271#
272# CONFIG_BFIN_KERNEL_CLOCK is not set
273
274#
275# Asynchonous Memory Configuration 283# Asynchonous Memory Configuration
276# 284#
277 285
@@ -298,6 +306,7 @@ CONFIG_BANK_3=0x99B3
298# Bus options (PCI, PCMCIA, EISA, MCA, ISA) 306# Bus options (PCI, PCMCIA, EISA, MCA, ISA)
299# 307#
300# CONFIG_PCI is not set 308# CONFIG_PCI is not set
309# CONFIG_ARCH_SUPPORTS_MSI is not set
301 310
302# 311#
303# PCCARD (PCMCIA/CardBus) support 312# PCCARD (PCMCIA/CardBus) support
@@ -305,10 +314,6 @@ CONFIG_BANK_3=0x99B3
305# CONFIG_PCCARD is not set 314# CONFIG_PCCARD is not set
306 315
307# 316#
308# PCI Hotplug Support
309#
310
311#
312# Executable file formats 317# Executable file formats
313# 318#
314CONFIG_BINFMT_ELF_FDPIC=y 319CONFIG_BINFMT_ELF_FDPIC=y
@@ -342,7 +347,6 @@ CONFIG_NET=y
342# 347#
343# Networking options 348# Networking options
344# 349#
345# CONFIG_NETDEBUG is not set
346CONFIG_PACKET=y 350CONFIG_PACKET=y
347# CONFIG_PACKET_MMAP is not set 351# CONFIG_PACKET_MMAP is not set
348CONFIG_UNIX=y 352CONFIG_UNIX=y
@@ -383,20 +387,8 @@ CONFIG_DEFAULT_TCP_CONG="cubic"
383# CONFIG_NETLABEL is not set 387# CONFIG_NETLABEL is not set
384# CONFIG_NETWORK_SECMARK is not set 388# CONFIG_NETWORK_SECMARK is not set
385# CONFIG_NETFILTER is not set 389# CONFIG_NETFILTER is not set
386
387#
388# DCCP Configuration (EXPERIMENTAL)
389#
390# CONFIG_IP_DCCP is not set 390# CONFIG_IP_DCCP is not set
391
392#
393# SCTP Configuration (EXPERIMENTAL)
394#
395# CONFIG_IP_SCTP is not set 391# CONFIG_IP_SCTP is not set
396
397#
398# TIPC Configuration (EXPERIMENTAL)
399#
400# CONFIG_TIPC is not set 392# CONFIG_TIPC is not set
401# CONFIG_ATM is not set 393# CONFIG_ATM is not set
402# CONFIG_BRIDGE is not set 394# CONFIG_BRIDGE is not set
@@ -463,7 +455,16 @@ CONFIG_IRTTY_SIR=m
463# FIR device drivers 455# FIR device drivers
464# 456#
465# CONFIG_BT is not set 457# CONFIG_BT is not set
458# CONFIG_AF_RXRPC is not set
459
460#
461# Wireless
462#
463# CONFIG_CFG80211 is not set
464# CONFIG_WIRELESS_EXT is not set
465# CONFIG_MAC80211 is not set
466# CONFIG_IEEE80211 is not set 466# CONFIG_IEEE80211 is not set
467# CONFIG_RFKILL is not set
467 468
468# 469#
469# Device Drivers 470# Device Drivers
@@ -481,10 +482,6 @@ CONFIG_PREVENT_FIRMWARE_BUILD=y
481# Connector - unified userspace <-> kernelspace linker 482# Connector - unified userspace <-> kernelspace linker
482# 483#
483# CONFIG_CONNECTOR is not set 484# CONFIG_CONNECTOR is not set
484
485#
486# Memory Technology Devices (MTD)
487#
488CONFIG_MTD=y 485CONFIG_MTD=y
489# CONFIG_MTD_DEBUG is not set 486# CONFIG_MTD_DEBUG is not set
490# CONFIG_MTD_CONCAT is not set 487# CONFIG_MTD_CONCAT is not set
@@ -528,7 +525,6 @@ CONFIG_MTD_MW320D=m
528CONFIG_MTD_RAM=y 525CONFIG_MTD_RAM=y
529CONFIG_MTD_ROM=m 526CONFIG_MTD_ROM=m
530# CONFIG_MTD_ABSENT is not set 527# CONFIG_MTD_ABSENT is not set
531# CONFIG_MTD_OBSOLETE_CHIPS is not set
532 528
533# 529#
534# Mapping drivers for chip access 530# Mapping drivers for chip access
@@ -565,13 +561,10 @@ CONFIG_BFIN_FLASH_BANK_3=0x7BB0
565# CONFIG_MTD_DOC2000 is not set 561# CONFIG_MTD_DOC2000 is not set
566# CONFIG_MTD_DOC2001 is not set 562# CONFIG_MTD_DOC2001 is not set
567# CONFIG_MTD_DOC2001PLUS is not set 563# CONFIG_MTD_DOC2001PLUS is not set
568
569#
570# NAND Flash Device Drivers
571#
572CONFIG_MTD_NAND=m 564CONFIG_MTD_NAND=m
573# CONFIG_MTD_NAND_VERIFY_WRITE is not set 565# CONFIG_MTD_NAND_VERIFY_WRITE is not set
574# CONFIG_MTD_NAND_ECC_SMC is not set 566# CONFIG_MTD_NAND_ECC_SMC is not set
567# CONFIG_MTD_NAND_MUSEUM_IDS is not set
575CONFIG_MTD_NAND_BFIN=m 568CONFIG_MTD_NAND_BFIN=m
576CONFIG_BFIN_NAND_BASE=0x20212000 569CONFIG_BFIN_NAND_BASE=0x20212000
577CONFIG_BFIN_NAND_CLE=2 570CONFIG_BFIN_NAND_CLE=2
@@ -580,11 +573,13 @@ CONFIG_BFIN_NAND_READY=3
580CONFIG_MTD_NAND_IDS=m 573CONFIG_MTD_NAND_IDS=m
581# CONFIG_MTD_NAND_DISKONCHIP is not set 574# CONFIG_MTD_NAND_DISKONCHIP is not set
582# CONFIG_MTD_NAND_NANDSIM is not set 575# CONFIG_MTD_NAND_NANDSIM is not set
576# CONFIG_MTD_NAND_PLATFORM is not set
577# CONFIG_MTD_ONENAND is not set
583 578
584# 579#
585# OneNAND Flash Device Drivers 580# UBI - Unsorted block images
586# 581#
587# CONFIG_MTD_ONENAND is not set 582# CONFIG_MTD_UBI is not set
588 583
589# 584#
590# Parallel port support 585# Parallel port support
@@ -612,10 +607,6 @@ CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
612# 607#
613# Misc devices 608# Misc devices
614# 609#
615
616#
617# ATA/ATAPI/MFM/RLL support
618#
619# CONFIG_IDE is not set 610# CONFIG_IDE is not set
620 611
621# 612#
@@ -624,10 +615,6 @@ CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
624# CONFIG_RAID_ATTRS is not set 615# CONFIG_RAID_ATTRS is not set
625# CONFIG_SCSI is not set 616# CONFIG_SCSI is not set
626# CONFIG_SCSI_NETLINK is not set 617# CONFIG_SCSI_NETLINK is not set
627
628#
629# Serial ATA (prod) and Parallel ATA (experimental) drivers
630#
631# CONFIG_ATA is not set 618# CONFIG_ATA is not set
632 619
633# 620#
@@ -636,19 +623,6 @@ CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
636# CONFIG_MD is not set 623# CONFIG_MD is not set
637 624
638# 625#
639# Fusion MPT device support
640#
641# CONFIG_FUSION is not set
642
643#
644# IEEE 1394 (FireWire) support
645#
646
647#
648# I2O device support
649#
650
651#
652# Network device support 626# Network device support
653# 627#
654CONFIG_NETDEVICES=y 628CONFIG_NETDEVICES=y
@@ -656,11 +630,20 @@ CONFIG_NETDEVICES=y
656# CONFIG_BONDING is not set 630# CONFIG_BONDING is not set
657# CONFIG_EQUALIZER is not set 631# CONFIG_EQUALIZER is not set
658# CONFIG_TUN is not set 632# CONFIG_TUN is not set
633CONFIG_PHYLIB=y
659 634
660# 635#
661# PHY device support 636# MII PHY device drivers
662# 637#
663# CONFIG_PHYLIB is not set 638# CONFIG_MARVELL_PHY is not set
639# CONFIG_DAVICOM_PHY is not set
640# CONFIG_QSEMI_PHY is not set
641# CONFIG_LXT_PHY is not set
642# CONFIG_CICADA_PHY is not set
643# CONFIG_VITESSE_PHY is not set
644CONFIG_SMSC_PHY=y
645# CONFIG_BROADCOM_PHY is not set
646# CONFIG_FIXED_PHY is not set
664 647
665# 648#
666# Ethernet (10 or 100Mbit) 649# Ethernet (10 or 100Mbit)
@@ -674,27 +657,15 @@ CONFIG_BFIN_TX_DESC_NUM=10
674CONFIG_BFIN_RX_DESC_NUM=20 657CONFIG_BFIN_RX_DESC_NUM=20
675# CONFIG_BFIN_MAC_RMII is not set 658# CONFIG_BFIN_MAC_RMII is not set
676# CONFIG_SMSC911X is not set 659# CONFIG_SMSC911X is not set
660# CONFIG_DM9000 is not set
661CONFIG_NETDEV_1000=y
662CONFIG_NETDEV_10000=y
677 663
678# 664#
679# Ethernet (1000 Mbit) 665# Wireless LAN
680#
681
682#
683# Ethernet (10000 Mbit)
684#
685
686#
687# Token Ring devices
688#
689
690#
691# Wireless LAN (non-hamradio)
692#
693# CONFIG_NET_RADIO is not set
694
695#
696# Wan interfaces
697# 666#
667# CONFIG_WLAN_PRE80211 is not set
668# CONFIG_WLAN_80211 is not set
698# CONFIG_WAN is not set 669# CONFIG_WAN is not set
699# CONFIG_PPP is not set 670# CONFIG_PPP is not set
700# CONFIG_SLIP is not set 671# CONFIG_SLIP is not set
@@ -718,6 +689,7 @@ CONFIG_BFIN_RX_DESC_NUM=20
718# 689#
719CONFIG_INPUT=y 690CONFIG_INPUT=y
720# CONFIG_INPUT_FF_MEMLESS is not set 691# CONFIG_INPUT_FF_MEMLESS is not set
692# CONFIG_INPUT_POLLDEV is not set
721 693
722# 694#
723# Userland interfaces 695# Userland interfaces
@@ -734,8 +706,14 @@ CONFIG_INPUT_EVDEV=m
734# CONFIG_INPUT_KEYBOARD is not set 706# CONFIG_INPUT_KEYBOARD is not set
735# CONFIG_INPUT_MOUSE is not set 707# CONFIG_INPUT_MOUSE is not set
736# CONFIG_INPUT_JOYSTICK is not set 708# CONFIG_INPUT_JOYSTICK is not set
709# CONFIG_INPUT_TABLET is not set
737# CONFIG_INPUT_TOUCHSCREEN is not set 710# CONFIG_INPUT_TOUCHSCREEN is not set
738CONFIG_INPUT_MISC=y 711CONFIG_INPUT_MISC=y
712# CONFIG_INPUT_ATI_REMOTE is not set
713# CONFIG_INPUT_ATI_REMOTE2 is not set
714# CONFIG_INPUT_KEYSPAN_REMOTE is not set
715# CONFIG_INPUT_POWERMATE is not set
716# CONFIG_INPUT_YEALINK is not set
739# CONFIG_INPUT_UINPUT is not set 717# CONFIG_INPUT_UINPUT is not set
740# CONFIG_BF53X_PFBUTTONS is not set 718# CONFIG_BF53X_PFBUTTONS is not set
741CONFIG_TWI_KEYPAD=m 719CONFIG_TWI_KEYPAD=m
@@ -752,7 +730,7 @@ CONFIG_BFIN_TWIKEYPAD_IRQ_PFX=72
752# 730#
753# CONFIG_AD9960 is not set 731# CONFIG_AD9960 is not set
754# CONFIG_SPI_ADC_BF533 is not set 732# CONFIG_SPI_ADC_BF533 is not set
755# CONFIG_BF5xx_PFLAGS is not set 733# CONFIG_BFIN_PFLAGS is not set
756# CONFIG_BF5xx_PPIFCD is not set 734# CONFIG_BF5xx_PPIFCD is not set
757# CONFIG_BF5xx_TIMERS is not set 735# CONFIG_BF5xx_TIMERS is not set
758# CONFIG_BF5xx_PPI is not set 736# CONFIG_BF5xx_PPI is not set
@@ -803,10 +781,6 @@ CONFIG_CAN_BLACKFIN=m
803# IPMI 781# IPMI
804# 782#
805# CONFIG_IPMI_HANDLER is not set 783# CONFIG_IPMI_HANDLER is not set
806
807#
808# Watchdog Cards
809#
810CONFIG_WATCHDOG=y 784CONFIG_WATCHDOG=y
811# CONFIG_WATCHDOG_NOWAYOUT is not set 785# CONFIG_WATCHDOG_NOWAYOUT is not set
812 786
@@ -818,7 +792,6 @@ CONFIG_BFIN_WDT=y
818CONFIG_HW_RANDOM=y 792CONFIG_HW_RANDOM=y
819# CONFIG_GEN_RTC is not set 793# CONFIG_GEN_RTC is not set
820CONFIG_BLACKFIN_DPMC=y 794CONFIG_BLACKFIN_DPMC=y
821# CONFIG_DTLK is not set
822# CONFIG_R3964 is not set 795# CONFIG_R3964 is not set
823# CONFIG_RAW_DRIVER is not set 796# CONFIG_RAW_DRIVER is not set
824 797
@@ -826,11 +799,8 @@ CONFIG_BLACKFIN_DPMC=y
826# TPM devices 799# TPM devices
827# 800#
828# CONFIG_TCG_TPM is not set 801# CONFIG_TCG_TPM is not set
829
830#
831# I2C support
832#
833CONFIG_I2C=m 802CONFIG_I2C=m
803CONFIG_I2C_BOARDINFO=y
834CONFIG_I2C_CHARDEV=m 804CONFIG_I2C_CHARDEV=m
835 805
836# 806#
@@ -846,10 +816,11 @@ CONFIG_I2C_CHARDEV=m
846# CONFIG_I2C_BLACKFIN_GPIO is not set 816# CONFIG_I2C_BLACKFIN_GPIO is not set
847CONFIG_I2C_BLACKFIN_TWI=m 817CONFIG_I2C_BLACKFIN_TWI=m
848CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ=50 818CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ=50
819# CONFIG_I2C_GPIO is not set
849# CONFIG_I2C_OCORES is not set 820# CONFIG_I2C_OCORES is not set
850# CONFIG_I2C_PARPORT_LIGHT is not set 821# CONFIG_I2C_PARPORT_LIGHT is not set
822# CONFIG_I2C_SIMTEC is not set
851# CONFIG_I2C_STUB is not set 823# CONFIG_I2C_STUB is not set
852# CONFIG_I2C_PCA_ISA is not set
853 824
854# 825#
855# Miscellaneous I2C Chip support 826# Miscellaneous I2C Chip support
@@ -885,18 +856,16 @@ CONFIG_SPI_BFIN=y
885# SPI Protocol Masters 856# SPI Protocol Masters
886# 857#
887# CONFIG_SPI_AT25 is not set 858# CONFIG_SPI_AT25 is not set
859# CONFIG_SPI_SPIDEV is not set
888 860
889# 861#
890# Dallas's 1-wire bus 862# Dallas's 1-wire bus
891# 863#
892# CONFIG_W1 is not set 864# CONFIG_W1 is not set
893
894#
895# Hardware Monitoring support
896#
897CONFIG_HWMON=y 865CONFIG_HWMON=y
898# CONFIG_HWMON_VID is not set 866# CONFIG_HWMON_VID is not set
899# CONFIG_SENSORS_ABITUGURU is not set 867# CONFIG_SENSORS_ABITUGURU is not set
868# CONFIG_SENSORS_AD7418 is not set
900# CONFIG_SENSORS_ADM1021 is not set 869# CONFIG_SENSORS_ADM1021 is not set
901# CONFIG_SENSORS_ADM1025 is not set 870# CONFIG_SENSORS_ADM1025 is not set
902# CONFIG_SENSORS_ADM1026 is not set 871# CONFIG_SENSORS_ADM1026 is not set
@@ -924,6 +893,7 @@ CONFIG_HWMON=y
924# CONFIG_SENSORS_LM90 is not set 893# CONFIG_SENSORS_LM90 is not set
925# CONFIG_SENSORS_LM92 is not set 894# CONFIG_SENSORS_LM92 is not set
926# CONFIG_SENSORS_MAX1619 is not set 895# CONFIG_SENSORS_MAX1619 is not set
896# CONFIG_SENSORS_MAX6650 is not set
927# CONFIG_SENSORS_PC87360 is not set 897# CONFIG_SENSORS_PC87360 is not set
928# CONFIG_SENSORS_PC87427 is not set 898# CONFIG_SENSORS_PC87427 is not set
929# CONFIG_SENSORS_SMSC47M1 is not set 899# CONFIG_SENSORS_SMSC47M1 is not set
@@ -948,11 +918,8 @@ CONFIG_HWMON=y
948# Multimedia devices 918# Multimedia devices
949# 919#
950# CONFIG_VIDEO_DEV is not set 920# CONFIG_VIDEO_DEV is not set
951 921# CONFIG_DVB_CORE is not set
952# 922CONFIG_DAB=y
953# Digital Video Broadcasting Devices
954#
955# CONFIG_DVB is not set
956 923
957# 924#
958# Graphics support 925# Graphics support
@@ -960,12 +927,23 @@ CONFIG_HWMON=y
960CONFIG_BACKLIGHT_LCD_SUPPORT=y 927CONFIG_BACKLIGHT_LCD_SUPPORT=y
961CONFIG_BACKLIGHT_CLASS_DEVICE=m 928CONFIG_BACKLIGHT_CLASS_DEVICE=m
962CONFIG_LCD_CLASS_DEVICE=m 929CONFIG_LCD_CLASS_DEVICE=m
930
931#
932# Display device support
933#
934# CONFIG_DISPLAY_SUPPORT is not set
935# CONFIG_VGASTATE is not set
963CONFIG_FB=m 936CONFIG_FB=m
964CONFIG_FIRMWARE_EDID=y 937CONFIG_FIRMWARE_EDID=y
965# CONFIG_FB_DDC is not set 938# CONFIG_FB_DDC is not set
966CONFIG_FB_CFB_FILLRECT=m 939CONFIG_FB_CFB_FILLRECT=m
967CONFIG_FB_CFB_COPYAREA=m 940CONFIG_FB_CFB_COPYAREA=m
968CONFIG_FB_CFB_IMAGEBLIT=m 941CONFIG_FB_CFB_IMAGEBLIT=m
942# CONFIG_FB_SYS_FILLRECT is not set
943# CONFIG_FB_SYS_COPYAREA is not set
944# CONFIG_FB_SYS_IMAGEBLIT is not set
945# CONFIG_FB_SYS_FOPS is not set
946CONFIG_FB_DEFERRED_IO=y
969# CONFIG_FB_SVGALIB is not set 947# CONFIG_FB_SVGALIB is not set
970# CONFIG_FB_MACMODES is not set 948# CONFIG_FB_MACMODES is not set
971# CONFIG_FB_BACKLIGHT is not set 949# CONFIG_FB_BACKLIGHT is not set
@@ -991,10 +969,6 @@ CONFIG_LQ035_SLAVE_ADDR=0x58
991# CONFIG_FB_BFIN_BGR is not set 969# CONFIG_FB_BFIN_BGR is not set
992# CONFIG_FB_S1D13XXX is not set 970# CONFIG_FB_S1D13XXX is not set
993# CONFIG_FB_VIRTUAL is not set 971# CONFIG_FB_VIRTUAL is not set
994
995#
996# Logo configuration
997#
998# CONFIG_LOGO is not set 972# CONFIG_LOGO is not set
999 973
1000# 974#
@@ -1035,7 +1009,6 @@ CONFIG_SND_BLACKFIN_AD1836_TDM=y
1035# CONFIG_SND_BLACKFIN_AD1836_I2S is not set 1009# CONFIG_SND_BLACKFIN_AD1836_I2S is not set
1036CONFIG_SND_BLACKFIN_AD1836_MULSUB=y 1010CONFIG_SND_BLACKFIN_AD1836_MULSUB=y
1037# CONFIG_SND_BLACKFIN_AD1836_5P1 is not set 1011# CONFIG_SND_BLACKFIN_AD1836_5P1 is not set
1038CONFIG_SND_BLACKFIN_AD1981B=m
1039CONFIG_SND_BLACKFIN_SPORT=0 1012CONFIG_SND_BLACKFIN_SPORT=0
1040CONFIG_SND_BLACKFIN_SPI_PFBIT=4 1013CONFIG_SND_BLACKFIN_SPI_PFBIT=4
1041CONFIG_SND_BFIN_AD73311=m 1014CONFIG_SND_BFIN_AD73311=m
@@ -1043,11 +1016,16 @@ CONFIG_SND_BFIN_SPORT=0
1043CONFIG_SND_BFIN_AD73311_SE=4 1016CONFIG_SND_BFIN_AD73311_SE=4
1044 1017
1045# 1018#
1046# SoC audio support 1019# System on Chip audio support
1047# 1020#
1048# CONFIG_SND_SOC is not set 1021# CONFIG_SND_SOC is not set
1049 1022
1050# 1023#
1024# SoC Audio for the ADI Blackfin
1025#
1026# CONFIG_SND_BF5XX_HAVE_COLD_RESET is not set
1027
1028#
1051# Open Sound System 1029# Open Sound System
1052# 1030#
1053# CONFIG_SOUND_PRIME is not set 1031# CONFIG_SOUND_PRIME is not set
@@ -1067,18 +1045,17 @@ CONFIG_USB_ARCH_HAS_HCD=y
1067# CONFIG_USB is not set 1045# CONFIG_USB is not set
1068 1046
1069# 1047#
1070# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support' 1048# Enable Host or Gadget support to see Inventra options
1071# 1049#
1072 1050
1073# 1051#
1074# USB Gadget Support 1052# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support'
1075# 1053#
1076# CONFIG_USB_GADGET is not set
1077 1054
1078# 1055#
1079# MMC/SD Card support 1056# USB Gadget Support
1080# 1057#
1081# CONFIG_SPI_MMC is not set 1058# CONFIG_USB_GADGET is not set
1082# CONFIG_MMC is not set 1059# CONFIG_MMC is not set
1083 1060
1084# 1061#
@@ -1118,44 +1095,50 @@ CONFIG_RTC_INTF_SYSFS=y
1118CONFIG_RTC_INTF_PROC=y 1095CONFIG_RTC_INTF_PROC=y
1119CONFIG_RTC_INTF_DEV=y 1096CONFIG_RTC_INTF_DEV=y
1120# CONFIG_RTC_INTF_DEV_UIE_EMUL is not set 1097# CONFIG_RTC_INTF_DEV_UIE_EMUL is not set
1098# CONFIG_RTC_DRV_TEST is not set
1121 1099
1122# 1100#
1123# RTC drivers 1101# I2C RTC drivers
1124# 1102#
1125# CONFIG_RTC_DRV_X1205 is not set
1126# CONFIG_RTC_DRV_DS1307 is not set 1103# CONFIG_RTC_DRV_DS1307 is not set
1127# CONFIG_RTC_DRV_DS1553 is not set
1128# CONFIG_RTC_DRV_ISL1208 is not set
1129# CONFIG_RTC_DRV_DS1672 is not set 1104# CONFIG_RTC_DRV_DS1672 is not set
1130# CONFIG_RTC_DRV_DS1742 is not set 1105# CONFIG_RTC_DRV_MAX6900 is not set
1106# CONFIG_RTC_DRV_RS5C372 is not set
1107# CONFIG_RTC_DRV_ISL1208 is not set
1108# CONFIG_RTC_DRV_X1205 is not set
1131# CONFIG_RTC_DRV_PCF8563 is not set 1109# CONFIG_RTC_DRV_PCF8563 is not set
1110# CONFIG_RTC_DRV_PCF8583 is not set
1111
1112#
1113# SPI RTC drivers
1114#
1132# CONFIG_RTC_DRV_RS5C348 is not set 1115# CONFIG_RTC_DRV_RS5C348 is not set
1133# CONFIG_RTC_DRV_RS5C372 is not set
1134# CONFIG_RTC_DRV_M48T86 is not set
1135# CONFIG_RTC_DRV_TEST is not set
1136# CONFIG_RTC_DRV_MAX6902 is not set 1116# CONFIG_RTC_DRV_MAX6902 is not set
1137# CONFIG_RTC_DRV_V3020 is not set
1138CONFIG_RTC_DRV_BFIN=y
1139 1117
1140# 1118#
1141# DMA Engine support 1119# Platform RTC drivers
1142# 1120#
1143# CONFIG_DMA_ENGINE is not set 1121# CONFIG_RTC_DRV_DS1553 is not set
1122# CONFIG_RTC_DRV_DS1742 is not set
1123# CONFIG_RTC_DRV_M48T86 is not set
1124# CONFIG_RTC_DRV_V3020 is not set
1144 1125
1145# 1126#
1146# DMA Clients 1127# on-CPU RTC drivers
1147# 1128#
1129CONFIG_RTC_DRV_BFIN=y
1148 1130
1149# 1131#
1150# DMA Devices 1132# DMA Engine support
1151# 1133#
1134# CONFIG_DMA_ENGINE is not set
1152 1135
1153# 1136#
1154# Auxiliary Display support 1137# DMA Clients
1155# 1138#
1156 1139
1157# 1140#
1158# Virtualization 1141# DMA Devices
1159# 1142#
1160 1143
1161# 1144#
@@ -1258,6 +1241,7 @@ CONFIG_LOCKD=m
1258CONFIG_LOCKD_V4=y 1241CONFIG_LOCKD_V4=y
1259CONFIG_NFS_COMMON=y 1242CONFIG_NFS_COMMON=y
1260CONFIG_SUNRPC=m 1243CONFIG_SUNRPC=m
1244# CONFIG_SUNRPC_BIND34 is not set
1261# CONFIG_RPCSEC_GSS_KRB5 is not set 1245# CONFIG_RPCSEC_GSS_KRB5 is not set
1262# CONFIG_RPCSEC_GSS_SPKM3 is not set 1246# CONFIG_RPCSEC_GSS_SPKM3 is not set
1263CONFIG_SMB_FS=m 1247CONFIG_SMB_FS=m
@@ -1335,14 +1319,20 @@ CONFIG_NLS_DEFAULT="iso8859-1"
1335CONFIG_ENABLE_MUST_CHECK=y 1319CONFIG_ENABLE_MUST_CHECK=y
1336# CONFIG_MAGIC_SYSRQ is not set 1320# CONFIG_MAGIC_SYSRQ is not set
1337# CONFIG_UNUSED_SYMBOLS is not set 1321# CONFIG_UNUSED_SYMBOLS is not set
1338# CONFIG_DEBUG_FS is not set 1322CONFIG_DEBUG_FS=y
1339# CONFIG_HEADERS_CHECK is not set 1323# CONFIG_HEADERS_CHECK is not set
1340# CONFIG_DEBUG_KERNEL is not set 1324# CONFIG_DEBUG_KERNEL is not set
1341CONFIG_LOG_BUF_SHIFT=14
1342# CONFIG_DEBUG_BUGVERBOSE is not set 1325# CONFIG_DEBUG_BUGVERBOSE is not set
1343# CONFIG_DEBUG_SERIAL_EARLY_INIT is not set 1326CONFIG_DEBUG_MMRS=y
1344CONFIG_DEBUG_HUNT_FOR_ZERO=y 1327CONFIG_DEBUG_HUNT_FOR_ZERO=y
1328CONFIG_DEBUG_BFIN_HWTRACE_ON=y
1329CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_OFF=y
1330# CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_ONE is not set
1331# CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_TWO is not set
1332CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION=0
1333# CONFIG_DEBUG_BFIN_HWTRACE_EXPAND is not set
1345# CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE is not set 1334# CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE is not set
1335CONFIG_EARLY_PRINTK=y
1346CONFIG_CPLB_INFO=y 1336CONFIG_CPLB_INFO=y
1347CONFIG_ACCESS_CHECK=y 1337CONFIG_ACCESS_CHECK=y
1348 1338
@@ -1365,6 +1355,7 @@ CONFIG_SECURITY_CAPABILITIES=m
1365CONFIG_BITREVERSE=y 1355CONFIG_BITREVERSE=y
1366CONFIG_CRC_CCITT=m 1356CONFIG_CRC_CCITT=m
1367# CONFIG_CRC16 is not set 1357# CONFIG_CRC16 is not set
1358# CONFIG_CRC_ITU_T is not set
1368CONFIG_CRC32=y 1359CONFIG_CRC32=y
1369# CONFIG_LIBCRC32C is not set 1360# CONFIG_LIBCRC32C is not set
1370CONFIG_ZLIB_INFLATE=y 1361CONFIG_ZLIB_INFLATE=y
@@ -1372,3 +1363,4 @@ CONFIG_ZLIB_DEFLATE=m
1372CONFIG_PLIST=y 1363CONFIG_PLIST=y
1373CONFIG_HAS_IOMEM=y 1364CONFIG_HAS_IOMEM=y
1374CONFIG_HAS_IOPORT=y 1365CONFIG_HAS_IOPORT=y
1366CONFIG_HAS_DMA=y
diff --git a/arch/blackfin/configs/BF548-EZKIT_defconfig b/arch/blackfin/configs/BF548-EZKIT_defconfig
index ac8390fafa9c..e80f3d59c283 100644
--- a/arch/blackfin/configs/BF548-EZKIT_defconfig
+++ b/arch/blackfin/configs/BF548-EZKIT_defconfig
@@ -1,6 +1,6 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.21.5 3# Linux kernel version: 2.6.22.6
4# 4#
5# CONFIG_MMU is not set 5# CONFIG_MMU is not set
6# CONFIG_FPU is not set 6# CONFIG_FPU is not set
@@ -15,8 +15,9 @@ CONFIG_GENERIC_HWEIGHT=y
15CONFIG_GENERIC_HARDIRQS=y 15CONFIG_GENERIC_HARDIRQS=y
16CONFIG_GENERIC_IRQ_PROBE=y 16CONFIG_GENERIC_IRQ_PROBE=y
17# CONFIG_GENERIC_TIME is not set 17# CONFIG_GENERIC_TIME is not set
18CONFIG_GENERIC_CALIBRATE_DELAY=y 18CONFIG_GENERIC_GPIO=y
19CONFIG_FORCE_MAX_ZONEORDER=14 19CONFIG_FORCE_MAX_ZONEORDER=14
20CONFIG_GENERIC_CALIBRATE_DELAY=y
20CONFIG_IRQCHIP_DEMUX_GPIO=y 21CONFIG_IRQCHIP_DEMUX_GPIO=y
21CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config" 22CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
22 23
@@ -40,7 +41,9 @@ CONFIG_SYSVIPC_SYSCTL=y
40# CONFIG_TASKSTATS is not set 41# CONFIG_TASKSTATS is not set
41# CONFIG_UTS_NS is not set 42# CONFIG_UTS_NS is not set
42# CONFIG_AUDIT is not set 43# CONFIG_AUDIT is not set
43# CONFIG_IKCONFIG is not set 44CONFIG_IKCONFIG=y
45CONFIG_IKCONFIG_PROC=y
46CONFIG_LOG_BUF_SHIFT=14
44CONFIG_SYSFS_DEPRECATED=y 47CONFIG_SYSFS_DEPRECATED=y
45# CONFIG_RELAY is not set 48# CONFIG_RELAY is not set
46CONFIG_BLK_DEV_INITRD=y 49CONFIG_BLK_DEV_INITRD=y
@@ -51,7 +54,6 @@ CONFIG_EMBEDDED=y
51CONFIG_UID16=y 54CONFIG_UID16=y
52CONFIG_SYSCTL_SYSCALL=y 55CONFIG_SYSCTL_SYSCALL=y
53CONFIG_KALLSYMS=y 56CONFIG_KALLSYMS=y
54# CONFIG_KALLSYMS_ALL is not set
55# CONFIG_KALLSYMS_EXTRA_PASS is not set 57# CONFIG_KALLSYMS_EXTRA_PASS is not set
56CONFIG_HOTPLUG=y 58CONFIG_HOTPLUG=y
57CONFIG_PRINTK=y 59CONFIG_PRINTK=y
@@ -59,14 +61,20 @@ CONFIG_BUG=y
59CONFIG_ELF_CORE=y 61CONFIG_ELF_CORE=y
60CONFIG_BASE_FULL=y 62CONFIG_BASE_FULL=y
61CONFIG_FUTEX=y 63CONFIG_FUTEX=y
64CONFIG_ANON_INODES=y
65CONFIG_EPOLL=y
66CONFIG_SIGNALFD=y
67CONFIG_TIMERFD=y
68CONFIG_EVENTFD=y
69CONFIG_VM_EVENT_COUNTERS=y
62CONFIG_BIG_ORDER_ALLOC_NOFAIL_MAGIC=3 70CONFIG_BIG_ORDER_ALLOC_NOFAIL_MAGIC=3
63# CONFIG_NP2 is not set 71# CONFIG_NP2 is not set
64CONFIG_SLAB=y 72CONFIG_SLAB=y
65CONFIG_VM_EVENT_COUNTERS=y 73# CONFIG_SLUB is not set
74# CONFIG_SLOB is not set
66CONFIG_RT_MUTEXES=y 75CONFIG_RT_MUTEXES=y
67CONFIG_TINY_SHMEM=y 76CONFIG_TINY_SHMEM=y
68CONFIG_BASE_SMALL=0 77CONFIG_BASE_SMALL=0
69# CONFIG_SLOB is not set
70 78
71# 79#
72# Loadable module support 80# Loadable module support
@@ -165,6 +173,7 @@ CONFIG_IRQ_UART1_TX=10
165# 173#
166# BF548 Specific Configuration 174# BF548 Specific Configuration
167# 175#
176# CONFIG_DEB_DMA_URGENT is not set
168 177
169# 178#
170# Interrupt Priority Assignment 179# Interrupt Priority Assignment
@@ -242,24 +251,35 @@ CONFIG_IRQ_PINT2=11
242CONFIG_IRQ_PINT3=11 251CONFIG_IRQ_PINT3=11
243 252
244# 253#
245# Board customizations 254# Pin Interrupt to Port Assignment
246# 255#
247# CONFIG_CMDLINE_BOOL is not set
248 256
249# 257#
250# Board Setup 258# Assignment
251# 259#
252CONFIG_CLKIN_HZ=25000000 260CONFIG_PINTx_REASSIGN=y
253CONFIG_MEM_SIZE=64 261CONFIG_PINT0_ASSIGN=0x00000101
254CONFIG_MEM_ADD_WIDTH=10 262CONFIG_PINT1_ASSIGN=0x01010000
255CONFIG_BOOT_LOAD=0x1000 263CONFIG_PINT2_ASSIGN=0x07000101
264CONFIG_PINT3_ASSIGN=0x02020303
256 265
257# 266#
258# Blackfin Kernel Optimizations 267# Board customizations
259# 268#
269# CONFIG_CMDLINE_BOOL is not set
260 270
261# 271#
262# Timer Tick 272# Clock/PLL Setup
273#
274CONFIG_CLKIN_HZ=25000000
275# CONFIG_BFIN_KERNEL_CLOCK is not set
276CONFIG_MAX_VCO_HZ=533000000
277CONFIG_MIN_VCO_HZ=50000000
278CONFIG_MAX_SCLK_HZ=133000000
279CONFIG_MIN_SCLK_HZ=27000000
280
281#
282# Kernel Timer/Scheduler
263# 283#
264# CONFIG_HZ_100 is not set 284# CONFIG_HZ_100 is not set
265CONFIG_HZ_250=y 285CONFIG_HZ_250=y
@@ -268,6 +288,20 @@ CONFIG_HZ_250=y
268CONFIG_HZ=250 288CONFIG_HZ=250
269 289
270# 290#
291# Memory Setup
292#
293CONFIG_MEM_SIZE=64
294CONFIG_MEM_ADD_WIDTH=10
295CONFIG_BOOT_LOAD=0x1000
296CONFIG_BFIN_SCRATCH_REG_RETN=y
297# CONFIG_BFIN_SCRATCH_REG_RETE is not set
298# CONFIG_BFIN_SCRATCH_REG_CYCLES is not set
299
300#
301# Blackfin Kernel Optimizations
302#
303
304#
271# Memory Optimizations 305# Memory Optimizations
272# 306#
273CONFIG_I_ENTRY_L1=y 307CONFIG_I_ENTRY_L1=y
@@ -275,12 +309,12 @@ CONFIG_EXCPT_IRQ_SYSC_L1=y
275CONFIG_DO_IRQ_L1=y 309CONFIG_DO_IRQ_L1=y
276CONFIG_CORE_TIMER_IRQ_L1=y 310CONFIG_CORE_TIMER_IRQ_L1=y
277CONFIG_IDLE_L1=y 311CONFIG_IDLE_L1=y
278CONFIG_SCHEDULE_L1=y 312# CONFIG_SCHEDULE_L1 is not set
279CONFIG_ARITHMETIC_OPS_L1=y 313CONFIG_ARITHMETIC_OPS_L1=y
280CONFIG_ACCESS_OK_L1=y 314CONFIG_ACCESS_OK_L1=y
281CONFIG_MEMSET_L1=y 315# CONFIG_MEMSET_L1 is not set
282CONFIG_MEMCPY_L1=y 316# CONFIG_MEMCPY_L1 is not set
283CONFIG_SYS_BFIN_SPINLOCK_L1=y 317# CONFIG_SYS_BFIN_SPINLOCK_L1 is not set
284# CONFIG_IP_CHECKSUM_L1 is not set 318# CONFIG_IP_CHECKSUM_L1 is not set
285CONFIG_CACHELINE_ALIGNED_L1=y 319CONFIG_CACHELINE_ALIGNED_L1=y
286# CONFIG_SYSCALL_TAB_L1 is not set 320# CONFIG_SYSCALL_TAB_L1 is not set
@@ -306,20 +340,15 @@ CONFIG_DMA_UNCACHED_1M=y
306# 340#
307# Cache Support 341# Cache Support
308# 342#
309CONFIG_BLKFIN_CACHE=y 343CONFIG_BFIN_ICACHE=y
310CONFIG_BLKFIN_DCACHE=y 344CONFIG_BFIN_DCACHE=y
311# CONFIG_BLKFIN_DCACHE_BANKA is not set 345# CONFIG_BFIN_DCACHE_BANKA is not set
312# CONFIG_BLKFIN_CACHE_LOCK is not set 346# CONFIG_BFIN_ICACHE_LOCK is not set
313# CONFIG_BLKFIN_WB is not set 347# CONFIG_BFIN_WB is not set
314CONFIG_BLKFIN_WT=y 348CONFIG_BFIN_WT=y
315CONFIG_L1_MAX_PIECE=16 349CONFIG_L1_MAX_PIECE=16
316 350
317# 351#
318# Clock Settings
319#
320# CONFIG_BFIN_KERNEL_CLOCK is not set
321
322#
323# Asynchonous Memory Configuration 352# Asynchonous Memory Configuration
324# 353#
325 354
@@ -327,7 +356,6 @@ CONFIG_L1_MAX_PIECE=16
327# EBIU_AMBCTL Global Control 356# EBIU_AMBCTL Global Control
328# 357#
329CONFIG_C_AMCKEN=y 358CONFIG_C_AMCKEN=y
330CONFIG_C_CDPRIO=y
331# CONFIG_C_AMBEN is not set 359# CONFIG_C_AMBEN is not set
332# CONFIG_C_AMBEN_B0 is not set 360# CONFIG_C_AMBEN_B0 is not set
333# CONFIG_C_AMBEN_B0_B1 is not set 361# CONFIG_C_AMBEN_B0_B1 is not set
@@ -338,7 +366,7 @@ CONFIG_C_AMBEN_ALL=y
338# EBIU_AMBCTL Control 366# EBIU_AMBCTL Control
339# 367#
340CONFIG_BANK_0=0x7BB0 368CONFIG_BANK_0=0x7BB0
341CONFIG_BANK_1=0x7BB0 369CONFIG_BANK_1=0x5554
342CONFIG_BANK_2=0x7BB0 370CONFIG_BANK_2=0x7BB0
343CONFIG_BANK_3=0x99B3 371CONFIG_BANK_3=0x99B3
344 372
@@ -346,6 +374,7 @@ CONFIG_BANK_3=0x99B3
346# Bus options (PCI, PCMCIA, EISA, MCA, ISA) 374# Bus options (PCI, PCMCIA, EISA, MCA, ISA)
347# 375#
348# CONFIG_PCI is not set 376# CONFIG_PCI is not set
377# CONFIG_ARCH_SUPPORTS_MSI is not set
349 378
350# 379#
351# PCCARD (PCMCIA/CardBus) support 380# PCCARD (PCMCIA/CardBus) support
@@ -353,10 +382,6 @@ CONFIG_BANK_3=0x99B3
353# CONFIG_PCCARD is not set 382# CONFIG_PCCARD is not set
354 383
355# 384#
356# PCI Hotplug Support
357#
358
359#
360# Executable file formats 385# Executable file formats
361# 386#
362CONFIG_BINFMT_ELF_FDPIC=y 387CONFIG_BINFMT_ELF_FDPIC=y
@@ -383,7 +408,6 @@ CONFIG_NET=y
383# 408#
384# Networking options 409# Networking options
385# 410#
386# CONFIG_NETDEBUG is not set
387CONFIG_PACKET=y 411CONFIG_PACKET=y
388# CONFIG_PACKET_MMAP is not set 412# CONFIG_PACKET_MMAP is not set
389CONFIG_UNIX=y 413CONFIG_UNIX=y
@@ -424,20 +448,8 @@ CONFIG_DEFAULT_TCP_CONG="cubic"
424# CONFIG_NETLABEL is not set 448# CONFIG_NETLABEL is not set
425# CONFIG_NETWORK_SECMARK is not set 449# CONFIG_NETWORK_SECMARK is not set
426# CONFIG_NETFILTER is not set 450# CONFIG_NETFILTER is not set
427
428#
429# DCCP Configuration (EXPERIMENTAL)
430#
431# CONFIG_IP_DCCP is not set 451# CONFIG_IP_DCCP is not set
432
433#
434# SCTP Configuration (EXPERIMENTAL)
435#
436# CONFIG_IP_SCTP is not set 452# CONFIG_IP_SCTP is not set
437
438#
439# TIPC Configuration (EXPERIMENTAL)
440#
441# CONFIG_TIPC is not set 453# CONFIG_TIPC is not set
442# CONFIG_ATM is not set 454# CONFIG_ATM is not set
443# CONFIG_BRIDGE is not set 455# CONFIG_BRIDGE is not set
@@ -463,7 +475,16 @@ CONFIG_DEFAULT_TCP_CONG="cubic"
463# CONFIG_HAMRADIO is not set 475# CONFIG_HAMRADIO is not set
464# CONFIG_IRDA is not set 476# CONFIG_IRDA is not set
465# CONFIG_BT is not set 477# CONFIG_BT is not set
478# CONFIG_AF_RXRPC is not set
479
480#
481# Wireless
482#
483# CONFIG_CFG80211 is not set
484# CONFIG_WIRELESS_EXT is not set
485# CONFIG_MAC80211 is not set
466# CONFIG_IEEE80211 is not set 486# CONFIG_IEEE80211 is not set
487# CONFIG_RFKILL is not set
467 488
468# 489#
469# Device Drivers 490# Device Drivers
@@ -475,29 +496,23 @@ CONFIG_DEFAULT_TCP_CONG="cubic"
475CONFIG_STANDALONE=y 496CONFIG_STANDALONE=y
476CONFIG_PREVENT_FIRMWARE_BUILD=y 497CONFIG_PREVENT_FIRMWARE_BUILD=y
477# CONFIG_FW_LOADER is not set 498# CONFIG_FW_LOADER is not set
478# CONFIG_DEBUG_DRIVER is not set
479# CONFIG_DEBUG_DEVRES is not set
480# CONFIG_SYS_HYPERVISOR is not set 499# CONFIG_SYS_HYPERVISOR is not set
481 500
482# 501#
483# Connector - unified userspace <-> kernelspace linker 502# Connector - unified userspace <-> kernelspace linker
484# 503#
485# CONFIG_CONNECTOR is not set 504# CONFIG_CONNECTOR is not set
486
487#
488# Memory Technology Devices (MTD)
489#
490CONFIG_MTD=y 505CONFIG_MTD=y
491# CONFIG_MTD_DEBUG is not set 506# CONFIG_MTD_DEBUG is not set
492# CONFIG_MTD_CONCAT is not set 507# CONFIG_MTD_CONCAT is not set
493CONFIG_MTD_PARTITIONS=y 508CONFIG_MTD_PARTITIONS=y
494# CONFIG_MTD_REDBOOT_PARTS is not set 509# CONFIG_MTD_REDBOOT_PARTS is not set
495# CONFIG_MTD_CMDLINE_PARTS is not set 510CONFIG_MTD_CMDLINE_PARTS=y
496 511
497# 512#
498# User Modules And Translation Layers 513# User Modules And Translation Layers
499# 514#
500# CONFIG_MTD_CHAR is not set 515CONFIG_MTD_CHAR=y
501CONFIG_MTD_BLKDEVS=y 516CONFIG_MTD_BLKDEVS=y
502CONFIG_MTD_BLOCK=y 517CONFIG_MTD_BLOCK=y
503# CONFIG_FTL is not set 518# CONFIG_FTL is not set
@@ -509,8 +524,10 @@ CONFIG_MTD_BLOCK=y
509# 524#
510# RAM/ROM/Flash chip drivers 525# RAM/ROM/Flash chip drivers
511# 526#
512# CONFIG_MTD_CFI is not set 527CONFIG_MTD_CFI=y
513# CONFIG_MTD_JEDECPROBE is not set 528# CONFIG_MTD_JEDECPROBE is not set
529CONFIG_MTD_GEN_PROBE=y
530# CONFIG_MTD_CFI_ADV_OPTIONS is not set
514CONFIG_MTD_MAP_BANK_WIDTH_1=y 531CONFIG_MTD_MAP_BANK_WIDTH_1=y
515CONFIG_MTD_MAP_BANK_WIDTH_2=y 532CONFIG_MTD_MAP_BANK_WIDTH_2=y
516CONFIG_MTD_MAP_BANK_WIDTH_4=y 533CONFIG_MTD_MAP_BANK_WIDTH_4=y
@@ -521,22 +538,32 @@ CONFIG_MTD_CFI_I1=y
521CONFIG_MTD_CFI_I2=y 538CONFIG_MTD_CFI_I2=y
522# CONFIG_MTD_CFI_I4 is not set 539# CONFIG_MTD_CFI_I4 is not set
523# CONFIG_MTD_CFI_I8 is not set 540# CONFIG_MTD_CFI_I8 is not set
541CONFIG_MTD_CFI_INTELEXT=y
542# CONFIG_MTD_CFI_AMDSTD is not set
543# CONFIG_MTD_CFI_STAA is not set
544# CONFIG_MTD_MW320D is not set
545CONFIG_MTD_CFI_UTIL=y
524CONFIG_MTD_RAM=y 546CONFIG_MTD_RAM=y
525# CONFIG_MTD_ROM is not set 547# CONFIG_MTD_ROM is not set
526# CONFIG_MTD_ABSENT is not set 548# CONFIG_MTD_ABSENT is not set
527# CONFIG_MTD_OBSOLETE_CHIPS is not set
528 549
529# 550#
530# Mapping drivers for chip access 551# Mapping drivers for chip access
531# 552#
532CONFIG_MTD_COMPLEX_MAPPINGS=y 553CONFIG_MTD_COMPLEX_MAPPINGS=y
554CONFIG_MTD_PHYSMAP=y
555CONFIG_MTD_PHYSMAP_START=0x20000000
556CONFIG_MTD_PHYSMAP_LEN=0x400000
557CONFIG_MTD_PHYSMAP_BANKWIDTH=2
533# CONFIG_MTD_BF5xx is not set 558# CONFIG_MTD_BF5xx is not set
534CONFIG_MTD_UCLINUX=y 559# CONFIG_MTD_UCLINUX is not set
535# CONFIG_MTD_PLATRAM is not set 560# CONFIG_MTD_PLATRAM is not set
536 561
537# 562#
538# Self-contained MTD device drivers 563# Self-contained MTD device drivers
539# 564#
565# CONFIG_MTD_DATAFLASH is not set
566# CONFIG_MTD_M25P80 is not set
540# CONFIG_MTD_SLRAM is not set 567# CONFIG_MTD_SLRAM is not set
541# CONFIG_MTD_PHRAM is not set 568# CONFIG_MTD_PHRAM is not set
542# CONFIG_MTD_MTDRAM is not set 569# CONFIG_MTD_MTDRAM is not set
@@ -548,16 +575,23 @@ CONFIG_MTD_UCLINUX=y
548# CONFIG_MTD_DOC2000 is not set 575# CONFIG_MTD_DOC2000 is not set
549# CONFIG_MTD_DOC2001 is not set 576# CONFIG_MTD_DOC2001 is not set
550# CONFIG_MTD_DOC2001PLUS is not set 577# CONFIG_MTD_DOC2001PLUS is not set
578CONFIG_MTD_NAND=y
579# CONFIG_MTD_NAND_VERIFY_WRITE is not set
580# CONFIG_MTD_NAND_ECC_SMC is not set
581# CONFIG_MTD_NAND_MUSEUM_IDS is not set
582# CONFIG_MTD_NAND_BFIN is not set
583CONFIG_MTD_NAND_IDS=y
584CONFIG_MTD_NAND_BF5XX=y
585CONFIG_MTD_NAND_BF5XX_HWECC=y
586# CONFIG_MTD_NAND_DISKONCHIP is not set
587# CONFIG_MTD_NAND_NANDSIM is not set
588# CONFIG_MTD_NAND_PLATFORM is not set
589# CONFIG_MTD_ONENAND is not set
551 590
552# 591#
553# NAND Flash Device Drivers 592# UBI - Unsorted block images
554#
555# CONFIG_MTD_NAND is not set
556
557#
558# OneNAND Flash Device Drivers
559# 593#
560# CONFIG_MTD_ONENAND is not set 594# CONFIG_MTD_UBI is not set
561 595
562# 596#
563# Parallel port support 597# Parallel port support
@@ -585,41 +619,61 @@ CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
585# 619#
586# Misc devices 620# Misc devices
587# 621#
588
589#
590# ATA/ATAPI/MFM/RLL support
591#
592# CONFIG_IDE is not set 622# CONFIG_IDE is not set
593 623
594# 624#
595# SCSI device support 625# SCSI device support
596# 626#
597# CONFIG_RAID_ATTRS is not set 627# CONFIG_RAID_ATTRS is not set
598# CONFIG_SCSI is not set 628CONFIG_SCSI=y
629# CONFIG_SCSI_TGT is not set
599# CONFIG_SCSI_NETLINK is not set 630# CONFIG_SCSI_NETLINK is not set
631CONFIG_SCSI_PROC_FS=y
600 632
601# 633#
602# Serial ATA (prod) and Parallel ATA (experimental) drivers 634# SCSI support type (disk, tape, CD-ROM)
603# 635#
604# CONFIG_ATA is not set 636CONFIG_BLK_DEV_SD=y
637# CONFIG_CHR_DEV_ST is not set
638# CONFIG_CHR_DEV_OSST is not set
639CONFIG_BLK_DEV_SR=y
640# CONFIG_BLK_DEV_SR_VENDOR is not set
641# CONFIG_CHR_DEV_SG is not set
642# CONFIG_CHR_DEV_SCH is not set
605 643
606# 644#
607# Multi-device support (RAID and LVM) 645# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
608# 646#
609# CONFIG_MD is not set 647# CONFIG_SCSI_MULTI_LUN is not set
648# CONFIG_SCSI_CONSTANTS is not set
649# CONFIG_SCSI_LOGGING is not set
650# CONFIG_SCSI_SCAN_ASYNC is not set
651CONFIG_SCSI_WAIT_SCAN=m
610 652
611# 653#
612# Fusion MPT device support 654# SCSI Transports
613# 655#
614# CONFIG_FUSION is not set 656# CONFIG_SCSI_SPI_ATTRS is not set
657# CONFIG_SCSI_FC_ATTRS is not set
658# CONFIG_SCSI_ISCSI_ATTRS is not set
659# CONFIG_SCSI_SAS_ATTRS is not set
660# CONFIG_SCSI_SAS_LIBSAS is not set
615 661
616# 662#
617# IEEE 1394 (FireWire) support 663# SCSI low-level drivers
618# 664#
665# CONFIG_ISCSI_TCP is not set
666# CONFIG_SCSI_DEBUG is not set
667CONFIG_ATA=y
668# CONFIG_ATA_NONSTANDARD is not set
669# CONFIG_PATA_PLATFORM is not set
670CONFIG_PATA_BF54X=y
671CONFIG_PATA_BF54X_DMA=y
619 672
620# 673#
621# I2O device support 674# Multi-device support (RAID and LVM)
622# 675#
676# CONFIG_MD is not set
623 677
624# 678#
625# Network device support 679# Network device support
@@ -629,10 +683,6 @@ CONFIG_NETDEVICES=y
629# CONFIG_BONDING is not set 683# CONFIG_BONDING is not set
630# CONFIG_EQUALIZER is not set 684# CONFIG_EQUALIZER is not set
631# CONFIG_TUN is not set 685# CONFIG_TUN is not set
632
633#
634# PHY device support
635#
636# CONFIG_PHYLIB is not set 686# CONFIG_PHYLIB is not set
637 687
638# 688#
@@ -641,28 +691,16 @@ CONFIG_NETDEVICES=y
641CONFIG_NET_ETHERNET=y 691CONFIG_NET_ETHERNET=y
642CONFIG_MII=y 692CONFIG_MII=y
643# CONFIG_SMC91X is not set 693# CONFIG_SMC91X is not set
644# CONFIG_SMSC911X is not set 694CONFIG_SMSC911X=y
645 695# CONFIG_DM9000 is not set
646# 696CONFIG_NETDEV_1000=y
647# Ethernet (1000 Mbit) 697CONFIG_NETDEV_10000=y
648#
649
650#
651# Ethernet (10000 Mbit)
652#
653 698
654# 699#
655# Token Ring devices 700# Wireless LAN
656#
657
658#
659# Wireless LAN (non-hamradio)
660#
661# CONFIG_NET_RADIO is not set
662
663#
664# Wan interfaces
665# 701#
702# CONFIG_WLAN_PRE80211 is not set
703# CONFIG_WLAN_80211 is not set
666# CONFIG_WAN is not set 704# CONFIG_WAN is not set
667# CONFIG_PPP is not set 705# CONFIG_PPP is not set
668# CONFIG_SLIP is not set 706# CONFIG_SLIP is not set
@@ -686,6 +724,7 @@ CONFIG_MII=y
686# 724#
687CONFIG_INPUT=y 725CONFIG_INPUT=y
688# CONFIG_INPUT_FF_MEMLESS is not set 726# CONFIG_INPUT_FF_MEMLESS is not set
727# CONFIG_INPUT_POLLDEV is not set
689 728
690# 729#
691# Userland interfaces 730# Userland interfaces
@@ -702,10 +741,17 @@ CONFIG_INPUT=y
702# CONFIG_INPUT_KEYBOARD is not set 741# CONFIG_INPUT_KEYBOARD is not set
703# CONFIG_INPUT_MOUSE is not set 742# CONFIG_INPUT_MOUSE is not set
704# CONFIG_INPUT_JOYSTICK is not set 743# CONFIG_INPUT_JOYSTICK is not set
744# CONFIG_INPUT_TABLET is not set
705# CONFIG_INPUT_TOUCHSCREEN is not set 745# CONFIG_INPUT_TOUCHSCREEN is not set
706CONFIG_INPUT_MISC=y 746CONFIG_INPUT_MISC=y
747# CONFIG_INPUT_ATI_REMOTE is not set
748# CONFIG_INPUT_ATI_REMOTE2 is not set
749# CONFIG_INPUT_KEYSPAN_REMOTE is not set
750# CONFIG_INPUT_POWERMATE is not set
751# CONFIG_INPUT_YEALINK is not set
707# CONFIG_INPUT_UINPUT is not set 752# CONFIG_INPUT_UINPUT is not set
708# CONFIG_BF53X_PFBUTTONS is not set 753# CONFIG_BF53X_PFBUTTONS is not set
754# CONFIG_TWI_KEYPAD is not set
709 755
710# 756#
711# Hardware I/O ports 757# Hardware I/O ports
@@ -718,12 +764,15 @@ CONFIG_INPUT_MISC=y
718# 764#
719# CONFIG_AD9960 is not set 765# CONFIG_AD9960 is not set
720# CONFIG_SPI_ADC_BF533 is not set 766# CONFIG_SPI_ADC_BF533 is not set
721# CONFIG_BF5xx_PFLAGS is not set 767# CONFIG_BFIN_PFLAGS is not set
722# CONFIG_BF5xx_PPIFCD is not set 768# CONFIG_BF5xx_PPIFCD is not set
723# CONFIG_BF5xx_TIMERS is not set 769# CONFIG_BF5xx_TIMERS is not set
724# CONFIG_BF5xx_PPI is not set 770# CONFIG_BF5xx_PPI is not set
725# CONFIG_BFIN_SPORT is not set 771# CONFIG_BFIN_SPORT is not set
726# CONFIG_BFIN_TIMER_LATENCY is not set 772# CONFIG_BFIN_TIMER_LATENCY is not set
773# CONFIG_TWI_LCD is not set
774# CONFIG_AD5304 is not set
775# CONFIG_BF5xx_TEA5764 is not set
727# CONFIG_BF5xx_FBDMA is not set 776# CONFIG_BF5xx_FBDMA is not set
728# CONFIG_VT is not set 777# CONFIG_VT is not set
729# CONFIG_SERIAL_NONSTANDARD is not set 778# CONFIG_SERIAL_NONSTANDARD is not set
@@ -760,14 +809,9 @@ CONFIG_UNIX98_PTYS=y
760# IPMI 809# IPMI
761# 810#
762# CONFIG_IPMI_HANDLER is not set 811# CONFIG_IPMI_HANDLER is not set
763
764#
765# Watchdog Cards
766#
767# CONFIG_WATCHDOG is not set 812# CONFIG_WATCHDOG is not set
768CONFIG_HW_RANDOM=y 813CONFIG_HW_RANDOM=y
769# CONFIG_GEN_RTC is not set 814# CONFIG_GEN_RTC is not set
770# CONFIG_DTLK is not set
771# CONFIG_R3964 is not set 815# CONFIG_R3964 is not set
772# CONFIG_RAW_DRIVER is not set 816# CONFIG_RAW_DRIVER is not set
773 817
@@ -775,32 +819,114 @@ CONFIG_HW_RANDOM=y
775# TPM devices 819# TPM devices
776# 820#
777# CONFIG_TCG_TPM is not set 821# CONFIG_TCG_TPM is not set
822CONFIG_I2C=y
823CONFIG_I2C_BOARDINFO=y
824CONFIG_I2C_CHARDEV=y
825
826#
827# I2C Algorithms
828#
829# CONFIG_I2C_ALGOBIT is not set
830# CONFIG_I2C_ALGOPCF is not set
831# CONFIG_I2C_ALGOPCA is not set
778 832
779# 833#
780# I2C support 834# I2C Hardware Bus support
781# 835#
782# CONFIG_I2C is not set 836# CONFIG_I2C_BLACKFIN_GPIO is not set
837CONFIG_I2C_BLACKFIN_TWI=y
838CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ=50
839# CONFIG_I2C_GPIO is not set
840# CONFIG_I2C_OCORES is not set
841# CONFIG_I2C_PARPORT_LIGHT is not set
842# CONFIG_I2C_SIMTEC is not set
843# CONFIG_I2C_STUB is not set
844
845#
846# Miscellaneous I2C Chip support
847#
848# CONFIG_SENSORS_DS1337 is not set
849# CONFIG_SENSORS_DS1374 is not set
850# CONFIG_SENSORS_AD5252 is not set
851# CONFIG_SENSORS_EEPROM is not set
852# CONFIG_SENSORS_PCF8574 is not set
853# CONFIG_SENSORS_PCF8575 is not set
854# CONFIG_SENSORS_PCA9543 is not set
855# CONFIG_SENSORS_PCA9539 is not set
856# CONFIG_SENSORS_PCF8591 is not set
857# CONFIG_SENSORS_MAX6875 is not set
858# CONFIG_I2C_DEBUG_CORE is not set
859# CONFIG_I2C_DEBUG_ALGO is not set
860# CONFIG_I2C_DEBUG_BUS is not set
861# CONFIG_I2C_DEBUG_CHIP is not set
783 862
784# 863#
785# SPI support 864# SPI support
786# 865#
787# CONFIG_SPI is not set 866CONFIG_SPI=y
788# CONFIG_SPI_MASTER is not set 867CONFIG_SPI_MASTER=y
789 868
790# 869#
791# Dallas's 1-wire bus 870# SPI Master Controller Drivers
792# 871#
793# CONFIG_W1 is not set 872CONFIG_SPI_BFIN=y
873# CONFIG_SPI_BITBANG is not set
874
875#
876# SPI Protocol Masters
877#
878# CONFIG_SPI_AT25 is not set
879# CONFIG_SPI_SPIDEV is not set
794 880
795# 881#
796# Hardware Monitoring support 882# Dallas's 1-wire bus
797# 883#
884# CONFIG_W1 is not set
798CONFIG_HWMON=y 885CONFIG_HWMON=y
799# CONFIG_HWMON_VID is not set 886# CONFIG_HWMON_VID is not set
800# CONFIG_SENSORS_ABITUGURU is not set 887# CONFIG_SENSORS_ABITUGURU is not set
888# CONFIG_SENSORS_AD7418 is not set
889# CONFIG_SENSORS_ADM1021 is not set
890# CONFIG_SENSORS_ADM1025 is not set
891# CONFIG_SENSORS_ADM1026 is not set
892# CONFIG_SENSORS_ADM1029 is not set
893# CONFIG_SENSORS_ADM1031 is not set
894# CONFIG_SENSORS_ADM9240 is not set
895# CONFIG_SENSORS_ASB100 is not set
896# CONFIG_SENSORS_ATXP1 is not set
897# CONFIG_SENSORS_DS1621 is not set
801# CONFIG_SENSORS_F71805F is not set 898# CONFIG_SENSORS_F71805F is not set
899# CONFIG_SENSORS_FSCHER is not set
900# CONFIG_SENSORS_FSCPOS is not set
901# CONFIG_SENSORS_GL518SM is not set
902# CONFIG_SENSORS_GL520SM is not set
903# CONFIG_SENSORS_IT87 is not set
904# CONFIG_SENSORS_LM63 is not set
905# CONFIG_SENSORS_LM70 is not set
906# CONFIG_SENSORS_LM75 is not set
907# CONFIG_SENSORS_LM77 is not set
908# CONFIG_SENSORS_LM78 is not set
909# CONFIG_SENSORS_LM80 is not set
910# CONFIG_SENSORS_LM83 is not set
911# CONFIG_SENSORS_LM85 is not set
912# CONFIG_SENSORS_LM87 is not set
913# CONFIG_SENSORS_LM90 is not set
914# CONFIG_SENSORS_LM92 is not set
915# CONFIG_SENSORS_MAX1619 is not set
916# CONFIG_SENSORS_MAX6650 is not set
917# CONFIG_SENSORS_PC87360 is not set
802# CONFIG_SENSORS_PC87427 is not set 918# CONFIG_SENSORS_PC87427 is not set
919# CONFIG_SENSORS_SMSC47M1 is not set
920# CONFIG_SENSORS_SMSC47M192 is not set
921# CONFIG_SENSORS_SMSC47B397 is not set
803# CONFIG_SENSORS_VT1211 is not set 922# CONFIG_SENSORS_VT1211 is not set
923# CONFIG_SENSORS_W83781D is not set
924# CONFIG_SENSORS_W83791D is not set
925# CONFIG_SENSORS_W83792D is not set
926# CONFIG_SENSORS_W83793 is not set
927# CONFIG_SENSORS_W83L785TS is not set
928# CONFIG_SENSORS_W83627HF is not set
929# CONFIG_SENSORS_W83627EHF is not set
804# CONFIG_HWMON_DEBUG_CHIP is not set 930# CONFIG_HWMON_DEBUG_CHIP is not set
805 931
806# 932#
@@ -812,16 +938,19 @@ CONFIG_HWMON=y
812# Multimedia devices 938# Multimedia devices
813# 939#
814# CONFIG_VIDEO_DEV is not set 940# CONFIG_VIDEO_DEV is not set
941# CONFIG_DVB_CORE is not set
942CONFIG_DAB=y
815 943
816# 944#
817# Digital Video Broadcasting Devices 945# Graphics support
818# 946#
819# CONFIG_DVB is not set 947# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
820 948
821# 949#
822# Graphics support 950# Display device support
823# 951#
824# CONFIG_BACKLIGHT_LCD_SUPPORT is not set 952# CONFIG_DISPLAY_SUPPORT is not set
953# CONFIG_VGASTATE is not set
825# CONFIG_FB is not set 954# CONFIG_FB is not set
826 955
827# 956#
@@ -844,6 +973,10 @@ CONFIG_USB_ARCH_HAS_HCD=y
844# CONFIG_USB is not set 973# CONFIG_USB is not set
845 974
846# 975#
976# Enable Host or Gadget support to see Inventra options
977#
978
979#
847# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support' 980# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support'
848# 981#
849 982
@@ -851,11 +984,20 @@ CONFIG_USB_ARCH_HAS_HCD=y
851# USB Gadget Support 984# USB Gadget Support
852# 985#
853# CONFIG_USB_GADGET is not set 986# CONFIG_USB_GADGET is not set
987CONFIG_MMC=m
988# CONFIG_MMC_DEBUG is not set
989# CONFIG_MMC_UNSAFE_RESUME is not set
990
991#
992# MMC/SD Card Drivers
993#
994CONFIG_MMC_BLOCK=m
854 995
855# 996#
856# MMC/SD Card support 997# MMC/SD Host Controller Drivers
857# 998#
858# CONFIG_MMC is not set 999CONFIG_SDH_BFIN=m
1000# CONFIG_SPI_MMC is not set
859 1001
860# 1002#
861# LED devices 1003# LED devices
@@ -894,15 +1036,37 @@ CONFIG_RTC_INTF_SYSFS=y
894CONFIG_RTC_INTF_PROC=y 1036CONFIG_RTC_INTF_PROC=y
895CONFIG_RTC_INTF_DEV=y 1037CONFIG_RTC_INTF_DEV=y
896# CONFIG_RTC_INTF_DEV_UIE_EMUL is not set 1038# CONFIG_RTC_INTF_DEV_UIE_EMUL is not set
1039# CONFIG_RTC_DRV_TEST is not set
897 1040
898# 1041#
899# RTC drivers 1042# I2C RTC drivers
1043#
1044# CONFIG_RTC_DRV_DS1307 is not set
1045# CONFIG_RTC_DRV_DS1672 is not set
1046# CONFIG_RTC_DRV_MAX6900 is not set
1047# CONFIG_RTC_DRV_RS5C372 is not set
1048# CONFIG_RTC_DRV_ISL1208 is not set
1049# CONFIG_RTC_DRV_X1205 is not set
1050# CONFIG_RTC_DRV_PCF8563 is not set
1051# CONFIG_RTC_DRV_PCF8583 is not set
1052
1053#
1054# SPI RTC drivers
1055#
1056# CONFIG_RTC_DRV_RS5C348 is not set
1057# CONFIG_RTC_DRV_MAX6902 is not set
1058
1059#
1060# Platform RTC drivers
900# 1061#
901# CONFIG_RTC_DRV_DS1553 is not set 1062# CONFIG_RTC_DRV_DS1553 is not set
902# CONFIG_RTC_DRV_DS1742 is not set 1063# CONFIG_RTC_DRV_DS1742 is not set
903# CONFIG_RTC_DRV_M48T86 is not set 1064# CONFIG_RTC_DRV_M48T86 is not set
904# CONFIG_RTC_DRV_TEST is not set
905# CONFIG_RTC_DRV_V3020 is not set 1065# CONFIG_RTC_DRV_V3020 is not set
1066
1067#
1068# on-CPU RTC drivers
1069#
906CONFIG_RTC_DRV_BFIN=y 1070CONFIG_RTC_DRV_BFIN=y
907 1071
908# 1072#
@@ -919,14 +1083,6 @@ CONFIG_RTC_DRV_BFIN=y
919# 1083#
920 1084
921# 1085#
922# Auxiliary Display support
923#
924
925#
926# Virtualization
927#
928
929#
930# PBX support 1086# PBX support
931# 1087#
932# CONFIG_PBX is not set 1088# CONFIG_PBX is not set
@@ -991,8 +1147,25 @@ CONFIG_RAMFS=y
991# CONFIG_BEFS_FS is not set 1147# CONFIG_BEFS_FS is not set
992# CONFIG_BFS_FS is not set 1148# CONFIG_BFS_FS is not set
993# CONFIG_EFS_FS is not set 1149# CONFIG_EFS_FS is not set
994# CONFIG_YAFFS_FS is not set 1150CONFIG_YAFFS_FS=m
995# CONFIG_JFFS2_FS is not set 1151CONFIG_YAFFS_YAFFS1=y
1152# CONFIG_YAFFS_DOES_ECC is not set
1153CONFIG_YAFFS_YAFFS2=y
1154CONFIG_YAFFS_AUTO_YAFFS2=y
1155# CONFIG_YAFFS_DISABLE_LAZY_LOAD is not set
1156CONFIG_YAFFS_CHECKPOINT_RESERVED_BLOCKS=10
1157# CONFIG_YAFFS_DISABLE_WIDE_TNODES is not set
1158# CONFIG_YAFFS_ALWAYS_CHECK_CHUNK_ERASED is not set
1159CONFIG_YAFFS_SHORT_NAMES_IN_RAM=y
1160CONFIG_JFFS2_FS=m
1161CONFIG_JFFS2_FS_DEBUG=0
1162CONFIG_JFFS2_FS_WRITEBUFFER=y
1163# CONFIG_JFFS2_SUMMARY is not set
1164# CONFIG_JFFS2_FS_XATTR is not set
1165# CONFIG_JFFS2_COMPRESSION_OPTIONS is not set
1166CONFIG_JFFS2_ZLIB=y
1167CONFIG_JFFS2_RTIME=y
1168# CONFIG_JFFS2_RUBIN is not set
996# CONFIG_CRAMFS is not set 1169# CONFIG_CRAMFS is not set
997# CONFIG_VXFS_FS is not set 1170# CONFIG_VXFS_FS is not set
998# CONFIG_HPFS_FS is not set 1171# CONFIG_HPFS_FS is not set
@@ -1040,36 +1213,20 @@ CONFIG_MSDOS_PARTITION=y
1040CONFIG_ENABLE_MUST_CHECK=y 1213CONFIG_ENABLE_MUST_CHECK=y
1041CONFIG_MAGIC_SYSRQ=y 1214CONFIG_MAGIC_SYSRQ=y
1042# CONFIG_UNUSED_SYMBOLS is not set 1215# CONFIG_UNUSED_SYMBOLS is not set
1043# CONFIG_DEBUG_FS is not set 1216CONFIG_DEBUG_FS=y
1044# CONFIG_HEADERS_CHECK is not set 1217# CONFIG_HEADERS_CHECK is not set
1045CONFIG_DEBUG_KERNEL=y 1218# CONFIG_DEBUG_KERNEL is not set
1046# CONFIG_DEBUG_SHIRQ is not set
1047CONFIG_LOG_BUF_SHIFT=14
1048CONFIG_DETECT_SOFTLOCKUP=y
1049# CONFIG_SCHEDSTATS is not set
1050# CONFIG_TIMER_STATS is not set
1051# CONFIG_DEBUG_SLAB is not set
1052# CONFIG_DEBUG_RT_MUTEXES is not set
1053# CONFIG_RT_MUTEX_TESTER is not set
1054# CONFIG_DEBUG_SPINLOCK is not set
1055# CONFIG_DEBUG_MUTEXES is not set
1056# CONFIG_DEBUG_SPINLOCK_SLEEP is not set
1057# CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set
1058# CONFIG_DEBUG_KOBJECT is not set
1059# CONFIG_DEBUG_BUGVERBOSE is not set 1219# CONFIG_DEBUG_BUGVERBOSE is not set
1060CONFIG_DEBUG_INFO=y 1220CONFIG_DEBUG_MMRS=y
1061# CONFIG_DEBUG_VM is not set
1062# CONFIG_DEBUG_LIST is not set
1063CONFIG_FRAME_POINTER=y
1064CONFIG_FORCED_INLINING=y
1065# CONFIG_RCU_TORTURE_TEST is not set
1066# CONFIG_FAULT_INJECTION is not set
1067CONFIG_DEBUG_HWERR=y
1068# CONFIG_DEBUG_ICACHE_CHECK is not set
1069# CONFIG_DEBUG_KERNEL_START is not set
1070# CONFIG_DEBUG_SERIAL_EARLY_INIT is not set
1071CONFIG_DEBUG_HUNT_FOR_ZERO=y 1221CONFIG_DEBUG_HUNT_FOR_ZERO=y
1222CONFIG_DEBUG_BFIN_HWTRACE_ON=y
1223CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_OFF=y
1224# CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_ONE is not set
1225# CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_TWO is not set
1226CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION=0
1227# CONFIG_DEBUG_BFIN_HWTRACE_EXPAND is not set
1072# CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE is not set 1228# CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE is not set
1229CONFIG_EARLY_PRINTK=y
1073CONFIG_CPLB_INFO=y 1230CONFIG_CPLB_INFO=y
1074CONFIG_ACCESS_CHECK=y 1231CONFIG_ACCESS_CHECK=y
1075 1232
@@ -1092,9 +1249,12 @@ CONFIG_SECURITY_CAPABILITIES=y
1092CONFIG_BITREVERSE=y 1249CONFIG_BITREVERSE=y
1093# CONFIG_CRC_CCITT is not set 1250# CONFIG_CRC_CCITT is not set
1094# CONFIG_CRC16 is not set 1251# CONFIG_CRC16 is not set
1252# CONFIG_CRC_ITU_T is not set
1095CONFIG_CRC32=y 1253CONFIG_CRC32=y
1096# CONFIG_LIBCRC32C is not set 1254# CONFIG_LIBCRC32C is not set
1097CONFIG_ZLIB_INFLATE=y 1255CONFIG_ZLIB_INFLATE=y
1256CONFIG_ZLIB_DEFLATE=m
1098CONFIG_PLIST=y 1257CONFIG_PLIST=y
1099CONFIG_HAS_IOMEM=y 1258CONFIG_HAS_IOMEM=y
1100CONFIG_HAS_IOPORT=y 1259CONFIG_HAS_IOPORT=y
1260CONFIG_HAS_DMA=y
diff --git a/arch/blackfin/configs/BF561-EZKIT_defconfig b/arch/blackfin/configs/BF561-EZKIT_defconfig
index 51c0b6f97798..85e647f87759 100644
--- a/arch/blackfin/configs/BF561-EZKIT_defconfig
+++ b/arch/blackfin/configs/BF561-EZKIT_defconfig
@@ -1,6 +1,6 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.21.5 3# Linux kernel version: 2.6.22.6
4# 4#
5# CONFIG_MMU is not set 5# CONFIG_MMU is not set
6# CONFIG_FPU is not set 6# CONFIG_FPU is not set
@@ -15,8 +15,9 @@ CONFIG_GENERIC_HWEIGHT=y
15CONFIG_GENERIC_HARDIRQS=y 15CONFIG_GENERIC_HARDIRQS=y
16CONFIG_GENERIC_IRQ_PROBE=y 16CONFIG_GENERIC_IRQ_PROBE=y
17# CONFIG_GENERIC_TIME is not set 17# CONFIG_GENERIC_TIME is not set
18CONFIG_GENERIC_CALIBRATE_DELAY=y 18CONFIG_GENERIC_GPIO=y
19CONFIG_FORCE_MAX_ZONEORDER=14 19CONFIG_FORCE_MAX_ZONEORDER=14
20CONFIG_GENERIC_CALIBRATE_DELAY=y
20CONFIG_IRQCHIP_DEMUX_GPIO=y 21CONFIG_IRQCHIP_DEMUX_GPIO=y
21CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config" 22CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
22 23
@@ -40,7 +41,9 @@ CONFIG_SYSVIPC_SYSCTL=y
40# CONFIG_TASKSTATS is not set 41# CONFIG_TASKSTATS is not set
41# CONFIG_UTS_NS is not set 42# CONFIG_UTS_NS is not set
42# CONFIG_AUDIT is not set 43# CONFIG_AUDIT is not set
43# CONFIG_IKCONFIG is not set 44CONFIG_IKCONFIG=y
45CONFIG_IKCONFIG_PROC=y
46CONFIG_LOG_BUF_SHIFT=14
44CONFIG_SYSFS_DEPRECATED=y 47CONFIG_SYSFS_DEPRECATED=y
45# CONFIG_RELAY is not set 48# CONFIG_RELAY is not set
46CONFIG_BLK_DEV_INITRD=y 49CONFIG_BLK_DEV_INITRD=y
@@ -58,15 +61,20 @@ CONFIG_BUG=y
58CONFIG_ELF_CORE=y 61CONFIG_ELF_CORE=y
59CONFIG_BASE_FULL=y 62CONFIG_BASE_FULL=y
60CONFIG_FUTEX=y 63CONFIG_FUTEX=y
64CONFIG_ANON_INODES=y
65CONFIG_EPOLL=y
66CONFIG_SIGNALFD=y
67CONFIG_TIMERFD=y
68CONFIG_EVENTFD=y
69CONFIG_VM_EVENT_COUNTERS=y
61CONFIG_BIG_ORDER_ALLOC_NOFAIL_MAGIC=3 70CONFIG_BIG_ORDER_ALLOC_NOFAIL_MAGIC=3
62CONFIG_BUDDY=y
63# CONFIG_NP2 is not set 71# CONFIG_NP2 is not set
64CONFIG_SLAB=y 72CONFIG_SLAB=y
65CONFIG_VM_EVENT_COUNTERS=y 73# CONFIG_SLUB is not set
74# CONFIG_SLOB is not set
66CONFIG_RT_MUTEXES=y 75CONFIG_RT_MUTEXES=y
67CONFIG_TINY_SHMEM=y 76CONFIG_TINY_SHMEM=y
68CONFIG_BASE_SMALL=0 77CONFIG_BASE_SMALL=0
69# CONFIG_SLOB is not set
70 78
71# 79#
72# Loadable module support 80# Loadable module support
@@ -229,19 +237,17 @@ CONFIG_IRQ_WDTIMER=13
229# CONFIG_CMDLINE_BOOL is not set 237# CONFIG_CMDLINE_BOOL is not set
230 238
231# 239#
232# Board Setup 240# Clock/PLL Setup
233# 241#
234CONFIG_CLKIN_HZ=30000000 242CONFIG_CLKIN_HZ=30000000
235CONFIG_MEM_SIZE=64 243# CONFIG_BFIN_KERNEL_CLOCK is not set
236CONFIG_MEM_ADD_WIDTH=9 244CONFIG_MAX_VCO_HZ=600000000
237CONFIG_BOOT_LOAD=0x1000 245CONFIG_MIN_VCO_HZ=50000000
238 246CONFIG_MAX_SCLK_HZ=133000000
239# 247CONFIG_MIN_SCLK_HZ=27000000
240# Blackfin Kernel Optimizations
241#
242 248
243# 249#
244# Timer Tick 250# Kernel Timer/Scheduler
245# 251#
246# CONFIG_HZ_100 is not set 252# CONFIG_HZ_100 is not set
247CONFIG_HZ_250=y 253CONFIG_HZ_250=y
@@ -250,6 +256,20 @@ CONFIG_HZ_250=y
250CONFIG_HZ=250 256CONFIG_HZ=250
251 257
252# 258#
259# Memory Setup
260#
261CONFIG_MEM_SIZE=64
262CONFIG_MEM_ADD_WIDTH=9
263CONFIG_BOOT_LOAD=0x1000
264CONFIG_BFIN_SCRATCH_REG_RETN=y
265# CONFIG_BFIN_SCRATCH_REG_RETE is not set
266# CONFIG_BFIN_SCRATCH_REG_CYCLES is not set
267
268#
269# Blackfin Kernel Optimizations
270#
271
272#
253# Memory Optimizations 273# Memory Optimizations
254# 274#
255CONFIG_I_ENTRY_L1=y 275CONFIG_I_ENTRY_L1=y
@@ -288,20 +308,15 @@ CONFIG_DMA_UNCACHED_1M=y
288# 308#
289# Cache Support 309# Cache Support
290# 310#
291CONFIG_BLKFIN_CACHE=y 311CONFIG_BFIN_ICACHE=y
292CONFIG_BLKFIN_DCACHE=y 312CONFIG_BFIN_DCACHE=y
293# CONFIG_BLKFIN_DCACHE_BANKA is not set 313# CONFIG_BFIN_DCACHE_BANKA is not set
294# CONFIG_BLKFIN_CACHE_LOCK is not set 314# CONFIG_BFIN_ICACHE_LOCK is not set
295# CONFIG_BLKFIN_WB is not set 315# CONFIG_BFIN_WB is not set
296CONFIG_BLKFIN_WT=y 316CONFIG_BFIN_WT=y
297CONFIG_L1_MAX_PIECE=16 317CONFIG_L1_MAX_PIECE=16
298 318
299# 319#
300# Clock Settings
301#
302# CONFIG_BFIN_KERNEL_CLOCK is not set
303
304#
305# Asynchonous Memory Configuration 320# Asynchonous Memory Configuration
306# 321#
307 322
@@ -326,12 +341,13 @@ CONFIG_C_AMBEN_ALL=y
326CONFIG_BANK_0=0x7BB0 341CONFIG_BANK_0=0x7BB0
327CONFIG_BANK_1=0x7BB0 342CONFIG_BANK_1=0x7BB0
328CONFIG_BANK_2=0x7BB0 343CONFIG_BANK_2=0x7BB0
329CONFIG_BANK_3=0x99B3 344CONFIG_BANK_3=0xAAC3
330 345
331# 346#
332# Bus options (PCI, PCMCIA, EISA, MCA, ISA) 347# Bus options (PCI, PCMCIA, EISA, MCA, ISA)
333# 348#
334# CONFIG_PCI is not set 349# CONFIG_PCI is not set
350# CONFIG_ARCH_SUPPORTS_MSI is not set
335 351
336# 352#
337# PCCARD (PCMCIA/CardBus) support 353# PCCARD (PCMCIA/CardBus) support
@@ -339,10 +355,6 @@ CONFIG_BANK_3=0x99B3
339# CONFIG_PCCARD is not set 355# CONFIG_PCCARD is not set
340 356
341# 357#
342# PCI Hotplug Support
343#
344
345#
346# Executable file formats 358# Executable file formats
347# 359#
348CONFIG_BINFMT_ELF_FDPIC=y 360CONFIG_BINFMT_ELF_FDPIC=y
@@ -364,7 +376,6 @@ CONFIG_NET=y
364# 376#
365# Networking options 377# Networking options
366# 378#
367# CONFIG_NETDEBUG is not set
368CONFIG_PACKET=y 379CONFIG_PACKET=y
369# CONFIG_PACKET_MMAP is not set 380# CONFIG_PACKET_MMAP is not set
370CONFIG_UNIX=y 381CONFIG_UNIX=y
@@ -405,20 +416,8 @@ CONFIG_DEFAULT_TCP_CONG="cubic"
405# CONFIG_NETLABEL is not set 416# CONFIG_NETLABEL is not set
406# CONFIG_NETWORK_SECMARK is not set 417# CONFIG_NETWORK_SECMARK is not set
407# CONFIG_NETFILTER is not set 418# CONFIG_NETFILTER is not set
408
409#
410# DCCP Configuration (EXPERIMENTAL)
411#
412# CONFIG_IP_DCCP is not set 419# CONFIG_IP_DCCP is not set
413
414#
415# SCTP Configuration (EXPERIMENTAL)
416#
417# CONFIG_IP_SCTP is not set 420# CONFIG_IP_SCTP is not set
418
419#
420# TIPC Configuration (EXPERIMENTAL)
421#
422# CONFIG_TIPC is not set 421# CONFIG_TIPC is not set
423# CONFIG_ATM is not set 422# CONFIG_ATM is not set
424# CONFIG_BRIDGE is not set 423# CONFIG_BRIDGE is not set
@@ -485,7 +484,16 @@ CONFIG_IRTTY_SIR=m
485# FIR device drivers 484# FIR device drivers
486# 485#
487# CONFIG_BT is not set 486# CONFIG_BT is not set
487# CONFIG_AF_RXRPC is not set
488
489#
490# Wireless
491#
492# CONFIG_CFG80211 is not set
493# CONFIG_WIRELESS_EXT is not set
494# CONFIG_MAC80211 is not set
488# CONFIG_IEEE80211 is not set 495# CONFIG_IEEE80211 is not set
496# CONFIG_RFKILL is not set
489 497
490# 498#
491# Device Drivers 499# Device Drivers
@@ -503,10 +511,6 @@ CONFIG_PREVENT_FIRMWARE_BUILD=y
503# Connector - unified userspace <-> kernelspace linker 511# Connector - unified userspace <-> kernelspace linker
504# 512#
505# CONFIG_CONNECTOR is not set 513# CONFIG_CONNECTOR is not set
506
507#
508# Memory Technology Devices (MTD)
509#
510CONFIG_MTD=y 514CONFIG_MTD=y
511# CONFIG_MTD_DEBUG is not set 515# CONFIG_MTD_DEBUG is not set
512# CONFIG_MTD_CONCAT is not set 516# CONFIG_MTD_CONCAT is not set
@@ -550,7 +554,6 @@ CONFIG_MTD_MW320D=m
550CONFIG_MTD_RAM=y 554CONFIG_MTD_RAM=y
551CONFIG_MTD_ROM=m 555CONFIG_MTD_ROM=m
552# CONFIG_MTD_ABSENT is not set 556# CONFIG_MTD_ABSENT is not set
553# CONFIG_MTD_OBSOLETE_CHIPS is not set
554 557
555# 558#
556# Mapping drivers for chip access 559# Mapping drivers for chip access
@@ -588,16 +591,13 @@ CONFIG_BFIN_FLASH_BANK_3=0x7BB0
588# CONFIG_MTD_DOC2000 is not set 591# CONFIG_MTD_DOC2000 is not set
589# CONFIG_MTD_DOC2001 is not set 592# CONFIG_MTD_DOC2001 is not set
590# CONFIG_MTD_DOC2001PLUS is not set 593# CONFIG_MTD_DOC2001PLUS is not set
591
592#
593# NAND Flash Device Drivers
594#
595# CONFIG_MTD_NAND is not set 594# CONFIG_MTD_NAND is not set
595# CONFIG_MTD_ONENAND is not set
596 596
597# 597#
598# OneNAND Flash Device Drivers 598# UBI - Unsorted block images
599# 599#
600# CONFIG_MTD_ONENAND is not set 600# CONFIG_MTD_UBI is not set
601 601
602# 602#
603# Parallel port support 603# Parallel port support
@@ -625,10 +625,6 @@ CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
625# 625#
626# Misc devices 626# Misc devices
627# 627#
628
629#
630# ATA/ATAPI/MFM/RLL support
631#
632# CONFIG_IDE is not set 628# CONFIG_IDE is not set
633 629
634# 630#
@@ -637,10 +633,6 @@ CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
637# CONFIG_RAID_ATTRS is not set 633# CONFIG_RAID_ATTRS is not set
638# CONFIG_SCSI is not set 634# CONFIG_SCSI is not set
639# CONFIG_SCSI_NETLINK is not set 635# CONFIG_SCSI_NETLINK is not set
640
641#
642# Serial ATA (prod) and Parallel ATA (experimental) drivers
643#
644# CONFIG_ATA is not set 636# CONFIG_ATA is not set
645 637
646# 638#
@@ -649,19 +641,6 @@ CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
649# CONFIG_MD is not set 641# CONFIG_MD is not set
650 642
651# 643#
652# Fusion MPT device support
653#
654# CONFIG_FUSION is not set
655
656#
657# IEEE 1394 (FireWire) support
658#
659
660#
661# I2O device support
662#
663
664#
665# Network device support 644# Network device support
666# 645#
667CONFIG_NETDEVICES=y 646CONFIG_NETDEVICES=y
@@ -669,10 +648,6 @@ CONFIG_NETDEVICES=y
669# CONFIG_BONDING is not set 648# CONFIG_BONDING is not set
670# CONFIG_EQUALIZER is not set 649# CONFIG_EQUALIZER is not set
671# CONFIG_TUN is not set 650# CONFIG_TUN is not set
672
673#
674# PHY device support
675#
676# CONFIG_PHYLIB is not set 651# CONFIG_PHYLIB is not set
677 652
678# 653#
@@ -682,27 +657,15 @@ CONFIG_NET_ETHERNET=y
682CONFIG_MII=y 657CONFIG_MII=y
683CONFIG_SMC91X=y 658CONFIG_SMC91X=y
684# CONFIG_SMSC911X is not set 659# CONFIG_SMSC911X is not set
660# CONFIG_DM9000 is not set
661CONFIG_NETDEV_1000=y
662CONFIG_NETDEV_10000=y
685 663
686# 664#
687# Ethernet (1000 Mbit) 665# Wireless LAN
688#
689
690#
691# Ethernet (10000 Mbit)
692#
693
694#
695# Token Ring devices
696#
697
698#
699# Wireless LAN (non-hamradio)
700#
701# CONFIG_NET_RADIO is not set
702
703#
704# Wan interfaces
705# 666#
667# CONFIG_WLAN_PRE80211 is not set
668# CONFIG_WLAN_80211 is not set
706# CONFIG_WAN is not set 669# CONFIG_WAN is not set
707# CONFIG_PPP is not set 670# CONFIG_PPP is not set
708# CONFIG_SLIP is not set 671# CONFIG_SLIP is not set
@@ -726,6 +689,7 @@ CONFIG_SMC91X=y
726# 689#
727CONFIG_INPUT=m 690CONFIG_INPUT=m
728# CONFIG_INPUT_FF_MEMLESS is not set 691# CONFIG_INPUT_FF_MEMLESS is not set
692# CONFIG_INPUT_POLLDEV is not set
729 693
730# 694#
731# Userland interfaces 695# Userland interfaces
@@ -742,6 +706,7 @@ CONFIG_INPUT_EVDEV=m
742# CONFIG_INPUT_KEYBOARD is not set 706# CONFIG_INPUT_KEYBOARD is not set
743# CONFIG_INPUT_MOUSE is not set 707# CONFIG_INPUT_MOUSE is not set
744# CONFIG_INPUT_JOYSTICK is not set 708# CONFIG_INPUT_JOYSTICK is not set
709# CONFIG_INPUT_TABLET is not set
745# CONFIG_INPUT_TOUCHSCREEN is not set 710# CONFIG_INPUT_TOUCHSCREEN is not set
746# CONFIG_INPUT_MISC is not set 711# CONFIG_INPUT_MISC is not set
747 712
@@ -756,7 +721,7 @@ CONFIG_INPUT_EVDEV=m
756# 721#
757# CONFIG_AD9960 is not set 722# CONFIG_AD9960 is not set
758# CONFIG_SPI_ADC_BF533 is not set 723# CONFIG_SPI_ADC_BF533 is not set
759# CONFIG_BF5xx_PFLAGS is not set 724# CONFIG_BFIN_PFLAGS is not set
760# CONFIG_BF5xx_PPIFCD is not set 725# CONFIG_BF5xx_PPIFCD is not set
761# CONFIG_BF5xx_TIMERS is not set 726# CONFIG_BF5xx_TIMERS is not set
762# CONFIG_BF5xx_PPI is not set 727# CONFIG_BF5xx_PPI is not set
@@ -796,10 +761,6 @@ CONFIG_UNIX98_PTYS=y
796# IPMI 761# IPMI
797# 762#
798# CONFIG_IPMI_HANDLER is not set 763# CONFIG_IPMI_HANDLER is not set
799
800#
801# Watchdog Cards
802#
803CONFIG_WATCHDOG=y 764CONFIG_WATCHDOG=y
804# CONFIG_WATCHDOG_NOWAYOUT is not set 765# CONFIG_WATCHDOG_NOWAYOUT is not set
805 766
@@ -810,7 +771,6 @@ CONFIG_WATCHDOG=y
810CONFIG_BFIN_WDT=y 771CONFIG_BFIN_WDT=y
811CONFIG_HW_RANDOM=y 772CONFIG_HW_RANDOM=y
812# CONFIG_GEN_RTC is not set 773# CONFIG_GEN_RTC is not set
813# CONFIG_DTLK is not set
814# CONFIG_R3964 is not set 774# CONFIG_R3964 is not set
815# CONFIG_RAW_DRIVER is not set 775# CONFIG_RAW_DRIVER is not set
816 776
@@ -818,10 +778,6 @@ CONFIG_HW_RANDOM=y
818# TPM devices 778# TPM devices
819# 779#
820# CONFIG_TCG_TPM is not set 780# CONFIG_TCG_TPM is not set
821
822#
823# I2C support
824#
825# CONFIG_I2C is not set 781# CONFIG_I2C is not set
826 782
827# 783#
@@ -840,22 +796,22 @@ CONFIG_SPI_BFIN=y
840# SPI Protocol Masters 796# SPI Protocol Masters
841# 797#
842# CONFIG_SPI_AT25 is not set 798# CONFIG_SPI_AT25 is not set
799# CONFIG_SPI_SPIDEV is not set
843 800
844# 801#
845# Dallas's 1-wire bus 802# Dallas's 1-wire bus
846# 803#
847# CONFIG_W1 is not set 804# CONFIG_W1 is not set
848
849#
850# Hardware Monitoring support
851#
852CONFIG_HWMON=y 805CONFIG_HWMON=y
853# CONFIG_HWMON_VID is not set 806# CONFIG_HWMON_VID is not set
854# CONFIG_SENSORS_ABITUGURU is not set 807# CONFIG_SENSORS_ABITUGURU is not set
855# CONFIG_SENSORS_F71805F is not set 808# CONFIG_SENSORS_F71805F is not set
856# CONFIG_SENSORS_LM70 is not set 809# CONFIG_SENSORS_LM70 is not set
857# CONFIG_SENSORS_PC87427 is not set 810# CONFIG_SENSORS_PC87427 is not set
811# CONFIG_SENSORS_SMSC47M1 is not set
812# CONFIG_SENSORS_SMSC47B397 is not set
858# CONFIG_SENSORS_VT1211 is not set 813# CONFIG_SENSORS_VT1211 is not set
814# CONFIG_SENSORS_W83627HF is not set
859# CONFIG_HWMON_DEBUG_CHIP is not set 815# CONFIG_HWMON_DEBUG_CHIP is not set
860 816
861# 817#
@@ -867,16 +823,19 @@ CONFIG_HWMON=y
867# Multimedia devices 823# Multimedia devices
868# 824#
869# CONFIG_VIDEO_DEV is not set 825# CONFIG_VIDEO_DEV is not set
826# CONFIG_DVB_CORE is not set
827CONFIG_DAB=y
870 828
871# 829#
872# Digital Video Broadcasting Devices 830# Graphics support
873# 831#
874# CONFIG_DVB is not set 832# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
875 833
876# 834#
877# Graphics support 835# Display device support
878# 836#
879# CONFIG_BACKLIGHT_LCD_SUPPORT is not set 837# CONFIG_DISPLAY_SUPPORT is not set
838# CONFIG_VGASTATE is not set
880# CONFIG_FB is not set 839# CONFIG_FB is not set
881 840
882# 841#
@@ -899,18 +858,17 @@ CONFIG_USB_ARCH_HAS_HCD=y
899# CONFIG_USB is not set 858# CONFIG_USB is not set
900 859
901# 860#
902# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support' 861# Enable Host or Gadget support to see Inventra options
903# 862#
904 863
905# 864#
906# USB Gadget Support 865# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support'
907# 866#
908# CONFIG_USB_GADGET is not set
909 867
910# 868#
911# MMC/SD Card support 869# USB Gadget Support
912# 870#
913# CONFIG_SPI_MMC is not set 871# CONFIG_USB_GADGET is not set
914# CONFIG_MMC is not set 872# CONFIG_MMC is not set
915 873
916# 874#
@@ -953,14 +911,6 @@ CONFIG_USB_ARCH_HAS_HCD=y
953# 911#
954 912
955# 913#
956# Auxiliary Display support
957#
958
959#
960# Virtualization
961#
962
963#
964# PBX support 914# PBX support
965# 915#
966# CONFIG_PBX is not set 916# CONFIG_PBX is not set
@@ -1060,6 +1010,7 @@ CONFIG_LOCKD=m
1060CONFIG_LOCKD_V4=y 1010CONFIG_LOCKD_V4=y
1061CONFIG_NFS_COMMON=y 1011CONFIG_NFS_COMMON=y
1062CONFIG_SUNRPC=m 1012CONFIG_SUNRPC=m
1013# CONFIG_SUNRPC_BIND34 is not set
1063# CONFIG_RPCSEC_GSS_KRB5 is not set 1014# CONFIG_RPCSEC_GSS_KRB5 is not set
1064# CONFIG_RPCSEC_GSS_SPKM3 is not set 1015# CONFIG_RPCSEC_GSS_SPKM3 is not set
1065CONFIG_SMB_FS=m 1016CONFIG_SMB_FS=m
@@ -1137,14 +1088,20 @@ CONFIG_NLS_DEFAULT="iso8859-1"
1137CONFIG_ENABLE_MUST_CHECK=y 1088CONFIG_ENABLE_MUST_CHECK=y
1138# CONFIG_MAGIC_SYSRQ is not set 1089# CONFIG_MAGIC_SYSRQ is not set
1139# CONFIG_UNUSED_SYMBOLS is not set 1090# CONFIG_UNUSED_SYMBOLS is not set
1140# CONFIG_DEBUG_FS is not set 1091CONFIG_DEBUG_FS=y
1141# CONFIG_HEADERS_CHECK is not set 1092# CONFIG_HEADERS_CHECK is not set
1142# CONFIG_DEBUG_KERNEL is not set 1093# CONFIG_DEBUG_KERNEL is not set
1143CONFIG_LOG_BUF_SHIFT=14
1144# CONFIG_DEBUG_BUGVERBOSE is not set 1094# CONFIG_DEBUG_BUGVERBOSE is not set
1145# CONFIG_DEBUG_SERIAL_EARLY_INIT is not set 1095CONFIG_DEBUG_MMRS=y
1146CONFIG_DEBUG_HUNT_FOR_ZERO=y 1096CONFIG_DEBUG_HUNT_FOR_ZERO=y
1097CONFIG_DEBUG_BFIN_HWTRACE_ON=y
1098CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_OFF=y
1099# CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_ONE is not set
1100# CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_TWO is not set
1101CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION=0
1102# CONFIG_DEBUG_BFIN_HWTRACE_EXPAND is not set
1147# CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE is not set 1103# CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE is not set
1104CONFIG_EARLY_PRINTK=y
1148# CONFIG_DUAL_CORE_TEST_MODULE is not set 1105# CONFIG_DUAL_CORE_TEST_MODULE is not set
1149CONFIG_CPLB_INFO=y 1106CONFIG_CPLB_INFO=y
1150CONFIG_ACCESS_CHECK=y 1107CONFIG_ACCESS_CHECK=y
@@ -1168,6 +1125,7 @@ CONFIG_SECURITY_CAPABILITIES=m
1168CONFIG_BITREVERSE=y 1125CONFIG_BITREVERSE=y
1169CONFIG_CRC_CCITT=m 1126CONFIG_CRC_CCITT=m
1170# CONFIG_CRC16 is not set 1127# CONFIG_CRC16 is not set
1128# CONFIG_CRC_ITU_T is not set
1171CONFIG_CRC32=y 1129CONFIG_CRC32=y
1172# CONFIG_LIBCRC32C is not set 1130# CONFIG_LIBCRC32C is not set
1173CONFIG_ZLIB_INFLATE=y 1131CONFIG_ZLIB_INFLATE=y
@@ -1175,3 +1133,4 @@ CONFIG_ZLIB_DEFLATE=m
1175CONFIG_PLIST=y 1133CONFIG_PLIST=y
1176CONFIG_HAS_IOMEM=y 1134CONFIG_HAS_IOMEM=y
1177CONFIG_HAS_IOPORT=y 1135CONFIG_HAS_IOPORT=y
1136CONFIG_HAS_DMA=y
diff --git a/arch/blackfin/configs/PNAV-10_defconfig b/arch/blackfin/configs/PNAV-10_defconfig
index 983ed181c896..15e36aaf2186 100644
--- a/arch/blackfin/configs/PNAV-10_defconfig
+++ b/arch/blackfin/configs/PNAV-10_defconfig
@@ -1,6 +1,6 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.21.5 3# Linux kernel version: 2.6.22.6
4# 4#
5# CONFIG_MMU is not set 5# CONFIG_MMU is not set
6# CONFIG_FPU is not set 6# CONFIG_FPU is not set
@@ -15,8 +15,9 @@ CONFIG_GENERIC_HWEIGHT=y
15CONFIG_GENERIC_HARDIRQS=y 15CONFIG_GENERIC_HARDIRQS=y
16CONFIG_GENERIC_IRQ_PROBE=y 16CONFIG_GENERIC_IRQ_PROBE=y
17# CONFIG_GENERIC_TIME is not set 17# CONFIG_GENERIC_TIME is not set
18CONFIG_GENERIC_CALIBRATE_DELAY=y 18CONFIG_GENERIC_GPIO=y
19CONFIG_FORCE_MAX_ZONEORDER=14 19CONFIG_FORCE_MAX_ZONEORDER=14
20CONFIG_GENERIC_CALIBRATE_DELAY=y
20CONFIG_IRQCHIP_DEMUX_GPIO=y 21CONFIG_IRQCHIP_DEMUX_GPIO=y
21CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config" 22CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
22 23
@@ -41,6 +42,7 @@ CONFIG_SYSVIPC_SYSCTL=y
41# CONFIG_UTS_NS is not set 42# CONFIG_UTS_NS is not set
42# CONFIG_AUDIT is not set 43# CONFIG_AUDIT is not set
43# CONFIG_IKCONFIG is not set 44# CONFIG_IKCONFIG is not set
45CONFIG_LOG_BUF_SHIFT=14
44CONFIG_SYSFS_DEPRECATED=y 46CONFIG_SYSFS_DEPRECATED=y
45# CONFIG_RELAY is not set 47# CONFIG_RELAY is not set
46# CONFIG_BLK_DEV_INITRD is not set 48# CONFIG_BLK_DEV_INITRD is not set
@@ -57,15 +59,20 @@ CONFIG_BUG=y
57CONFIG_ELF_CORE=y 59CONFIG_ELF_CORE=y
58CONFIG_BASE_FULL=y 60CONFIG_BASE_FULL=y
59CONFIG_FUTEX=y 61CONFIG_FUTEX=y
62CONFIG_ANON_INODES=y
63CONFIG_EPOLL=y
64CONFIG_SIGNALFD=y
65CONFIG_TIMERFD=y
66CONFIG_EVENTFD=y
67CONFIG_VM_EVENT_COUNTERS=y
60CONFIG_BIG_ORDER_ALLOC_NOFAIL_MAGIC=9 68CONFIG_BIG_ORDER_ALLOC_NOFAIL_MAGIC=9
61CONFIG_BUDDY=y
62# CONFIG_NP2 is not set 69# CONFIG_NP2 is not set
63CONFIG_SLAB=y 70CONFIG_SLAB=y
64CONFIG_VM_EVENT_COUNTERS=y 71# CONFIG_SLUB is not set
72# CONFIG_SLOB is not set
65CONFIG_RT_MUTEXES=y 73CONFIG_RT_MUTEXES=y
66CONFIG_TINY_SHMEM=y 74CONFIG_TINY_SHMEM=y
67CONFIG_BASE_SMALL=0 75CONFIG_BASE_SMALL=0
68# CONFIG_SLOB is not set
69 76
70# 77#
71# Loadable module support 78# Loadable module support
@@ -147,13 +154,6 @@ CONFIG_IRQ_PLL_WAKEUP=7
147# 154#
148 155
149# 156#
150# PORT F/G Selection
151#
152CONFIG_BF537_PORT_F=y
153# CONFIG_BF537_PORT_G is not set
154# CONFIG_BF537_PORT_H is not set
155
156#
157# Interrupt Priority Assignment 157# Interrupt Priority Assignment
158# 158#
159 159
@@ -198,19 +198,17 @@ CONFIG_IRQ_WATCH=13
198# CONFIG_CMDLINE_BOOL is not set 198# CONFIG_CMDLINE_BOOL is not set
199 199
200# 200#
201# Board Setup 201# Clock/PLL Setup
202# 202#
203CONFIG_CLKIN_HZ=24576000 203CONFIG_CLKIN_HZ=24576000
204CONFIG_MEM_SIZE=64 204# CONFIG_BFIN_KERNEL_CLOCK is not set
205CONFIG_MEM_ADD_WIDTH=10 205CONFIG_MAX_VCO_HZ=600000000
206CONFIG_BOOT_LOAD=0x1000 206CONFIG_MIN_VCO_HZ=50000000
207 207CONFIG_MAX_SCLK_HZ=133000000
208# 208CONFIG_MIN_SCLK_HZ=27000000
209# Blackfin Kernel Optimizations
210#
211 209
212# 210#
213# Timer Tick 211# Kernel Timer/Scheduler
214# 212#
215# CONFIG_HZ_100 is not set 213# CONFIG_HZ_100 is not set
216CONFIG_HZ_250=y 214CONFIG_HZ_250=y
@@ -219,6 +217,20 @@ CONFIG_HZ_250=y
219CONFIG_HZ=250 217CONFIG_HZ=250
220 218
221# 219#
220# Memory Setup
221#
222CONFIG_MEM_SIZE=64
223CONFIG_MEM_ADD_WIDTH=10
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#
222# Memory Optimizations 234# Memory Optimizations
223# 235#
224CONFIG_I_ENTRY_L1=y 236CONFIG_I_ENTRY_L1=y
@@ -257,20 +269,15 @@ CONFIG_DMA_UNCACHED_1M=y
257# 269#
258# Cache Support 270# Cache Support
259# 271#
260CONFIG_BLKFIN_CACHE=y 272CONFIG_BFIN_ICACHE=y
261CONFIG_BLKFIN_DCACHE=y 273CONFIG_BFIN_DCACHE=y
262# CONFIG_BLKFIN_DCACHE_BANKA is not set 274# CONFIG_BFIN_DCACHE_BANKA is not set
263# CONFIG_BLKFIN_CACHE_LOCK is not set 275# CONFIG_BFIN_ICACHE_LOCK is not set
264CONFIG_BLKFIN_WB=y 276CONFIG_BFIN_WB=y
265# CONFIG_BLKFIN_WT is not set 277# CONFIG_BFIN_WT is not set
266CONFIG_L1_MAX_PIECE=16 278CONFIG_L1_MAX_PIECE=16
267 279
268# 280#
269# Clock Settings
270#
271# CONFIG_BFIN_KERNEL_CLOCK is not set
272
273#
274# Asynchonous Memory Configuration 281# Asynchonous Memory Configuration
275# 282#
276 283
@@ -297,6 +304,7 @@ CONFIG_BANK_3=0x99B3
297# Bus options (PCI, PCMCIA, EISA, MCA, ISA) 304# Bus options (PCI, PCMCIA, EISA, MCA, ISA)
298# 305#
299# CONFIG_PCI is not set 306# CONFIG_PCI is not set
307# CONFIG_ARCH_SUPPORTS_MSI is not set
300 308
301# 309#
302# PCCARD (PCMCIA/CardBus) support 310# PCCARD (PCMCIA/CardBus) support
@@ -304,10 +312,6 @@ CONFIG_BANK_3=0x99B3
304# CONFIG_PCCARD is not set 312# CONFIG_PCCARD is not set
305 313
306# 314#
307# PCI Hotplug Support
308#
309
310#
311# Executable file formats 315# Executable file formats
312# 316#
313CONFIG_BINFMT_ELF_FDPIC=y 317CONFIG_BINFMT_ELF_FDPIC=y
@@ -334,7 +338,6 @@ CONFIG_NET=y
334# 338#
335# Networking options 339# Networking options
336# 340#
337# CONFIG_NETDEBUG is not set
338CONFIG_PACKET=y 341CONFIG_PACKET=y
339# CONFIG_PACKET_MMAP is not set 342# CONFIG_PACKET_MMAP is not set
340CONFIG_UNIX=y 343CONFIG_UNIX=y
@@ -375,20 +378,8 @@ CONFIG_DEFAULT_TCP_CONG="cubic"
375# CONFIG_NETLABEL is not set 378# CONFIG_NETLABEL is not set
376# CONFIG_NETWORK_SECMARK is not set 379# CONFIG_NETWORK_SECMARK is not set
377# CONFIG_NETFILTER is not set 380# CONFIG_NETFILTER is not set
378
379#
380# DCCP Configuration (EXPERIMENTAL)
381#
382# CONFIG_IP_DCCP is not set 381# CONFIG_IP_DCCP is not set
383
384#
385# SCTP Configuration (EXPERIMENTAL)
386#
387# CONFIG_IP_SCTP is not set 382# CONFIG_IP_SCTP is not set
388
389#
390# TIPC Configuration (EXPERIMENTAL)
391#
392# CONFIG_TIPC is not set 383# CONFIG_TIPC is not set
393# CONFIG_ATM is not set 384# CONFIG_ATM is not set
394# CONFIG_BRIDGE is not set 385# CONFIG_BRIDGE is not set
@@ -414,7 +405,16 @@ CONFIG_DEFAULT_TCP_CONG="cubic"
414# CONFIG_HAMRADIO is not set 405# CONFIG_HAMRADIO is not set
415# CONFIG_IRDA is not set 406# CONFIG_IRDA is not set
416# CONFIG_BT is not set 407# CONFIG_BT is not set
408# CONFIG_AF_RXRPC is not set
409
410#
411# Wireless
412#
413# CONFIG_CFG80211 is not set
414# CONFIG_WIRELESS_EXT is not set
415# CONFIG_MAC80211 is not set
417# CONFIG_IEEE80211 is not set 416# CONFIG_IEEE80211 is not set
417# CONFIG_RFKILL is not set
418 418
419# 419#
420# Device Drivers 420# Device Drivers
@@ -432,10 +432,6 @@ CONFIG_PREVENT_FIRMWARE_BUILD=y
432# Connector - unified userspace <-> kernelspace linker 432# Connector - unified userspace <-> kernelspace linker
433# 433#
434# CONFIG_CONNECTOR is not set 434# CONFIG_CONNECTOR is not set
435
436#
437# Memory Technology Devices (MTD)
438#
439CONFIG_MTD=y 435CONFIG_MTD=y
440# CONFIG_MTD_DEBUG is not set 436# CONFIG_MTD_DEBUG is not set
441# CONFIG_MTD_CONCAT is not set 437# CONFIG_MTD_CONCAT is not set
@@ -473,7 +469,6 @@ CONFIG_MTD_CFI_I2=y
473CONFIG_MTD_RAM=y 469CONFIG_MTD_RAM=y
474# CONFIG_MTD_ROM is not set 470# CONFIG_MTD_ROM is not set
475# CONFIG_MTD_ABSENT is not set 471# CONFIG_MTD_ABSENT is not set
476# CONFIG_MTD_OBSOLETE_CHIPS is not set
477 472
478# 473#
479# Mapping drivers for chip access 474# Mapping drivers for chip access
@@ -499,13 +494,10 @@ CONFIG_MTD_UCLINUX=y
499# CONFIG_MTD_DOC2000 is not set 494# CONFIG_MTD_DOC2000 is not set
500# CONFIG_MTD_DOC2001 is not set 495# CONFIG_MTD_DOC2001 is not set
501# CONFIG_MTD_DOC2001PLUS is not set 496# CONFIG_MTD_DOC2001PLUS is not set
502
503#
504# NAND Flash Device Drivers
505#
506CONFIG_MTD_NAND=y 497CONFIG_MTD_NAND=y
507# CONFIG_MTD_NAND_VERIFY_WRITE is not set 498# CONFIG_MTD_NAND_VERIFY_WRITE is not set
508# CONFIG_MTD_NAND_ECC_SMC is not set 499# CONFIG_MTD_NAND_ECC_SMC is not set
500# CONFIG_MTD_NAND_MUSEUM_IDS is not set
509CONFIG_MTD_NAND_BFIN=y 501CONFIG_MTD_NAND_BFIN=y
510CONFIG_BFIN_NAND_BASE=0x20100000 502CONFIG_BFIN_NAND_BASE=0x20100000
511CONFIG_BFIN_NAND_CLE=2 503CONFIG_BFIN_NAND_CLE=2
@@ -514,11 +506,13 @@ CONFIG_BFIN_NAND_READY=44
514CONFIG_MTD_NAND_IDS=y 506CONFIG_MTD_NAND_IDS=y
515# CONFIG_MTD_NAND_DISKONCHIP is not set 507# CONFIG_MTD_NAND_DISKONCHIP is not set
516# CONFIG_MTD_NAND_NANDSIM is not set 508# CONFIG_MTD_NAND_NANDSIM is not set
509# CONFIG_MTD_NAND_PLATFORM is not set
510# CONFIG_MTD_ONENAND is not set
517 511
518# 512#
519# OneNAND Flash Device Drivers 513# UBI - Unsorted block images
520# 514#
521# CONFIG_MTD_ONENAND is not set 515# CONFIG_MTD_UBI is not set
522 516
523# 517#
524# Parallel port support 518# Parallel port support
@@ -546,10 +540,6 @@ CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
546# 540#
547# Misc devices 541# Misc devices
548# 542#
549
550#
551# ATA/ATAPI/MFM/RLL support
552#
553# CONFIG_IDE is not set 543# CONFIG_IDE is not set
554 544
555# 545#
@@ -558,10 +548,6 @@ CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
558# CONFIG_RAID_ATTRS is not set 548# CONFIG_RAID_ATTRS is not set
559# CONFIG_SCSI is not set 549# CONFIG_SCSI is not set
560# CONFIG_SCSI_NETLINK is not set 550# CONFIG_SCSI_NETLINK is not set
561
562#
563# Serial ATA (prod) and Parallel ATA (experimental) drivers
564#
565# CONFIG_ATA is not set 551# CONFIG_ATA is not set
566 552
567# 553#
@@ -570,19 +556,6 @@ CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
570# CONFIG_MD is not set 556# CONFIG_MD is not set
571 557
572# 558#
573# Fusion MPT device support
574#
575# CONFIG_FUSION is not set
576
577#
578# IEEE 1394 (FireWire) support
579#
580
581#
582# I2O device support
583#
584
585#
586# Network device support 559# Network device support
587# 560#
588CONFIG_NETDEVICES=y 561CONFIG_NETDEVICES=y
@@ -590,11 +563,20 @@ CONFIG_NETDEVICES=y
590# CONFIG_BONDING is not set 563# CONFIG_BONDING is not set
591# CONFIG_EQUALIZER is not set 564# CONFIG_EQUALIZER is not set
592# CONFIG_TUN is not set 565# CONFIG_TUN is not set
566CONFIG_PHYLIB=y
593 567
594# 568#
595# PHY device support 569# MII PHY device drivers
596# 570#
597# CONFIG_PHYLIB is not set 571# CONFIG_MARVELL_PHY is not set
572# CONFIG_DAVICOM_PHY is not set
573# CONFIG_QSEMI_PHY is not set
574# CONFIG_LXT_PHY is not set
575# CONFIG_CICADA_PHY is not set
576# CONFIG_VITESSE_PHY is not set
577# CONFIG_SMSC_PHY is not set
578# CONFIG_BROADCOM_PHY is not set
579# CONFIG_FIXED_PHY is not set
598 580
599# 581#
600# Ethernet (10 or 100Mbit) 582# Ethernet (10 or 100Mbit)
@@ -608,27 +590,15 @@ CONFIG_BFIN_TX_DESC_NUM=100
608CONFIG_BFIN_RX_DESC_NUM=100 590CONFIG_BFIN_RX_DESC_NUM=100
609CONFIG_BFIN_MAC_RMII=y 591CONFIG_BFIN_MAC_RMII=y
610# CONFIG_SMSC911X is not set 592# CONFIG_SMSC911X is not set
593# CONFIG_DM9000 is not set
594CONFIG_NETDEV_1000=y
595CONFIG_NETDEV_10000=y
611 596
612# 597#
613# Ethernet (1000 Mbit) 598# Wireless LAN
614#
615
616#
617# Ethernet (10000 Mbit)
618#
619
620#
621# Token Ring devices
622#
623
624#
625# Wireless LAN (non-hamradio)
626#
627# CONFIG_NET_RADIO is not set
628
629#
630# Wan interfaces
631# 599#
600# CONFIG_WLAN_PRE80211 is not set
601# CONFIG_WLAN_80211 is not set
632# CONFIG_WAN is not set 602# CONFIG_WAN is not set
633# CONFIG_PPP is not set 603# CONFIG_PPP is not set
634# CONFIG_SLIP is not set 604# CONFIG_SLIP is not set
@@ -652,6 +622,7 @@ CONFIG_BFIN_MAC_RMII=y
652# 622#
653CONFIG_INPUT=y 623CONFIG_INPUT=y
654# CONFIG_INPUT_FF_MEMLESS is not set 624# CONFIG_INPUT_FF_MEMLESS is not set
625# CONFIG_INPUT_POLLDEV is not set
655 626
656# 627#
657# Userland interfaces 628# Userland interfaces
@@ -670,6 +641,7 @@ CONFIG_INPUT_EVDEV=y
670# CONFIG_INPUT_KEYBOARD is not set 641# CONFIG_INPUT_KEYBOARD is not set
671# CONFIG_INPUT_MOUSE is not set 642# CONFIG_INPUT_MOUSE is not set
672# CONFIG_INPUT_JOYSTICK is not set 643# CONFIG_INPUT_JOYSTICK is not set
644# CONFIG_INPUT_TABLET is not set
673CONFIG_INPUT_TOUCHSCREEN=y 645CONFIG_INPUT_TOUCHSCREEN=y
674# CONFIG_TOUCHSCREEN_ADS7846 is not set 646# CONFIG_TOUCHSCREEN_ADS7846 is not set
675CONFIG_TOUCHSCREEN_AD7877=y 647CONFIG_TOUCHSCREEN_AD7877=y
@@ -681,7 +653,13 @@ CONFIG_TOUCHSCREEN_AD7877=y
681# CONFIG_TOUCHSCREEN_TOUCHRIGHT is not set 653# CONFIG_TOUCHSCREEN_TOUCHRIGHT is not set
682# CONFIG_TOUCHSCREEN_TOUCHWIN is not set 654# CONFIG_TOUCHSCREEN_TOUCHWIN is not set
683# CONFIG_TOUCHSCREEN_UCB1400 is not set 655# CONFIG_TOUCHSCREEN_UCB1400 is not set
656# CONFIG_TOUCHSCREEN_USB_COMPOSITE is not set
684CONFIG_INPUT_MISC=y 657CONFIG_INPUT_MISC=y
658# CONFIG_INPUT_ATI_REMOTE is not set
659# CONFIG_INPUT_ATI_REMOTE2 is not set
660# CONFIG_INPUT_KEYSPAN_REMOTE is not set
661# CONFIG_INPUT_POWERMATE is not set
662# CONFIG_INPUT_YEALINK is not set
685CONFIG_INPUT_UINPUT=y 663CONFIG_INPUT_UINPUT=y
686# CONFIG_BF53X_PFBUTTONS is not set 664# CONFIG_BF53X_PFBUTTONS is not set
687# CONFIG_TWI_KEYPAD is not set 665# CONFIG_TWI_KEYPAD is not set
@@ -697,7 +675,7 @@ CONFIG_INPUT_UINPUT=y
697# 675#
698# CONFIG_AD9960 is not set 676# CONFIG_AD9960 is not set
699# CONFIG_SPI_ADC_BF533 is not set 677# CONFIG_SPI_ADC_BF533 is not set
700# CONFIG_BF5xx_PFLAGS is not set 678# CONFIG_BFIN_PFLAGS is not set
701# CONFIG_BF5xx_PPIFCD is not set 679# CONFIG_BF5xx_PPIFCD is not set
702# CONFIG_BF5xx_TIMERS is not set 680# CONFIG_BF5xx_TIMERS is not set
703# CONFIG_BF5xx_PPI is not set 681# CONFIG_BF5xx_PPI is not set
@@ -749,14 +727,9 @@ CONFIG_CAN_BLACKFIN=m
749# IPMI 727# IPMI
750# 728#
751# CONFIG_IPMI_HANDLER is not set 729# CONFIG_IPMI_HANDLER is not set
752
753#
754# Watchdog Cards
755#
756# CONFIG_WATCHDOG is not set 730# CONFIG_WATCHDOG is not set
757CONFIG_HW_RANDOM=y 731CONFIG_HW_RANDOM=y
758# CONFIG_GEN_RTC is not set 732# CONFIG_GEN_RTC is not set
759# CONFIG_DTLK is not set
760# CONFIG_R3964 is not set 733# CONFIG_R3964 is not set
761# CONFIG_RAW_DRIVER is not set 734# CONFIG_RAW_DRIVER is not set
762 735
@@ -764,11 +737,8 @@ CONFIG_HW_RANDOM=y
764# TPM devices 737# TPM devices
765# 738#
766# CONFIG_TCG_TPM is not set 739# CONFIG_TCG_TPM is not set
767
768#
769# I2C support
770#
771CONFIG_I2C=y 740CONFIG_I2C=y
741CONFIG_I2C_BOARDINFO=y
772CONFIG_I2C_CHARDEV=y 742CONFIG_I2C_CHARDEV=y
773 743
774# 744#
@@ -784,10 +754,11 @@ CONFIG_I2C_CHARDEV=y
784# CONFIG_I2C_BLACKFIN_GPIO is not set 754# CONFIG_I2C_BLACKFIN_GPIO is not set
785CONFIG_I2C_BLACKFIN_TWI=y 755CONFIG_I2C_BLACKFIN_TWI=y
786CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ=50 756CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ=50
757# CONFIG_I2C_GPIO is not set
787# CONFIG_I2C_OCORES is not set 758# CONFIG_I2C_OCORES is not set
788# CONFIG_I2C_PARPORT_LIGHT is not set 759# CONFIG_I2C_PARPORT_LIGHT is not set
760# CONFIG_I2C_SIMTEC is not set
789# CONFIG_I2C_STUB is not set 761# CONFIG_I2C_STUB is not set
790# CONFIG_I2C_PCA_ISA is not set
791 762
792# 763#
793# Miscellaneous I2C Chip support 764# Miscellaneous I2C Chip support
@@ -823,18 +794,16 @@ CONFIG_SPI_BFIN=y
823# SPI Protocol Masters 794# SPI Protocol Masters
824# 795#
825# CONFIG_SPI_AT25 is not set 796# CONFIG_SPI_AT25 is not set
797# CONFIG_SPI_SPIDEV is not set
826 798
827# 799#
828# Dallas's 1-wire bus 800# Dallas's 1-wire bus
829# 801#
830# CONFIG_W1 is not set 802# CONFIG_W1 is not set
831
832#
833# Hardware Monitoring support
834#
835CONFIG_HWMON=y 803CONFIG_HWMON=y
836# CONFIG_HWMON_VID is not set 804# CONFIG_HWMON_VID is not set
837# CONFIG_SENSORS_ABITUGURU is not set 805# CONFIG_SENSORS_ABITUGURU is not set
806# CONFIG_SENSORS_AD7418 is not set
838# CONFIG_SENSORS_ADM1021 is not set 807# CONFIG_SENSORS_ADM1021 is not set
839# CONFIG_SENSORS_ADM1025 is not set 808# CONFIG_SENSORS_ADM1025 is not set
840# CONFIG_SENSORS_ADM1026 is not set 809# CONFIG_SENSORS_ADM1026 is not set
@@ -862,6 +831,7 @@ CONFIG_HWMON=y
862# CONFIG_SENSORS_LM90 is not set 831# CONFIG_SENSORS_LM90 is not set
863# CONFIG_SENSORS_LM92 is not set 832# CONFIG_SENSORS_LM92 is not set
864# CONFIG_SENSORS_MAX1619 is not set 833# CONFIG_SENSORS_MAX1619 is not set
834# CONFIG_SENSORS_MAX6650 is not set
865# CONFIG_SENSORS_PC87360 is not set 835# CONFIG_SENSORS_PC87360 is not set
866# CONFIG_SENSORS_PC87427 is not set 836# CONFIG_SENSORS_PC87427 is not set
867# CONFIG_SENSORS_SMSC47M1 is not set 837# CONFIG_SENSORS_SMSC47M1 is not set
@@ -886,11 +856,8 @@ CONFIG_HWMON=y
886# Multimedia devices 856# Multimedia devices
887# 857#
888# CONFIG_VIDEO_DEV is not set 858# CONFIG_VIDEO_DEV is not set
889 859# CONFIG_DVB_CORE is not set
890# 860CONFIG_DAB=y
891# Digital Video Broadcasting Devices
892#
893# CONFIG_DVB is not set
894 861
895# 862#
896# Graphics support 863# Graphics support
@@ -898,12 +865,23 @@ CONFIG_HWMON=y
898CONFIG_BACKLIGHT_LCD_SUPPORT=y 865CONFIG_BACKLIGHT_LCD_SUPPORT=y
899CONFIG_BACKLIGHT_CLASS_DEVICE=y 866CONFIG_BACKLIGHT_CLASS_DEVICE=y
900CONFIG_LCD_CLASS_DEVICE=y 867CONFIG_LCD_CLASS_DEVICE=y
868
869#
870# Display device support
871#
872# CONFIG_DISPLAY_SUPPORT is not set
873# CONFIG_VGASTATE is not set
901CONFIG_FB=y 874CONFIG_FB=y
902CONFIG_FIRMWARE_EDID=y 875CONFIG_FIRMWARE_EDID=y
903# CONFIG_FB_DDC is not set 876# CONFIG_FB_DDC is not set
904CONFIG_FB_CFB_FILLRECT=y 877CONFIG_FB_CFB_FILLRECT=y
905CONFIG_FB_CFB_COPYAREA=y 878CONFIG_FB_CFB_COPYAREA=y
906CONFIG_FB_CFB_IMAGEBLIT=y 879CONFIG_FB_CFB_IMAGEBLIT=y
880# CONFIG_FB_SYS_FILLRECT is not set
881# CONFIG_FB_SYS_COPYAREA is not set
882# CONFIG_FB_SYS_IMAGEBLIT is not set
883# CONFIG_FB_SYS_FOPS is not set
884CONFIG_FB_DEFERRED_IO=y
907# CONFIG_FB_SVGALIB is not set 885# CONFIG_FB_SVGALIB is not set
908# CONFIG_FB_MACMODES is not set 886# CONFIG_FB_MACMODES is not set
909# CONFIG_FB_BACKLIGHT is not set 887# CONFIG_FB_BACKLIGHT is not set
@@ -921,10 +899,6 @@ CONFIG_FB_BFIN_LANDSCAPE=y
921# CONFIG_FB_BFIN_BGR is not set 899# CONFIG_FB_BFIN_BGR is not set
922# CONFIG_FB_S1D13XXX is not set 900# CONFIG_FB_S1D13XXX is not set
923# CONFIG_FB_VIRTUAL is not set 901# CONFIG_FB_VIRTUAL is not set
924
925#
926# Logo configuration
927#
928# CONFIG_LOGO is not set 902# CONFIG_LOGO is not set
929 903
930# 904#
@@ -936,8 +910,6 @@ CONFIG_SOUND=y
936# Advanced Linux Sound Architecture 910# Advanced Linux Sound Architecture
937# 911#
938CONFIG_SND=m 912CONFIG_SND=m
939CONFIG_SND_TIMER=m
940CONFIG_SND_PCM=m
941# CONFIG_SND_SEQUENCER is not set 913# CONFIG_SND_SEQUENCER is not set
942# CONFIG_SND_MIXER_OSS is not set 914# CONFIG_SND_MIXER_OSS is not set
943# CONFIG_SND_PCM_OSS is not set 915# CONFIG_SND_PCM_OSS is not set
@@ -959,19 +931,23 @@ CONFIG_SND_PCM=m
959# ALSA Blackfin devices 931# ALSA Blackfin devices
960# 932#
961# CONFIG_SND_BLACKFIN_AD1836 is not set 933# CONFIG_SND_BLACKFIN_AD1836 is not set
962CONFIG_SND_BLACKFIN_AD1981B=m
963# CONFIG_SND_BFIN_AD73311 is not set 934# CONFIG_SND_BFIN_AD73311 is not set
964 935
965# 936#
966# SoC audio support 937# System on Chip audio support
967# 938#
968# CONFIG_SND_SOC is not set 939# CONFIG_SND_SOC is not set
969 940
970# 941#
942# SoC Audio for the ADI Blackfin
943#
944# CONFIG_SND_BF5XX_HAVE_COLD_RESET is not set
945
946#
971# Open Sound System 947# Open Sound System
972# 948#
973CONFIG_SOUND_PRIME=y 949CONFIG_SOUND_PRIME=y
974# CONFIG_OBSOLETE_OSS is not set 950# CONFIG_OSS_OBSOLETE is not set
975# CONFIG_SOUND_MSNDCLAS is not set 951# CONFIG_SOUND_MSNDCLAS is not set
976# CONFIG_SOUND_MSNDPIN is not set 952# CONFIG_SOUND_MSNDPIN is not set
977 953
@@ -989,18 +965,17 @@ CONFIG_USB_ARCH_HAS_HCD=y
989# CONFIG_USB is not set 965# CONFIG_USB is not set
990 966
991# 967#
992# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support' 968# Enable Host or Gadget support to see Inventra options
993# 969#
994 970
995# 971#
996# USB Gadget Support 972# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support'
997# 973#
998# CONFIG_USB_GADGET is not set
999 974
1000# 975#
1001# MMC/SD Card support 976# USB Gadget Support
1002# 977#
1003# CONFIG_SPI_MMC is not set 978# CONFIG_USB_GADGET is not set
1004# CONFIG_MMC is not set 979# CONFIG_MMC is not set
1005 980
1006# 981#
@@ -1040,44 +1015,50 @@ CONFIG_RTC_INTF_SYSFS=y
1040CONFIG_RTC_INTF_PROC=y 1015CONFIG_RTC_INTF_PROC=y
1041CONFIG_RTC_INTF_DEV=y 1016CONFIG_RTC_INTF_DEV=y
1042# CONFIG_RTC_INTF_DEV_UIE_EMUL is not set 1017# CONFIG_RTC_INTF_DEV_UIE_EMUL is not set
1018# CONFIG_RTC_DRV_TEST is not set
1043 1019
1044# 1020#
1045# RTC drivers 1021# I2C RTC drivers
1046# 1022#
1047# CONFIG_RTC_DRV_X1205 is not set
1048# CONFIG_RTC_DRV_DS1307 is not set 1023# CONFIG_RTC_DRV_DS1307 is not set
1049# CONFIG_RTC_DRV_DS1553 is not set
1050# CONFIG_RTC_DRV_ISL1208 is not set
1051# CONFIG_RTC_DRV_DS1672 is not set 1024# CONFIG_RTC_DRV_DS1672 is not set
1052# CONFIG_RTC_DRV_DS1742 is not set 1025# CONFIG_RTC_DRV_MAX6900 is not set
1026# CONFIG_RTC_DRV_RS5C372 is not set
1027# CONFIG_RTC_DRV_ISL1208 is not set
1028# CONFIG_RTC_DRV_X1205 is not set
1053# CONFIG_RTC_DRV_PCF8563 is not set 1029# CONFIG_RTC_DRV_PCF8563 is not set
1030# CONFIG_RTC_DRV_PCF8583 is not set
1031
1032#
1033# SPI RTC drivers
1034#
1054# CONFIG_RTC_DRV_RS5C348 is not set 1035# CONFIG_RTC_DRV_RS5C348 is not set
1055# CONFIG_RTC_DRV_RS5C372 is not set
1056# CONFIG_RTC_DRV_M48T86 is not set
1057# CONFIG_RTC_DRV_TEST is not set
1058# CONFIG_RTC_DRV_MAX6902 is not set 1036# CONFIG_RTC_DRV_MAX6902 is not set
1059# CONFIG_RTC_DRV_V3020 is not set
1060CONFIG_RTC_DRV_BFIN=y
1061 1037
1062# 1038#
1063# DMA Engine support 1039# Platform RTC drivers
1064# 1040#
1065# CONFIG_DMA_ENGINE is not set 1041# CONFIG_RTC_DRV_DS1553 is not set
1042# CONFIG_RTC_DRV_DS1742 is not set
1043# CONFIG_RTC_DRV_M48T86 is not set
1044# CONFIG_RTC_DRV_V3020 is not set
1066 1045
1067# 1046#
1068# DMA Clients 1047# on-CPU RTC drivers
1069# 1048#
1049CONFIG_RTC_DRV_BFIN=y
1070 1050
1071# 1051#
1072# DMA Devices 1052# DMA Engine support
1073# 1053#
1054# CONFIG_DMA_ENGINE is not set
1074 1055
1075# 1056#
1076# Auxiliary Display support 1057# DMA Clients
1077# 1058#
1078 1059
1079# 1060#
1080# Virtualization 1061# DMA Devices
1081# 1062#
1082 1063
1083# 1064#
@@ -1176,6 +1157,7 @@ CONFIG_LOCKD=m
1176CONFIG_LOCKD_V4=y 1157CONFIG_LOCKD_V4=y
1177CONFIG_NFS_COMMON=y 1158CONFIG_NFS_COMMON=y
1178CONFIG_SUNRPC=m 1159CONFIG_SUNRPC=m
1160# CONFIG_SUNRPC_BIND34 is not set
1179# CONFIG_RPCSEC_GSS_KRB5 is not set 1161# CONFIG_RPCSEC_GSS_KRB5 is not set
1180# CONFIG_RPCSEC_GSS_SPKM3 is not set 1162# CONFIG_RPCSEC_GSS_SPKM3 is not set
1181CONFIG_SMB_FS=m 1163CONFIG_SMB_FS=m
@@ -1256,11 +1238,17 @@ CONFIG_ENABLE_MUST_CHECK=y
1256# CONFIG_DEBUG_FS is not set 1238# CONFIG_DEBUG_FS is not set
1257# CONFIG_HEADERS_CHECK is not set 1239# CONFIG_HEADERS_CHECK is not set
1258# CONFIG_DEBUG_KERNEL is not set 1240# CONFIG_DEBUG_KERNEL is not set
1259CONFIG_LOG_BUF_SHIFT=14
1260# CONFIG_DEBUG_BUGVERBOSE is not set 1241# CONFIG_DEBUG_BUGVERBOSE is not set
1261# CONFIG_DEBUG_SERIAL_EARLY_INIT is not set 1242# CONFIG_DEBUG_MMRS is not set
1262# CONFIG_DEBUG_HUNT_FOR_ZERO is not set 1243# CONFIG_DEBUG_HUNT_FOR_ZERO is not set
1244CONFIG_DEBUG_BFIN_HWTRACE_ON=y
1245CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_OFF=y
1246# CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_ONE is not set
1247# CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_TWO is not set
1248CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION=0
1249# CONFIG_DEBUG_BFIN_HWTRACE_EXPAND is not set
1263# CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE is not set 1250# CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE is not set
1251# CONFIG_EARLY_PRINTK is not set
1264# CONFIG_CPLB_INFO is not set 1252# CONFIG_CPLB_INFO is not set
1265# CONFIG_ACCESS_CHECK is not set 1253# CONFIG_ACCESS_CHECK is not set
1266 1254
@@ -1283,9 +1271,11 @@ CONFIG_SECURITY_CAPABILITIES=y
1283CONFIG_BITREVERSE=y 1271CONFIG_BITREVERSE=y
1284CONFIG_CRC_CCITT=m 1272CONFIG_CRC_CCITT=m
1285# CONFIG_CRC16 is not set 1273# CONFIG_CRC16 is not set
1274# CONFIG_CRC_ITU_T is not set
1286CONFIG_CRC32=y 1275CONFIG_CRC32=y
1287# CONFIG_LIBCRC32C is not set 1276# CONFIG_LIBCRC32C is not set
1288CONFIG_ZLIB_INFLATE=y 1277CONFIG_ZLIB_INFLATE=y
1289CONFIG_PLIST=y 1278CONFIG_PLIST=y
1290CONFIG_HAS_IOMEM=y 1279CONFIG_HAS_IOMEM=y
1291CONFIG_HAS_IOPORT=y 1280CONFIG_HAS_IOPORT=y
1281CONFIG_HAS_DMA=y
diff --git a/arch/blackfin/kernel/Makefile b/arch/blackfin/kernel/Makefile
index f429ebc3a961..8aeb6066b19b 100644
--- a/arch/blackfin/kernel/Makefile
+++ b/arch/blackfin/kernel/Makefile
@@ -7,11 +7,10 @@ extra-y := init_task.o vmlinux.lds
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 time.o traps.o irqchip.o dma-mapping.o flat.o \
10 fixed_code.o cplbinit.o cacheinit.o 10 fixed_code.o cplbinit.o cacheinit.o reboot.o bfin_gpio.o
11 11
12obj-$(CONFIG_BF53x) += bfin_gpio.o
13obj-$(CONFIG_BF561) += bfin_gpio.o
14obj-$(CONFIG_MODULES) += module.o 12obj-$(CONFIG_MODULES) += module.o
15obj-$(CONFIG_BFIN_DMA_5XX) += bfin_dma_5xx.o 13obj-$(CONFIG_BFIN_DMA_5XX) += bfin_dma_5xx.o
16obj-$(CONFIG_DUAL_CORE_TEST_MODULE) += dualcore_test.o 14obj-$(CONFIG_DUAL_CORE_TEST_MODULE) += dualcore_test.o
17obj-$(CONFIG_KGDB) += kgdb.o 15obj-$(CONFIG_KGDB) += kgdb.o
16obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
diff --git a/arch/blackfin/kernel/bfin_dma_5xx.c b/arch/blackfin/kernel/bfin_dma_5xx.c
index 7cf02f02a1db..e19164fb4cd1 100644
--- a/arch/blackfin/kernel/bfin_dma_5xx.c
+++ b/arch/blackfin/kernel/bfin_dma_5xx.c
@@ -73,6 +73,11 @@ static int __init blackfin_dma_init(void)
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 */
74 dma_ch[CH_MEM_STREAM0_DEST].chan_status = DMA_CHANNEL_REQUESTED; 74 dma_ch[CH_MEM_STREAM0_DEST].chan_status = DMA_CHANNEL_REQUESTED;
75 dma_ch[CH_MEM_STREAM0_SRC].chan_status = DMA_CHANNEL_REQUESTED; 75 dma_ch[CH_MEM_STREAM0_SRC].chan_status = DMA_CHANNEL_REQUESTED;
76
77#if defined(CONFIG_DEB_DMA_URGENT)
78 bfin_write_EBIU_DDRQUE(bfin_read_EBIU_DDRQUE()
79 | DEB1_URGENT | DEB2_URGENT | DEB3_URGENT);
80#endif
76 return 0; 81 return 0;
77} 82}
78 83
@@ -265,10 +270,23 @@ void set_dma_next_desc_addr(unsigned int channel, unsigned long addr)
265 270
266 dma_ch[channel].regs->next_desc_ptr = addr; 271 dma_ch[channel].regs->next_desc_ptr = addr;
267 SSYNC(); 272 SSYNC();
268 pr_debug("set_dma_start_addr() : END\n"); 273 pr_debug("set_dma_next_desc_addr() : END\n");
269} 274}
270EXPORT_SYMBOL(set_dma_next_desc_addr); 275EXPORT_SYMBOL(set_dma_next_desc_addr);
271 276
277void set_dma_curr_desc_addr(unsigned int channel, unsigned long addr)
278{
279 pr_debug("set_dma_curr_desc_addr() : BEGIN \n");
280
281 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
282 && channel < MAX_BLACKFIN_DMA_CHANNEL));
283
284 dma_ch[channel].regs->curr_desc_ptr = addr;
285 SSYNC();
286 pr_debug("set_dma_curr_desc_addr() : END\n");
287}
288EXPORT_SYMBOL(set_dma_curr_desc_addr);
289
272void set_dma_x_count(unsigned int channel, unsigned short x_count) 290void set_dma_x_count(unsigned int channel, unsigned short x_count)
273{ 291{
274 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE 292 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
@@ -345,6 +363,16 @@ void set_dma_sg(unsigned int channel, struct dmasg *sg, int nr_sg)
345} 363}
346EXPORT_SYMBOL(set_dma_sg); 364EXPORT_SYMBOL(set_dma_sg);
347 365
366void set_dma_curr_addr(unsigned int channel, unsigned long addr)
367{
368 BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
369 && channel < MAX_BLACKFIN_DMA_CHANNEL));
370
371 dma_ch[channel].regs->curr_addr_ptr = addr;
372 SSYNC();
373}
374EXPORT_SYMBOL(set_dma_curr_addr);
375
348/*------------------------------------------------------------------------------ 376/*------------------------------------------------------------------------------
349 * Get the DMA status of a specific DMA channel from the system. 377 * Get the DMA status of a specific DMA channel from the system.
350 *-----------------------------------------------------------------------------*/ 378 *-----------------------------------------------------------------------------*/
@@ -408,6 +436,10 @@ static void *__dma_memcpy(void *dest, const void *src, size_t size)
408 blackfin_dcache_flush_range((unsigned int)src, 436 blackfin_dcache_flush_range((unsigned int)src,
409 (unsigned int)(src + size)); 437 (unsigned int)(src + size));
410 438
439 if ((unsigned long)dest < memory_end)
440 blackfin_dcache_invalidate_range((unsigned int)dest,
441 (unsigned int)(dest + size));
442
411 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR); 443 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
412 444
413 if ((unsigned long)src < (unsigned long)dest) 445 if ((unsigned long)src < (unsigned long)dest)
@@ -515,6 +547,8 @@ static void *__dma_memcpy(void *dest, const void *src, size_t size)
515 } 547 }
516 } 548 }
517 549
550 SSYNC();
551
518 while (!(bfin_read_MDMA_D0_IRQ_STATUS() & DMA_DONE)) 552 while (!(bfin_read_MDMA_D0_IRQ_STATUS() & DMA_DONE))
519 ; 553 ;
520 554
@@ -524,9 +558,6 @@ static void *__dma_memcpy(void *dest, const void *src, size_t size)
524 bfin_write_MDMA_S0_CONFIG(0); 558 bfin_write_MDMA_S0_CONFIG(0);
525 bfin_write_MDMA_D0_CONFIG(0); 559 bfin_write_MDMA_D0_CONFIG(0);
526 560
527 if ((unsigned long)dest < memory_end)
528 blackfin_dcache_invalidate_range((unsigned int)dest,
529 (unsigned int)(dest + size));
530 local_irq_restore(flags); 561 local_irq_restore(flags);
531 562
532 return dest; 563 return dest;
@@ -555,13 +586,14 @@ void *safe_dma_memcpy(void *dest, const void *src, size_t size)
555} 586}
556EXPORT_SYMBOL(safe_dma_memcpy); 587EXPORT_SYMBOL(safe_dma_memcpy);
557 588
558void dma_outsb(void __iomem *addr, const void *buf, unsigned short len) 589void dma_outsb(unsigned long addr, const void *buf, unsigned short len)
559{ 590{
560 unsigned long flags; 591 unsigned long flags;
561 592
562 local_irq_save(flags); 593 local_irq_save(flags);
563 594
564 blackfin_dcache_flush_range((unsigned int)buf, (unsigned int)(buf) + len); 595 blackfin_dcache_flush_range((unsigned int)buf,
596 (unsigned int)(buf) + len);
565 597
566 bfin_write_MDMA_D0_START_ADDR(addr); 598 bfin_write_MDMA_D0_START_ADDR(addr);
567 bfin_write_MDMA_D0_X_COUNT(len); 599 bfin_write_MDMA_D0_X_COUNT(len);
@@ -576,6 +608,8 @@ void dma_outsb(void __iomem *addr, const void *buf, unsigned short len)
576 bfin_write_MDMA_S0_CONFIG(DMAEN | WDSIZE_8); 608 bfin_write_MDMA_S0_CONFIG(DMAEN | WDSIZE_8);
577 bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | WDSIZE_8); 609 bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | WDSIZE_8);
578 610
611 SSYNC();
612
579 while (!(bfin_read_MDMA_D0_IRQ_STATUS() & DMA_DONE)); 613 while (!(bfin_read_MDMA_D0_IRQ_STATUS() & DMA_DONE));
580 614
581 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR); 615 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
@@ -588,10 +622,13 @@ void dma_outsb(void __iomem *addr, const void *buf, unsigned short len)
588EXPORT_SYMBOL(dma_outsb); 622EXPORT_SYMBOL(dma_outsb);
589 623
590 624
591void dma_insb(const void __iomem *addr, void *buf, unsigned short len) 625void dma_insb(unsigned long addr, void *buf, unsigned short len)
592{ 626{
593 unsigned long flags; 627 unsigned long flags;
594 628
629 blackfin_dcache_invalidate_range((unsigned int)buf,
630 (unsigned int)(buf) + len);
631
595 local_irq_save(flags); 632 local_irq_save(flags);
596 bfin_write_MDMA_D0_START_ADDR(buf); 633 bfin_write_MDMA_D0_START_ADDR(buf);
597 bfin_write_MDMA_D0_X_COUNT(len); 634 bfin_write_MDMA_D0_X_COUNT(len);
@@ -606,7 +643,7 @@ void dma_insb(const void __iomem *addr, void *buf, unsigned short len)
606 bfin_write_MDMA_S0_CONFIG(DMAEN | WDSIZE_8); 643 bfin_write_MDMA_S0_CONFIG(DMAEN | WDSIZE_8);
607 bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | WDSIZE_8); 644 bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | WDSIZE_8);
608 645
609 blackfin_dcache_invalidate_range((unsigned int)buf, (unsigned int)(buf) + len); 646 SSYNC();
610 647
611 while (!(bfin_read_MDMA_D0_IRQ_STATUS() & DMA_DONE)); 648 while (!(bfin_read_MDMA_D0_IRQ_STATUS() & DMA_DONE));
612 649
@@ -619,13 +656,14 @@ void dma_insb(const void __iomem *addr, void *buf, unsigned short len)
619} 656}
620EXPORT_SYMBOL(dma_insb); 657EXPORT_SYMBOL(dma_insb);
621 658
622void dma_outsw(void __iomem *addr, const void *buf, unsigned short len) 659void dma_outsw(unsigned long addr, const void *buf, unsigned short len)
623{ 660{
624 unsigned long flags; 661 unsigned long flags;
625 662
626 local_irq_save(flags); 663 local_irq_save(flags);
627 664
628 blackfin_dcache_flush_range((unsigned int)buf, (unsigned int)(buf) + len); 665 blackfin_dcache_flush_range((unsigned int)buf,
666 (unsigned int)(buf) + len * sizeof(short));
629 667
630 bfin_write_MDMA_D0_START_ADDR(addr); 668 bfin_write_MDMA_D0_START_ADDR(addr);
631 bfin_write_MDMA_D0_X_COUNT(len); 669 bfin_write_MDMA_D0_X_COUNT(len);
@@ -640,6 +678,8 @@ void dma_outsw(void __iomem *addr, const void *buf, unsigned short len)
640 bfin_write_MDMA_S0_CONFIG(DMAEN | WDSIZE_16); 678 bfin_write_MDMA_S0_CONFIG(DMAEN | WDSIZE_16);
641 bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | WDSIZE_16); 679 bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | WDSIZE_16);
642 680
681 SSYNC();
682
643 while (!(bfin_read_MDMA_D0_IRQ_STATUS() & DMA_DONE)); 683 while (!(bfin_read_MDMA_D0_IRQ_STATUS() & DMA_DONE));
644 684
645 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR); 685 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
@@ -651,10 +691,13 @@ void dma_outsw(void __iomem *addr, const void *buf, unsigned short len)
651} 691}
652EXPORT_SYMBOL(dma_outsw); 692EXPORT_SYMBOL(dma_outsw);
653 693
654void dma_insw(const void __iomem *addr, void *buf, unsigned short len) 694void dma_insw(unsigned long addr, void *buf, unsigned short len)
655{ 695{
656 unsigned long flags; 696 unsigned long flags;
657 697
698 blackfin_dcache_invalidate_range((unsigned int)buf,
699 (unsigned int)(buf) + len * sizeof(short));
700
658 local_irq_save(flags); 701 local_irq_save(flags);
659 702
660 bfin_write_MDMA_D0_START_ADDR(buf); 703 bfin_write_MDMA_D0_START_ADDR(buf);
@@ -670,7 +713,7 @@ void dma_insw(const void __iomem *addr, void *buf, unsigned short len)
670 bfin_write_MDMA_S0_CONFIG(DMAEN | WDSIZE_16); 713 bfin_write_MDMA_S0_CONFIG(DMAEN | WDSIZE_16);
671 bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | WDSIZE_16); 714 bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | WDSIZE_16);
672 715
673 blackfin_dcache_invalidate_range((unsigned int)buf, (unsigned int)(buf) + len); 716 SSYNC();
674 717
675 while (!(bfin_read_MDMA_D0_IRQ_STATUS() & DMA_DONE)); 718 while (!(bfin_read_MDMA_D0_IRQ_STATUS() & DMA_DONE));
676 719
@@ -683,13 +726,14 @@ void dma_insw(const void __iomem *addr, void *buf, unsigned short len)
683} 726}
684EXPORT_SYMBOL(dma_insw); 727EXPORT_SYMBOL(dma_insw);
685 728
686void dma_outsl(void __iomem *addr, const void *buf, unsigned short len) 729void dma_outsl(unsigned long addr, const void *buf, unsigned short len)
687{ 730{
688 unsigned long flags; 731 unsigned long flags;
689 732
690 local_irq_save(flags); 733 local_irq_save(flags);
691 734
692 blackfin_dcache_flush_range((unsigned int)buf, (unsigned int)(buf) + len); 735 blackfin_dcache_flush_range((unsigned int)buf,
736 (unsigned int)(buf) + len * sizeof(long));
693 737
694 bfin_write_MDMA_D0_START_ADDR(addr); 738 bfin_write_MDMA_D0_START_ADDR(addr);
695 bfin_write_MDMA_D0_X_COUNT(len); 739 bfin_write_MDMA_D0_X_COUNT(len);
@@ -704,6 +748,8 @@ void dma_outsl(void __iomem *addr, const void *buf, unsigned short len)
704 bfin_write_MDMA_S0_CONFIG(DMAEN | WDSIZE_32); 748 bfin_write_MDMA_S0_CONFIG(DMAEN | WDSIZE_32);
705 bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | WDSIZE_32); 749 bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | WDSIZE_32);
706 750
751 SSYNC();
752
707 while (!(bfin_read_MDMA_D0_IRQ_STATUS() & DMA_DONE)); 753 while (!(bfin_read_MDMA_D0_IRQ_STATUS() & DMA_DONE));
708 754
709 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR); 755 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
@@ -715,10 +761,13 @@ void dma_outsl(void __iomem *addr, const void *buf, unsigned short len)
715} 761}
716EXPORT_SYMBOL(dma_outsl); 762EXPORT_SYMBOL(dma_outsl);
717 763
718void dma_insl(const void __iomem *addr, void *buf, unsigned short len) 764void dma_insl(unsigned long addr, void *buf, unsigned short len)
719{ 765{
720 unsigned long flags; 766 unsigned long flags;
721 767
768 blackfin_dcache_invalidate_range((unsigned int)buf,
769 (unsigned int)(buf) + len * sizeof(long));
770
722 local_irq_save(flags); 771 local_irq_save(flags);
723 772
724 bfin_write_MDMA_D0_START_ADDR(buf); 773 bfin_write_MDMA_D0_START_ADDR(buf);
@@ -734,7 +783,7 @@ void dma_insl(const void __iomem *addr, void *buf, unsigned short len)
734 bfin_write_MDMA_S0_CONFIG(DMAEN | WDSIZE_32); 783 bfin_write_MDMA_S0_CONFIG(DMAEN | WDSIZE_32);
735 bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | WDSIZE_32); 784 bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | WDSIZE_32);
736 785
737 blackfin_dcache_invalidate_range((unsigned int)buf, (unsigned int)(buf) + len); 786 SSYNC();
738 787
739 while (!(bfin_read_MDMA_D0_IRQ_STATUS() & DMA_DONE)); 788 while (!(bfin_read_MDMA_D0_IRQ_STATUS() & DMA_DONE));
740 789
diff --git a/arch/blackfin/kernel/bfin_gpio.c b/arch/blackfin/kernel/bfin_gpio.c
index 5d488ef965ce..3fe0cd49e8db 100644
--- a/arch/blackfin/kernel/bfin_gpio.c
+++ b/arch/blackfin/kernel/bfin_gpio.c
@@ -7,7 +7,7 @@
7 * Description: GPIO Abstraction Layer 7 * Description: GPIO Abstraction Layer
8 * 8 *
9 * Modified: 9 * Modified:
10 * Copyright 2006 Analog Devices Inc. 10 * Copyright 2007 Analog Devices Inc.
11 * 11 *
12 * Bugs: Enter bugs at http://blackfin.uclinux.org/ 12 * Bugs: Enter bugs at http://blackfin.uclinux.org/
13 * 13 *
@@ -28,9 +28,9 @@
28 */ 28 */
29 29
30/* 30/*
31* Number BF537/6/4 BF561 BF533/2/1 31* Number BF537/6/4 BF561 BF533/2/1 BF549/8/4/2
32* 32*
33* GPIO_0 PF0 PF0 PF0 33* GPIO_0 PF0 PF0 PF0 PA0...PJ13
34* GPIO_1 PF1 PF1 PF1 34* GPIO_1 PF1 PF1 PF1
35* GPIO_2 PF2 PF2 PF2 35* GPIO_2 PF2 PF2 PF2
36* GPIO_3 PF3 PF3 PF3 36* GPIO_3 PF3 PF3 PF3
@@ -80,6 +80,7 @@
80* GPIO_47 PH15 PF47 80* GPIO_47 PH15 PF47
81*/ 81*/
82 82
83#include <linux/delay.h>
83#include <linux/module.h> 84#include <linux/module.h>
84#include <linux/err.h> 85#include <linux/err.h>
85#include <asm/blackfin.h> 86#include <asm/blackfin.h>
@@ -87,6 +88,36 @@
87#include <asm/portmux.h> 88#include <asm/portmux.h>
88#include <linux/irq.h> 89#include <linux/irq.h>
89 90
91#if ANOMALY_05000311 || ANOMALY_05000323
92enum {
93 AWA_data = SYSCR,
94 AWA_data_clear = SYSCR,
95 AWA_data_set = SYSCR,
96 AWA_toggle = SYSCR,
97 AWA_maska = UART_SCR,
98 AWA_maska_clear = UART_SCR,
99 AWA_maska_set = UART_SCR,
100 AWA_maska_toggle = UART_SCR,
101 AWA_maskb = UART_GCTL,
102 AWA_maskb_clear = UART_GCTL,
103 AWA_maskb_set = UART_GCTL,
104 AWA_maskb_toggle = UART_GCTL,
105 AWA_dir = SPORT1_STAT,
106 AWA_polar = SPORT1_STAT,
107 AWA_edge = SPORT1_STAT,
108 AWA_both = SPORT1_STAT,
109#if ANOMALY_05000311
110 AWA_inen = TIMER_ENABLE,
111#elif ANOMALY_05000323
112 AWA_inen = DMA1_1_CONFIG,
113#endif
114};
115 /* Anomaly Workaround */
116#define AWA_DUMMY_READ(name) bfin_read16(AWA_ ## name)
117#else
118#define AWA_DUMMY_READ(...) do { } while (0)
119#endif
120
90#ifdef BF533_FAMILY 121#ifdef BF533_FAMILY
91static struct gpio_port_t *gpio_bankb[gpio_bank(MAX_BLACKFIN_GPIOS)] = { 122static struct gpio_port_t *gpio_bankb[gpio_bank(MAX_BLACKFIN_GPIOS)] = {
92 (struct gpio_port_t *) FIO_FLAG_D, 123 (struct gpio_port_t *) FIO_FLAG_D,
@@ -116,11 +147,31 @@ static struct gpio_port_t *gpio_bankb[gpio_bank(MAX_BLACKFIN_GPIOS)] = {
116}; 147};
117#endif 148#endif
118 149
150#ifdef BF548_FAMILY
151static struct gpio_port_t *gpio_array[gpio_bank(MAX_BLACKFIN_GPIOS)] = {
152 (struct gpio_port_t *)PORTA_FER,
153 (struct gpio_port_t *)PORTB_FER,
154 (struct gpio_port_t *)PORTC_FER,
155 (struct gpio_port_t *)PORTD_FER,
156 (struct gpio_port_t *)PORTE_FER,
157 (struct gpio_port_t *)PORTF_FER,
158 (struct gpio_port_t *)PORTG_FER,
159 (struct gpio_port_t *)PORTH_FER,
160 (struct gpio_port_t *)PORTI_FER,
161 (struct gpio_port_t *)PORTJ_FER,
162};
163#endif
164
119static unsigned short reserved_gpio_map[gpio_bank(MAX_BLACKFIN_GPIOS)]; 165static unsigned short reserved_gpio_map[gpio_bank(MAX_BLACKFIN_GPIOS)];
120static unsigned short reserved_peri_map[gpio_bank(MAX_BLACKFIN_GPIOS + 16)]; 166static unsigned short reserved_peri_map[gpio_bank(MAX_BLACKFIN_GPIOS + 16)];
121char *str_ident = NULL;
122 167
123#define RESOURCE_LABEL_SIZE 16 168#define MAX_RESOURCES 256
169#define RESOURCE_LABEL_SIZE 16
170
171struct str_ident {
172 char name[RESOURCE_LABEL_SIZE];
173} *str_ident;
174
124 175
125#ifdef CONFIG_PM 176#ifdef CONFIG_PM
126static unsigned short wakeup_map[gpio_bank(MAX_BLACKFIN_GPIOS)]; 177static unsigned short wakeup_map[gpio_bank(MAX_BLACKFIN_GPIOS)];
@@ -141,21 +192,32 @@ static unsigned int sic_iwr_irqs[gpio_bank(MAX_BLACKFIN_GPIOS)] = {IRQ_PROG0_INT
141 192
142#endif /* CONFIG_PM */ 193#endif /* CONFIG_PM */
143 194
195#if defined(BF548_FAMILY)
196inline int check_gpio(unsigned short gpio)
197{
198 if (gpio == GPIO_PB15 || gpio == GPIO_PC14 || gpio == GPIO_PC15
199 || gpio == GPIO_PH14 || gpio == GPIO_PH15
200 || gpio == GPIO_PJ14 || gpio == GPIO_PJ15
201 || gpio > MAX_BLACKFIN_GPIOS)
202 return -EINVAL;
203 return 0;
204}
205#else
144inline int check_gpio(unsigned short gpio) 206inline int check_gpio(unsigned short gpio)
145{ 207{
146 if (gpio >= MAX_BLACKFIN_GPIOS) 208 if (gpio >= MAX_BLACKFIN_GPIOS)
147 return -EINVAL; 209 return -EINVAL;
148 return 0; 210 return 0;
149} 211}
212#endif
150 213
151static void set_label(unsigned short ident, const char *label) 214static void set_label(unsigned short ident, const char *label)
152{ 215{
153 216
154 if (label && str_ident) { 217 if (label && str_ident) {
155 strncpy(str_ident + ident * RESOURCE_LABEL_SIZE, label, 218 strncpy(str_ident[ident].name, label,
156 RESOURCE_LABEL_SIZE); 219 RESOURCE_LABEL_SIZE);
157 str_ident[ident * RESOURCE_LABEL_SIZE + 220 str_ident[ident].name[RESOURCE_LABEL_SIZE - 1] = 0;
158 RESOURCE_LABEL_SIZE - 1] = 0;
159 } 221 }
160} 222}
161 223
@@ -164,14 +226,13 @@ static char *get_label(unsigned short ident)
164 if (!str_ident) 226 if (!str_ident)
165 return "UNKNOWN"; 227 return "UNKNOWN";
166 228
167 return (str_ident[ident * RESOURCE_LABEL_SIZE] ? 229 return (*str_ident[ident].name ? str_ident[ident].name : "UNKNOWN");
168 (str_ident + ident * RESOURCE_LABEL_SIZE) : "UNKNOWN");
169} 230}
170 231
171static int cmp_label(unsigned short ident, const char *label) 232static int cmp_label(unsigned short ident, const char *label)
172{ 233{
173 if (label && str_ident) 234 if (label && str_ident)
174 return strncmp(str_ident + ident * RESOURCE_LABEL_SIZE, 235 return strncmp(str_ident[ident].name,
175 label, strlen(label)); 236 label, strlen(label));
176 else 237 else
177 return -EINVAL; 238 return -EINVAL;
@@ -181,50 +242,84 @@ static int cmp_label(unsigned short ident, const char *label)
181static void port_setup(unsigned short gpio, unsigned short usage) 242static void port_setup(unsigned short gpio, unsigned short usage)
182{ 243{
183 if (!check_gpio(gpio)) { 244 if (!check_gpio(gpio)) {
184 if (usage == GPIO_USAGE) { 245 if (usage == GPIO_USAGE)
185 *port_fer[gpio_bank(gpio)] &= ~gpio_bit(gpio); 246 *port_fer[gpio_bank(gpio)] &= ~gpio_bit(gpio);
186 } else 247 else
187 *port_fer[gpio_bank(gpio)] |= gpio_bit(gpio); 248 *port_fer[gpio_bank(gpio)] |= gpio_bit(gpio);
188 SSYNC(); 249 SSYNC();
189 } 250 }
190} 251}
252#elif defined(BF548_FAMILY)
253static void port_setup(unsigned short gpio, unsigned short usage)
254{
255 if (usage == GPIO_USAGE)
256 gpio_array[gpio_bank(gpio)]->port_fer &= ~gpio_bit(gpio);
257 else
258 gpio_array[gpio_bank(gpio)]->port_fer |= gpio_bit(gpio);
259 SSYNC();
260}
191#else 261#else
192# define port_setup(...) do { } while (0) 262# define port_setup(...) do { } while (0)
193#endif 263#endif
194 264
195#ifdef BF537_FAMILY 265#ifdef BF537_FAMILY
196 266static struct {
197#define PMUX_LUT_RES 0 267 unsigned short res;
198#define PMUX_LUT_OFFSET 1 268 unsigned short offset;
199#define PMUX_LUT_ENTRIES 41 269} port_mux_lut[] = {
200#define PMUX_LUT_SIZE 2 270 {.res = P_PPI0_D13, .offset = 11},
201 271 {.res = P_PPI0_D14, .offset = 11},
202static unsigned short port_mux_lut[PMUX_LUT_ENTRIES][PMUX_LUT_SIZE] = { 272 {.res = P_PPI0_D15, .offset = 11},
203 {P_PPI0_D13, 11}, {P_PPI0_D14, 11}, {P_PPI0_D15, 11}, 273 {.res = P_SPORT1_TFS, .offset = 11},
204 {P_SPORT1_TFS, 11}, {P_SPORT1_TSCLK, 11}, {P_SPORT1_DTPRI, 11}, 274 {.res = P_SPORT1_TSCLK, .offset = 11},
205 {P_PPI0_D10, 10}, {P_PPI0_D11, 10}, {P_PPI0_D12, 10}, 275 {.res = P_SPORT1_DTPRI, .offset = 11},
206 {P_SPORT1_RSCLK, 10}, {P_SPORT1_RFS, 10}, {P_SPORT1_DRPRI, 10}, 276 {.res = P_PPI0_D10, .offset = 10},
207 {P_PPI0_D8, 9}, {P_PPI0_D9, 9}, {P_SPORT1_DRSEC, 9}, 277 {.res = P_PPI0_D11, .offset = 10},
208 {P_SPORT1_DTSEC, 9}, {P_TMR2, 8}, {P_PPI0_FS3, 8}, {P_TMR3, 7}, 278 {.res = P_PPI0_D12, .offset = 10},
209 {P_SPI0_SSEL4, 7}, {P_TMR4, 6}, {P_SPI0_SSEL5, 6}, {P_TMR5, 5}, 279 {.res = P_SPORT1_RSCLK, .offset = 10},
210 {P_SPI0_SSEL6, 5}, {P_UART1_RX, 4}, {P_UART1_TX, 4}, {P_TMR6, 4}, 280 {.res = P_SPORT1_RFS, .offset = 10},
211 {P_TMR7, 4}, {P_UART0_RX, 3}, {P_UART0_TX, 3}, {P_DMAR0, 3}, 281 {.res = P_SPORT1_DRPRI, .offset = 10},
212 {P_DMAR1, 3}, {P_SPORT0_DTSEC, 1}, {P_SPORT0_DRSEC, 1}, 282 {.res = P_PPI0_D8, .offset = 9},
213 {P_CAN0_RX, 1}, {P_CAN0_TX, 1}, {P_SPI0_SSEL7, 1}, 283 {.res = P_PPI0_D9, .offset = 9},
214 {P_SPORT0_TFS, 0}, {P_SPORT0_DTPRI, 0}, {P_SPI0_SSEL2, 0}, 284 {.res = P_SPORT1_DRSEC, .offset = 9},
215 {P_SPI0_SSEL3, 0} 285 {.res = P_SPORT1_DTSEC, .offset = 9},
286 {.res = P_TMR2, .offset = 8},
287 {.res = P_PPI0_FS3, .offset = 8},
288 {.res = P_TMR3, .offset = 7},
289 {.res = P_SPI0_SSEL4, .offset = 7},
290 {.res = P_TMR4, .offset = 6},
291 {.res = P_SPI0_SSEL5, .offset = 6},
292 {.res = P_TMR5, .offset = 5},
293 {.res = P_SPI0_SSEL6, .offset = 5},
294 {.res = P_UART1_RX, .offset = 4},
295 {.res = P_UART1_TX, .offset = 4},
296 {.res = P_TMR6, .offset = 4},
297 {.res = P_TMR7, .offset = 4},
298 {.res = P_UART0_RX, .offset = 3},
299 {.res = P_UART0_TX, .offset = 3},
300 {.res = P_DMAR0, .offset = 3},
301 {.res = P_DMAR1, .offset = 3},
302 {.res = P_SPORT0_DTSEC, .offset = 1},
303 {.res = P_SPORT0_DRSEC, .offset = 1},
304 {.res = P_CAN0_RX, .offset = 1},
305 {.res = P_CAN0_TX, .offset = 1},
306 {.res = P_SPI0_SSEL7, .offset = 1},
307 {.res = P_SPORT0_TFS, .offset = 0},
308 {.res = P_SPORT0_DTPRI, .offset = 0},
309 {.res = P_SPI0_SSEL2, .offset = 0},
310 {.res = P_SPI0_SSEL3, .offset = 0},
216}; 311};
217 312
218static void portmux_setup(unsigned short per, unsigned short function) 313static void portmux_setup(unsigned short per, unsigned short function)
219{ 314{
220 u16 y, muxreg, offset; 315 u16 y, offset, muxreg;
221 316
222 for (y = 0; y < PMUX_LUT_ENTRIES; y++) { 317 for (y = 0; y < ARRAY_SIZE(port_mux_lut); y++) {
223 if (port_mux_lut[y][PMUX_LUT_RES] == per) { 318 if (port_mux_lut[y].res == per) {
224 319
225 /* SET PORTMUX REG */ 320 /* SET PORTMUX REG */
226 321
227 offset = port_mux_lut[y][PMUX_LUT_OFFSET]; 322 offset = port_mux_lut[y].offset;
228 muxreg = bfin_read_PORT_MUX(); 323 muxreg = bfin_read_PORT_MUX();
229 324
230 if (offset != 1) { 325 if (offset != 1) {
@@ -238,18 +333,42 @@ static void portmux_setup(unsigned short per, unsigned short function)
238 } 333 }
239 } 334 }
240} 335}
336#elif defined(BF548_FAMILY)
337inline void portmux_setup(unsigned short portno, unsigned short function)
338{
339 u32 pmux;
340
341 pmux = gpio_array[gpio_bank(portno)]->port_mux;
342
343 pmux &= ~(0x3 << (2 * gpio_sub_n(portno)));
344 pmux |= (function & 0x3) << (2 * gpio_sub_n(portno));
241 345
346 gpio_array[gpio_bank(portno)]->port_mux = pmux;
347}
348
349inline u16 get_portmux(unsigned short portno)
350{
351 u32 pmux;
352
353 pmux = gpio_array[gpio_bank(portno)]->port_mux;
354
355 return (pmux >> (2 * gpio_sub_n(portno)) & 0x3);
356}
242#else 357#else
243# define portmux_setup(...) do { } while (0) 358# define portmux_setup(...) do { } while (0)
244#endif 359#endif
245 360
361#ifndef BF548_FAMILY
246static void default_gpio(unsigned short gpio) 362static void default_gpio(unsigned short gpio)
247{ 363{
248 unsigned short bank, bitmask; 364 unsigned short bank, bitmask;
365 unsigned long flags;
249 366
250 bank = gpio_bank(gpio); 367 bank = gpio_bank(gpio);
251 bitmask = gpio_bit(gpio); 368 bitmask = gpio_bit(gpio);
252 369
370 local_irq_save(flags);
371
253 gpio_bankb[bank]->maska_clear = bitmask; 372 gpio_bankb[bank]->maska_clear = bitmask;
254 gpio_bankb[bank]->maskb_clear = bitmask; 373 gpio_bankb[bank]->maskb_clear = bitmask;
255 SSYNC(); 374 SSYNC();
@@ -258,24 +377,32 @@ static void default_gpio(unsigned short gpio)
258 gpio_bankb[bank]->polar &= ~bitmask; 377 gpio_bankb[bank]->polar &= ~bitmask;
259 gpio_bankb[bank]->both &= ~bitmask; 378 gpio_bankb[bank]->both &= ~bitmask;
260 gpio_bankb[bank]->edge &= ~bitmask; 379 gpio_bankb[bank]->edge &= ~bitmask;
380 AWA_DUMMY_READ(edge);
381 local_irq_restore(flags);
382
261} 383}
384#else
385# define default_gpio(...) do { } while (0)
386#endif
262 387
263static int __init bfin_gpio_init(void) 388static int __init bfin_gpio_init(void)
264{ 389{
265 390 str_ident = kcalloc(MAX_RESOURCES,
266 str_ident = kzalloc(RESOURCE_LABEL_SIZE * 256, GFP_KERNEL); 391 sizeof(struct str_ident), GFP_KERNEL);
267 if (!str_ident) 392 if (str_ident == NULL)
268 return -ENOMEM; 393 return -ENOMEM;
269 394
395 memset(str_ident, 0, MAX_RESOURCES * sizeof(struct str_ident));
396
270 printk(KERN_INFO "Blackfin GPIO Controller\n"); 397 printk(KERN_INFO "Blackfin GPIO Controller\n");
271 398
272 return 0; 399 return 0;
273 400
274} 401}
275
276arch_initcall(bfin_gpio_init); 402arch_initcall(bfin_gpio_init);
277 403
278 404
405#ifndef BF548_FAMILY
279/*********************************************************** 406/***********************************************************
280* 407*
281* FUNCTIONS: Blackfin General Purpose Ports Access Functions 408* FUNCTIONS: Blackfin General Purpose Ports Access Functions
@@ -305,6 +432,7 @@ void set_gpio_ ## name(unsigned short gpio, unsigned short arg) \
305 gpio_bankb[gpio_bank(gpio)]->name |= gpio_bit(gpio); \ 432 gpio_bankb[gpio_bank(gpio)]->name |= gpio_bit(gpio); \
306 else \ 433 else \
307 gpio_bankb[gpio_bank(gpio)]->name &= ~gpio_bit(gpio); \ 434 gpio_bankb[gpio_bank(gpio)]->name &= ~gpio_bit(gpio); \
435 AWA_DUMMY_READ(name); \
308 local_irq_restore(flags); \ 436 local_irq_restore(flags); \
309} \ 437} \
310EXPORT_SYMBOL(set_gpio_ ## name); 438EXPORT_SYMBOL(set_gpio_ ## name);
@@ -316,6 +444,22 @@ SET_GPIO(edge)
316SET_GPIO(both) 444SET_GPIO(both)
317 445
318 446
447#if ANOMALY_05000311 || ANOMALY_05000323
448#define SET_GPIO_SC(name) \
449void set_gpio_ ## name(unsigned short gpio, unsigned short arg) \
450{ \
451 unsigned long flags; \
452 BUG_ON(!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))); \
453 local_irq_save(flags); \
454 if (arg) \
455 gpio_bankb[gpio_bank(gpio)]->name ## _set = gpio_bit(gpio); \
456 else \
457 gpio_bankb[gpio_bank(gpio)]->name ## _clear = gpio_bit(gpio); \
458 AWA_DUMMY_READ(name); \
459 local_irq_restore(flags); \
460} \
461EXPORT_SYMBOL(set_gpio_ ## name);
462#else
319#define SET_GPIO_SC(name) \ 463#define SET_GPIO_SC(name) \
320void set_gpio_ ## name(unsigned short gpio, unsigned short arg) \ 464void set_gpio_ ## name(unsigned short gpio, unsigned short arg) \
321{ \ 465{ \
@@ -326,37 +470,20 @@ void set_gpio_ ## name(unsigned short gpio, unsigned short arg) \
326 gpio_bankb[gpio_bank(gpio)]->name ## _clear = gpio_bit(gpio); \ 470 gpio_bankb[gpio_bank(gpio)]->name ## _clear = gpio_bit(gpio); \
327} \ 471} \
328EXPORT_SYMBOL(set_gpio_ ## name); 472EXPORT_SYMBOL(set_gpio_ ## name);
473#endif
329 474
330SET_GPIO_SC(maska) 475SET_GPIO_SC(maska)
331SET_GPIO_SC(maskb) 476SET_GPIO_SC(maskb)
332
333#if defined(ANOMALY_05000311)
334void set_gpio_data(unsigned short gpio, unsigned short arg)
335{
336 unsigned long flags;
337 BUG_ON(!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio)));
338 local_irq_save(flags);
339 if (arg)
340 gpio_bankb[gpio_bank(gpio)]->data_set = gpio_bit(gpio);
341 else
342 gpio_bankb[gpio_bank(gpio)]->data_clear = gpio_bit(gpio);
343 bfin_read_CHIPID();
344 local_irq_restore(flags);
345}
346EXPORT_SYMBOL(set_gpio_data);
347#else
348SET_GPIO_SC(data) 477SET_GPIO_SC(data)
349#endif
350
351 478
352#if defined(ANOMALY_05000311) 479#if ANOMALY_05000311 || ANOMALY_05000323
353void set_gpio_toggle(unsigned short gpio) 480void set_gpio_toggle(unsigned short gpio)
354{ 481{
355 unsigned long flags; 482 unsigned long flags;
356 BUG_ON(!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))); 483 BUG_ON(!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio)));
357 local_irq_save(flags); 484 local_irq_save(flags);
358 gpio_bankb[gpio_bank(gpio)]->toggle = gpio_bit(gpio); 485 gpio_bankb[gpio_bank(gpio)]->toggle = gpio_bit(gpio);
359 bfin_read_CHIPID(); 486 AWA_DUMMY_READ(toggle);
360 local_irq_restore(flags); 487 local_irq_restore(flags);
361} 488}
362#else 489#else
@@ -371,13 +498,27 @@ EXPORT_SYMBOL(set_gpio_toggle);
371 498
372/*Set current PORT date (16-bit word)*/ 499/*Set current PORT date (16-bit word)*/
373 500
501#if ANOMALY_05000311 || ANOMALY_05000323
374#define SET_GPIO_P(name) \ 502#define SET_GPIO_P(name) \
375void set_gpiop_ ## name(unsigned short gpio, unsigned short arg) \ 503void set_gpiop_ ## name(unsigned short gpio, unsigned short arg) \
376{ \ 504{ \
505 unsigned long flags; \
506 local_irq_save(flags); \
377 gpio_bankb[gpio_bank(gpio)]->name = arg; \ 507 gpio_bankb[gpio_bank(gpio)]->name = arg; \
508 AWA_DUMMY_READ(name); \
509 local_irq_restore(flags); \
378} \ 510} \
379EXPORT_SYMBOL(set_gpiop_ ## name); 511EXPORT_SYMBOL(set_gpiop_ ## name);
512#else
513#define SET_GPIO_P(name) \
514void set_gpiop_ ## name(unsigned short gpio, unsigned short arg) \
515{ \
516 gpio_bankb[gpio_bank(gpio)]->name = arg; \
517} \
518EXPORT_SYMBOL(set_gpiop_ ## name);
519#endif
380 520
521SET_GPIO_P(data)
381SET_GPIO_P(dir) 522SET_GPIO_P(dir)
382SET_GPIO_P(inen) 523SET_GPIO_P(inen)
383SET_GPIO_P(polar) 524SET_GPIO_P(polar)
@@ -387,31 +528,30 @@ SET_GPIO_P(maska)
387SET_GPIO_P(maskb) 528SET_GPIO_P(maskb)
388 529
389 530
390#if defined(ANOMALY_05000311)
391void set_gpiop_data(unsigned short gpio, unsigned short arg)
392{
393 unsigned long flags;
394 local_irq_save(flags);
395 gpio_bankb[gpio_bank(gpio)]->data = arg;
396 bfin_read_CHIPID();
397 local_irq_restore(flags);
398}
399EXPORT_SYMBOL(set_gpiop_data);
400#else
401SET_GPIO_P(data)
402#endif
403
404
405
406/* Get a specific bit */ 531/* Get a specific bit */
407 532#if ANOMALY_05000311 || ANOMALY_05000323
533#define GET_GPIO(name) \
534unsigned short get_gpio_ ## name(unsigned short gpio) \
535{ \
536 unsigned long flags; \
537 unsigned short ret; \
538 local_irq_save(flags); \
539 ret = 0x01 & (gpio_bankb[gpio_bank(gpio)]->name >> gpio_sub_n(gpio)); \
540 AWA_DUMMY_READ(name); \
541 local_irq_restore(flags); \
542 return ret; \
543} \
544EXPORT_SYMBOL(get_gpio_ ## name);
545#else
408#define GET_GPIO(name) \ 546#define GET_GPIO(name) \
409unsigned short get_gpio_ ## name(unsigned short gpio) \ 547unsigned short get_gpio_ ## name(unsigned short gpio) \
410{ \ 548{ \
411 return (0x01 & (gpio_bankb[gpio_bank(gpio)]->name >> gpio_sub_n(gpio))); \ 549 return (0x01 & (gpio_bankb[gpio_bank(gpio)]->name >> gpio_sub_n(gpio))); \
412} \ 550} \
413EXPORT_SYMBOL(get_gpio_ ## name); 551EXPORT_SYMBOL(get_gpio_ ## name);
552#endif
414 553
554GET_GPIO(data)
415GET_GPIO(dir) 555GET_GPIO(dir)
416GET_GPIO(inen) 556GET_GPIO(inen)
417GET_GPIO(polar) 557GET_GPIO(polar)
@@ -420,33 +560,31 @@ GET_GPIO(both)
420GET_GPIO(maska) 560GET_GPIO(maska)
421GET_GPIO(maskb) 561GET_GPIO(maskb)
422 562
423
424#if defined(ANOMALY_05000311)
425unsigned short get_gpio_data(unsigned short gpio)
426{
427 unsigned long flags;
428 unsigned short ret;
429 BUG_ON(!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio)));
430 local_irq_save(flags);
431 ret = 0x01 & (gpio_bankb[gpio_bank(gpio)]->data >> gpio_sub_n(gpio));
432 bfin_read_CHIPID();
433 local_irq_restore(flags);
434 return ret;
435}
436EXPORT_SYMBOL(get_gpio_data);
437#else
438GET_GPIO(data)
439#endif
440
441/*Get current PORT date (16-bit word)*/ 563/*Get current PORT date (16-bit word)*/
442 564
565#if ANOMALY_05000311 || ANOMALY_05000323
566#define GET_GPIO_P(name) \
567unsigned short get_gpiop_ ## name(unsigned short gpio) \
568{ \
569 unsigned long flags; \
570 unsigned short ret; \
571 local_irq_save(flags); \
572 ret = (gpio_bankb[gpio_bank(gpio)]->name); \
573 AWA_DUMMY_READ(name); \
574 local_irq_restore(flags); \
575 return ret; \
576} \
577EXPORT_SYMBOL(get_gpiop_ ## name);
578#else
443#define GET_GPIO_P(name) \ 579#define GET_GPIO_P(name) \
444unsigned short get_gpiop_ ## name(unsigned short gpio) \ 580unsigned short get_gpiop_ ## name(unsigned short gpio) \
445{ \ 581{ \
446 return (gpio_bankb[gpio_bank(gpio)]->name);\ 582 return (gpio_bankb[gpio_bank(gpio)]->name);\
447} \ 583} \
448EXPORT_SYMBOL(get_gpiop_ ## name); 584EXPORT_SYMBOL(get_gpiop_ ## name);
585#endif
449 586
587GET_GPIO_P(data)
450GET_GPIO_P(dir) 588GET_GPIO_P(dir)
451GET_GPIO_P(inen) 589GET_GPIO_P(inen)
452GET_GPIO_P(polar) 590GET_GPIO_P(polar)
@@ -455,21 +593,6 @@ GET_GPIO_P(both)
455GET_GPIO_P(maska) 593GET_GPIO_P(maska)
456GET_GPIO_P(maskb) 594GET_GPIO_P(maskb)
457 595
458#if defined(ANOMALY_05000311)
459unsigned short get_gpiop_data(unsigned short gpio)
460{
461 unsigned long flags;
462 unsigned short ret;
463 local_irq_save(flags);
464 ret = gpio_bankb[gpio_bank(gpio)]->data;
465 bfin_read_CHIPID();
466 local_irq_restore(flags);
467 return ret;
468}
469EXPORT_SYMBOL(get_gpiop_data);
470#else
471GET_GPIO_P(data)
472#endif
473 596
474#ifdef CONFIG_PM 597#ifdef CONFIG_PM
475/*********************************************************** 598/***********************************************************
@@ -593,6 +716,8 @@ u32 gpio_pm_setup(void)
593 } 716 }
594 } 717 }
595 718
719 AWA_DUMMY_READ(maskb_set);
720
596 if (sic_iwr) 721 if (sic_iwr)
597 return sic_iwr; 722 return sic_iwr;
598 else 723 else
@@ -624,12 +749,99 @@ void gpio_pm_restore(void)
624 749
625 gpio_bankb[bank]->maskb = gpio_bank_saved[bank].maskb; 750 gpio_bankb[bank]->maskb = gpio_bank_saved[bank].maskb;
626 } 751 }
752 AWA_DUMMY_READ(maskb);
627} 753}
628 754
629#endif 755#endif
756#endif /* BF548_FAMILY */
630 757
758/***********************************************************
759*
760* FUNCTIONS: Blackfin Peripheral Resource Allocation
761* and PortMux Setup
762*
763* INPUTS/OUTPUTS:
764* per Peripheral Identifier
765* label String
766*
767* DESCRIPTION: Blackfin Peripheral Resource Allocation and Setup API
768*
769* CAUTION:
770*************************************************************
771* MODIFICATION HISTORY :
772**************************************************************/
773
774#ifdef BF548_FAMILY
775int peripheral_request(unsigned short per, const char *label)
776{
777 unsigned long flags;
778 unsigned short ident = P_IDENT(per);
779
780 /*
781 * Don't cares are pins with only one dedicated function
782 */
783
784 if (per & P_DONTCARE)
785 return 0;
786
787 if (!(per & P_DEFINED))
788 return -ENODEV;
789
790 if (check_gpio(ident) < 0)
791 return -EINVAL;
792
793 local_irq_save(flags);
794
795 if (unlikely(reserved_gpio_map[gpio_bank(ident)] & gpio_bit(ident))) {
796 printk(KERN_ERR
797 "%s: Peripheral %d is already reserved as GPIO by %s !\n",
798 __FUNCTION__, ident, get_label(ident));
799 dump_stack();
800 local_irq_restore(flags);
801 return -EBUSY;
802 }
803
804 if (unlikely(reserved_peri_map[gpio_bank(ident)] & gpio_bit(ident))) {
805
806 u16 funct = get_portmux(ident);
807
808 /*
809 * Pin functions like AMC address strobes my
810 * be requested and used by several drivers
811 */
812
813 if (!((per & P_MAYSHARE) && (funct == P_FUNCT2MUX(per)))) {
814
815 /*
816 * Allow that the identical pin function can
817 * be requested from the same driver twice
818 */
819
820 if (cmp_label(ident, label) == 0)
821 goto anyway;
631 822
823 printk(KERN_ERR
824 "%s: Peripheral %d function %d is already reserved by %s !\n",
825 __FUNCTION__, ident, P_FUNCT2MUX(per), get_label(ident));
826 dump_stack();
827 local_irq_restore(flags);
828 return -EBUSY;
829 }
830 }
632 831
832anyway:
833 reserved_peri_map[gpio_bank(ident)] |= gpio_bit(ident);
834
835 portmux_setup(ident, P_FUNCT2MUX(per));
836 port_setup(ident, PERIPHERAL_USAGE);
837
838 local_irq_restore(flags);
839 set_label(ident, label);
840
841 return 0;
842}
843EXPORT_SYMBOL(peripheral_request);
844#else
633 845
634int peripheral_request(unsigned short per, const char *label) 846int peripheral_request(unsigned short per, const char *label)
635{ 847{
@@ -680,7 +892,7 @@ int peripheral_request(unsigned short per, const char *label)
680 892
681 printk(KERN_ERR 893 printk(KERN_ERR
682 "%s: Peripheral %d function %d is already" 894 "%s: Peripheral %d function %d is already"
683 "reserved by %s !\n", 895 " reserved by %s !\n",
684 __FUNCTION__, ident, P_FUNCT2MUX(per), 896 __FUNCTION__, ident, P_FUNCT2MUX(per),
685 get_label(ident)); 897 get_label(ident));
686 dump_stack(); 898 dump_stack();
@@ -691,8 +903,6 @@ int peripheral_request(unsigned short per, const char *label)
691 } 903 }
692 904
693anyway: 905anyway:
694
695
696 portmux_setup(per, P_FUNCT2MUX(per)); 906 portmux_setup(per, P_FUNCT2MUX(per));
697 907
698 port_setup(ident, PERIPHERAL_USAGE); 908 port_setup(ident, PERIPHERAL_USAGE);
@@ -704,6 +914,7 @@ anyway:
704 return 0; 914 return 0;
705} 915}
706EXPORT_SYMBOL(peripheral_request); 916EXPORT_SYMBOL(peripheral_request);
917#endif
707 918
708int peripheral_request_list(unsigned short per[], const char *label) 919int peripheral_request_list(unsigned short per[], const char *label)
709{ 920{
@@ -711,9 +922,15 @@ int peripheral_request_list(unsigned short per[], const char *label)
711 int ret; 922 int ret;
712 923
713 for (cnt = 0; per[cnt] != 0; cnt++) { 924 for (cnt = 0; per[cnt] != 0; cnt++) {
925
714 ret = peripheral_request(per[cnt], label); 926 ret = peripheral_request(per[cnt], label);
715 if (ret < 0) 927
716 return ret; 928 if (ret < 0) {
929 for ( ; cnt > 0; cnt--) {
930 peripheral_free(per[cnt - 1]);
931 }
932 return ret;
933 }
717 } 934 }
718 935
719 return 0; 936 return 0;
@@ -748,6 +965,8 @@ void peripheral_free(unsigned short per)
748 965
749 reserved_peri_map[gpio_bank(ident)] &= ~gpio_bit(ident); 966 reserved_peri_map[gpio_bank(ident)] &= ~gpio_bit(ident);
750 967
968 set_label(ident, "free");
969
751 local_irq_restore(flags); 970 local_irq_restore(flags);
752} 971}
753EXPORT_SYMBOL(peripheral_free); 972EXPORT_SYMBOL(peripheral_free);
@@ -768,8 +987,8 @@ EXPORT_SYMBOL(peripheral_free_list);
768* FUNCTIONS: Blackfin GPIO Driver 987* FUNCTIONS: Blackfin GPIO Driver
769* 988*
770* INPUTS/OUTPUTS: 989* INPUTS/OUTPUTS:
771* gpio - GPIO Number between 0 and MAX_BLACKFIN_GPIOS 990* gpio PIO Number between 0 and MAX_BLACKFIN_GPIOS
772* 991* label String
773* 992*
774* DESCRIPTION: Blackfin GPIO Driver API 993* DESCRIPTION: Blackfin GPIO Driver API
775* 994*
@@ -787,17 +1006,39 @@ int gpio_request(unsigned short gpio, const char *label)
787 1006
788 local_irq_save(flags); 1007 local_irq_save(flags);
789 1008
1009 /*
1010 * Allow that the identical GPIO can
1011 * be requested from the same driver twice
1012 * Do nothing and return -
1013 */
1014
1015 if (cmp_label(gpio, label) == 0) {
1016 local_irq_restore(flags);
1017 return 0;
1018 }
1019
790 if (unlikely(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))) { 1020 if (unlikely(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
791 printk(KERN_ERR "bfin-gpio: GPIO %d is already reserved!\n", gpio); 1021 printk(KERN_ERR "bfin-gpio: GPIO %d is already reserved by %s !\n",
1022 gpio, get_label(gpio));
792 dump_stack(); 1023 dump_stack();
793 local_irq_restore(flags); 1024 local_irq_restore(flags);
794 return -EBUSY; 1025 return -EBUSY;
795 } 1026 }
1027 if (unlikely(reserved_peri_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
1028 printk(KERN_ERR
1029 "bfin-gpio: GPIO %d is already reserved as Peripheral by %s !\n",
1030 gpio, get_label(gpio));
1031 dump_stack();
1032 local_irq_restore(flags);
1033 return -EBUSY;
1034 }
1035
796 reserved_gpio_map[gpio_bank(gpio)] |= gpio_bit(gpio); 1036 reserved_gpio_map[gpio_bank(gpio)] |= gpio_bit(gpio);
797 1037
798 local_irq_restore(flags); 1038 local_irq_restore(flags);
799 1039
800 port_setup(gpio, GPIO_USAGE); 1040 port_setup(gpio, GPIO_USAGE);
1041 set_label(gpio, label);
801 1042
802 return 0; 1043 return 0;
803} 1044}
@@ -823,10 +1064,57 @@ void gpio_free(unsigned short gpio)
823 1064
824 reserved_gpio_map[gpio_bank(gpio)] &= ~gpio_bit(gpio); 1065 reserved_gpio_map[gpio_bank(gpio)] &= ~gpio_bit(gpio);
825 1066
1067 set_label(gpio, "free");
1068
826 local_irq_restore(flags); 1069 local_irq_restore(flags);
827} 1070}
828EXPORT_SYMBOL(gpio_free); 1071EXPORT_SYMBOL(gpio_free);
829 1072
1073#ifdef BF548_FAMILY
1074void gpio_direction_input(unsigned short gpio)
1075{
1076 unsigned long flags;
1077
1078 BUG_ON(!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio)));
1079
1080 local_irq_save(flags);
1081 gpio_array[gpio_bank(gpio)]->port_dir_clear = gpio_bit(gpio);
1082 gpio_array[gpio_bank(gpio)]->port_inen |= gpio_bit(gpio);
1083 local_irq_restore(flags);
1084}
1085EXPORT_SYMBOL(gpio_direction_input);
1086
1087void gpio_direction_output(unsigned short gpio)
1088{
1089 unsigned long flags;
1090
1091 BUG_ON(!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio)));
1092
1093 local_irq_save(flags);
1094 gpio_array[gpio_bank(gpio)]->port_inen &= ~gpio_bit(gpio);
1095 gpio_array[gpio_bank(gpio)]->port_dir_set = gpio_bit(gpio);
1096 local_irq_restore(flags);
1097}
1098EXPORT_SYMBOL(gpio_direction_output);
1099
1100void gpio_set_value(unsigned short gpio, unsigned short arg)
1101{
1102 if (arg)
1103 gpio_array[gpio_bank(gpio)]->port_set = gpio_bit(gpio);
1104 else
1105 gpio_array[gpio_bank(gpio)]->port_clear = gpio_bit(gpio);
1106
1107}
1108EXPORT_SYMBOL(gpio_set_value);
1109
1110unsigned short gpio_get_value(unsigned short gpio)
1111{
1112 return (1 & (gpio_array[gpio_bank(gpio)]->port_data >> gpio_sub_n(gpio)));
1113}
1114EXPORT_SYMBOL(gpio_get_value);
1115
1116#else
1117
830void gpio_direction_input(unsigned short gpio) 1118void gpio_direction_input(unsigned short gpio)
831{ 1119{
832 unsigned long flags; 1120 unsigned long flags;
@@ -836,6 +1124,7 @@ void gpio_direction_input(unsigned short gpio)
836 local_irq_save(flags); 1124 local_irq_save(flags);
837 gpio_bankb[gpio_bank(gpio)]->dir &= ~gpio_bit(gpio); 1125 gpio_bankb[gpio_bank(gpio)]->dir &= ~gpio_bit(gpio);
838 gpio_bankb[gpio_bank(gpio)]->inen |= gpio_bit(gpio); 1126 gpio_bankb[gpio_bank(gpio)]->inen |= gpio_bit(gpio);
1127 AWA_DUMMY_READ(inen);
839 local_irq_restore(flags); 1128 local_irq_restore(flags);
840} 1129}
841EXPORT_SYMBOL(gpio_direction_input); 1130EXPORT_SYMBOL(gpio_direction_input);
@@ -849,6 +1138,28 @@ void gpio_direction_output(unsigned short gpio)
849 local_irq_save(flags); 1138 local_irq_save(flags);
850 gpio_bankb[gpio_bank(gpio)]->inen &= ~gpio_bit(gpio); 1139 gpio_bankb[gpio_bank(gpio)]->inen &= ~gpio_bit(gpio);
851 gpio_bankb[gpio_bank(gpio)]->dir |= gpio_bit(gpio); 1140 gpio_bankb[gpio_bank(gpio)]->dir |= gpio_bit(gpio);
1141 AWA_DUMMY_READ(dir);
852 local_irq_restore(flags); 1142 local_irq_restore(flags);
853} 1143}
854EXPORT_SYMBOL(gpio_direction_output); 1144EXPORT_SYMBOL(gpio_direction_output);
1145
1146/* If we are booting from SPI and our board lacks a strong enough pull up,
1147 * the core can reset and execute the bootrom faster than the resistor can
1148 * pull the signal logically high. To work around this (common) error in
1149 * board design, we explicitly set the pin back to GPIO mode, force /CS
1150 * high, and wait for the electrons to do their thing.
1151 *
1152 * This function only makes sense to be called from reset code, but it
1153 * lives here as we need to force all the GPIO states w/out going through
1154 * BUG() checks and such.
1155 */
1156void bfin_gpio_reset_spi0_ssel1(void)
1157{
1158 u16 gpio = P_IDENT(P_SPI0_SSEL1);
1159
1160 port_setup(gpio, GPIO_USAGE);
1161 gpio_bankb[gpio_bank(gpio)]->data_set = gpio_bit(gpio);
1162 udelay(1);
1163}
1164
1165#endif /*BF548_FAMILY */
diff --git a/arch/blackfin/kernel/bfin_ksyms.c b/arch/blackfin/kernel/bfin_ksyms.c
index 70455949cfd2..2198afe40f33 100644
--- a/arch/blackfin/kernel/bfin_ksyms.c
+++ b/arch/blackfin/kernel/bfin_ksyms.c
@@ -60,6 +60,7 @@ EXPORT_SYMBOL(csum_partial_copy);
60 * their interface isn't gonna change any time soon now, so 60 * their interface isn't gonna change any time soon now, so
61 * it's OK to leave it out of version control. 61 * it's OK to leave it out of version control.
62 */ 62 */
63EXPORT_SYMBOL(strcpy);
63EXPORT_SYMBOL(memcpy); 64EXPORT_SYMBOL(memcpy);
64EXPORT_SYMBOL(memset); 65EXPORT_SYMBOL(memset);
65EXPORT_SYMBOL(memcmp); 66EXPORT_SYMBOL(memcmp);
diff --git a/arch/blackfin/kernel/cacheinit.c b/arch/blackfin/kernel/cacheinit.c
index 4d41a40e8133..62cbba7364b0 100644
--- a/arch/blackfin/kernel/cacheinit.c
+++ b/arch/blackfin/kernel/cacheinit.c
@@ -21,9 +21,10 @@
21 21
22#include <asm/cacheflush.h> 22#include <asm/cacheflush.h>
23#include <asm/blackfin.h> 23#include <asm/blackfin.h>
24#include <asm/cplb.h>
24#include <asm/cplbinit.h> 25#include <asm/cplbinit.h>
25 26
26#if defined(CONFIG_BLKFIN_CACHE) 27#if defined(CONFIG_BFIN_ICACHE)
27void bfin_icache_init(void) 28void bfin_icache_init(void)
28{ 29{
29 unsigned long *table = icplb_table; 30 unsigned long *table = icplb_table;
@@ -44,7 +45,7 @@ void bfin_icache_init(void)
44} 45}
45#endif 46#endif
46 47
47#if defined(CONFIG_BLKFIN_DCACHE) 48#if defined(CONFIG_BFIN_DCACHE)
48void bfin_dcache_init(void) 49void bfin_dcache_init(void)
49{ 50{
50 unsigned long *table = dcplb_table; 51 unsigned long *table = dcplb_table;
diff --git a/arch/blackfin/kernel/cplbinit.c b/arch/blackfin/kernel/cplbinit.c
index bbdb403fcb55..f2db6a5e2b5b 100644
--- a/arch/blackfin/kernel/cplbinit.c
+++ b/arch/blackfin/kernel/cplbinit.c
@@ -23,6 +23,7 @@
23#include <linux/module.h> 23#include <linux/module.h>
24 24
25#include <asm/blackfin.h> 25#include <asm/blackfin.h>
26#include <asm/cplb.h>
26#include <asm/cplbinit.h> 27#include <asm/cplbinit.h>
27 28
28u_long icplb_table[MAX_CPLBS+1]; 29u_long icplb_table[MAX_CPLBS+1];
@@ -56,7 +57,7 @@ struct s_cplb {
56 struct cplb_tab switch_d; 57 struct cplb_tab switch_d;
57}; 58};
58 59
59#if defined(CONFIG_BLKFIN_DCACHE) || defined(CONFIG_BLKFIN_CACHE) 60#if defined(CONFIG_BFIN_DCACHE) || defined(CONFIG_BFIN_ICACHE)
60static struct cplb_desc cplb_data[] = { 61static struct cplb_desc cplb_data[] = {
61 { 62 {
62 .start = 0, 63 .start = 0,
@@ -230,8 +231,8 @@ static void __fill_code_cplbtab(struct cplb_tab *t, int i, u32 a_start, u32 a_en
230 cplb_data[i].psize, 231 cplb_data[i].psize,
231 cplb_data[i].i_conf); 232 cplb_data[i].i_conf);
232 } else { 233 } else {
233#if (defined(CONFIG_BLKFIN_CACHE) && defined(ANOMALY_05000263)) 234#if defined(CONFIG_BFIN_ICACHE)
234 if (i == SDRAM_KERN) { 235 if (ANOMALY_05000263 && i == SDRAM_KERN) {
235 fill_cplbtab(t, 236 fill_cplbtab(t,
236 cplb_data[i].start, 237 cplb_data[i].start,
237 cplb_data[i].end, 238 cplb_data[i].end,
diff --git a/arch/blackfin/kernel/early_printk.c b/arch/blackfin/kernel/early_printk.c
new file mode 100644
index 000000000000..6ec518a81113
--- /dev/null
+++ b/arch/blackfin/kernel/early_printk.c
@@ -0,0 +1,214 @@
1/*
2 * File: arch/blackfin/kernel/early_printk.c
3 * Based on: arch/x86_64/kernel/early_printk.c
4 * Author: Robin Getz <rgetz@blackfin.uclinux.org
5 *
6 * Created: 14Aug2007
7 * Description: allow a console to be used for early printk
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
25#include <linux/kernel.h>
26#include <linux/init.h>
27#include <linux/serial_core.h>
28#include <linux/console.h>
29#include <linux/string.h>
30#include <asm/blackfin.h>
31#include <asm/irq_handler.h>
32#include <asm/early_printk.h>
33
34#ifdef CONFIG_SERIAL_BFIN
35extern struct console *bfin_earlyserial_init(unsigned int port,
36 unsigned int cflag);
37#endif
38
39static struct console *early_console;
40
41/* Default console */
42#define DEFAULT_PORT 0
43#define DEFAULT_CFLAG CS8|B57600
44
45/* Default console for early crashes */
46#define DEFAULT_EARLY_PORT "serial,uart0,57600"
47
48#ifdef CONFIG_SERIAL_CORE
49/* What should get here is "0,57600" */
50static struct console * __init earlyserial_init(char *buf)
51{
52 int baud, bit;
53 char parity;
54 unsigned int serial_port = DEFAULT_PORT;
55 unsigned int cflag = DEFAULT_CFLAG;
56
57 serial_port = simple_strtoul(buf, &buf, 10);
58 buf++;
59
60 cflag = 0;
61 baud = simple_strtoul(buf, &buf, 10);
62 switch (baud) {
63 case 1200:
64 cflag |= B1200;
65 break;
66 case 2400:
67 cflag |= B2400;
68 break;
69 case 4800:
70 cflag |= B4800;
71 break;
72 case 9600:
73 cflag |= B9600;
74 break;
75 case 19200:
76 cflag |= B19200;
77 break;
78 case 38400:
79 cflag |= B38400;
80 break;
81 case 115200:
82 cflag |= B115200;
83 break;
84 default:
85 cflag |= B57600;
86 }
87
88 parity = buf[0];
89 buf++;
90 switch (parity) {
91 case 'e':
92 cflag |= PARENB;
93 break;
94 case 'o':
95 cflag |= PARODD;
96 break;
97 }
98
99 bit = simple_strtoul(buf, &buf, 10);
100 switch (bit) {
101 case 5:
102 cflag |= CS5;
103 break;
104 case 6:
105 cflag |= CS5;
106 break;
107 case 7:
108 cflag |= CS5;
109 break;
110 default:
111 cflag |= CS8;
112 }
113
114#ifdef CONFIG_SERIAL_BFIN
115 return bfin_earlyserial_init(serial_port, cflag);
116#else
117 return NULL;
118#endif
119
120}
121#endif
122
123int __init setup_early_printk(char *buf)
124{
125
126 /* Crashing in here would be really bad, so check both the var
127 and the pointer before we start using it
128 */
129 if (!buf)
130 return 0;
131
132 if (!*buf)
133 return 0;
134
135 if (early_console != NULL)
136 return 0;
137
138#ifdef CONFIG_SERIAL_BFIN
139 /* Check for Blackfin Serial */
140 if (!strncmp(buf, "serial,uart", 11)) {
141 buf += 11;
142 early_console = earlyserial_init(buf);
143 }
144#endif
145#ifdef CONFIG_FB
146 /* TODO: add framebuffer console support */
147#endif
148
149 if (likely(early_console)) {
150 early_console->flags |= CON_BOOT;
151
152 register_console(early_console);
153 printk(KERN_INFO "early printk enabled on %s%d\n",
154 early_console->name,
155 early_console->index);
156 }
157
158 return 0;
159}
160
161/*
162 * Set up a temporary Event Vector Table, so if something bad happens before
163 * the kernel is fully started, it doesn't vector off into somewhere we don't
164 * know
165 */
166
167asmlinkage void __init init_early_exception_vectors(void)
168{
169 SSYNC();
170
171 /* cannot program in software:
172 * evt0 - emulation (jtag)
173 * evt1 - reset
174 */
175 bfin_write_EVT2(early_trap);
176 bfin_write_EVT3(early_trap);
177 bfin_write_EVT5(early_trap);
178 bfin_write_EVT6(early_trap);
179 bfin_write_EVT7(early_trap);
180 bfin_write_EVT8(early_trap);
181 bfin_write_EVT9(early_trap);
182 bfin_write_EVT10(early_trap);
183 bfin_write_EVT11(early_trap);
184 bfin_write_EVT12(early_trap);
185 bfin_write_EVT13(early_trap);
186 bfin_write_EVT14(early_trap);
187 bfin_write_EVT15(early_trap);
188 CSYNC();
189
190 /* Set all the return from interupt, exception, NMI to a known place
191 * so if we do a RETI, RETX or RETN by mistake - we go somewhere known
192 * Note - don't change RETS - we are in a subroutine, or
193 * RETE - since it might screw up if emulator is attached
194 */
195 asm("\tRETI = %0; RETX = %0; RETN = %0;\n"
196 : : "p"(early_trap));
197
198}
199
200asmlinkage void __init early_trap_c(struct pt_regs *fp, void *retaddr)
201{
202 /* This can happen before the uart is initialized, so initialize
203 * the UART now
204 */
205 if (likely(early_console == NULL))
206 setup_early_printk(DEFAULT_EARLY_PORT);
207
208 dump_bfin_regs(fp, retaddr);
209 dump_bfin_trace_buffer();
210
211 panic("Died early");
212}
213
214early_param("earlyprintk", setup_early_printk);
diff --git a/arch/blackfin/kernel/irqchip.c b/arch/blackfin/kernel/irqchip.c
index 1fc001c7abda..73647c158774 100644
--- a/arch/blackfin/kernel/irqchip.c
+++ b/arch/blackfin/kernel/irqchip.c
@@ -34,6 +34,7 @@
34#include <linux/kallsyms.h> 34#include <linux/kallsyms.h>
35#include <linux/interrupt.h> 35#include <linux/interrupt.h>
36#include <linux/irq.h> 36#include <linux/irq.h>
37#include <asm/trace.h>
37 38
38static unsigned long irq_err_count; 39static unsigned long irq_err_count;
39static spinlock_t irq_controller_lock; 40static spinlock_t irq_controller_lock;
@@ -97,9 +98,8 @@ int show_interrupts(struct seq_file *p, void *v)
97 */ 98 */
98 99
99#ifdef CONFIG_DO_IRQ_L1 100#ifdef CONFIG_DO_IRQ_L1
100asmlinkage void asm_do_IRQ(unsigned int irq, struct pt_regs *regs)__attribute__((l1_text)); 101__attribute__((l1_text))
101#endif 102#endif
102
103asmlinkage void asm_do_IRQ(unsigned int irq, struct pt_regs *regs) 103asmlinkage void asm_do_IRQ(unsigned int irq, struct pt_regs *regs)
104{ 104{
105 struct pt_regs *old_regs; 105 struct pt_regs *old_regs;
@@ -144,4 +144,12 @@ void __init init_IRQ(void)
144 } 144 }
145 145
146 init_arch_irq(); 146 init_arch_irq();
147
148#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
149 /* Now that evt_ivhw is set up, turn this on */
150 trace_buff_offset = 0;
151 bfin_write_TBUFCTL(BFIN_TRACE_ON);
152 printk(KERN_INFO "Hardware Trace expanded to %ik\n",
153 1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN);
154#endif
147} 155}
diff --git a/arch/blackfin/kernel/process.c b/arch/blackfin/kernel/process.c
index 6a7aefe48346..9124467651c4 100644
--- a/arch/blackfin/kernel/process.c
+++ b/arch/blackfin/kernel/process.c
@@ -134,31 +134,6 @@ void cpu_idle(void)
134 } 134 }
135} 135}
136 136
137void machine_restart(char *__unused)
138{
139#if defined(CONFIG_BLKFIN_CACHE)
140 bfin_write_IMEM_CONTROL(0x01);
141 SSYNC();
142#endif
143 bfin_reset();
144 /* Dont do anything till the reset occurs */
145 while (1) {
146 SSYNC();
147 }
148}
149
150void machine_halt(void)
151{
152 for (;;)
153 asm volatile ("idle");
154}
155
156void machine_power_off(void)
157{
158 for (;;)
159 asm volatile ("idle");
160}
161
162void show_regs(struct pt_regs *regs) 137void show_regs(struct pt_regs *regs)
163{ 138{
164 printk(KERN_NOTICE "\n"); 139 printk(KERN_NOTICE "\n");
@@ -420,7 +395,8 @@ void finish_atomic_sections (struct pt_regs *regs)
420#if defined(CONFIG_ACCESS_CHECK) 395#if defined(CONFIG_ACCESS_CHECK)
421int _access_ok(unsigned long addr, unsigned long size) 396int _access_ok(unsigned long addr, unsigned long size)
422{ 397{
423 398 if (size == 0)
399 return 1;
424 if (addr > (addr + size)) 400 if (addr > (addr + size))
425 return 0; 401 return 0;
426 if (segment_eq(get_fs(), KERNEL_DS)) 402 if (segment_eq(get_fs(), KERNEL_DS))
diff --git a/arch/blackfin/kernel/ptrace.c b/arch/blackfin/kernel/ptrace.c
index ed800c7456dd..64ce5fea8609 100644
--- a/arch/blackfin/kernel/ptrace.c
+++ b/arch/blackfin/kernel/ptrace.c
@@ -44,6 +44,7 @@
44#include <asm/processor.h> 44#include <asm/processor.h>
45#include <asm/asm-offsets.h> 45#include <asm/asm-offsets.h>
46#include <asm/dma.h> 46#include <asm/dma.h>
47#include <asm/fixed_code.h>
47 48
48#define MAX_SHARED_LIBS 3 49#define MAX_SHARED_LIBS 3
49#define TEXT_OFFSET 0 50#define TEXT_OFFSET 0
@@ -169,6 +170,9 @@ static inline int is_user_addr_valid(struct task_struct *child,
169 && start + len <= (unsigned long)sraml->addr + sraml->length) 170 && start + len <= (unsigned long)sraml->addr + sraml->length)
170 return 0; 171 return 0;
171 172
173 if (start >= FIXED_CODE_START && start + len <= FIXED_CODE_END)
174 return 0;
175
172 return -EIO; 176 return -EIO;
173} 177}
174 178
@@ -215,9 +219,13 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
215 copied = sizeof(tmp); 219 copied = sizeof(tmp);
216 } else 220 } else
217#endif 221#endif
218 copied = 222 if (addr + add >= FIXED_CODE_START
219 access_process_vm(child, addr + add, &tmp, 223 && addr + add + sizeof(tmp) <= FIXED_CODE_END) {
220 sizeof(tmp), 0); 224 memcpy(&tmp, (const void *)(addr + add), sizeof(tmp));
225 copied = sizeof(tmp);
226 } else
227 copied = access_process_vm(child, addr + add, &tmp,
228 sizeof(tmp), 0);
221 pr_debug("ptrace: copied size %d [0x%08lx]\n", copied, tmp); 229 pr_debug("ptrace: copied size %d [0x%08lx]\n", copied, tmp);
222 if (copied != sizeof(tmp)) 230 if (copied != sizeof(tmp))
223 break; 231 break;
@@ -281,9 +289,13 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
281 copied = sizeof(data); 289 copied = sizeof(data);
282 } else 290 } else
283#endif 291#endif
284 copied = 292 if (addr + add >= FIXED_CODE_START
285 access_process_vm(child, addr + add, &data, 293 && addr + add + sizeof(data) <= FIXED_CODE_END) {
286 sizeof(data), 1); 294 memcpy((void *)(addr + add), &data, sizeof(data));
295 copied = sizeof(data);
296 } else
297 copied = access_process_vm(child, addr + add, &data,
298 sizeof(data), 1);
287 pr_debug("ptrace: copied size %d\n", copied); 299 pr_debug("ptrace: copied size %d\n", copied);
288 if (copied != sizeof(data)) 300 if (copied != sizeof(data))
289 break; 301 break;
diff --git a/arch/blackfin/kernel/reboot.c b/arch/blackfin/kernel/reboot.c
new file mode 100644
index 000000000000..356078ec462b
--- /dev/null
+++ b/arch/blackfin/kernel/reboot.c
@@ -0,0 +1,78 @@
1/*
2 * arch/blackfin/kernel/reboot.c - handle shutdown/reboot
3 *
4 * Copyright 2004-2007 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#include <linux/interrupt.h>
10#include <asm/bfin-global.h>
11#include <asm/reboot.h>
12#include <asm/system.h>
13
14#if defined(BF537_FAMILY) || defined(BF533_FAMILY)
15#define SYSCR_VAL 0x0
16#elif defined(BF561_FAMILY)
17#define SYSCR_VAL 0x20
18#elif defined(BF548_FAMILY)
19#define SYSCR_VAL 0x10
20#endif
21
22/* A system soft reset makes external memory unusable
23 * so force this function into L1.
24 */
25__attribute__((l1_text))
26void bfin_reset(void)
27{
28 /* force BMODE and disable Core B (as needed) */
29 bfin_write_SYSCR(SYSCR_VAL);
30
31 /* we use asm ssync here because it's save and we save some L1 */
32 asm("ssync;");
33
34 while (1) {
35 /* initiate system soft reset with magic 0x7 */
36 bfin_write_SWRST(0x7);
37 asm("ssync;");
38 /* clear system soft reset */
39 bfin_write_SWRST(0);
40 asm("ssync;");
41 /* issue core reset */
42 asm("raise 1");
43 }
44}
45
46__attribute__((weak))
47void native_machine_restart(char *cmd)
48{
49}
50
51void machine_restart(char *cmd)
52{
53 native_machine_restart(cmd);
54 local_irq_disable();
55 bfin_reset();
56}
57
58__attribute__((weak))
59void native_machine_halt(void)
60{
61 idle_with_irq_disabled();
62}
63
64void machine_halt(void)
65{
66 native_machine_halt();
67}
68
69__attribute__((weak))
70void native_machine_power_off(void)
71{
72 idle_with_irq_disabled();
73}
74
75void machine_power_off(void)
76{
77 native_machine_power_off();
78}
diff --git a/arch/blackfin/kernel/setup.c b/arch/blackfin/kernel/setup.c
index 88f221b89b33..8dcd76e87ed5 100644
--- a/arch/blackfin/kernel/setup.c
+++ b/arch/blackfin/kernel/setup.c
@@ -39,10 +39,12 @@
39#include <linux/cramfs_fs.h> 39#include <linux/cramfs_fs.h>
40#include <linux/romfs_fs.h> 40#include <linux/romfs_fs.h>
41 41
42#include <asm/cplb.h>
42#include <asm/cacheflush.h> 43#include <asm/cacheflush.h>
43#include <asm/blackfin.h> 44#include <asm/blackfin.h>
44#include <asm/cplbinit.h> 45#include <asm/cplbinit.h>
45#include <asm/fixed_code.h> 46#include <asm/fixed_code.h>
47#include <asm/early_printk.h>
46 48
47u16 _bfin_swrst; 49u16 _bfin_swrst;
48 50
@@ -66,21 +68,21 @@ char __initdata command_line[COMMAND_LINE_SIZE];
66 68
67void __init bf53x_cache_init(void) 69void __init bf53x_cache_init(void)
68{ 70{
69#if defined(CONFIG_BLKFIN_DCACHE) || defined(CONFIG_BLKFIN_CACHE) 71#if defined(CONFIG_BFIN_DCACHE) || defined(CONFIG_BFIN_ICACHE)
70 generate_cpl_tables(); 72 generate_cpl_tables();
71#endif 73#endif
72 74
73#ifdef CONFIG_BLKFIN_CACHE 75#ifdef CONFIG_BFIN_ICACHE
74 bfin_icache_init(); 76 bfin_icache_init();
75 printk(KERN_INFO "Instruction Cache Enabled\n"); 77 printk(KERN_INFO "Instruction Cache Enabled\n");
76#endif 78#endif
77 79
78#ifdef CONFIG_BLKFIN_DCACHE 80#ifdef CONFIG_BFIN_DCACHE
79 bfin_dcache_init(); 81 bfin_dcache_init();
80 printk(KERN_INFO "Data Cache Enabled" 82 printk(KERN_INFO "Data Cache Enabled"
81# if defined CONFIG_BLKFIN_WB 83# if defined CONFIG_BFIN_WB
82 " (write-back)" 84 " (write-back)"
83# elif defined CONFIG_BLKFIN_WT 85# elif defined CONFIG_BFIN_WT
84 " (write-through)" 86 " (write-through)"
85# endif 87# endif
86 "\n"); 88 "\n");
@@ -156,8 +158,10 @@ static __init void parse_cmdline_early(char *cmdline_p)
156 1; 158 1;
157 } 159 }
158 } 160 }
161 } else if (!memcmp(to, "earlyprintk=", 12)) {
162 to += 12;
163 setup_early_printk(to);
159 } 164 }
160
161 } 165 }
162 c = *(to++); 166 c = *(to++);
163 if (!c) 167 if (!c)
@@ -176,22 +180,36 @@ void __init setup_arch(char **cmdline_p)
176#ifdef CONFIG_DUMMY_CONSOLE 180#ifdef CONFIG_DUMMY_CONSOLE
177 conswitchp = &dummy_con; 181 conswitchp = &dummy_con;
178#endif 182#endif
183
184#if defined(CONFIG_CMDLINE_BOOL)
185 strncpy(&command_line[0], CONFIG_CMDLINE, sizeof(command_line));
186 command_line[sizeof(command_line) - 1] = 0;
187#endif
188
189 /* Keep a copy of command line */
190 *cmdline_p = &command_line[0];
191 memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
192 boot_command_line[COMMAND_LINE_SIZE - 1] = '\0';
193
194 /* setup memory defaults from the user config */
195 physical_mem_end = 0;
196 _ramend = CONFIG_MEM_SIZE * 1024 * 1024;
197
198 parse_cmdline_early(&command_line[0]);
199
179 cclk = get_cclk(); 200 cclk = get_cclk();
180 sclk = get_sclk(); 201 sclk = get_sclk();
181 202
182#if !defined(CONFIG_BFIN_KERNEL_CLOCK) && defined(ANOMALY_05000273) 203#if !defined(CONFIG_BFIN_KERNEL_CLOCK)
183 if (cclk == sclk) 204 if (ANOMALY_05000273 && cclk == sclk)
184 panic("ANOMALY 05000273, SCLK can not be same as CCLK"); 205 panic("ANOMALY 05000273, SCLK can not be same as CCLK");
185#endif 206#endif
186 207
187#if defined(ANOMALY_05000266) 208#ifdef BF561_FAMILY
188 bfin_read_IMDMA_D0_IRQ_STATUS(); 209 if (ANOMALY_05000266) {
189 bfin_read_IMDMA_D1_IRQ_STATUS(); 210 bfin_read_IMDMA_D0_IRQ_STATUS();
190#endif 211 bfin_read_IMDMA_D1_IRQ_STATUS();
191 212 }
192#ifdef DEBUG_SERIAL_EARLY_INIT
193 bfin_console_init(); /* early console registration */
194 /* this give a chance to get printk() working before crash. */
195#endif 213#endif
196 214
197 printk(KERN_INFO "Hardware Trace "); 215 printk(KERN_INFO "Hardware Trace ");
@@ -212,22 +230,6 @@ void __init setup_arch(char **cmdline_p)
212 flash_probe(); 230 flash_probe();
213#endif 231#endif
214 232
215#if defined(CONFIG_CMDLINE_BOOL)
216 strncpy(&command_line[0], CONFIG_CMDLINE, sizeof(command_line));
217 command_line[sizeof(command_line) - 1] = 0;
218#endif
219
220 /* Keep a copy of command line */
221 *cmdline_p = &command_line[0];
222 memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
223 boot_command_line[COMMAND_LINE_SIZE - 1] = '\0';
224
225 /* setup memory defaults from the user config */
226 physical_mem_end = 0;
227 _ramend = CONFIG_MEM_SIZE * 1024 * 1024;
228
229 parse_cmdline_early(&command_line[0]);
230
231 if (physical_mem_end == 0) 233 if (physical_mem_end == 0)
232 physical_mem_end = _ramend; 234 physical_mem_end = _ramend;
233 235
@@ -260,7 +262,7 @@ void __init setup_arch(char **cmdline_p)
260 && ((unsigned long *)mtd_phys)[1] == ROMSB_WORD1) 262 && ((unsigned long *)mtd_phys)[1] == ROMSB_WORD1)
261 mtd_size = 263 mtd_size =
262 PAGE_ALIGN(be32_to_cpu(((unsigned long *)mtd_phys)[2])); 264 PAGE_ALIGN(be32_to_cpu(((unsigned long *)mtd_phys)[2]));
263# if (defined(CONFIG_BLKFIN_CACHE) && defined(ANOMALY_05000263)) 265# if (defined(CONFIG_BFIN_ICACHE) && ANOMALY_05000263)
264 /* Due to a Hardware Anomaly we need to limit the size of usable 266 /* Due to a Hardware Anomaly we need to limit the size of usable
265 * instruction memory to max 60MB, 56 if HUNT_FOR_ZERO is on 267 * instruction memory to max 60MB, 56 if HUNT_FOR_ZERO is on
266 * 05000263 - Hardware loop corrupted when taking an ICPLB exception 268 * 05000263 - Hardware loop corrupted when taking an ICPLB exception
@@ -289,7 +291,7 @@ void __init setup_arch(char **cmdline_p)
289 _ebss = memory_mtd_start; /* define _ebss for compatible */ 291 _ebss = memory_mtd_start; /* define _ebss for compatible */
290#endif /* CONFIG_MTD_UCLINUX */ 292#endif /* CONFIG_MTD_UCLINUX */
291 293
292#if (defined(CONFIG_BLKFIN_CACHE) && defined(ANOMALY_05000263)) 294#if (defined(CONFIG_BFIN_ICACHE) && ANOMALY_05000263)
293 /* Due to a Hardware Anomaly we need to limit the size of usable 295 /* Due to a Hardware Anomaly we need to limit the size of usable
294 * instruction memory to max 60MB, 56 if HUNT_FOR_ZERO is on 296 * instruction memory to max 60MB, 56 if HUNT_FOR_ZERO is on
295 * 05000263 - Hardware loop corrupted when taking an ICPLB exception 297 * 05000263 - Hardware loop corrupted when taking an ICPLB exception
@@ -334,13 +336,11 @@ void __init setup_arch(char **cmdline_p)
334 CPU, bfin_revid()); 336 CPU, bfin_revid());
335 printk(KERN_INFO "Blackfin Linux support by http://blackfin.uclinux.org/\n"); 337 printk(KERN_INFO "Blackfin Linux support by http://blackfin.uclinux.org/\n");
336 338
337 printk(KERN_INFO "Processor Speed: %lu MHz core clock and %lu Mhz System Clock\n", 339 printk(KERN_INFO "Processor Speed: %lu MHz core clock and %lu MHz System Clock\n",
338 cclk / 1000000, sclk / 1000000); 340 cclk / 1000000, sclk / 1000000);
339 341
340#if defined(ANOMALY_05000273) 342 if (ANOMALY_05000273 && (cclk >> 1) <= sclk)
341 if ((cclk >> 1) <= sclk)
342 printk("\n\n\nANOMALY_05000273: CCLK must be >= 2*SCLK !!!\n\n\n"); 343 printk("\n\n\nANOMALY_05000273: CCLK must be >= 2*SCLK !!!\n\n\n");
343#endif
344 344
345 printk(KERN_INFO "Board Memory: %ldMB\n", physical_mem_end >> 20); 345 printk(KERN_INFO "Board Memory: %ldMB\n", physical_mem_end >> 20);
346 printk(KERN_INFO "Kernel Managed Memory: %ldMB\n", _ramend >> 20); 346 printk(KERN_INFO "Kernel Managed Memory: %ldMB\n", _ramend >> 20);
@@ -535,9 +535,9 @@ static int show_cpuinfo(struct seq_file *m, void *v)
535 seq_printf(m, "I-CACHE:\tOFF\n"); 535 seq_printf(m, "I-CACHE:\tOFF\n");
536 if ((bfin_read_DMEM_CONTROL()) & (ENDCPLB | DMC_ENABLE)) 536 if ((bfin_read_DMEM_CONTROL()) & (ENDCPLB | DMC_ENABLE))
537 seq_printf(m, "D-CACHE:\tON" 537 seq_printf(m, "D-CACHE:\tON"
538#if defined CONFIG_BLKFIN_WB 538#if defined CONFIG_BFIN_WB
539 " (write-back)" 539 " (write-back)"
540#elif defined CONFIG_BLKFIN_WT 540#elif defined CONFIG_BFIN_WT
541 " (write-through)" 541 " (write-through)"
542#endif 542#endif
543 "\n"); 543 "\n");
@@ -566,15 +566,15 @@ static int show_cpuinfo(struct seq_file *m, void *v)
566 } 566 }
567 567
568 568
569 seq_printf(m, "I-CACHE Size:\t%dKB\n", BLKFIN_ICACHESIZE / 1024); 569 seq_printf(m, "I-CACHE Size:\t%dKB\n", BFIN_ICACHESIZE / 1024);
570 seq_printf(m, "D-CACHE Size:\t%dKB\n", dcache_size); 570 seq_printf(m, "D-CACHE Size:\t%dKB\n", dcache_size);
571 seq_printf(m, "I-CACHE Setup:\t%d Sub-banks/%d Ways, %d Lines/Way\n", 571 seq_printf(m, "I-CACHE Setup:\t%d Sub-banks/%d Ways, %d Lines/Way\n",
572 BLKFIN_ISUBBANKS, BLKFIN_IWAYS, BLKFIN_ILINES); 572 BFIN_ISUBBANKS, BFIN_IWAYS, BFIN_ILINES);
573 seq_printf(m, 573 seq_printf(m,
574 "D-CACHE Setup:\t%d Super-banks/%d Sub-banks/%d Ways, %d Lines/Way\n", 574 "D-CACHE Setup:\t%d Super-banks/%d Sub-banks/%d Ways, %d Lines/Way\n",
575 dsup_banks, BLKFIN_DSUBBANKS, BLKFIN_DWAYS, 575 dsup_banks, BFIN_DSUBBANKS, BFIN_DWAYS,
576 BLKFIN_DLINES); 576 BFIN_DLINES);
577#ifdef CONFIG_BLKFIN_CACHE_LOCK 577#ifdef CONFIG_BFIN_ICACHE_LOCK
578 switch (read_iloc()) { 578 switch (read_iloc()) {
579 case WAY0_L: 579 case WAY0_L:
580 seq_printf(m, "Way0 Locked-Down\n"); 580 seq_printf(m, "Way0 Locked-Down\n");
diff --git a/arch/blackfin/kernel/traps.c b/arch/blackfin/kernel/traps.c
index 792a8416fe10..8823e9ade584 100644
--- a/arch/blackfin/kernel/traps.c
+++ b/arch/blackfin/kernel/traps.c
@@ -51,10 +51,9 @@ void __init trap_init(void)
51 CSYNC(); 51 CSYNC();
52} 52}
53 53
54asmlinkage void trap_c(struct pt_regs *fp);
55
56int kstack_depth_to_print = 48; 54int kstack_depth_to_print = 48;
57 55
56#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
58static int printk_address(unsigned long address) 57static int printk_address(unsigned long address)
59{ 58{
60 struct vm_list_struct *vml; 59 struct vm_list_struct *vml;
@@ -131,10 +130,22 @@ static int printk_address(unsigned long address)
131 /* we were unable to find this address anywhere */ 130 /* we were unable to find this address anywhere */
132 return printk("[<0x%p>]", (void *)address); 131 return printk("[<0x%p>]", (void *)address);
133} 132}
133#endif
134
135asmlinkage void double_fault_c(struct pt_regs *fp)
136{
137 printk(KERN_EMERG "\n" KERN_EMERG "Double Fault\n");
138 dump_bfin_regs(fp, (void *)fp->retx);
139 panic("Double Fault - unrecoverable event\n");
140
141}
134 142
135asmlinkage void trap_c(struct pt_regs *fp) 143asmlinkage void trap_c(struct pt_regs *fp)
136{ 144{
137 int j, sig = 0; 145#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
146 int j;
147#endif
148 int sig = 0;
138 siginfo_t info; 149 siginfo_t info;
139 unsigned long trapnr = fp->seqstat & SEQSTAT_EXCAUSE; 150 unsigned long trapnr = fp->seqstat & SEQSTAT_EXCAUSE;
140 151
@@ -391,10 +402,6 @@ asmlinkage void trap_c(struct pt_regs *fp)
391 break; 402 break;
392 } 403 }
393 404
394 info.si_signo = sig;
395 info.si_errno = 0;
396 info.si_addr = (void *)fp->pc;
397 force_sig_info(sig, &info, current);
398 if (sig != 0 && sig != SIGTRAP) { 405 if (sig != 0 && sig != SIGTRAP) {
399 unsigned long stack; 406 unsigned long stack;
400 dump_bfin_regs(fp, (void *)fp->retx); 407 dump_bfin_regs(fp, (void *)fp->retx);
@@ -403,6 +410,10 @@ asmlinkage void trap_c(struct pt_regs *fp)
403 if (current->mm == NULL) 410 if (current->mm == NULL)
404 panic("Kernel exception"); 411 panic("Kernel exception");
405 } 412 }
413 info.si_signo = sig;
414 info.si_errno = 0;
415 info.si_addr = (void *)fp->pc;
416 force_sig_info(sig, &info, current);
406 417
407 /* if the address that we are about to return to is not valid, set it 418 /* if the address that we are about to return to is not valid, set it
408 * to a valid address, if we have a current application or panic 419 * to a valid address, if we have a current application or panic
@@ -429,24 +440,56 @@ asmlinkage void trap_c(struct pt_regs *fp)
429 440
430/* Typical exception handling routines */ 441/* Typical exception handling routines */
431 442
443#define EXPAND_LEN ((1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 256 - 1)
444
432void dump_bfin_trace_buffer(void) 445void dump_bfin_trace_buffer(void)
433{ 446{
434 int tflags; 447#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
448 int tflags, i = 0;
449#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
450 int j, index;
451#endif
452
435 trace_buffer_save(tflags); 453 trace_buffer_save(tflags);
436 454
455 printk(KERN_EMERG "Hardware Trace:\n");
456
437 if (likely(bfin_read_TBUFSTAT() & TBUFCNT)) { 457 if (likely(bfin_read_TBUFSTAT() & TBUFCNT)) {
438 int i; 458 for (; bfin_read_TBUFSTAT() & TBUFCNT; i++) {
439 printk(KERN_EMERG "Hardware Trace:\n"); 459 printk(KERN_EMERG "%4i Target : ", i);
440 for (i = 0; bfin_read_TBUFSTAT() & TBUFCNT; i++) {
441 printk(KERN_EMERG "%2i Target : ", i);
442 printk_address((unsigned long)bfin_read_TBUF()); 460 printk_address((unsigned long)bfin_read_TBUF());
443 printk("\n" KERN_EMERG " Source : "); 461 printk("\n" KERN_EMERG " Source : ");
444 printk_address((unsigned long)bfin_read_TBUF()); 462 printk_address((unsigned long)bfin_read_TBUF());
445 printk("\n"); 463 printk("\n");
446 } 464 }
447 } 465 }
448 466
467#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
468 if (trace_buff_offset)
469 index = trace_buff_offset/4 - 1;
470 else
471 index = EXPAND_LEN;
472
473 j = (1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN) * 128;
474 while (j) {
475 printk(KERN_EMERG "%4i Target : ", i);
476 printk_address(software_trace_buff[index]);
477 index -= 1;
478 if (index < 0 )
479 index = EXPAND_LEN;
480 printk("\n" KERN_EMERG " Source : ");
481 printk_address(software_trace_buff[index]);
482 index -= 1;
483 if (index < 0)
484 index = EXPAND_LEN;
485 printk("\n");
486 j--;
487 i++;
488 }
489#endif
490
449 trace_buffer_restore(tflags); 491 trace_buffer_restore(tflags);
492#endif
450} 493}
451EXPORT_SYMBOL(dump_bfin_trace_buffer); 494EXPORT_SYMBOL(dump_bfin_trace_buffer);
452 495
@@ -510,7 +553,9 @@ void show_stack(struct task_struct *task, unsigned long *stack)
510void dump_stack(void) 553void dump_stack(void)
511{ 554{
512 unsigned long stack; 555 unsigned long stack;
556#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
513 int tflags; 557 int tflags;
558#endif
514 trace_buffer_save(tflags); 559 trace_buffer_save(tflags);
515 dump_bfin_trace_buffer(); 560 dump_bfin_trace_buffer();
516 show_stack(current, &stack); 561 show_stack(current, &stack);
@@ -559,8 +604,7 @@ void dump_bfin_regs(struct pt_regs *fp, void *retaddr)
559 unsigned short x = 0; 604 unsigned short x = 0;
560 for (; i < ((unsigned int)retaddr & 0xFFFFFFF0) + 32; i += 2) { 605 for (; i < ((unsigned int)retaddr & 0xFFFFFFF0) + 32; i += 2) {
561 if (!(i & 0xF)) 606 if (!(i & 0xF))
562 printk(KERN_EMERG "\n" KERN_EMERG 607 printk("\n" KERN_EMERG "0x%08x: ", i);
563 "0x%08x: ", i);
564 608
565 if (get_user(x, (unsigned short *)i)) 609 if (get_user(x, (unsigned short *)i))
566 break; 610 break;
@@ -655,6 +699,42 @@ asmlinkage int sys_bfin_spinlock(int *spinlock)
655 return ret; 699 return ret;
656} 700}
657 701
702int bfin_request_exception(unsigned int exception, void (*handler)(void))
703{
704 void (*curr_handler)(void);
705
706 if (exception > 0x3F)
707 return -EINVAL;
708
709 curr_handler = ex_table[exception];
710
711 if (curr_handler != ex_replaceable)
712 return -EBUSY;
713
714 ex_table[exception] = handler;
715
716 return 0;
717}
718EXPORT_SYMBOL(bfin_request_exception);
719
720int bfin_free_exception(unsigned int exception, void (*handler)(void))
721{
722 void (*curr_handler)(void);
723
724 if (exception > 0x3F)
725 return -EINVAL;
726
727 curr_handler = ex_table[exception];
728
729 if (curr_handler != handler)
730 return -EBUSY;
731
732 ex_table[exception] = ex_replaceable;
733
734 return 0;
735}
736EXPORT_SYMBOL(bfin_free_exception);
737
658void panic_cplb_error(int cplb_panic, struct pt_regs *fp) 738void panic_cplb_error(int cplb_panic, struct pt_regs *fp)
659{ 739{
660 switch (cplb_panic) { 740 switch (cplb_panic) {
diff --git a/arch/blackfin/kernel/vmlinux.lds.S b/arch/blackfin/kernel/vmlinux.lds.S
index fb53780247bc..eec43674a465 100644
--- a/arch/blackfin/kernel/vmlinux.lds.S
+++ b/arch/blackfin/kernel/vmlinux.lds.S
@@ -49,7 +49,8 @@ SECTIONS
49 TEXT_TEXT 49 TEXT_TEXT
50 SCHED_TEXT 50 SCHED_TEXT
51 LOCK_TEXT 51 LOCK_TEXT
52 *(.text.lock) 52 KPROBES_TEXT
53 *(.text.*)
53 *(.fixup) 54 *(.fixup)
54 55
55 . = ALIGN(16); 56 . = ALIGN(16);
@@ -61,7 +62,7 @@ SECTIONS
61 __etext = .; 62 __etext = .;
62 } 63 }
63 64
64 RODATA 65 RO_DATA(PAGE_SIZE)
65 66
66 .data : 67 .data :
67 { 68 {
@@ -72,50 +73,63 @@ SECTIONS
72 __sdata = .; 73 __sdata = .;
73 . = ALIGN(THREAD_SIZE); 74 . = ALIGN(THREAD_SIZE);
74 *(.data.init_task) 75 *(.data.init_task)
75 DATA_DATA
76 CONSTRUCTORS
77 76
78 . = ALIGN(32); 77 . = ALIGN(32);
79 *(.data.cacheline_aligned) 78 *(.data.cacheline_aligned)
80 79
80 DATA_DATA
81 *(.data.*)
82 CONSTRUCTORS
83
81 . = ALIGN(THREAD_SIZE); 84 . = ALIGN(THREAD_SIZE);
82 __edata = .; 85 __edata = .;
83 } 86 }
84 87
85 ___init_begin = .; 88 ___init_begin = .;
86 .init : 89
90 .init.text :
87 { 91 {
88 . = ALIGN(PAGE_SIZE); 92 . = ALIGN(PAGE_SIZE);
89 __sinittext = .; 93 __sinittext = .;
90 *(.init.text) 94 *(.init.text)
91 __einittext = .; 95 __einittext = .;
96 }
97 .init.data :
98 {
99 . = ALIGN(16);
92 *(.init.data) 100 *(.init.data)
101 }
102 .init.setup :
103 {
93 . = ALIGN(16); 104 . = ALIGN(16);
94 ___setup_start = .; 105 ___setup_start = .;
95 *(.init.setup) 106 *(.init.setup)
96 ___setup_end = .; 107 ___setup_end = .;
97 ___start___param = .; 108 }
98 *(__param) 109 .initcall.init :
99 ___stop___param = .; 110 {
100 ___initcall_start = .; 111 ___initcall_start = .;
101 INITCALLS 112 INITCALLS
102 ___initcall_end = .; 113 ___initcall_end = .;
114 }
115 .con_initcall.init :
116 {
103 ___con_initcall_start = .; 117 ___con_initcall_start = .;
104 *(.con_initcall.init) 118 *(.con_initcall.init)
105 ___con_initcall_end = .; 119 ___con_initcall_end = .;
106 ___security_initcall_start = .; 120 }
107 *(.security_initcall.init) 121 SECURITY_INIT
108 ___security_initcall_end = .; 122 .init.ramfs :
123 {
109 . = ALIGN(4); 124 . = ALIGN(4);
110 ___initramfs_start = .; 125 ___initramfs_start = .;
111 *(.init.ramfs) 126 *(.init.ramfs)
112 ___initramfs_end = .; 127 ___initramfs_end = .;
113 . = ALIGN(4);
114 } 128 }
115 129
116 __l1_lma_start = .; 130 __l1_lma_start = .;
117 131
118 .text_l1 L1_CODE_START : AT(LOADADDR(.init) + SIZEOF(.init)) 132 .text_l1 L1_CODE_START : AT(LOADADDR(.init.ramfs) + SIZEOF(.init.ramfs))
119 { 133 {
120 . = ALIGN(4); 134 . = ALIGN(4);
121 __stext_l1 = .; 135 __stext_l1 = .;
@@ -164,13 +178,19 @@ SECTIONS
164 { 178 {
165 . = ALIGN(4); 179 . = ALIGN(4);
166 ___bss_start = .; 180 ___bss_start = .;
167 *(.bss) 181 *(.bss .bss.*)
168 *(COMMON) 182 *(COMMON)
169 . = ALIGN(4); 183 . = ALIGN(4);
170 ___bss_stop = .; 184 ___bss_stop = .;
171 __end = .; 185 __end = .;
172 } 186 }
173 187
188 STABS_DEBUG
189
190 DWARF_DEBUG
191
192 NOTES
193
174 /DISCARD/ : 194 /DISCARD/ :
175 { 195 {
176 *(.exit.text) 196 *(.exit.text)
diff --git a/arch/blackfin/lib/memcmp.S b/arch/blackfin/lib/memcmp.S
index b88c5d2d1ebe..219fa2877c62 100644
--- a/arch/blackfin/lib/memcmp.S
+++ b/arch/blackfin/lib/memcmp.S
@@ -61,7 +61,7 @@ ENTRY(_memcmp)
61 61
62 LSETUP (.Lquad_loop_s, .Lquad_loop_e) LC0=P1; 62 LSETUP (.Lquad_loop_s, .Lquad_loop_e) LC0=P1;
63.Lquad_loop_s: 63.Lquad_loop_s:
64#ifdef ANOMALY_05000202 64#if ANOMALY_05000202
65 R0 = [P0++]; 65 R0 = [P0++];
66 R1 = [I0++]; 66 R1 = [I0++];
67#else 67#else
diff --git a/arch/blackfin/lib/memcpy.S b/arch/blackfin/lib/memcpy.S
index 14a5585bbd02..2e6336492b4b 100644
--- a/arch/blackfin/lib/memcpy.S
+++ b/arch/blackfin/lib/memcpy.S
@@ -98,7 +98,7 @@ ENTRY(_memcpy)
98 R0 = R1; 98 R0 = R1;
99 I1 = P1; 99 I1 = P1;
100 R3 = [I1++]; 100 R3 = [I1++];
101#ifdef ANOMALY_05000202 101#if ANOMALY_05000202
102.Lword_loops: 102.Lword_loops:
103 [P0++] = R3; 103 [P0++] = R3;
104.Lword_loope: 104.Lword_loope:
diff --git a/arch/blackfin/lib/memmove.S b/arch/blackfin/lib/memmove.S
index 6ee6e206e77c..33f8653145b7 100644
--- a/arch/blackfin/lib/memmove.S
+++ b/arch/blackfin/lib/memmove.S
@@ -70,7 +70,7 @@ ENTRY(_memmove)
70 R1 = [I0++]; 70 R1 = [I0++];
71 71
72 LSETUP (.Lquad_loops, .Lquad_loope) LC0=P1; 72 LSETUP (.Lquad_loops, .Lquad_loope) LC0=P1;
73#ifdef ANOMALY_05000202 73#if ANOMALY_05000202
74.Lquad_loops: 74.Lquad_loops:
75 [P0++] = R1; 75 [P0++] = R1;
76.Lquad_loope: 76.Lquad_loope:
@@ -102,7 +102,7 @@ ENTRY(_memmove)
102 R1 = B[P3--] (Z); 102 R1 = B[P3--] (Z);
103 CC = P2 == 0; 103 CC = P2 == 0;
104 IF CC JUMP .Lno_loop; 104 IF CC JUMP .Lno_loop;
105#ifdef ANOMALY_05000245 105#if ANOMALY_05000245
106 NOP; 106 NOP;
107 NOP; 107 NOP;
108#endif 108#endif
diff --git a/arch/blackfin/mach-bf533/boards/cm_bf533.c b/arch/blackfin/mach-bf533/boards/cm_bf533.c
index 4545f363e641..a57b52d207cd 100644
--- a/arch/blackfin/mach-bf533/boards/cm_bf533.c
+++ b/arch/blackfin/mach-bf533/boards/cm_bf533.c
@@ -34,7 +34,9 @@
34#include <linux/spi/spi.h> 34#include <linux/spi/spi.h>
35#include <linux/spi/flash.h> 35#include <linux/spi/flash.h>
36#include <linux/usb_isp1362.h> 36#include <linux/usb_isp1362.h>
37#include <linux/pata_platform.h>
37#include <linux/irq.h> 38#include <linux/irq.h>
39#include <asm/dma.h>
38#include <asm/bfin5xx_spi.h> 40#include <asm/bfin5xx_spi.h>
39 41
40/* 42/*
@@ -93,7 +95,7 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
93 /* the modalias must be the same as spi device driver name */ 95 /* the modalias must be the same as spi device driver name */
94 .modalias = "m25p80", /* Name of spi_driver for this device */ 96 .modalias = "m25p80", /* Name of spi_driver for this device */
95 .max_speed_hz = 25000000, /* max spi clock (SCK) speed in HZ */ 97 .max_speed_hz = 25000000, /* max spi clock (SCK) speed in HZ */
96 .bus_num = 1, /* Framework bus number */ 98 .bus_num = 0, /* Framework bus number */
97 .chip_select = 1, /* Framework chip select. On STAMP537 it is SPISSEL1*/ 99 .chip_select = 1, /* Framework chip select. On STAMP537 it is SPISSEL1*/
98 .platform_data = &bfin_spi_flash_data, 100 .platform_data = &bfin_spi_flash_data,
99 .controller_data = &spi_flash_chip_info, 101 .controller_data = &spi_flash_chip_info,
@@ -101,7 +103,7 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
101 }, { 103 }, {
102 .modalias = "bfin_spi_adc", /* Name of spi_driver for this device */ 104 .modalias = "bfin_spi_adc", /* Name of spi_driver for this device */
103 .max_speed_hz = 6250000, /* max spi clock (SCK) speed in HZ */ 105 .max_speed_hz = 6250000, /* max spi clock (SCK) speed in HZ */
104 .bus_num = 1, /* Framework bus number */ 106 .bus_num = 0, /* Framework bus number */
105 .chip_select = 2, /* Framework chip select. */ 107 .chip_select = 2, /* Framework chip select. */
106 .platform_data = NULL, /* No spi_driver specific config */ 108 .platform_data = NULL, /* No spi_driver specific config */
107 .controller_data = &spi_adc_chip_info, 109 .controller_data = &spi_adc_chip_info,
@@ -110,24 +112,40 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
110 { 112 {
111 .modalias = "ad1836-spi", 113 .modalias = "ad1836-spi",
112 .max_speed_hz = 3125000, /* max spi clock (SCK) speed in HZ */ 114 .max_speed_hz = 3125000, /* max spi clock (SCK) speed in HZ */
113 .bus_num = 1, 115 .bus_num = 0,
114 .chip_select = CONFIG_SND_BLACKFIN_SPI_PFBIT, 116 .chip_select = CONFIG_SND_BLACKFIN_SPI_PFBIT,
115 .controller_data = &ad1836_spi_chip_info, 117 .controller_data = &ad1836_spi_chip_info,
116 }, 118 },
117#endif 119#endif
118}; 120};
119 121
122/* SPI (0) */
123static struct resource bfin_spi0_resource[] = {
124 [0] = {
125 .start = SPI0_REGBASE,
126 .end = SPI0_REGBASE + 0xFF,
127 .flags = IORESOURCE_MEM,
128 },
129 [1] = {
130 .start = CH_SPI,
131 .end = CH_SPI,
132 .flags = IORESOURCE_IRQ,
133 }
134};
135
120/* SPI controller data */ 136/* SPI controller data */
121static struct bfin5xx_spi_master spi_bfin_master_info = { 137static struct bfin5xx_spi_master bfin_spi0_info = {
122 .num_chipselect = 8, 138 .num_chipselect = 8,
123 .enable_dma = 1, /* master has the ability to do dma transfer */ 139 .enable_dma = 1, /* master has the ability to do dma transfer */
124}; 140};
125 141
126static struct platform_device spi_bfin_master_device = { 142static struct platform_device bfin_spi0_device = {
127 .name = "bfin-spi-master", 143 .name = "bfin-spi",
128 .id = 1, /* Bus number */ 144 .id = 0, /* Bus number */
145 .num_resources = ARRAY_SIZE(bfin_spi0_resource),
146 .resource = bfin_spi0_resource,
129 .dev = { 147 .dev = {
130 .platform_data = &spi_bfin_master_info, /* Passed to driver */ 148 .platform_data = &bfin_spi0_info, /* Passed to driver */
131 }, 149 },
132}; 150};
133#endif /* spi master and devices */ 151#endif /* spi master and devices */
@@ -227,6 +245,43 @@ static struct platform_device isp1362_hcd_device = {
227}; 245};
228#endif 246#endif
229 247
248#if defined(CONFIG_PATA_PLATFORM) || defined(CONFIG_PATA_PLATFORM_MODULE)
249#define PATA_INT 38
250
251static struct pata_platform_info bfin_pata_platform_data = {
252 .ioport_shift = 2,
253 .irq_type = IRQF_TRIGGER_HIGH | IRQF_DISABLED,
254};
255
256static struct resource bfin_pata_resources[] = {
257 {
258 .start = 0x2030C000,
259 .end = 0x2030C01F,
260 .flags = IORESOURCE_MEM,
261 },
262 {
263 .start = 0x2030D018,
264 .end = 0x2030D01B,
265 .flags = IORESOURCE_MEM,
266 },
267 {
268 .start = PATA_INT,
269 .end = PATA_INT,
270 .flags = IORESOURCE_IRQ,
271 },
272};
273
274static struct platform_device bfin_pata_device = {
275 .name = "pata_platform",
276 .id = -1,
277 .num_resources = ARRAY_SIZE(bfin_pata_resources),
278 .resource = bfin_pata_resources,
279 .dev = {
280 .platform_data = &bfin_pata_platform_data,
281 }
282};
283#endif
284
230static struct platform_device *cm_bf533_devices[] __initdata = { 285static struct platform_device *cm_bf533_devices[] __initdata = {
231#if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE) 286#if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE)
232 &bfin_uart_device, 287 &bfin_uart_device,
@@ -250,7 +305,11 @@ static struct platform_device *cm_bf533_devices[] __initdata = {
250#endif 305#endif
251 306
252#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE) 307#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
253 &spi_bfin_master_device, 308 &bfin_spi0_device,
309#endif
310
311#if defined(CONFIG_PATA_PLATFORM) || defined(CONFIG_PATA_PLATFORM_MODULE)
312 &bfin_pata_device,
254#endif 313#endif
255}; 314};
256 315
@@ -261,6 +320,10 @@ static int __init cm_bf533_init(void)
261#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE) 320#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
262 spi_register_board_info(bfin_spi_board_info, ARRAY_SIZE(bfin_spi_board_info)); 321 spi_register_board_info(bfin_spi_board_info, ARRAY_SIZE(bfin_spi_board_info));
263#endif 322#endif
323
324#if defined(CONFIG_PATA_PLATFORM) || defined(CONFIG_PATA_PLATFORM_MODULE)
325 irq_desc[PATA_INT].status |= IRQ_NOAUTOEN;
326#endif
264 return 0; 327 return 0;
265} 328}
266 329
diff --git a/arch/blackfin/mach-bf533/boards/ezkit.c b/arch/blackfin/mach-bf533/boards/ezkit.c
index 0000b8f1239c..5c1e35d3c012 100644
--- a/arch/blackfin/mach-bf533/boards/ezkit.c
+++ b/arch/blackfin/mach-bf533/boards/ezkit.c
@@ -35,7 +35,9 @@
35#include <linux/spi/spi.h> 35#include <linux/spi/spi.h>
36#include <linux/spi/flash.h> 36#include <linux/spi/flash.h>
37#include <linux/usb_isp1362.h> 37#include <linux/usb_isp1362.h>
38#include <linux/pata_platform.h>
38#include <linux/irq.h> 39#include <linux/irq.h>
40#include <asm/dma.h>
39#include <asm/bfin5xx_spi.h> 41#include <asm/bfin5xx_spi.h>
40 42
41/* 43/*
@@ -50,6 +52,12 @@ static struct platform_device rtc_device = {
50}; 52};
51#endif 53#endif
52 54
55#if defined(CONFIG_FB_BFIN_7393) || defined(CONFIG_FB_BFIN_7393_MODULE)
56static struct platform_device bfin_fb_adv7393_device = {
57 .name = "bfin-adv7393",
58};
59#endif
60
53/* 61/*
54 * USB-LAN EzExtender board 62 * USB-LAN EzExtender board
55 * Driver needs to know address, irq and flag pin. 63 * Driver needs to know address, irq and flag pin.
@@ -131,7 +139,7 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
131 /* the modalias must be the same as spi device driver name */ 139 /* the modalias must be the same as spi device driver name */
132 .modalias = "m25p80", /* Name of spi_driver for this device */ 140 .modalias = "m25p80", /* Name of spi_driver for this device */
133 .max_speed_hz = 25000000, /* max spi clock (SCK) speed in HZ */ 141 .max_speed_hz = 25000000, /* max spi clock (SCK) speed in HZ */
134 .bus_num = 1, /* Framework bus number */ 142 .bus_num = 0, /* Framework bus number */
135 .chip_select = 2, /* Framework chip select. On STAMP537 it is SPISSEL2*/ 143 .chip_select = 2, /* Framework chip select. On STAMP537 it is SPISSEL2*/
136 .platform_data = &bfin_spi_flash_data, 144 .platform_data = &bfin_spi_flash_data,
137 .controller_data = &spi_flash_chip_info, 145 .controller_data = &spi_flash_chip_info,
@@ -143,7 +151,7 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
143 { 151 {
144 .modalias = "bfin_spi_adc", /* Name of spi_driver for this device */ 152 .modalias = "bfin_spi_adc", /* Name of spi_driver for this device */
145 .max_speed_hz = 6250000, /* max spi clock (SCK) speed in HZ */ 153 .max_speed_hz = 6250000, /* max spi clock (SCK) speed in HZ */
146 .bus_num = 1, /* Framework bus number */ 154 .bus_num = 0, /* Framework bus number */
147 .chip_select = 1, /* Framework chip select. */ 155 .chip_select = 1, /* Framework chip select. */
148 .platform_data = NULL, /* No spi_driver specific config */ 156 .platform_data = NULL, /* No spi_driver specific config */
149 .controller_data = &spi_adc_chip_info, 157 .controller_data = &spi_adc_chip_info,
@@ -154,24 +162,40 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
154 { 162 {
155 .modalias = "ad1836-spi", 163 .modalias = "ad1836-spi",
156 .max_speed_hz = 3125000, /* max spi clock (SCK) speed in HZ */ 164 .max_speed_hz = 3125000, /* max spi clock (SCK) speed in HZ */
157 .bus_num = 1, 165 .bus_num = 0,
158 .chip_select = CONFIG_SND_BLACKFIN_SPI_PFBIT, 166 .chip_select = CONFIG_SND_BLACKFIN_SPI_PFBIT,
159 .controller_data = &ad1836_spi_chip_info, 167 .controller_data = &ad1836_spi_chip_info,
160 }, 168 },
161#endif 169#endif
162}; 170};
163 171
172/* SPI (0) */
173static struct resource bfin_spi0_resource[] = {
174 [0] = {
175 .start = SPI0_REGBASE,
176 .end = SPI0_REGBASE + 0xFF,
177 .flags = IORESOURCE_MEM,
178 },
179 [1] = {
180 .start = CH_SPI,
181 .end = CH_SPI,
182 .flags = IORESOURCE_IRQ,
183 }
184};
185
164/* SPI controller data */ 186/* SPI controller data */
165static struct bfin5xx_spi_master spi_bfin_master_info = { 187static struct bfin5xx_spi_master bfin_spi0_info = {
166 .num_chipselect = 8, 188 .num_chipselect = 8,
167 .enable_dma = 1, /* master has the ability to do dma transfer */ 189 .enable_dma = 1, /* master has the ability to do dma transfer */
168}; 190};
169 191
170static struct platform_device spi_bfin_master_device = { 192static struct platform_device bfin_spi0_device = {
171 .name = "bfin-spi-master", 193 .name = "bfin-spi",
172 .id = 1, /* Bus number */ 194 .id = 0, /* Bus number */
195 .num_resources = ARRAY_SIZE(bfin_spi0_resource),
196 .resource = bfin_spi0_resource,
173 .dev = { 197 .dev = {
174 .platform_data = &spi_bfin_master_info, /* Passed to driver */ 198 .platform_data = &bfin_spi0_info, /* Passed to driver */
175 }, 199 },
176}; 200};
177#endif /* spi master and devices */ 201#endif /* spi master and devices */
@@ -193,13 +217,54 @@ static struct platform_device bfin_uart_device = {
193}; 217};
194#endif 218#endif
195 219
220#if defined(CONFIG_PATA_PLATFORM) || defined(CONFIG_PATA_PLATFORM_MODULE)
221#define PATA_INT 55
222
223static struct pata_platform_info bfin_pata_platform_data = {
224 .ioport_shift = 1,
225 .irq_type = IRQF_TRIGGER_HIGH | IRQF_DISABLED,
226};
227
228static struct resource bfin_pata_resources[] = {
229 {
230 .start = 0x20314020,
231 .end = 0x2031403F,
232 .flags = IORESOURCE_MEM,
233 },
234 {
235 .start = 0x2031401C,
236 .end = 0x2031401F,
237 .flags = IORESOURCE_MEM,
238 },
239 {
240 .start = PATA_INT,
241 .end = PATA_INT,
242 .flags = IORESOURCE_IRQ,
243 },
244};
245
246static struct platform_device bfin_pata_device = {
247 .name = "pata_platform",
248 .id = -1,
249 .num_resources = ARRAY_SIZE(bfin_pata_resources),
250 .resource = bfin_pata_resources,
251 .dev = {
252 .platform_data = &bfin_pata_platform_data,
253 }
254};
255#endif
256
196static struct platform_device *ezkit_devices[] __initdata = { 257static struct platform_device *ezkit_devices[] __initdata = {
197#if defined(CONFIG_SMC91X) || defined(CONFIG_SMC91X_MODULE) 258#if defined(CONFIG_SMC91X) || defined(CONFIG_SMC91X_MODULE)
198 &smc91x_device, 259 &smc91x_device,
199#endif 260#endif
200 261
201#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE) 262#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
202 &spi_bfin_master_device, 263 &bfin_spi0_device,
264#endif
265
266#if defined(CONFIG_FB_BFIN_7393) || defined(CONFIG_FB_BFIN_7393_MODULE)
267 &bfin_fb_adv7393_device,
203#endif 268#endif
204 269
205#if defined(CONFIG_RTC_DRV_BFIN) || defined(CONFIG_RTC_DRV_BFIN_MODULE) 270#if defined(CONFIG_RTC_DRV_BFIN) || defined(CONFIG_RTC_DRV_BFIN_MODULE)
@@ -209,6 +274,10 @@ static struct platform_device *ezkit_devices[] __initdata = {
209#if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE) 274#if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE)
210 &bfin_uart_device, 275 &bfin_uart_device,
211#endif 276#endif
277
278#if defined(CONFIG_PATA_PLATFORM) || defined(CONFIG_PATA_PLATFORM_MODULE)
279 &bfin_pata_device,
280#endif
212}; 281};
213 282
214static int __init ezkit_init(void) 283static int __init ezkit_init(void)
@@ -218,6 +287,10 @@ static int __init ezkit_init(void)
218#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE) 287#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
219 spi_register_board_info(bfin_spi_board_info, ARRAY_SIZE(bfin_spi_board_info)); 288 spi_register_board_info(bfin_spi_board_info, ARRAY_SIZE(bfin_spi_board_info));
220#endif 289#endif
290
291#if defined(CONFIG_PATA_PLATFORM) || defined(CONFIG_PATA_PLATFORM_MODULE)
292 irq_desc[PATA_INT].status |= IRQ_NOAUTOEN;
293#endif
221 return 0; 294 return 0;
222} 295}
223 296
diff --git a/arch/blackfin/mach-bf533/boards/stamp.c b/arch/blackfin/mach-bf533/boards/stamp.c
index a9143c4cbdcd..8975e06ea158 100644
--- a/arch/blackfin/mach-bf533/boards/stamp.c
+++ b/arch/blackfin/mach-bf533/boards/stamp.c
@@ -37,8 +37,11 @@
37#if defined(CONFIG_USB_ISP1362_HCD) || defined(CONFIG_USB_ISP1362_HCD_MODULE) 37#if defined(CONFIG_USB_ISP1362_HCD) || defined(CONFIG_USB_ISP1362_HCD_MODULE)
38#include <linux/usb_isp1362.h> 38#include <linux/usb_isp1362.h>
39#endif 39#endif
40#include <linux/pata_platform.h>
40#include <linux/irq.h> 41#include <linux/irq.h>
42#include <asm/dma.h>
41#include <asm/bfin5xx_spi.h> 43#include <asm/bfin5xx_spi.h>
44#include <asm/reboot.h>
42 45
43/* 46/*
44 * Name the Board for the /proc/cpuinfo 47 * Name the Board for the /proc/cpuinfo
@@ -77,6 +80,12 @@ static struct platform_device smc91x_device = {
77}; 80};
78#endif 81#endif
79 82
83#if defined(CONFIG_FB_BFIN_7393) || defined(CONFIG_FB_BFIN_7393_MODULE)
84static struct platform_device bfin_fb_adv7393_device = {
85 .name = "bfin-adv7393",
86};
87#endif
88
80#if defined(CONFIG_USB_NET2272) || defined(CONFIG_USB_NET2272_MODULE) 89#if defined(CONFIG_USB_NET2272) || defined(CONFIG_USB_NET2272_MODULE)
81static struct resource net2272_bfin_resources[] = { 90static struct resource net2272_bfin_resources[] = {
82 { 91 {
@@ -177,7 +186,7 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
177 /* the modalias must be the same as spi device driver name */ 186 /* the modalias must be the same as spi device driver name */
178 .modalias = "m25p80", /* Name of spi_driver for this device */ 187 .modalias = "m25p80", /* Name of spi_driver for this device */
179 .max_speed_hz = 25000000, /* max spi clock (SCK) speed in HZ */ 188 .max_speed_hz = 25000000, /* max spi clock (SCK) speed in HZ */
180 .bus_num = 1, /* Framework bus number */ 189 .bus_num = 0, /* Framework bus number */
181 .chip_select = 2, /* Framework chip select. On STAMP537 it is SPISSEL2*/ 190 .chip_select = 2, /* Framework chip select. On STAMP537 it is SPISSEL2*/
182 .platform_data = &bfin_spi_flash_data, 191 .platform_data = &bfin_spi_flash_data,
183 .controller_data = &spi_flash_chip_info, 192 .controller_data = &spi_flash_chip_info,
@@ -189,7 +198,7 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
189 { 198 {
190 .modalias = "bfin_spi_adc", /* Name of spi_driver for this device */ 199 .modalias = "bfin_spi_adc", /* Name of spi_driver for this device */
191 .max_speed_hz = 6250000, /* max spi clock (SCK) speed in HZ */ 200 .max_speed_hz = 6250000, /* max spi clock (SCK) speed in HZ */
192 .bus_num = 1, /* Framework bus number */ 201 .bus_num = 0, /* Framework bus number */
193 .chip_select = 1, /* Framework chip select. */ 202 .chip_select = 1, /* Framework chip select. */
194 .platform_data = NULL, /* No spi_driver specific config */ 203 .platform_data = NULL, /* No spi_driver specific config */
195 .controller_data = &spi_adc_chip_info, 204 .controller_data = &spi_adc_chip_info,
@@ -200,7 +209,7 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
200 { 209 {
201 .modalias = "ad1836-spi", 210 .modalias = "ad1836-spi",
202 .max_speed_hz = 31250000, /* max spi clock (SCK) speed in HZ */ 211 .max_speed_hz = 31250000, /* max spi clock (SCK) speed in HZ */
203 .bus_num = 1, 212 .bus_num = 0,
204 .chip_select = CONFIG_SND_BLACKFIN_SPI_PFBIT, 213 .chip_select = CONFIG_SND_BLACKFIN_SPI_PFBIT,
205 .controller_data = &ad1836_spi_chip_info, 214 .controller_data = &ad1836_spi_chip_info,
206 }, 215 },
@@ -210,7 +219,7 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
210 { 219 {
211 .modalias = "spi_mmc_dummy", 220 .modalias = "spi_mmc_dummy",
212 .max_speed_hz = 25000000, /* max spi clock (SCK) speed in HZ */ 221 .max_speed_hz = 25000000, /* max spi clock (SCK) speed in HZ */
213 .bus_num = 1, 222 .bus_num = 0,
214 .chip_select = 0, 223 .chip_select = 0,
215 .platform_data = NULL, 224 .platform_data = NULL,
216 .controller_data = &spi_mmc_chip_info, 225 .controller_data = &spi_mmc_chip_info,
@@ -219,7 +228,7 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
219 { 228 {
220 .modalias = "spi_mmc", 229 .modalias = "spi_mmc",
221 .max_speed_hz = 25000000, /* max spi clock (SCK) speed in HZ */ 230 .max_speed_hz = 25000000, /* max spi clock (SCK) speed in HZ */
222 .bus_num = 1, 231 .bus_num = 0,
223 .chip_select = CONFIG_SPI_MMC_CS_CHAN, 232 .chip_select = CONFIG_SPI_MMC_CS_CHAN,
224 .platform_data = NULL, 233 .platform_data = NULL,
225 .controller_data = &spi_mmc_chip_info, 234 .controller_data = &spi_mmc_chip_info,
@@ -231,16 +240,16 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
231 { 240 {
232 .modalias = "fxs-spi", 241 .modalias = "fxs-spi",
233 .max_speed_hz = 12500000, /* max spi clock (SCK) speed in HZ */ 242 .max_speed_hz = 12500000, /* max spi clock (SCK) speed in HZ */
234 .bus_num = 1, 243 .bus_num = 0,
235 .chip_select = 3, 244 .chip_select = 8 - CONFIG_J11_JUMPER,
236 .controller_data = &spi_si3xxx_chip_info, 245 .controller_data = &spi_si3xxx_chip_info,
237 .mode = SPI_MODE_3, 246 .mode = SPI_MODE_3,
238 }, 247 },
239 { 248 {
240 .modalias = "fxo-spi", 249 .modalias = "fxo-spi",
241 .max_speed_hz = 12500000, /* max spi clock (SCK) speed in HZ */ 250 .max_speed_hz = 12500000, /* max spi clock (SCK) speed in HZ */
242 .bus_num = 1, 251 .bus_num = 0,
243 .chip_select = 2, 252 .chip_select = 8 - CONFIG_J19_JUMPER,
244 .controller_data = &spi_si3xxx_chip_info, 253 .controller_data = &spi_si3xxx_chip_info,
245 .mode = SPI_MODE_3, 254 .mode = SPI_MODE_3,
246 }, 255 },
@@ -250,7 +259,7 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
250 { 259 {
251 .modalias = "ad5304_spi", 260 .modalias = "ad5304_spi",
252 .max_speed_hz = 1000000, /* max spi clock (SCK) speed in HZ */ 261 .max_speed_hz = 1000000, /* max spi clock (SCK) speed in HZ */
253 .bus_num = 1, 262 .bus_num = 0,
254 .chip_select = 2, 263 .chip_select = 2,
255 .platform_data = NULL, 264 .platform_data = NULL,
256 .controller_data = &ad5304_chip_info, 265 .controller_data = &ad5304_chip_info,
@@ -259,17 +268,33 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
259#endif 268#endif
260}; 269};
261 270
271/* SPI (0) */
272static struct resource bfin_spi0_resource[] = {
273 [0] = {
274 .start = SPI0_REGBASE,
275 .end = SPI0_REGBASE + 0xFF,
276 .flags = IORESOURCE_MEM,
277 },
278 [1] = {
279 .start = CH_SPI,
280 .end = CH_SPI,
281 .flags = IORESOURCE_IRQ,
282 }
283};
284
262/* SPI controller data */ 285/* SPI controller data */
263static struct bfin5xx_spi_master spi_bfin_master_info = { 286static struct bfin5xx_spi_master bfin_spi0_info = {
264 .num_chipselect = 8, 287 .num_chipselect = 8,
265 .enable_dma = 1, /* master has the ability to do dma transfer */ 288 .enable_dma = 1, /* master has the ability to do dma transfer */
266}; 289};
267 290
268static struct platform_device spi_bfin_master_device = { 291static struct platform_device bfin_spi0_device = {
269 .name = "bfin-spi-master", 292 .name = "bfin-spi",
270 .id = 1, /* Bus number */ 293 .id = 0, /* Bus number */
294 .num_resources = ARRAY_SIZE(bfin_spi0_resource),
295 .resource = bfin_spi0_resource,
271 .dev = { 296 .dev = {
272 .platform_data = &spi_bfin_master_info, /* Passed to driver */ 297 .platform_data = &bfin_spi0_info, /* Passed to driver */
273 }, 298 },
274}; 299};
275#endif /* spi master and devices */ 300#endif /* spi master and devices */
@@ -309,6 +334,43 @@ static struct platform_device bfin_sport1_uart_device = {
309}; 334};
310#endif 335#endif
311 336
337#if defined(CONFIG_PATA_PLATFORM) || defined(CONFIG_PATA_PLATFORM_MODULE)
338#define PATA_INT 55
339
340static struct pata_platform_info bfin_pata_platform_data = {
341 .ioport_shift = 1,
342 .irq_type = IRQF_TRIGGER_HIGH | IRQF_DISABLED,
343};
344
345static struct resource bfin_pata_resources[] = {
346 {
347 .start = 0x20314020,
348 .end = 0x2031403F,
349 .flags = IORESOURCE_MEM,
350 },
351 {
352 .start = 0x2031401C,
353 .end = 0x2031401F,
354 .flags = IORESOURCE_MEM,
355 },
356 {
357 .start = PATA_INT,
358 .end = PATA_INT,
359 .flags = IORESOURCE_IRQ,
360 },
361};
362
363static struct platform_device bfin_pata_device = {
364 .name = "pata_platform",
365 .id = -1,
366 .num_resources = ARRAY_SIZE(bfin_pata_resources),
367 .resource = bfin_pata_resources,
368 .dev = {
369 .platform_data = &bfin_pata_platform_data,
370 }
371};
372#endif
373
312static struct platform_device *stamp_devices[] __initdata = { 374static struct platform_device *stamp_devices[] __initdata = {
313#if defined(CONFIG_RTC_DRV_BFIN) || defined(CONFIG_RTC_DRV_BFIN_MODULE) 375#if defined(CONFIG_RTC_DRV_BFIN) || defined(CONFIG_RTC_DRV_BFIN_MODULE)
314 &rtc_device, 376 &rtc_device,
@@ -318,12 +380,16 @@ static struct platform_device *stamp_devices[] __initdata = {
318 &smc91x_device, 380 &smc91x_device,
319#endif 381#endif
320 382
383#if defined(CONFIG_FB_BFIN_7393) || defined(CONFIG_FB_BFIN_7393_MODULE)
384 &bfin_fb_adv7393_device,
385#endif
386
321#if defined(CONFIG_USB_NET2272) || defined(CONFIG_USB_NET2272_MODULE) 387#if defined(CONFIG_USB_NET2272) || defined(CONFIG_USB_NET2272_MODULE)
322 &net2272_bfin_device, 388 &net2272_bfin_device,
323#endif 389#endif
324 390
325#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE) 391#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
326 &spi_bfin_master_device, 392 &bfin_spi0_device,
327#endif 393#endif
328 394
329#if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE) 395#if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE)
@@ -334,6 +400,10 @@ static struct platform_device *stamp_devices[] __initdata = {
334 &bfin_sport0_uart_device, 400 &bfin_sport0_uart_device,
335 &bfin_sport1_uart_device, 401 &bfin_sport1_uart_device,
336#endif 402#endif
403
404#if defined(CONFIG_PATA_PLATFORM) || defined(CONFIG_PATA_PLATFORM_MODULE)
405 &bfin_pata_device,
406#endif
337}; 407};
338 408
339static int __init stamp_init(void) 409static int __init stamp_init(void)
@@ -355,8 +425,23 @@ static int __init stamp_init(void)
355#endif 425#endif
356 426
357#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE) 427#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
358 return spi_register_board_info(bfin_spi_board_info, ARRAY_SIZE(bfin_spi_board_info)); 428 spi_register_board_info(bfin_spi_board_info,
429 ARRAY_SIZE(bfin_spi_board_info));
430#endif
431#if defined(CONFIG_PATA_PLATFORM) || defined(CONFIG_PATA_PLATFORM_MODULE)
432 irq_desc[PATA_INT].status |= IRQ_NOAUTOEN;
359#endif 433#endif
434 return 0;
360} 435}
361 436
362arch_initcall(stamp_init); 437arch_initcall(stamp_init);
438
439void native_machine_restart(char *cmd)
440{
441#if defined(CONFIG_BFIN_SHARED_FLASH_ENET)
442# define BIT_TO_SET (1 << CONFIG_ENET_FLASH_PIN)
443 bfin_write_FIO_INEN(~BIT_TO_SET);
444 bfin_write_FIO_DIR(BIT_TO_SET);
445 bfin_write_FIO_FLAG_C(BIT_TO_SET);
446#endif
447}
diff --git a/arch/blackfin/mach-bf533/head.S b/arch/blackfin/mach-bf533/head.S
index 7dd0e9c3a936..1ded945a6fa0 100644
--- a/arch/blackfin/mach-bf533/head.S
+++ b/arch/blackfin/mach-bf533/head.S
@@ -32,11 +32,9 @@
32#include <asm/blackfin.h> 32#include <asm/blackfin.h>
33#include <asm/trace.h> 33#include <asm/trace.h>
34#if CONFIG_BFIN_KERNEL_CLOCK 34#if CONFIG_BFIN_KERNEL_CLOCK
35#include <asm/mach-common/clocks.h>
35#include <asm/mach/mem_init.h> 36#include <asm/mach/mem_init.h>
36#endif 37#endif
37#if CONFIG_DEBUG_KERNEL_START
38#include <asm/mach-common/def_LPBlackfin.h>
39#endif
40 38
41.global __rambase 39.global __rambase
42.global __ramstart 40.global __ramstart
@@ -52,10 +50,12 @@ __INIT
52ENTRY(__start) 50ENTRY(__start)
53 /* R0: argument of command line string, passed from uboot, save it */ 51 /* R0: argument of command line string, passed from uboot, save it */
54 R7 = R0; 52 R7 = R0;
55 /* Set the SYSCFG register: 53 /* Enable Cycle Counter and Nesting Of Interrupts */
56 * Enable Cycle Counter and Nesting Of Interrupts (3rd Bit) 54#ifdef CONFIG_BFIN_SCRATCH_REG_CYCLES
57 */ 55 R0 = SYSCFG_SNEN;
58 R0 = 0x36; 56#else
57 R0 = SYSCFG_SNEN | SYSCFG_CCEN;
58#endif
59 SYSCFG = R0; 59 SYSCFG = R0;
60 R0 = 0; 60 R0 = 0;
61 61
@@ -97,40 +97,10 @@ ENTRY(__start)
97 M2 = r0; 97 M2 = r0;
98 M3 = r0; 98 M3 = r0;
99 99
100 trace_buffer_start(p0,r0); 100 trace_buffer_init(p0,r0);
101 P0 = R1; 101 P0 = R1;
102 R0 = R1; 102 R0 = R1;
103 103
104#if CONFIG_DEBUG_KERNEL_START
105
106/*
107 * Set up a temporary Event Vector Table, so if something bad happens before
108 * the kernel is fully started, it doesn't vector off into the bootloaders
109 * table
110 */
111 P0.l = lo(EVT2);
112 P0.h = hi(EVT2);
113 P1.l = lo(EVT15);
114 P1.h = hi(EVT15);
115 P2.l = debug_kernel_start_trap;
116 P2.h = debug_kernel_start_trap;
117
118 RTS = P2;
119 RTI = P2;
120 RTX = P2;
121 RTN = P2;
122 RTE = P2;
123
124.Lfill_temp_vector_table:
125 [P0++] = P2; /* Core Event Vector Table */
126 CC = P0 == P1;
127 if !CC JUMP .Lfill_temp_vector_table
128 P0 = r0;
129 P1 = r0;
130 P2 = r0;
131
132#endif
133
134 p0.h = hi(FIO_MASKA_C); 104 p0.h = hi(FIO_MASKA_C);
135 p0.l = lo(FIO_MASKA_C); 105 p0.l = lo(FIO_MASKA_C);
136 r0 = 0xFFFF(Z); 106 r0 = 0xFFFF(Z);
@@ -144,38 +114,38 @@ ENTRY(__start)
144 ssync; 114 ssync;
145 115
146 /* Turn off the icache */ 116 /* Turn off the icache */
147 p0.l = (IMEM_CONTROL & 0xFFFF); 117 p0.l = LO(IMEM_CONTROL);
148 p0.h = (IMEM_CONTROL >> 16); 118 p0.h = HI(IMEM_CONTROL);
149 R1 = [p0]; 119 R1 = [p0];
150 R0 = ~ENICPLB; 120 R0 = ~ENICPLB;
151 R0 = R0 & R1; 121 R0 = R0 & R1;
152 122
153 /* Anomaly 05000125 */ 123 /* Anomaly 05000125 */
154#ifdef ANOMALY_05000125 124#if ANOMALY_05000125
155 CLI R2; 125 CLI R2;
156 SSYNC; 126 SSYNC;
157#endif 127#endif
158 [p0] = R0; 128 [p0] = R0;
159 SSYNC; 129 SSYNC;
160#ifdef ANOMALY_05000125 130#if ANOMALY_05000125
161 STI R2; 131 STI R2;
162#endif 132#endif
163 133
164 /* Turn off the dcache */ 134 /* Turn off the dcache */
165 p0.l = (DMEM_CONTROL & 0xFFFF); 135 p0.l = LO(DMEM_CONTROL);
166 p0.h = (DMEM_CONTROL >> 16); 136 p0.h = HI(DMEM_CONTROL);
167 R1 = [p0]; 137 R1 = [p0];
168 R0 = ~ENDCPLB; 138 R0 = ~ENDCPLB;
169 R0 = R0 & R1; 139 R0 = R0 & R1;
170 140
171 /* Anomaly 05000125 */ 141 /* Anomaly 05000125 */
172#ifdef ANOMALY_05000125 142#if ANOMALY_05000125
173 CLI R2; 143 CLI R2;
174 SSYNC; 144 SSYNC;
175#endif 145#endif
176 [p0] = R0; 146 [p0] = R0;
177 SSYNC; 147 SSYNC;
178#ifdef ANOMALY_05000125 148#if ANOMALY_05000125
179 STI R2; 149 STI R2;
180#endif 150#endif
181 151
@@ -211,6 +181,12 @@ ENTRY(__start)
211 fp = sp; 181 fp = sp;
212 usp = sp; 182 usp = sp;
213 183
184#ifdef CONFIG_EARLY_PRINTK
185 SP += -12;
186 call _init_early_exception_vectors;
187 SP += 12;
188#endif
189
214 /* Put The Code for PLL Programming and SDRAM Programming in L1 ISRAM */ 190 /* Put The Code for PLL Programming and SDRAM Programming in L1 ISRAM */
215 call _bf53x_relocate_l1_mem; 191 call _bf53x_relocate_l1_mem;
216#if CONFIG_BFIN_KERNEL_CLOCK 192#if CONFIG_BFIN_KERNEL_CLOCK
@@ -264,7 +240,7 @@ ENTRY(__start)
264 p0.l = .LWAIT_HERE; 240 p0.l = .LWAIT_HERE;
265 p0.h = .LWAIT_HERE; 241 p0.h = .LWAIT_HERE;
266 reti = p0; 242 reti = p0;
267#if defined(ANOMALY_05000281) 243#if ANOMALY_05000281
268 nop; nop; nop; 244 nop; nop; nop;
269#endif 245#endif
270 rti; 246 rti;
@@ -417,8 +393,8 @@ ENTRY(_start_dma_code)
417 w[p0] = r0.l; 393 w[p0] = r0.l;
418 ssync; 394 ssync;
419 395
420 p0.l = (EBIU_SDBCTL & 0xFFFF); 396 p0.l = LO(EBIU_SDBCTL);
421 p0.h = (EBIU_SDBCTL >> 16); /* SDRAM Memory Bank Control Register */ 397 p0.h = HI(EBIU_SDBCTL); /* SDRAM Memory Bank Control Register */
422 r0 = mem_SDBCTL; 398 r0 = mem_SDBCTL;
423 w[p0] = r0.l; 399 w[p0] = r0.l;
424 ssync; 400 ssync;
@@ -456,276 +432,6 @@ ENTRY(_start_dma_code)
456ENDPROC(_start_dma_code) 432ENDPROC(_start_dma_code)
457#endif /* CONFIG_BFIN_KERNEL_CLOCK */ 433#endif /* CONFIG_BFIN_KERNEL_CLOCK */
458 434
459ENTRY(_bfin_reset)
460 /* No more interrupts to be handled*/
461 CLI R6;
462 SSYNC;
463
464#if defined(CONFIG_BFIN_SHARED_FLASH_ENET)
465 p0.h = hi(FIO_INEN);
466 p0.l = lo(FIO_INEN);
467 r0.l = ~(1 << CONFIG_ENET_FLASH_PIN);
468 w[p0] = r0.l;
469
470 p0.h = hi(FIO_DIR);
471 p0.l = lo(FIO_DIR);
472 r0.l = (1 << CONFIG_ENET_FLASH_PIN);
473 w[p0] = r0.l;
474
475 p0.h = hi(FIO_FLAG_C);
476 p0.l = lo(FIO_FLAG_C);
477 r0.l = (1 << CONFIG_ENET_FLASH_PIN);
478 w[p0] = r0.l;
479#endif
480
481 /* Clear the IMASK register */
482 p0.h = hi(IMASK);
483 p0.l = lo(IMASK);
484 r0 = 0x0;
485 [p0] = r0;
486
487 /* Clear the ILAT register */
488 p0.h = hi(ILAT);
489 p0.l = lo(ILAT);
490 r0 = [p0];
491 [p0] = r0;
492 SSYNC;
493
494 /* make sure SYSCR is set to use BMODE */
495 P0.h = hi(SYSCR);
496 P0.l = lo(SYSCR);
497 R0.l = 0x0;
498 W[P0] = R0.l;
499 SSYNC;
500
501 /* issue a system soft reset */
502 P1.h = hi(SWRST);
503 P1.l = lo(SWRST);
504 R1.l = 0x0007;
505 W[P1] = R1;
506 SSYNC;
507
508 /* clear system soft reset */
509 R0.l = 0x0000;
510 W[P0] = R0;
511 SSYNC;
512
513 /* issue core reset */
514 raise 1;
515
516 RTS;
517ENDPROC(_bfin_reset)
518
519#if CONFIG_DEBUG_KERNEL_START
520debug_kernel_start_trap:
521 /* Set up a temp stack in L1 - SDRAM might not be working */
522 P0.L = lo(L1_DATA_A_START + 0x100);
523 P0.H = hi(L1_DATA_A_START + 0x100);
524 SP = P0;
525
526 /* Make sure the Clocks are the way I think they should be */
527 r0 = CONFIG_VCO_MULT & 63; /* Load the VCO multiplier */
528 r0 = r0 << 9; /* Shift it over, */
529 r1 = CLKIN_HALF; /* Do we need to divide CLKIN by 2?*/
530 r0 = r1 | r0;
531 r1 = PLL_BYPASS; /* Bypass the PLL? */
532 r1 = r1 << 8; /* Shift it over */
533 r0 = r1 | r0; /* add them all together */
534
535 p0.h = hi(PLL_CTL);
536 p0.l = lo(PLL_CTL); /* Load the address */
537 cli r2; /* Disable interrupts */
538 ssync;
539 w[p0] = r0.l; /* Set the value */
540 idle; /* Wait for the PLL to stablize */
541 sti r2; /* Enable interrupts */
542
543.Lcheck_again1:
544 p0.h = hi(PLL_STAT);
545 p0.l = lo(PLL_STAT);
546 R0 = W[P0](Z);
547 CC = BITTST(R0,5);
548 if ! CC jump .Lcheck_again1;
549
550 /* Configure SCLK & CCLK Dividers */
551 r0 = (CONFIG_CCLK_ACT_DIV | CONFIG_SCLK_DIV);
552 p0.h = hi(PLL_DIV);
553 p0.l = lo(PLL_DIV);
554 w[p0] = r0.l;
555 ssync;
556
557 /* Make sure UART is enabled - you can never be sure */
558
559/*
560 * Setup for console. Argument comes from the menuconfig
561 */
562
563#ifdef CONFIG_BAUD_9600
564#define CONSOLE_BAUD_RATE 9600
565#elif CONFIG_BAUD_19200
566#define CONSOLE_BAUD_RATE 19200
567#elif CONFIG_BAUD_38400
568#define CONSOLE_BAUD_RATE 38400
569#elif CONFIG_BAUD_57600
570#define CONSOLE_BAUD_RATE 57600
571#elif CONFIG_BAUD_115200
572#define CONSOLE_BAUD_RATE 115200
573#endif
574
575 p0.h = hi(UART_GCTL);
576 p0.l = lo(UART_GCTL);
577 r0 = 0x00(Z);
578 w[p0] = r0.L; /* To Turn off UART clocks */
579 ssync;
580
581 p0.h = hi(UART_LCR);
582 p0.l = lo(UART_LCR);
583 r0 = 0x83(Z);
584 w[p0] = r0.L; /* To enable DLL writes */
585 ssync;
586
587 R1 = (((CONFIG_CLKIN_HZ * CONFIG_VCO_MULT) / CONFIG_SCLK_DIV) / (CONSOLE_BAUD_RATE * 16));
588
589 p0.h = hi(UART_DLL);
590 p0.l = lo(UART_DLL);
591 r0 = 0xFF(Z);
592 r0 = R1 & R0;
593 w[p0] = r0.L;
594 ssync;
595
596 p0.h = hi(UART_DLH);
597 p0.l = lo(UART_DLH);
598 r1 >>= 8 ;
599 w[p0] = r1.L;
600 ssync;
601
602 p0.h = hi(UART_GCTL);
603 p0.l = lo(UART_GCTL);
604 r0 = 0x0(Z);
605 w[p0] = r0.L; /* To enable UART clock */
606 ssync;
607
608 p0.h = hi(UART_LCR);
609 p0.l = lo(UART_LCR);
610 r0 = 0x03(Z);
611 w[p0] = r0.L; /* To Turn on UART */
612 ssync;
613
614 p0.h = hi(UART_GCTL);
615 p0.l = lo(UART_GCTL);
616 r0 = 0x01(Z);
617 w[p0] = r0.L; /* To Turn on UART Clocks */
618 ssync;
619
620 P0.h = hi(UART_THR);
621 P0.l = lo(UART_THR);
622 P1.h = hi(UART_LSR);
623 P1.l = lo(UART_LSR);
624
625 R0.L = 'K';
626 call .Lwait_char;
627 R0.L='e';
628 call .Lwait_char;
629 R0.L='r';
630 call .Lwait_char;
631 R0.L='n'
632 call .Lwait_char;
633 R0.L='e'
634 call .Lwait_char;
635 R0.L='l';
636 call .Lwait_char;
637 R0.L=' ';
638 call .Lwait_char;
639 R0.L='c';
640 call .Lwait_char;
641 R0.L='r';
642 call .Lwait_char;
643 R0.L='a';
644 call .Lwait_char;
645 R0.L='s';
646 call .Lwait_char;
647 R0.L='h';
648 call .Lwait_char;
649 R0.L='\r';
650 call .Lwait_char;
651 R0.L='\n';
652 call .Lwait_char;
653
654 R0.L='S';
655 call .Lwait_char;
656 R0.L='E';
657 call .Lwait_char;
658 R0.L='Q'
659 call .Lwait_char;
660 R0.L='S'
661 call .Lwait_char;
662 R0.L='T';
663 call .Lwait_char;
664 R0.L='A';
665 call .Lwait_char;
666 R0.L='T';
667 call .Lwait_char;
668 R0.L='=';
669 call .Lwait_char;
670 R2 = SEQSTAT;
671 call .Ldump_reg;
672
673 R0.L=' ';
674 call .Lwait_char;
675 R0.L='R';
676 call .Lwait_char;
677 R0.L='E'
678 call .Lwait_char;
679 R0.L='T'
680 call .Lwait_char;
681 R0.L='X';
682 call .Lwait_char;
683 R0.L='=';
684 call .Lwait_char;
685 R2 = RETX;
686 call .Ldump_reg;
687
688 R0.L='\r';
689 call .Lwait_char;
690 R0.L='\n';
691 call .Lwait_char;
692
693.Ldebug_kernel_start_trap_done:
694 JUMP .Ldebug_kernel_start_trap_done;
695.Ldump_reg:
696 R3 = 32;
697 R4 = 0x0F;
698 R5 = ':'; /* one past 9 */
699
700.Ldump_reg2:
701 R0 = R2;
702 R3 += -4;
703 R0 >>>= R3;
704 R0 = R0 & R4;
705 R0 += 0x30;
706 CC = R0 <= R5;
707 if CC JUMP .Ldump_reg1;
708 R0 += 7;
709
710.Ldump_reg1:
711 R1.l = W[P1];
712 CC = BITTST(R1, 5);
713 if !CC JUMP .Ldump_reg1;
714 W[P0] = r0;
715
716 CC = R3 == 0;
717 if !CC JUMP .Ldump_reg2
718 RTS;
719
720.Lwait_char:
721 R1.l = W[P1];
722 CC = BITTST(R1, 5);
723 if !CC JUMP .Lwait_char;
724 W[P0] = r0;
725 RTS;
726
727#endif /* CONFIG_DEBUG_KERNEL_START */
728
729.data 435.data
730 436
731/* 437/*
diff --git a/arch/blackfin/mach-bf537/Kconfig b/arch/blackfin/mach-bf537/Kconfig
index cc9ae38a4dda..e6648db09519 100644
--- a/arch/blackfin/mach-bf537/Kconfig
+++ b/arch/blackfin/mach-bf537/Kconfig
@@ -2,33 +2,6 @@ if (BF537 || BF534 || BF536)
2 2
3menu "BF537 Specific Configuration" 3menu "BF537 Specific Configuration"
4 4
5comment "PORT F/G Selection"
6choice
7 prompt "Select BF537/6/4 default GPIO PFx PORTx"
8 help
9 Quick Hack for BF537/6/4 default GPIO PFx PORTF.
10
11config BF537_PORT_F
12 bool "Select BF537/6/4 default GPIO PFx PORTF"
13 depends on (BF537 || BF536 || BF534)
14 help
15 Quick Hack for BF537/6/4 default GPIO PFx PORTF.
16
17config BF537_PORT_G
18 bool "Select BF537/6/4 default GPIO PFx PORTG"
19 depends on (BF537 || BF536 || BF534)
20 help
21 Quick Hack for BF537/6/4 default GPIO PFx PORTG.
22
23config BF537_PORT_H
24 bool "Select BF537/6/4 default GPIO PFx PORTH"
25 depends on (BF537 || BF536 || BF534)
26 help
27 Quick Hack for BF537/6/4 default GPIO PFx PORTH
28 Use only when Blackfin EMAC support is not required.
29
30endchoice
31
32comment "Interrupt Priority Assignment" 5comment "Interrupt Priority Assignment"
33menu "Priority" 6menu "Priority"
34 7
diff --git a/arch/blackfin/mach-bf537/boards/cm_bf537.c b/arch/blackfin/mach-bf537/boards/cm_bf537.c
index a8f947b72754..44dea05e1d03 100644
--- a/arch/blackfin/mach-bf537/boards/cm_bf537.c
+++ b/arch/blackfin/mach-bf537/boards/cm_bf537.c
@@ -35,7 +35,9 @@
35#include <linux/spi/spi.h> 35#include <linux/spi/spi.h>
36#include <linux/spi/flash.h> 36#include <linux/spi/flash.h>
37#include <linux/usb_isp1362.h> 37#include <linux/usb_isp1362.h>
38#include <linux/pata_platform.h>
38#include <linux/irq.h> 39#include <linux/irq.h>
40#include <asm/dma.h>
39#include <asm/bfin5xx_spi.h> 41#include <asm/bfin5xx_spi.h>
40 42
41/* 43/*
@@ -113,7 +115,7 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
113 /* the modalias must be the same as spi device driver name */ 115 /* the modalias must be the same as spi device driver name */
114 .modalias = "m25p80", /* Name of spi_driver for this device */ 116 .modalias = "m25p80", /* Name of spi_driver for this device */
115 .max_speed_hz = 25000000, /* max spi clock (SCK) speed in HZ */ 117 .max_speed_hz = 25000000, /* max spi clock (SCK) speed in HZ */
116 .bus_num = 1, /* Framework bus number */ 118 .bus_num = 0, /* Framework bus number */
117 .chip_select = 1, /* Framework chip select. On STAMP537 it is SPISSEL1*/ 119 .chip_select = 1, /* Framework chip select. On STAMP537 it is SPISSEL1*/
118 .platform_data = &bfin_spi_flash_data, 120 .platform_data = &bfin_spi_flash_data,
119 .controller_data = &spi_flash_chip_info, 121 .controller_data = &spi_flash_chip_info,
@@ -125,7 +127,7 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
125 { 127 {
126 .modalias = "bfin_spi_adc", /* Name of spi_driver for this device */ 128 .modalias = "bfin_spi_adc", /* Name of spi_driver for this device */
127 .max_speed_hz = 6250000, /* max spi clock (SCK) speed in HZ */ 129 .max_speed_hz = 6250000, /* max spi clock (SCK) speed in HZ */
128 .bus_num = 1, /* Framework bus number */ 130 .bus_num = 0, /* Framework bus number */
129 .chip_select = 1, /* Framework chip select. */ 131 .chip_select = 1, /* Framework chip select. */
130 .platform_data = NULL, /* No spi_driver specific config */ 132 .platform_data = NULL, /* No spi_driver specific config */
131 .controller_data = &spi_adc_chip_info, 133 .controller_data = &spi_adc_chip_info,
@@ -136,7 +138,7 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
136 { 138 {
137 .modalias = "ad1836-spi", 139 .modalias = "ad1836-spi",
138 .max_speed_hz = 3125000, /* max spi clock (SCK) speed in HZ */ 140 .max_speed_hz = 3125000, /* max spi clock (SCK) speed in HZ */
139 .bus_num = 1, 141 .bus_num = 0,
140 .chip_select = CONFIG_SND_BLACKFIN_SPI_PFBIT, 142 .chip_select = CONFIG_SND_BLACKFIN_SPI_PFBIT,
141 .controller_data = &ad1836_spi_chip_info, 143 .controller_data = &ad1836_spi_chip_info,
142 }, 144 },
@@ -146,7 +148,7 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
146 { 148 {
147 .modalias = "ad9960-spi", 149 .modalias = "ad9960-spi",
148 .max_speed_hz = 10000000, /* max spi clock (SCK) speed in HZ */ 150 .max_speed_hz = 10000000, /* max spi clock (SCK) speed in HZ */
149 .bus_num = 1, 151 .bus_num = 0,
150 .chip_select = 1, 152 .chip_select = 1,
151 .controller_data = &ad9960_spi_chip_info, 153 .controller_data = &ad9960_spi_chip_info,
152 }, 154 },
@@ -156,7 +158,7 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
156 { 158 {
157 .modalias = "spi_mmc_dummy", 159 .modalias = "spi_mmc_dummy",
158 .max_speed_hz = 25000000, /* max spi clock (SCK) speed in HZ */ 160 .max_speed_hz = 25000000, /* max spi clock (SCK) speed in HZ */
159 .bus_num = 1, 161 .bus_num = 0,
160 .chip_select = 7, 162 .chip_select = 7,
161 .platform_data = NULL, 163 .platform_data = NULL,
162 .controller_data = &spi_mmc_chip_info, 164 .controller_data = &spi_mmc_chip_info,
@@ -165,7 +167,7 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
165 { 167 {
166 .modalias = "spi_mmc", 168 .modalias = "spi_mmc",
167 .max_speed_hz = 25000000, /* max spi clock (SCK) speed in HZ */ 169 .max_speed_hz = 25000000, /* max spi clock (SCK) speed in HZ */
168 .bus_num = 1, 170 .bus_num = 0,
169 .chip_select = CONFIG_SPI_MMC_CS_CHAN, 171 .chip_select = CONFIG_SPI_MMC_CS_CHAN,
170 .platform_data = NULL, 172 .platform_data = NULL,
171 .controller_data = &spi_mmc_chip_info, 173 .controller_data = &spi_mmc_chip_info,
@@ -174,17 +176,33 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
174#endif 176#endif
175}; 177};
176 178
179/* SPI (0) */
180static struct resource bfin_spi0_resource[] = {
181 [0] = {
182 .start = SPI0_REGBASE,
183 .end = SPI0_REGBASE + 0xFF,
184 .flags = IORESOURCE_MEM,
185 },
186 [1] = {
187 .start = CH_SPI,
188 .end = CH_SPI,
189 .flags = IORESOURCE_IRQ,
190 }
191};
192
177/* SPI controller data */ 193/* SPI controller data */
178static struct bfin5xx_spi_master spi_bfin_master_info = { 194static struct bfin5xx_spi_master bfin_spi0_info = {
179 .num_chipselect = 8, 195 .num_chipselect = 8,
180 .enable_dma = 1, /* master has the ability to do dma transfer */ 196 .enable_dma = 1, /* master has the ability to do dma transfer */
181}; 197};
182 198
183static struct platform_device spi_bfin_master_device = { 199static struct platform_device bfin_spi0_device = {
184 .name = "bfin-spi-master", 200 .name = "bfin-spi",
185 .id = 1, /* Bus number */ 201 .id = 0, /* Bus number */
202 .num_resources = ARRAY_SIZE(bfin_spi0_resource),
203 .resource = bfin_spi0_resource,
186 .dev = { 204 .dev = {
187 .platform_data = &spi_bfin_master_info, /* Passed to driver */ 205 .platform_data = &bfin_spi0_info, /* Passed to driver */
188 }, 206 },
189}; 207};
190#endif /* spi master and devices */ 208#endif /* spi master and devices */
@@ -316,6 +334,43 @@ static struct platform_device bfin_mac_device = {
316}; 334};
317#endif 335#endif
318 336
337#if defined(CONFIG_PATA_PLATFORM) || defined(CONFIG_PATA_PLATFORM_MODULE)
338#define PATA_INT 64
339
340static struct pata_platform_info bfin_pata_platform_data = {
341 .ioport_shift = 2,
342 .irq_type = IRQF_TRIGGER_HIGH | IRQF_DISABLED,
343};
344
345static struct resource bfin_pata_resources[] = {
346 {
347 .start = 0x2030C000,
348 .end = 0x2030C01F,
349 .flags = IORESOURCE_MEM,
350 },
351 {
352 .start = 0x2030D018,
353 .end = 0x2030D01B,
354 .flags = IORESOURCE_MEM,
355 },
356 {
357 .start = PATA_INT,
358 .end = PATA_INT,
359 .flags = IORESOURCE_IRQ,
360 },
361};
362
363static struct platform_device bfin_pata_device = {
364 .name = "pata_platform",
365 .id = -1,
366 .num_resources = ARRAY_SIZE(bfin_pata_resources),
367 .resource = bfin_pata_resources,
368 .dev = {
369 .platform_data = &bfin_pata_platform_data,
370 }
371};
372#endif
373
319static struct platform_device *cm_bf537_devices[] __initdata = { 374static struct platform_device *cm_bf537_devices[] __initdata = {
320#if defined(CONFIG_RTC_DRV_BFIN) || defined(CONFIG_RTC_DRV_BFIN_MODULE) 375#if defined(CONFIG_RTC_DRV_BFIN) || defined(CONFIG_RTC_DRV_BFIN_MODULE)
321 &rtc_device, 376 &rtc_device,
@@ -347,7 +402,11 @@ static struct platform_device *cm_bf537_devices[] __initdata = {
347#endif 402#endif
348 403
349#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE) 404#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
350 &spi_bfin_master_device, 405 &bfin_spi0_device,
406#endif
407
408#if defined(CONFIG_PATA_PLATFORM) || defined(CONFIG_PATA_PLATFORM_MODULE)
409 &bfin_pata_device,
351#endif 410#endif
352}; 411};
353 412
@@ -358,6 +417,10 @@ static int __init cm_bf537_init(void)
358#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE) 417#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
359 spi_register_board_info(bfin_spi_board_info, ARRAY_SIZE(bfin_spi_board_info)); 418 spi_register_board_info(bfin_spi_board_info, ARRAY_SIZE(bfin_spi_board_info));
360#endif 419#endif
420
421#if defined(CONFIG_PATA_PLATFORM) || defined(CONFIG_PATA_PLATFORM_MODULE)
422 irq_desc[PATA_INT].status |= IRQ_NOAUTOEN;
423#endif
361 return 0; 424 return 0;
362} 425}
363 426
diff --git a/arch/blackfin/mach-bf537/boards/generic_board.c b/arch/blackfin/mach-bf537/boards/generic_board.c
index 648d984e98d6..5e9d09eb8579 100644
--- a/arch/blackfin/mach-bf537/boards/generic_board.c
+++ b/arch/blackfin/mach-bf537/boards/generic_board.c
@@ -8,7 +8,7 @@
8 * 8 *
9 * Modified: 9 * Modified:
10 * Copyright 2005 National ICT Australia (NICTA) 10 * Copyright 2005 National ICT Australia (NICTA)
11 * Copyright 2004-2006 Analog Devices Inc. 11 * Copyright 2004-2007 Analog Devices Inc.
12 * 12 *
13 * Bugs: Enter bugs at http://blackfin.uclinux.org/ 13 * Bugs: Enter bugs at http://blackfin.uclinux.org/
14 * 14 *
@@ -34,20 +34,74 @@
34#include <linux/mtd/partitions.h> 34#include <linux/mtd/partitions.h>
35#include <linux/spi/spi.h> 35#include <linux/spi/spi.h>
36#include <linux/spi/flash.h> 36#include <linux/spi/flash.h>
37#if defined(CONFIG_USB_ISP1362_HCD) || defined(CONFIG_USB_ISP1362_HCD_MODULE)
37#include <linux/usb_isp1362.h> 38#include <linux/usb_isp1362.h>
39#endif
40#include <linux/pata_platform.h>
38#include <linux/irq.h> 41#include <linux/irq.h>
42#include <linux/interrupt.h>
39#include <linux/usb_sl811.h> 43#include <linux/usb_sl811.h>
44#include <asm/dma.h>
40#include <asm/bfin5xx_spi.h> 45#include <asm/bfin5xx_spi.h>
46#include <asm/reboot.h>
47#include <linux/spi/ad7877.h>
41 48
42/* 49/*
43 * Name the Board for the /proc/cpuinfo 50 * Name the Board for the /proc/cpuinfo
44 */ 51 */
45char *bfin_board_name = "UNKNOWN BOARD"; 52char *bfin_board_name = "GENERIC Board";
46 53
47/* 54/*
48 * Driver needs to know address, irq and flag pin. 55 * Driver needs to know address, irq and flag pin.
49 */ 56 */
50 57
58#define ISP1761_BASE 0x203C0000
59#define ISP1761_IRQ IRQ_PF7
60
61#if defined(CONFIG_USB_ISP1760_HCD) || defined(CONFIG_USB_ISP1760_HCD_MODULE)
62static struct resource bfin_isp1761_resources[] = {
63 [0] = {
64 .name = "isp1761-regs",
65 .start = ISP1761_BASE + 0x00000000,
66 .end = ISP1761_BASE + 0x000fffff,
67 .flags = IORESOURCE_MEM,
68 },
69 [1] = {
70 .start = ISP1761_IRQ,
71 .end = ISP1761_IRQ,
72 .flags = IORESOURCE_IRQ,
73 },
74};
75
76static struct platform_device bfin_isp1761_device = {
77 .name = "isp1761",
78 .id = 0,
79 .num_resources = ARRAY_SIZE(bfin_isp1761_resources),
80 .resource = bfin_isp1761_resources,
81};
82
83static struct platform_device *bfin_isp1761_devices[] = {
84 &bfin_isp1761_device,
85};
86
87int __init bfin_isp1761_init(void)
88{
89 unsigned int num_devices = ARRAY_SIZE(bfin_isp1761_devices);
90
91 printk(KERN_INFO "%s(): registering device resources\n", __FUNCTION__);
92 set_irq_type(ISP1761_IRQ, IRQF_TRIGGER_FALLING);
93
94 return platform_add_devices(bfin_isp1761_devices, num_devices);
95}
96
97void __exit bfin_isp1761_exit(void)
98{
99 platform_device_unregister(&bfin_isp1761_device);
100}
101
102arch_initcall(bfin_isp1761_init);
103#endif
104
51#if defined(CONFIG_BFIN_CFPCMCIA) || defined(CONFIG_BFIN_CFPCMCIA_MODULE) 105#if defined(CONFIG_BFIN_CFPCMCIA) || defined(CONFIG_BFIN_CFPCMCIA_MODULE)
52static struct resource bfin_pcmcia_cf_resources[] = { 106static struct resource bfin_pcmcia_cf_resources[] = {
53 { 107 {
@@ -59,10 +113,6 @@ static struct resource bfin_pcmcia_cf_resources[] = {
59 .end = 0x20311FFF, 113 .end = 0x20311FFF,
60 .flags = IORESOURCE_MEM, 114 .flags = IORESOURCE_MEM,
61 }, { 115 }, {
62 .start = IRQ_PROG_INTA,
63 .end = IRQ_PROG_INTA,
64 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
65 }, {
66 .start = IRQ_PF4, 116 .start = IRQ_PF4,
67 .end = IRQ_PF4, 117 .end = IRQ_PF4,
68 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL, 118 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
@@ -96,14 +146,7 @@ static struct resource smc91x_resources[] = {
96 .end = 0x20300300 + 16, 146 .end = 0x20300300 + 16,
97 .flags = IORESOURCE_MEM, 147 .flags = IORESOURCE_MEM,
98 }, { 148 }, {
99 .start = IRQ_PROG_INTB, 149
100 .end = IRQ_PROG_INTB,
101 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL,
102 }, {
103 /*
104 * denotes the flag pin and is used directly if
105 * CONFIG_IRQCHIP_DEMUX_GPIO is defined.
106 */
107 .start = IRQ_PF7, 150 .start = IRQ_PF7,
108 .end = IRQ_PF7, 151 .end = IRQ_PF7,
109 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL, 152 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL,
@@ -117,6 +160,28 @@ static struct platform_device smc91x_device = {
117}; 160};
118#endif 161#endif
119 162
163#if defined(CONFIG_DM9000) || defined(CONFIG_DM9000_MODULE)
164static struct resource dm9000_resources[] = {
165 [0] = {
166 .start = 0x203FB800,
167 .end = 0x203FB800 + 8,
168 .flags = IORESOURCE_MEM,
169 },
170 [1] = {
171 .start = IRQ_PF9,
172 .end = IRQ_PF9,
173 .flags = (IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE),
174 },
175};
176
177static struct platform_device dm9000_device = {
178 .name = "dm9000",
179 .id = -1,
180 .num_resources = ARRAY_SIZE(dm9000_resources),
181 .resource = dm9000_resources,
182};
183#endif
184
120#if defined(CONFIG_USB_SL811_HCD) || defined(CONFIG_USB_SL811_HCD_MODULE) 185#if defined(CONFIG_USB_SL811_HCD) || defined(CONFIG_USB_SL811_HCD_MODULE)
121static struct resource sl811_hcd_resources[] = { 186static struct resource sl811_hcd_resources[] = {
122 { 187 {
@@ -128,12 +193,8 @@ static struct resource sl811_hcd_resources[] = {
128 .end = 0x20340004, 193 .end = 0x20340004,
129 .flags = IORESOURCE_MEM, 194 .flags = IORESOURCE_MEM,
130 }, { 195 }, {
131 .start = IRQ_PROG_INTA, 196 .start = CONFIG_USB_SL811_BFIN_IRQ,
132 .end = IRQ_PROG_INTA, 197 .end = CONFIG_USB_SL811_BFIN_IRQ,
133 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL,
134 }, {
135 .start = IRQ_PF0 + CONFIG_USB_SL811_BFIN_GPIO,
136 .end = IRQ_PF0 + CONFIG_USB_SL811_BFIN_GPIO,
137 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL, 198 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL,
138 }, 199 },
139}; 200};
@@ -141,21 +202,19 @@ static struct resource sl811_hcd_resources[] = {
141#if defined(CONFIG_USB_SL811_BFIN_USE_VBUS) 202#if defined(CONFIG_USB_SL811_BFIN_USE_VBUS)
142void sl811_port_power(struct device *dev, int is_on) 203void sl811_port_power(struct device *dev, int is_on)
143{ 204{
144 unsigned short mask = (1<<CONFIG_USB_SL811_BFIN_GPIO_VBUS); 205 gpio_request(CONFIG_USB_SL811_BFIN_GPIO_VBUS, "usb:SL811_VBUS");
145 206 gpio_direction_output(CONFIG_USB_SL811_BFIN_GPIO_VBUS);
146 bfin_write_PORT_FER(bfin_read_PORT_FER() & ~mask);
147 bfin_write_FIO_DIR(bfin_read_FIO_DIR() | mask);
148 207
149 if (is_on) 208 if (is_on)
150 bfin_write_FIO_FLAG_S(mask); 209 gpio_set_value(CONFIG_USB_SL811_BFIN_GPIO_VBUS, 1);
151 else 210 else
152 bfin_write_FIO_FLAG_C(mask); 211 gpio_set_value(CONFIG_USB_SL811_BFIN_GPIO_VBUS, 0);
153} 212}
154#endif 213#endif
155 214
156static struct sl811_platform_data sl811_priv = { 215static struct sl811_platform_data sl811_priv = {
157 .potpg = 10, 216 .potpg = 10,
158 .power = 250, /* == 500mA */ 217 .power = 250, /* == 500mA */
159#if defined(CONFIG_USB_SL811_BFIN_USE_VBUS) 218#if defined(CONFIG_USB_SL811_BFIN_USE_VBUS)
160 .port_power = &sl811_port_power, 219 .port_power = &sl811_port_power,
161#endif 220#endif
@@ -170,7 +229,6 @@ static struct platform_device sl811_hcd_device = {
170 .num_resources = ARRAY_SIZE(sl811_hcd_resources), 229 .num_resources = ARRAY_SIZE(sl811_hcd_resources),
171 .resource = sl811_hcd_resources, 230 .resource = sl811_hcd_resources,
172}; 231};
173
174#endif 232#endif
175 233
176#if defined(CONFIG_USB_ISP1362_HCD) || defined(CONFIG_USB_ISP1362_HCD_MODULE) 234#if defined(CONFIG_USB_ISP1362_HCD) || defined(CONFIG_USB_ISP1362_HCD_MODULE)
@@ -184,13 +242,9 @@ static struct resource isp1362_hcd_resources[] = {
184 .end = 0x20360004, 242 .end = 0x20360004,
185 .flags = IORESOURCE_MEM, 243 .flags = IORESOURCE_MEM,
186 }, { 244 }, {
187 .start = IRQ_PROG_INTA, 245 .start = CONFIG_USB_ISP1362_BFIN_GPIO_IRQ,
188 .end = IRQ_PROG_INTA, 246 .end = CONFIG_USB_ISP1362_BFIN_GPIO_IRQ,
189 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL, 247 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL,
190 }, {
191 .start = IRQ_PF0 + CONFIG_USB_ISP1362_BFIN_GPIO,
192 .end = IRQ_PF0 + CONFIG_USB_ISP1362_BFIN_GPIO,
193 .flags = IORESOURCE_IRQ,
194 }, 248 },
195}; 249};
196 250
@@ -246,7 +300,8 @@ static struct platform_device net2272_bfin_device = {
246#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE) 300#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
247/* all SPI peripherals info goes here */ 301/* all SPI peripherals info goes here */
248 302
249#if defined(CONFIG_MTD_M25P80) || defined(CONFIG_MTD_M25P80_MODULE) 303#if defined(CONFIG_MTD_M25P80) \
304 || defined(CONFIG_MTD_M25P80_MODULE)
250static struct mtd_partition bfin_spi_flash_partitions[] = { 305static struct mtd_partition bfin_spi_flash_partitions[] = {
251 { 306 {
252 .name = "bootloader", 307 .name = "bootloader",
@@ -302,70 +357,198 @@ static struct bfin5xx_spi_chip ad9960_spi_chip_info = {
302}; 357};
303#endif 358#endif
304 359
360#if defined(CONFIG_SPI_MMC) || defined(CONFIG_SPI_MMC_MODULE)
361static struct bfin5xx_spi_chip spi_mmc_chip_info = {
362 .enable_dma = 1,
363 .bits_per_word = 8,
364};
365#endif
366
367#if defined(CONFIG_PBX)
368static struct bfin5xx_spi_chip spi_si3xxx_chip_info = {
369 .ctl_reg = 0x4, /* send zero */
370 .enable_dma = 0,
371 .bits_per_word = 8,
372 .cs_change_per_word = 1,
373};
374#endif
375
376#if defined(CONFIG_AD5304) || defined(CONFIG_AD5304_MODULE)
377static struct bfin5xx_spi_chip ad5304_chip_info = {
378 .enable_dma = 0,
379 .bits_per_word = 16,
380};
381#endif
382
383#if defined(CONFIG_TOUCHSCREEN_AD7877) || defined(CONFIG_TOUCHSCREEN_AD7877_MODULE)
384static struct bfin5xx_spi_chip spi_ad7877_chip_info = {
385 .enable_dma = 0,
386 .bits_per_word = 16,
387};
388
389static const struct ad7877_platform_data bfin_ad7877_ts_info = {
390 .model = 7877,
391 .vref_delay_usecs = 50, /* internal, no capacitor */
392 .x_plate_ohms = 419,
393 .y_plate_ohms = 486,
394 .pressure_max = 1000,
395 .pressure_min = 0,
396 .stopacq_polarity = 1,
397 .first_conversion_delay = 3,
398 .acquisition_time = 1,
399 .averaging = 1,
400 .pen_down_acc_interval = 1,
401};
402#endif
403
305static struct spi_board_info bfin_spi_board_info[] __initdata = { 404static struct spi_board_info bfin_spi_board_info[] __initdata = {
306#if defined(CONFIG_MTD_M25P80) || defined(CONFIG_MTD_M25P80_MODULE) 405#if defined(CONFIG_MTD_M25P80) \
406 || defined(CONFIG_MTD_M25P80_MODULE)
307 { 407 {
308 /* the modalias must be the same as spi device driver name */ 408 /* the modalias must be the same as spi device driver name */
309 .modalias = "m25p80", /* Name of spi_driver for this device */ 409 .modalias = "m25p80", /* Name of spi_driver for this device */
310 .max_speed_hz = 25000000, /* max spi clock (SCK) speed in HZ */ 410 .max_speed_hz = 25000000, /* max spi clock (SCK) speed in HZ */
311 .bus_num = 1, /* Framework bus number */ 411 .bus_num = 0, /* Framework bus number */
312 .chip_select = 2, /* Framework chip select. On STAMP537 it is SPISSEL1*/ 412 .chip_select = 1, /* Framework chip select. On STAMP537 it is SPISSEL1*/
313 .platform_data = &bfin_spi_flash_data, 413 .platform_data = &bfin_spi_flash_data,
314 .controller_data = &spi_flash_chip_info, 414 .controller_data = &spi_flash_chip_info,
315 .mode = SPI_MODE_3, 415 .mode = SPI_MODE_3,
316 }, 416 },
317#endif 417#endif
318 418
319#if defined(CONFIG_SPI_ADC_BF533) || defined(CONFIG_SPI_ADC_BF533_MODULE) 419#if defined(CONFIG_SPI_ADC_BF533) \
420 || defined(CONFIG_SPI_ADC_BF533_MODULE)
320 { 421 {
321 .modalias = "bfin_spi_adc", /* Name of spi_driver for this device */ 422 .modalias = "bfin_spi_adc", /* Name of spi_driver for this device */
322 .max_speed_hz = 6250000, /* max spi clock (SCK) speed in HZ */ 423 .max_speed_hz = 6250000, /* max spi clock (SCK) speed in HZ */
323 .bus_num = 1, /* Framework bus number */ 424 .bus_num = 0, /* Framework bus number */
324 .chip_select = 1, /* Framework chip select. */ 425 .chip_select = 1, /* Framework chip select. */
325 .platform_data = NULL, /* No spi_driver specific config */ 426 .platform_data = NULL, /* No spi_driver specific config */
326 .controller_data = &spi_adc_chip_info, 427 .controller_data = &spi_adc_chip_info,
327 }, 428 },
328#endif 429#endif
329 430
330#if defined(CONFIG_SND_BLACKFIN_AD1836) || defined(CONFIG_SND_BLACKFIN_AD1836_MODULE) 431#if defined(CONFIG_SND_BLACKFIN_AD1836) \
432 || defined(CONFIG_SND_BLACKFIN_AD1836_MODULE)
331 { 433 {
332 .modalias = "ad1836-spi", 434 .modalias = "ad1836-spi",
333 .max_speed_hz = 3125000, /* max spi clock (SCK) speed in HZ */ 435 .max_speed_hz = 3125000, /* max spi clock (SCK) speed in HZ */
334 .bus_num = 1, 436 .bus_num = 0,
335 .chip_select = CONFIG_SND_BLACKFIN_SPI_PFBIT, 437 .chip_select = CONFIG_SND_BLACKFIN_SPI_PFBIT,
336 .controller_data = &ad1836_spi_chip_info, 438 .controller_data = &ad1836_spi_chip_info,
337 }, 439 },
338#endif 440#endif
339
340#if defined(CONFIG_AD9960) || defined(CONFIG_AD9960_MODULE) 441#if defined(CONFIG_AD9960) || defined(CONFIG_AD9960_MODULE)
341 { 442 {
342 .modalias = "ad9960-spi", 443 .modalias = "ad9960-spi",
343 .max_speed_hz = 10000000, /* max spi clock (SCK) speed in HZ */ 444 .max_speed_hz = 10000000, /* max spi clock (SCK) speed in HZ */
344 .bus_num = 1, 445 .bus_num = 0,
345 .chip_select = 1, 446 .chip_select = 1,
346 .controller_data = &ad9960_spi_chip_info, 447 .controller_data = &ad9960_spi_chip_info,
347 }, 448 },
348#endif 449#endif
450#if defined(CONFIG_SPI_MMC) || defined(CONFIG_SPI_MMC_MODULE)
451 {
452 .modalias = "spi_mmc_dummy",
453 .max_speed_hz = 25000000, /* max spi clock (SCK) speed in HZ */
454 .bus_num = 0,
455 .chip_select = 0,
456 .platform_data = NULL,
457 .controller_data = &spi_mmc_chip_info,
458 .mode = SPI_MODE_3,
459 },
460 {
461 .modalias = "spi_mmc",
462 .max_speed_hz = 25000000, /* max spi clock (SCK) speed in HZ */
463 .bus_num = 0,
464 .chip_select = CONFIG_SPI_MMC_CS_CHAN,
465 .platform_data = NULL,
466 .controller_data = &spi_mmc_chip_info,
467 .mode = SPI_MODE_3,
468 },
469#endif
470#if defined(CONFIG_PBX)
471 {
472 .modalias = "fxs-spi",
473 .max_speed_hz = 12500000, /* max spi clock (SCK) speed in HZ */
474 .bus_num = 0,
475 .chip_select = 8 - CONFIG_J11_JUMPER,
476 .controller_data = &spi_si3xxx_chip_info,
477 .mode = SPI_MODE_3,
478 },
479 {
480 .modalias = "fxo-spi",
481 .max_speed_hz = 12500000, /* max spi clock (SCK) speed in HZ */
482 .bus_num = 0,
483 .chip_select = 8 - CONFIG_J19_JUMPER,
484 .controller_data = &spi_si3xxx_chip_info,
485 .mode = SPI_MODE_3,
486 },
487#endif
488#if defined(CONFIG_AD5304) || defined(CONFIG_AD5304_MODULE)
489 {
490 .modalias = "ad5304_spi",
491 .max_speed_hz = 1250000, /* max spi clock (SCK) speed in HZ */
492 .bus_num = 0,
493 .chip_select = 2,
494 .platform_data = NULL,
495 .controller_data = &ad5304_chip_info,
496 .mode = SPI_MODE_2,
497 },
498#endif
499#if defined(CONFIG_TOUCHSCREEN_AD7877) || defined(CONFIG_TOUCHSCREEN_AD7877_MODULE)
500 {
501 .modalias = "ad7877",
502 .platform_data = &bfin_ad7877_ts_info,
503 .irq = IRQ_PF6,
504 .max_speed_hz = 12500000, /* max spi clock (SCK) speed in HZ */
505 .bus_num = 1,
506 .chip_select = 1,
507 .controller_data = &spi_ad7877_chip_info,
508 },
509#endif
349}; 510};
350 511
351/* SPI controller data */ 512/* SPI controller data */
352static struct bfin5xx_spi_master spi_bfin_master_info = { 513static struct bfin5xx_spi_master bfin_spi0_info = {
353 .num_chipselect = 8, 514 .num_chipselect = 8,
354 .enable_dma = 1, /* master has the ability to do dma transfer */ 515 .enable_dma = 1, /* master has the ability to do dma transfer */
355}; 516};
356 517
357static struct platform_device spi_bfin_master_device = { 518/* SPI (0) */
358 .name = "bfin-spi-master", 519static struct resource bfin_spi0_resource[] = {
359 .id = 1, /* Bus number */ 520 [0] = {
521 .start = SPI0_REGBASE,
522 .end = SPI0_REGBASE + 0xFF,
523 .flags = IORESOURCE_MEM,
524 },
525 [1] = {
526 .start = CH_SPI,
527 .end = CH_SPI,
528 .flags = IORESOURCE_IRQ,
529 },
530};
531
532static struct platform_device bfin_spi0_device = {
533 .name = "bfin-spi",
534 .id = 0, /* Bus number */
535 .num_resources = ARRAY_SIZE(bfin_spi0_resource),
536 .resource = bfin_spi0_resource,
360 .dev = { 537 .dev = {
361 .platform_data = &spi_bfin_master_info, /* Passed to driver */ 538 .platform_data = &bfin_spi0_info, /* Passed to driver */
362 }, 539 },
363}; 540};
364#endif /* spi master and devices */ 541#endif /* spi master and devices */
365 542
366#if defined(CONFIG_FB_BF537_LQ035) || defined(CONFIG_FB_BF537_LQ035_MODULE) 543#if defined(CONFIG_FB_BF537_LQ035) || defined(CONFIG_FB_BF537_LQ035_MODULE)
367static struct platform_device bfin_fb_device = { 544static struct platform_device bfin_fb_device = {
368 .name = "bf537-fb", 545 .name = "bf537-lq035",
546};
547#endif
548
549#if defined(CONFIG_FB_BFIN_7393) || defined(CONFIG_FB_BFIN_7393_MODULE)
550static struct platform_device bfin_fb_adv7393_device = {
551 .name = "bfin-adv7393",
369}; 552};
370#endif 553#endif
371 554
@@ -390,15 +573,86 @@ static struct platform_device bfin_uart_device = {
390}; 573};
391#endif 574#endif
392 575
393static struct platform_device *stamp_devices[] __initdata = { 576#if defined(CONFIG_I2C_BLACKFIN_TWI) || defined(CONFIG_I2C_BLACKFIN_TWI_MODULE)
394#if defined(CONFIG_RTC_DRV_BFIN) || defined(CONFIG_RTC_DRV_BFIN_MODULE) 577static struct resource bfin_twi0_resource[] = {
395 &rtc_device, 578 [0] = {
579 .start = TWI0_REGBASE,
580 .end = TWI0_REGBASE + 0xFF,
581 .flags = IORESOURCE_MEM,
582 },
583 [1] = {
584 .start = IRQ_TWI,
585 .end = IRQ_TWI,
586 .flags = IORESOURCE_IRQ,
587 },
588};
589
590static struct platform_device i2c_bfin_twi_device = {
591 .name = "i2c-bfin-twi",
592 .id = 0,
593 .num_resources = ARRAY_SIZE(bfin_twi0_resource),
594 .resource = bfin_twi0_resource,
595};
596#endif
597
598#if defined(CONFIG_SERIAL_BFIN_SPORT) || defined(CONFIG_SERIAL_BFIN_SPORT_MODULE)
599static struct platform_device bfin_sport0_uart_device = {
600 .name = "bfin-sport-uart",
601 .id = 0,
602};
603
604static struct platform_device bfin_sport1_uart_device = {
605 .name = "bfin-sport-uart",
606 .id = 1,
607};
608#endif
609
610#if defined(CONFIG_PATA_PLATFORM) || defined(CONFIG_PATA_PLATFORM_MODULE)
611#define PATA_INT 55
612
613static struct pata_platform_info bfin_pata_platform_data = {
614 .ioport_shift = 1,
615 .irq_type = IRQF_TRIGGER_HIGH | IRQF_DISABLED,
616};
617
618static struct resource bfin_pata_resources[] = {
619 {
620 .start = 0x20314020,
621 .end = 0x2031403F,
622 .flags = IORESOURCE_MEM,
623 },
624 {
625 .start = 0x2031401C,
626 .end = 0x2031401F,
627 .flags = IORESOURCE_MEM,
628 },
629 {
630 .start = PATA_INT,
631 .end = PATA_INT,
632 .flags = IORESOURCE_IRQ,
633 },
634};
635
636static struct platform_device bfin_pata_device = {
637 .name = "pata_platform",
638 .id = -1,
639 .num_resources = ARRAY_SIZE(bfin_pata_resources),
640 .resource = bfin_pata_resources,
641 .dev = {
642 .platform_data = &bfin_pata_platform_data,
643 }
644};
396#endif 645#endif
397 646
647static struct platform_device *stamp_devices[] __initdata = {
398#if defined(CONFIG_BFIN_CFPCMCIA) || defined(CONFIG_BFIN_CFPCMCIA_MODULE) 648#if defined(CONFIG_BFIN_CFPCMCIA) || defined(CONFIG_BFIN_CFPCMCIA_MODULE)
399 &bfin_pcmcia_cf_device, 649 &bfin_pcmcia_cf_device,
400#endif 650#endif
401 651
652#if defined(CONFIG_RTC_DRV_BFIN) || defined(CONFIG_RTC_DRV_BFIN_MODULE)
653 &rtc_device,
654#endif
655
402#if defined(CONFIG_USB_SL811_HCD) || defined(CONFIG_USB_SL811_HCD_MODULE) 656#if defined(CONFIG_USB_SL811_HCD) || defined(CONFIG_USB_SL811_HCD_MODULE)
403 &sl811_hcd_device, 657 &sl811_hcd_device,
404#endif 658#endif
@@ -411,6 +665,10 @@ static struct platform_device *stamp_devices[] __initdata = {
411 &smc91x_device, 665 &smc91x_device,
412#endif 666#endif
413 667
668#if defined(CONFIG_DM9000) || defined(CONFIG_DM9000_MODULE)
669 &dm9000_device,
670#endif
671
414#if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE) 672#if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
415 &bfin_mac_device, 673 &bfin_mac_device,
416#endif 674#endif
@@ -420,16 +678,33 @@ static struct platform_device *stamp_devices[] __initdata = {
420#endif 678#endif
421 679
422#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE) 680#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
423 &spi_bfin_master_device, 681 &bfin_spi0_device,
424#endif 682#endif
425 683
426#if defined(CONFIG_FB_BF537_LQ035) || defined(CONFIG_FB_BF537_LQ035_MODULE) 684#if defined(CONFIG_FB_BF537_LQ035) || defined(CONFIG_FB_BF537_LQ035_MODULE)
427 &bfin_fb_device, 685 &bfin_fb_device,
428#endif 686#endif
429 687
688#if defined(CONFIG_FB_BFIN_7393) || defined(CONFIG_FB_BFIN_7393_MODULE)
689 &bfin_fb_adv7393_device,
690#endif
691
430#if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE) 692#if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE)
431 &bfin_uart_device, 693 &bfin_uart_device,
432#endif 694#endif
695
696#if defined(CONFIG_I2C_BLACKFIN_TWI) || defined(CONFIG_I2C_BLACKFIN_TWI_MODULE)
697 &i2c_bfin_twi_device,
698#endif
699
700#if defined(CONFIG_SERIAL_BFIN_SPORT) || defined(CONFIG_SERIAL_BFIN_SPORT_MODULE)
701 &bfin_sport0_uart_device,
702 &bfin_sport1_uart_device,
703#endif
704
705#if defined(CONFIG_PATA_PLATFORM) || defined(CONFIG_PATA_PLATFORM_MODULE)
706 &bfin_pata_device,
707#endif
433}; 708};
434 709
435static int __init stamp_init(void) 710static int __init stamp_init(void)
@@ -437,9 +712,21 @@ static int __init stamp_init(void)
437 printk(KERN_INFO "%s(): registering device resources\n", __FUNCTION__); 712 printk(KERN_INFO "%s(): registering device resources\n", __FUNCTION__);
438 platform_add_devices(stamp_devices, ARRAY_SIZE(stamp_devices)); 713 platform_add_devices(stamp_devices, ARRAY_SIZE(stamp_devices));
439#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE) 714#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
440 spi_register_board_info(bfin_spi_board_info, ARRAY_SIZE(bfin_spi_board_info)); 715 spi_register_board_info(bfin_spi_board_info,
716 ARRAY_SIZE(bfin_spi_board_info));
717#endif
718
719#if defined(CONFIG_PATA_PLATFORM) || defined(CONFIG_PATA_PLATFORM_MODULE)
720 irq_desc[PATA_INT].status |= IRQ_NOAUTOEN;
441#endif 721#endif
442 return 0; 722 return 0;
443} 723}
444 724
445arch_initcall(stamp_init); 725arch_initcall(stamp_init);
726
727void native_machine_restart(char *cmd)
728{
729 /* workaround reboot hang when booting from SPI */
730 if ((bfin_read_SYSCR() & 0x7) == 0x3)
731 bfin_gpio_reset_spi0_ssel1();
732}
diff --git a/arch/blackfin/mach-bf537/boards/pnav10.c b/arch/blackfin/mach-bf537/boards/pnav10.c
index 8806f1230f2d..20507e92a3a4 100644
--- a/arch/blackfin/mach-bf537/boards/pnav10.c
+++ b/arch/blackfin/mach-bf537/boards/pnav10.c
@@ -38,6 +38,7 @@
38#include <linux/usb_isp1362.h> 38#include <linux/usb_isp1362.h>
39#endif 39#endif
40#include <linux/irq.h> 40#include <linux/irq.h>
41#include <asm/dma.h>
41#include <asm/bfin5xx_spi.h> 42#include <asm/bfin5xx_spi.h>
42#include <linux/usb_sl811.h> 43#include <linux/usb_sl811.h>
43 44
@@ -130,15 +131,13 @@ static struct resource sl811_hcd_resources[] = {
130#if defined(CONFIG_USB_SL811_BFIN_USE_VBUS) 131#if defined(CONFIG_USB_SL811_BFIN_USE_VBUS)
131void sl811_port_power(struct device *dev, int is_on) 132void sl811_port_power(struct device *dev, int is_on)
132{ 133{
133 unsigned short mask = (1 << CONFIG_USB_SL811_BFIN_GPIO_VBUS); 134 gpio_request(CONFIG_USB_SL811_BFIN_GPIO_VBUS, "usb:SL811_VBUS");
134 135 gpio_direction_output(CONFIG_USB_SL811_BFIN_GPIO_VBUS);
135 bfin_write_PORT_FER(bfin_read_PORT_FER() & ~mask);
136 bfin_write_FIO_DIR(bfin_read_FIO_DIR() | mask);
137 136
138 if (is_on) 137 if (is_on)
139 bfin_write_FIO_FLAG_S(mask); 138 gpio_set_value(CONFIG_USB_SL811_BFIN_GPIO_VBUS, 1);
140 else 139 else
141 bfin_write_FIO_FLAG_C(mask); 140 gpio_set_value(CONFIG_USB_SL811_BFIN_GPIO_VBUS, 0);
142} 141}
143#endif 142#endif
144 143
@@ -323,7 +322,7 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
323 /* the modalias must be the same as spi device driver name */ 322 /* the modalias must be the same as spi device driver name */
324 .modalias = "m25p80", /* Name of spi_driver for this device */ 323 .modalias = "m25p80", /* Name of spi_driver for this device */
325 .max_speed_hz = 25000000, /* max spi clock (SCK) speed in HZ */ 324 .max_speed_hz = 25000000, /* max spi clock (SCK) speed in HZ */
326 .bus_num = 1, /* Framework bus number */ 325 .bus_num = 0, /* Framework bus number */
327 .chip_select = 1, /* Framework chip select. On STAMP537 it is SPISSEL1*/ 326 .chip_select = 1, /* Framework chip select. On STAMP537 it is SPISSEL1*/
328 .platform_data = &bfin_spi_flash_data, 327 .platform_data = &bfin_spi_flash_data,
329 .controller_data = &spi_flash_chip_info, 328 .controller_data = &spi_flash_chip_info,
@@ -336,7 +335,7 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
336 { 335 {
337 .modalias = "bfin_spi_adc", /* Name of spi_driver for this device */ 336 .modalias = "bfin_spi_adc", /* Name of spi_driver for this device */
338 .max_speed_hz = 6250000, /* max spi clock (SCK) speed in HZ */ 337 .max_speed_hz = 6250000, /* max spi clock (SCK) speed in HZ */
339 .bus_num = 1, /* Framework bus number */ 338 .bus_num = 0, /* Framework bus number */
340 .chip_select = 1, /* Framework chip select. */ 339 .chip_select = 1, /* Framework chip select. */
341 .platform_data = NULL, /* No spi_driver specific config */ 340 .platform_data = NULL, /* No spi_driver specific config */
342 .controller_data = &spi_adc_chip_info, 341 .controller_data = &spi_adc_chip_info,
@@ -348,7 +347,7 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
348 { 347 {
349 .modalias = "ad1836-spi", 348 .modalias = "ad1836-spi",
350 .max_speed_hz = 3125000, /* max spi clock (SCK) speed in HZ */ 349 .max_speed_hz = 3125000, /* max spi clock (SCK) speed in HZ */
351 .bus_num = 1, 350 .bus_num = 0,
352 .chip_select = CONFIG_SND_BLACKFIN_SPI_PFBIT, 351 .chip_select = CONFIG_SND_BLACKFIN_SPI_PFBIT,
353 .controller_data = &ad1836_spi_chip_info, 352 .controller_data = &ad1836_spi_chip_info,
354 }, 353 },
@@ -357,7 +356,7 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
357 { 356 {
358 .modalias = "ad9960-spi", 357 .modalias = "ad9960-spi",
359 .max_speed_hz = 10000000, /* max spi clock (SCK) speed in HZ */ 358 .max_speed_hz = 10000000, /* max spi clock (SCK) speed in HZ */
360 .bus_num = 1, 359 .bus_num = 0,
361 .chip_select = 1, 360 .chip_select = 1,
362 .controller_data = &ad9960_spi_chip_info, 361 .controller_data = &ad9960_spi_chip_info,
363 }, 362 },
@@ -366,7 +365,7 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
366 { 365 {
367 .modalias = "spi_mmc_dummy", 366 .modalias = "spi_mmc_dummy",
368 .max_speed_hz = 25000000, /* max spi clock (SCK) speed in HZ */ 367 .max_speed_hz = 25000000, /* max spi clock (SCK) speed in HZ */
369 .bus_num = 1, 368 .bus_num = 0,
370 .chip_select = 7, 369 .chip_select = 7,
371 .platform_data = NULL, 370 .platform_data = NULL,
372 .controller_data = &spi_mmc_chip_info, 371 .controller_data = &spi_mmc_chip_info,
@@ -375,7 +374,7 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
375 { 374 {
376 .modalias = "spi_mmc", 375 .modalias = "spi_mmc",
377 .max_speed_hz = 25000000, /* max spi clock (SCK) speed in HZ */ 376 .max_speed_hz = 25000000, /* max spi clock (SCK) speed in HZ */
378 .bus_num = 1, 377 .bus_num = 0,
379 .chip_select = CONFIG_SPI_MMC_CS_CHAN, 378 .chip_select = CONFIG_SPI_MMC_CS_CHAN,
380 .platform_data = NULL, 379 .platform_data = NULL,
381 .controller_data = &spi_mmc_chip_info, 380 .controller_data = &spi_mmc_chip_info,
@@ -396,24 +395,40 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
396 395
397}; 396};
398 397
398/* SPI (0) */
399static struct resource bfin_spi0_resource[] = {
400 [0] = {
401 .start = SPI0_REGBASE,
402 .end = SPI0_REGBASE + 0xFF,
403 .flags = IORESOURCE_MEM,
404 },
405 [1] = {
406 .start = CH_SPI,
407 .end = CH_SPI,
408 .flags = IORESOURCE_IRQ,
409 }
410};
411
399/* SPI controller data */ 412/* SPI controller data */
400static struct bfin5xx_spi_master spi_bfin_master_info = { 413static struct bfin5xx_spi_master bfin_spi0_info = {
401 .num_chipselect = 8, 414 .num_chipselect = 8,
402 .enable_dma = 1, /* master has the ability to do dma transfer */ 415 .enable_dma = 1, /* master has the ability to do dma transfer */
403}; 416};
404 417
405static struct platform_device spi_bfin_master_device = { 418static struct platform_device bfin_spi0_device = {
406 .name = "bfin-spi-master", 419 .name = "bfin-spi",
407 .id = 1, /* Bus number */ 420 .id = 0, /* Bus number */
421 .num_resources = ARRAY_SIZE(bfin_spi0_resource),
422 .resource = bfin_spi0_resource,
408 .dev = { 423 .dev = {
409 .platform_data = &spi_bfin_master_info, /* Passed to driver */ 424 .platform_data = &bfin_spi0_info, /* Passed to driver */
410 }, 425 },
411}; 426};
412#endif /* spi master and devices */ 427#endif /* spi master and devices */
413 428
414#if defined(CONFIG_FB_BF537_LQ035) || defined(CONFIG_FB_BF537_LQ035_MODULE) 429#if defined(CONFIG_FB_BF537_LQ035) || defined(CONFIG_FB_BF537_LQ035_MODULE)
415static struct platform_device bfin_fb_device = { 430static struct platform_device bfin_fb_device = {
416 .name = "bf537-fb", 431 .name = "bf537-lq035",
417}; 432};
418#endif 433#endif
419 434
@@ -469,7 +484,7 @@ static struct platform_device *stamp_devices[] __initdata = {
469#endif 484#endif
470 485
471#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE) 486#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
472 &spi_bfin_master_device, 487 &bfin_spi0_device,
473#endif 488#endif
474 489
475#if defined(CONFIG_FB_BF537_LQ035) || defined(CONFIG_FB_BF537_LQ035_MODULE) 490#if defined(CONFIG_FB_BF537_LQ035) || defined(CONFIG_FB_BF537_LQ035_MODULE)
diff --git a/arch/blackfin/mach-bf537/boards/stamp.c b/arch/blackfin/mach-bf537/boards/stamp.c
index 9c43d7756510..47d7d4a0e73d 100644
--- a/arch/blackfin/mach-bf537/boards/stamp.c
+++ b/arch/blackfin/mach-bf537/boards/stamp.c
@@ -37,10 +37,13 @@
37#if defined(CONFIG_USB_ISP1362_HCD) || defined(CONFIG_USB_ISP1362_HCD_MODULE) 37#if defined(CONFIG_USB_ISP1362_HCD) || defined(CONFIG_USB_ISP1362_HCD_MODULE)
38#include <linux/usb_isp1362.h> 38#include <linux/usb_isp1362.h>
39#endif 39#endif
40#include <linux/pata_platform.h>
40#include <linux/irq.h> 41#include <linux/irq.h>
41#include <linux/interrupt.h> 42#include <linux/interrupt.h>
42#include <linux/usb_sl811.h> 43#include <linux/usb_sl811.h>
44#include <asm/dma.h>
43#include <asm/bfin5xx_spi.h> 45#include <asm/bfin5xx_spi.h>
46#include <asm/reboot.h>
44#include <linux/spi/ad7877.h> 47#include <linux/spi/ad7877.h>
45 48
46/* 49/*
@@ -199,15 +202,13 @@ static struct resource sl811_hcd_resources[] = {
199#if defined(CONFIG_USB_SL811_BFIN_USE_VBUS) 202#if defined(CONFIG_USB_SL811_BFIN_USE_VBUS)
200void sl811_port_power(struct device *dev, int is_on) 203void sl811_port_power(struct device *dev, int is_on)
201{ 204{
202 unsigned short mask = (1 << CONFIG_USB_SL811_BFIN_GPIO_VBUS); 205 gpio_request(CONFIG_USB_SL811_BFIN_GPIO_VBUS, "usb:SL811_VBUS");
203 206 gpio_direction_output(CONFIG_USB_SL811_BFIN_GPIO_VBUS);
204 bfin_write_PORT_FER(bfin_read_PORT_FER() & ~mask);
205 bfin_write_FIO_DIR(bfin_read_FIO_DIR() | mask);
206 207
207 if (is_on) 208 if (is_on)
208 bfin_write_FIO_FLAG_S(mask); 209 gpio_set_value(CONFIG_USB_SL811_BFIN_GPIO_VBUS, 1);
209 else 210 else
210 bfin_write_FIO_FLAG_C(mask); 211 gpio_set_value(CONFIG_USB_SL811_BFIN_GPIO_VBUS, 0);
211} 212}
212#endif 213#endif
213 214
@@ -407,7 +408,7 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
407 /* the modalias must be the same as spi device driver name */ 408 /* the modalias must be the same as spi device driver name */
408 .modalias = "m25p80", /* Name of spi_driver for this device */ 409 .modalias = "m25p80", /* Name of spi_driver for this device */
409 .max_speed_hz = 25000000, /* max spi clock (SCK) speed in HZ */ 410 .max_speed_hz = 25000000, /* max spi clock (SCK) speed in HZ */
410 .bus_num = 1, /* Framework bus number */ 411 .bus_num = 0, /* Framework bus number */
411 .chip_select = 1, /* Framework chip select. On STAMP537 it is SPISSEL1*/ 412 .chip_select = 1, /* Framework chip select. On STAMP537 it is SPISSEL1*/
412 .platform_data = &bfin_spi_flash_data, 413 .platform_data = &bfin_spi_flash_data,
413 .controller_data = &spi_flash_chip_info, 414 .controller_data = &spi_flash_chip_info,
@@ -420,7 +421,7 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
420 { 421 {
421 .modalias = "bfin_spi_adc", /* Name of spi_driver for this device */ 422 .modalias = "bfin_spi_adc", /* Name of spi_driver for this device */
422 .max_speed_hz = 6250000, /* max spi clock (SCK) speed in HZ */ 423 .max_speed_hz = 6250000, /* max spi clock (SCK) speed in HZ */
423 .bus_num = 1, /* Framework bus number */ 424 .bus_num = 0, /* Framework bus number */
424 .chip_select = 1, /* Framework chip select. */ 425 .chip_select = 1, /* Framework chip select. */
425 .platform_data = NULL, /* No spi_driver specific config */ 426 .platform_data = NULL, /* No spi_driver specific config */
426 .controller_data = &spi_adc_chip_info, 427 .controller_data = &spi_adc_chip_info,
@@ -432,7 +433,7 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
432 { 433 {
433 .modalias = "ad1836-spi", 434 .modalias = "ad1836-spi",
434 .max_speed_hz = 3125000, /* max spi clock (SCK) speed in HZ */ 435 .max_speed_hz = 3125000, /* max spi clock (SCK) speed in HZ */
435 .bus_num = 1, 436 .bus_num = 0,
436 .chip_select = CONFIG_SND_BLACKFIN_SPI_PFBIT, 437 .chip_select = CONFIG_SND_BLACKFIN_SPI_PFBIT,
437 .controller_data = &ad1836_spi_chip_info, 438 .controller_data = &ad1836_spi_chip_info,
438 }, 439 },
@@ -441,7 +442,7 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
441 { 442 {
442 .modalias = "ad9960-spi", 443 .modalias = "ad9960-spi",
443 .max_speed_hz = 10000000, /* max spi clock (SCK) speed in HZ */ 444 .max_speed_hz = 10000000, /* max spi clock (SCK) speed in HZ */
444 .bus_num = 1, 445 .bus_num = 0,
445 .chip_select = 1, 446 .chip_select = 1,
446 .controller_data = &ad9960_spi_chip_info, 447 .controller_data = &ad9960_spi_chip_info,
447 }, 448 },
@@ -450,7 +451,7 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
450 { 451 {
451 .modalias = "spi_mmc_dummy", 452 .modalias = "spi_mmc_dummy",
452 .max_speed_hz = 25000000, /* max spi clock (SCK) speed in HZ */ 453 .max_speed_hz = 25000000, /* max spi clock (SCK) speed in HZ */
453 .bus_num = 1, 454 .bus_num = 0,
454 .chip_select = 0, 455 .chip_select = 0,
455 .platform_data = NULL, 456 .platform_data = NULL,
456 .controller_data = &spi_mmc_chip_info, 457 .controller_data = &spi_mmc_chip_info,
@@ -459,7 +460,7 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
459 { 460 {
460 .modalias = "spi_mmc", 461 .modalias = "spi_mmc",
461 .max_speed_hz = 25000000, /* max spi clock (SCK) speed in HZ */ 462 .max_speed_hz = 25000000, /* max spi clock (SCK) speed in HZ */
462 .bus_num = 1, 463 .bus_num = 0,
463 .chip_select = CONFIG_SPI_MMC_CS_CHAN, 464 .chip_select = CONFIG_SPI_MMC_CS_CHAN,
464 .platform_data = NULL, 465 .platform_data = NULL,
465 .controller_data = &spi_mmc_chip_info, 466 .controller_data = &spi_mmc_chip_info,
@@ -470,16 +471,16 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
470 { 471 {
471 .modalias = "fxs-spi", 472 .modalias = "fxs-spi",
472 .max_speed_hz = 12500000, /* max spi clock (SCK) speed in HZ */ 473 .max_speed_hz = 12500000, /* max spi clock (SCK) speed in HZ */
473 .bus_num = 1, 474 .bus_num = 0,
474 .chip_select = 3, 475 .chip_select = 8 - CONFIG_J11_JUMPER,
475 .controller_data = &spi_si3xxx_chip_info, 476 .controller_data = &spi_si3xxx_chip_info,
476 .mode = SPI_MODE_3, 477 .mode = SPI_MODE_3,
477 }, 478 },
478 { 479 {
479 .modalias = "fxo-spi", 480 .modalias = "fxo-spi",
480 .max_speed_hz = 12500000, /* max spi clock (SCK) speed in HZ */ 481 .max_speed_hz = 12500000, /* max spi clock (SCK) speed in HZ */
481 .bus_num = 1, 482 .bus_num = 0,
482 .chip_select = 2, 483 .chip_select = 8 - CONFIG_J19_JUMPER,
483 .controller_data = &spi_si3xxx_chip_info, 484 .controller_data = &spi_si3xxx_chip_info,
484 .mode = SPI_MODE_3, 485 .mode = SPI_MODE_3,
485 }, 486 },
@@ -488,7 +489,7 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
488 { 489 {
489 .modalias = "ad5304_spi", 490 .modalias = "ad5304_spi",
490 .max_speed_hz = 1250000, /* max spi clock (SCK) speed in HZ */ 491 .max_speed_hz = 1250000, /* max spi clock (SCK) speed in HZ */
491 .bus_num = 1, 492 .bus_num = 0,
492 .chip_select = 2, 493 .chip_select = 2,
493 .platform_data = NULL, 494 .platform_data = NULL,
494 .controller_data = &ad5304_chip_info, 495 .controller_data = &ad5304_chip_info,
@@ -509,23 +510,45 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
509}; 510};
510 511
511/* SPI controller data */ 512/* SPI controller data */
512static struct bfin5xx_spi_master spi_bfin_master_info = { 513static struct bfin5xx_spi_master bfin_spi0_info = {
513 .num_chipselect = 8, 514 .num_chipselect = 8,
514 .enable_dma = 1, /* master has the ability to do dma transfer */ 515 .enable_dma = 1, /* master has the ability to do dma transfer */
515}; 516};
516 517
517static struct platform_device spi_bfin_master_device = { 518/* SPI (0) */
518 .name = "bfin-spi-master", 519static struct resource bfin_spi0_resource[] = {
519 .id = 1, /* Bus number */ 520 [0] = {
521 .start = SPI0_REGBASE,
522 .end = SPI0_REGBASE + 0xFF,
523 .flags = IORESOURCE_MEM,
524 },
525 [1] = {
526 .start = CH_SPI,
527 .end = CH_SPI,
528 .flags = IORESOURCE_IRQ,
529 },
530};
531
532static struct platform_device bfin_spi0_device = {
533 .name = "bfin-spi",
534 .id = 0, /* Bus number */
535 .num_resources = ARRAY_SIZE(bfin_spi0_resource),
536 .resource = bfin_spi0_resource,
520 .dev = { 537 .dev = {
521 .platform_data = &spi_bfin_master_info, /* Passed to driver */ 538 .platform_data = &bfin_spi0_info, /* Passed to driver */
522 }, 539 },
523}; 540};
524#endif /* spi master and devices */ 541#endif /* spi master and devices */
525 542
526#if defined(CONFIG_FB_BF537_LQ035) || defined(CONFIG_FB_BF537_LQ035_MODULE) 543#if defined(CONFIG_FB_BF537_LQ035) || defined(CONFIG_FB_BF537_LQ035_MODULE)
527static struct platform_device bfin_fb_device = { 544static struct platform_device bfin_fb_device = {
528 .name = "bf537-fb", 545 .name = "bf537-lq035",
546};
547#endif
548
549#if defined(CONFIG_FB_BFIN_7393) || defined(CONFIG_FB_BFIN_7393_MODULE)
550static struct platform_device bfin_fb_adv7393_device = {
551 .name = "bfin-adv7393",
529}; 552};
530#endif 553#endif
531 554
@@ -551,9 +574,24 @@ static struct platform_device bfin_uart_device = {
551#endif 574#endif
552 575
553#if defined(CONFIG_I2C_BLACKFIN_TWI) || defined(CONFIG_I2C_BLACKFIN_TWI_MODULE) 576#if defined(CONFIG_I2C_BLACKFIN_TWI) || defined(CONFIG_I2C_BLACKFIN_TWI_MODULE)
577static struct resource bfin_twi0_resource[] = {
578 [0] = {
579 .start = TWI0_REGBASE,
580 .end = TWI0_REGBASE,
581 .flags = IORESOURCE_MEM,
582 },
583 [1] = {
584 .start = IRQ_TWI,
585 .end = IRQ_TWI,
586 .flags = IORESOURCE_IRQ,
587 },
588};
589
554static struct platform_device i2c_bfin_twi_device = { 590static struct platform_device i2c_bfin_twi_device = {
555 .name = "i2c-bfin-twi", 591 .name = "i2c-bfin-twi",
556 .id = 0, 592 .id = 0,
593 .num_resources = ARRAY_SIZE(bfin_twi0_resource),
594 .resource = bfin_twi0_resource,
557}; 595};
558#endif 596#endif
559 597
@@ -569,6 +607,43 @@ static struct platform_device bfin_sport1_uart_device = {
569}; 607};
570#endif 608#endif
571 609
610#if defined(CONFIG_PATA_PLATFORM) || defined(CONFIG_PATA_PLATFORM_MODULE)
611#define PATA_INT 55
612
613static struct pata_platform_info bfin_pata_platform_data = {
614 .ioport_shift = 1,
615 .irq_type = IRQF_TRIGGER_HIGH | IRQF_DISABLED,
616};
617
618static struct resource bfin_pata_resources[] = {
619 {
620 .start = 0x20314020,
621 .end = 0x2031403F,
622 .flags = IORESOURCE_MEM,
623 },
624 {
625 .start = 0x2031401C,
626 .end = 0x2031401F,
627 .flags = IORESOURCE_MEM,
628 },
629 {
630 .start = PATA_INT,
631 .end = PATA_INT,
632 .flags = IORESOURCE_IRQ,
633 },
634};
635
636static struct platform_device bfin_pata_device = {
637 .name = "pata_platform",
638 .id = -1,
639 .num_resources = ARRAY_SIZE(bfin_pata_resources),
640 .resource = bfin_pata_resources,
641 .dev = {
642 .platform_data = &bfin_pata_platform_data,
643 }
644};
645#endif
646
572static struct platform_device *stamp_devices[] __initdata = { 647static struct platform_device *stamp_devices[] __initdata = {
573#if defined(CONFIG_BFIN_CFPCMCIA) || defined(CONFIG_BFIN_CFPCMCIA_MODULE) 648#if defined(CONFIG_BFIN_CFPCMCIA) || defined(CONFIG_BFIN_CFPCMCIA_MODULE)
574 &bfin_pcmcia_cf_device, 649 &bfin_pcmcia_cf_device,
@@ -603,13 +678,17 @@ static struct platform_device *stamp_devices[] __initdata = {
603#endif 678#endif
604 679
605#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE) 680#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
606 &spi_bfin_master_device, 681 &bfin_spi0_device,
607#endif 682#endif
608 683
609#if defined(CONFIG_FB_BF537_LQ035) || defined(CONFIG_FB_BF537_LQ035_MODULE) 684#if defined(CONFIG_FB_BF537_LQ035) || defined(CONFIG_FB_BF537_LQ035_MODULE)
610 &bfin_fb_device, 685 &bfin_fb_device,
611#endif 686#endif
612 687
688#if defined(CONFIG_FB_BFIN_7393) || defined(CONFIG_FB_BFIN_7393_MODULE)
689 &bfin_fb_adv7393_device,
690#endif
691
613#if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE) 692#if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE)
614 &bfin_uart_device, 693 &bfin_uart_device,
615#endif 694#endif
@@ -622,6 +701,10 @@ static struct platform_device *stamp_devices[] __initdata = {
622 &bfin_sport0_uart_device, 701 &bfin_sport0_uart_device,
623 &bfin_sport1_uart_device, 702 &bfin_sport1_uart_device,
624#endif 703#endif
704
705#if defined(CONFIG_PATA_PLATFORM) || defined(CONFIG_PATA_PLATFORM_MODULE)
706 &bfin_pata_device,
707#endif
625}; 708};
626 709
627static int __init stamp_init(void) 710static int __init stamp_init(void)
@@ -632,7 +715,18 @@ static int __init stamp_init(void)
632 spi_register_board_info(bfin_spi_board_info, 715 spi_register_board_info(bfin_spi_board_info,
633 ARRAY_SIZE(bfin_spi_board_info)); 716 ARRAY_SIZE(bfin_spi_board_info));
634#endif 717#endif
718
719#if defined(CONFIG_PATA_PLATFORM) || defined(CONFIG_PATA_PLATFORM_MODULE)
720 irq_desc[PATA_INT].status |= IRQ_NOAUTOEN;
721#endif
635 return 0; 722 return 0;
636} 723}
637 724
638arch_initcall(stamp_init); 725arch_initcall(stamp_init);
726
727void native_machine_restart(char *cmd)
728{
729 /* workaround reboot hang when booting from SPI */
730 if ((bfin_read_SYSCR() & 0x7) == 0x3)
731 bfin_gpio_reset_spi0_ssel1();
732}
diff --git a/arch/blackfin/mach-bf537/head.S b/arch/blackfin/mach-bf537/head.S
index 429c8a1019da..3014fe8dd155 100644
--- a/arch/blackfin/mach-bf537/head.S
+++ b/arch/blackfin/mach-bf537/head.S
@@ -33,6 +33,7 @@
33#include <asm/trace.h> 33#include <asm/trace.h>
34 34
35#if CONFIG_BFIN_KERNEL_CLOCK 35#if CONFIG_BFIN_KERNEL_CLOCK
36#include <asm/mach-common/clocks.h>
36#include <asm/mach/mem_init.h> 37#include <asm/mach/mem_init.h>
37#endif 38#endif
38 39
@@ -50,10 +51,12 @@ __INIT
50ENTRY(__start) 51ENTRY(__start)
51 /* R0: argument of command line string, passed from uboot, save it */ 52 /* R0: argument of command line string, passed from uboot, save it */
52 R7 = R0; 53 R7 = R0;
53 /* Set the SYSCFG register: 54 /* Enable Cycle Counter and Nesting Of Interrupts */
54 * Enable Cycle Counter and Nesting Of Interrupts (3rd Bit) 55#ifdef CONFIG_BFIN_SCRATCH_REG_CYCLES
55 */ 56 R0 = SYSCFG_SNEN;
56 R0 = 0x36; 57#else
58 R0 = SYSCFG_SNEN | SYSCFG_CCEN;
59#endif
57 SYSCFG = R0; 60 SYSCFG = R0;
58 R0 = 0; 61 R0 = 0;
59 62
@@ -95,43 +98,43 @@ ENTRY(__start)
95 M2 = r0; 98 M2 = r0;
96 M3 = r0; 99 M3 = r0;
97 100
98 trace_buffer_start(p0,r0); 101 trace_buffer_init(p0,r0);
99 P0 = R1; 102 P0 = R1;
100 R0 = R1; 103 R0 = R1;
101 104
102 /* Turn off the icache */ 105 /* Turn off the icache */
103 p0.l = (IMEM_CONTROL & 0xFFFF); 106 p0.l = LO(IMEM_CONTROL);
104 p0.h = (IMEM_CONTROL >> 16); 107 p0.h = HI(IMEM_CONTROL);
105 R1 = [p0]; 108 R1 = [p0];
106 R0 = ~ENICPLB; 109 R0 = ~ENICPLB;
107 R0 = R0 & R1; 110 R0 = R0 & R1;
108 111
109 /* Anomaly 05000125 */ 112 /* Anomaly 05000125 */
110#ifdef ANOMALY_05000125 113#if ANOMALY_05000125
111 CLI R2; 114 CLI R2;
112 SSYNC; 115 SSYNC;
113#endif 116#endif
114 [p0] = R0; 117 [p0] = R0;
115 SSYNC; 118 SSYNC;
116#ifdef ANOMALY_05000125 119#if ANOMALY_05000125
117 STI R2; 120 STI R2;
118#endif 121#endif
119 122
120 /* Turn off the dcache */ 123 /* Turn off the dcache */
121 p0.l = (DMEM_CONTROL & 0xFFFF); 124 p0.l = LO(DMEM_CONTROL);
122 p0.h = (DMEM_CONTROL >> 16); 125 p0.h = HI(DMEM_CONTROL);
123 R1 = [p0]; 126 R1 = [p0];
124 R0 = ~ENDCPLB; 127 R0 = ~ENDCPLB;
125 R0 = R0 & R1; 128 R0 = R0 & R1;
126 129
127 /* Anomaly 05000125 */ 130 /* Anomaly 05000125 */
128#ifdef ANOMALY_05000125 131#if ANOMALY_05000125
129 CLI R2; 132 CLI R2;
130 SSYNC; 133 SSYNC;
131#endif 134#endif
132 [p0] = R0; 135 [p0] = R0;
133 SSYNC; 136 SSYNC;
134#ifdef ANOMALY_05000125 137#if ANOMALY_05000125
135 STI R2; 138 STI R2;
136#endif 139#endif
137 140
@@ -141,12 +144,12 @@ ENTRY(__start)
141 */ 144 */
142 p0.h = hi(BFIN_PORT_MUX); 145 p0.h = hi(BFIN_PORT_MUX);
143 p0.l = lo(BFIN_PORT_MUX); 146 p0.l = lo(BFIN_PORT_MUX);
144#ifdef ANOMALY_05000212 147#if ANOMALY_05000212
145 R0.L = W[P0]; /* Read */ 148 R0.L = W[P0]; /* Read */
146 SSYNC; 149 SSYNC;
147#endif 150#endif
148 R0 = (PGDE_UART | PFTE_UART)(Z); 151 R0 = (PGDE_UART | PFTE_UART)(Z);
149#ifdef ANOMALY_05000212 152#if ANOMALY_05000212
150 W[P0] = R0.L; /* Write */ 153 W[P0] = R0.L; /* Write */
151 SSYNC; 154 SSYNC;
152#endif 155#endif
@@ -155,12 +158,12 @@ ENTRY(__start)
155 158
156 p0.h = hi(PORTF_FER); 159 p0.h = hi(PORTF_FER);
157 p0.l = lo(PORTF_FER); 160 p0.l = lo(PORTF_FER);
158#ifdef ANOMALY_05000212 161#if ANOMALY_05000212
159 R0.L = W[P0]; /* Read */ 162 R0.L = W[P0]; /* Read */
160 SSYNC; 163 SSYNC;
161#endif 164#endif
162 R0 = 0x000F(Z); 165 R0 = 0x000F(Z);
163#ifdef ANOMALY_05000212 166#if ANOMALY_05000212
164 W[P0] = R0.L; /* Write */ 167 W[P0] = R0.L; /* Write */
165 SSYNC; 168 SSYNC;
166#endif 169#endif
@@ -221,6 +224,12 @@ ENTRY(__start)
221 fp = sp; 224 fp = sp;
222 usp = sp; 225 usp = sp;
223 226
227#ifdef CONFIG_EARLY_PRINTK
228 SP += -12;
229 call _init_early_exception_vectors;
230 SP += 12;
231#endif
232
224 /* Put The Code for PLL Programming and SDRAM Programming in L1 ISRAM */ 233 /* Put The Code for PLL Programming and SDRAM Programming in L1 ISRAM */
225 call _bf53x_relocate_l1_mem; 234 call _bf53x_relocate_l1_mem;
226#if CONFIG_BFIN_KERNEL_CLOCK 235#if CONFIG_BFIN_KERNEL_CLOCK
@@ -274,7 +283,7 @@ ENTRY(__start)
274 p0.l = .LWAIT_HERE; 283 p0.l = .LWAIT_HERE;
275 p0.h = .LWAIT_HERE; 284 p0.h = .LWAIT_HERE;
276 reti = p0; 285 reti = p0;
277#if defined(ANOMALY_05000281) 286#if ANOMALY_05000281
278 nop; nop; nop; 287 nop; nop; nop;
279#endif 288#endif
280 rti; 289 rti;
@@ -436,8 +445,8 @@ ENTRY(_start_dma_code)
436 w[p0] = r0.l; 445 w[p0] = r0.l;
437 ssync; 446 ssync;
438 447
439 p0.l = (EBIU_SDBCTL & 0xFFFF); 448 p0.l = LO(EBIU_SDBCTL);
440 p0.h = (EBIU_SDBCTL >> 16); /* SDRAM Memory Bank Control Register */ 449 p0.h = HI(EBIU_SDBCTL); /* SDRAM Memory Bank Control Register */
441 r0 = mem_SDBCTL; 450 r0 = mem_SDBCTL;
442 w[p0] = r0.l; 451 w[p0] = r0.l;
443 ssync; 452 ssync;
@@ -475,85 +484,6 @@ ENTRY(_start_dma_code)
475ENDPROC(_start_dma_code) 484ENDPROC(_start_dma_code)
476#endif /* CONFIG_BFIN_KERNEL_CLOCK */ 485#endif /* CONFIG_BFIN_KERNEL_CLOCK */
477 486
478ENTRY(_bfin_reset)
479 /* No more interrupts to be handled*/
480 CLI R6;
481 SSYNC;
482
483#if defined(CONFIG_MTD_M25P80)
484 /*
485 * The following code fix the SPI flash reboot issue,
486 * /CS signal of the chip which is using PF10 return to GPIO mode
487 */
488 p0.h = hi(PORTF_FER);
489 p0.l = lo(PORTF_FER);
490 r0.l = 0x0000;
491 w[p0] = r0.l;
492 SSYNC;
493
494 /* /CS return to high */
495 p0.h = hi(PORTFIO);
496 p0.l = lo(PORTFIO);
497 r0.l = 0xFFFF;
498 w[p0] = r0.l;
499 SSYNC;
500
501 /* Delay some time, This is necessary */
502 r1.h = 0;
503 r1.l = 0x400;
504 p1 = r1;
505 lsetup (.L_delay_lab1, .L_delay_lab1_end) lc1 = p1;
506.L_delay_lab1:
507 r0.h = 0;
508 r0.l = 0x8000;
509 p0 = r0;
510 lsetup (.L_delay_lab0, .L_delay_lab0_end) lc0 = p0;
511.L_delay_lab0:
512 nop;
513.L_delay_lab0_end:
514 nop;
515.L_delay_lab1_end:
516 nop;
517#endif
518
519 /* Clear the IMASK register */
520 p0.h = hi(IMASK);
521 p0.l = lo(IMASK);
522 r0 = 0x0;
523 [p0] = r0;
524
525 /* Clear the ILAT register */
526 p0.h = hi(ILAT);
527 p0.l = lo(ILAT);
528 r0 = [p0];
529 [p0] = r0;
530 SSYNC;
531
532 /* make sure SYSCR is set to use BMODE */
533 P0.h = hi(SYSCR);
534 P0.l = lo(SYSCR);
535 R0.l = 0x0;
536 W[P0] = R0.l;
537 SSYNC;
538
539 /* issue a system soft reset */
540 P1.h = hi(SWRST);
541 P1.l = lo(SWRST);
542 R1.l = 0x0007;
543 W[P1] = R1;
544 SSYNC;
545
546 /* clear system soft reset */
547 R0.l = 0x0000;
548 W[P0] = R0;
549 SSYNC;
550
551 /* issue core reset */
552 raise 1;
553
554 RTS;
555ENDPROC(_bfin_reset)
556
557.data 487.data
558 488
559/* 489/*
diff --git a/arch/blackfin/mach-bf548/Kconfig b/arch/blackfin/mach-bf548/Kconfig
index e78b03d56c7c..08d8dc83701c 100644
--- a/arch/blackfin/mach-bf548/Kconfig
+++ b/arch/blackfin/mach-bf548/Kconfig
@@ -2,6 +2,13 @@ if (BF54x)
2 2
3menu "BF548 Specific Configuration" 3menu "BF548 Specific Configuration"
4 4
5config DEB_DMA_URGENT
6 bool "DMA has priority over core for ext. accesses"
7 depends on BF54x
8 default n
9 help
10 Treat any DEB1, DEB2 and DEB3 request as Urgent
11
5comment "Interrupt Priority Assignment" 12comment "Interrupt Priority Assignment"
6menu "Priority" 13menu "Priority"
7 14
@@ -282,7 +289,7 @@ menu "Assignment"
282 289
283config PINTx_REASSIGN 290config PINTx_REASSIGN
284 bool "Reprogram PINT Assignment" 291 bool "Reprogram PINT Assignment"
285 default n 292 default y
286 help 293 help
287 The interrupt assignment registers controls the pin-to-interrupt 294 The interrupt assignment registers controls the pin-to-interrupt
288 assignment in a byte-wide manner. Each option allows you to select 295 assignment in a byte-wide manner. Each option allows you to select
@@ -303,7 +310,7 @@ config PINT1_ASSIGN
303config PINT2_ASSIGN 310config PINT2_ASSIGN
304 hex "PINT2_ASSIGN" 311 hex "PINT2_ASSIGN"
305 depends on PINTx_REASSIGN 312 depends on PINTx_REASSIGN
306 default 0x00000101 313 default 0x07000101
307config PINT3_ASSIGN 314config PINT3_ASSIGN
308 hex "PINT3_ASSIGN" 315 hex "PINT3_ASSIGN"
309 depends on PINTx_REASSIGN 316 depends on PINTx_REASSIGN
diff --git a/arch/blackfin/mach-bf548/Makefile b/arch/blackfin/mach-bf548/Makefile
index 060ad78ebf1d..7e7c9c8ac5b2 100644
--- a/arch/blackfin/mach-bf548/Makefile
+++ b/arch/blackfin/mach-bf548/Makefile
@@ -4,6 +4,6 @@
4 4
5extra-y := head.o 5extra-y := head.o
6 6
7obj-y := ints-priority.o dma.o gpio.o 7obj-y := ints-priority.o dma.o
8 8
9obj-$(CONFIG_CPU_FREQ) += cpu.o 9obj-$(CONFIG_CPU_FREQ) += cpu.o
diff --git a/arch/blackfin/mach-bf548/boards/ezkit.c b/arch/blackfin/mach-bf548/boards/ezkit.c
index 96ad95fab1a8..2c47db494f7d 100644
--- a/arch/blackfin/mach-bf548/boards/ezkit.c
+++ b/arch/blackfin/mach-bf548/boards/ezkit.c
@@ -35,9 +35,16 @@
35#include <linux/spi/spi.h> 35#include <linux/spi/spi.h>
36#include <linux/spi/flash.h> 36#include <linux/spi/flash.h>
37#include <linux/irq.h> 37#include <linux/irq.h>
38#include <linux/irq.h>
39#include <linux/interrupt.h> 38#include <linux/interrupt.h>
39#include <linux/usb/musb.h>
40#include <asm/bfin5xx_spi.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/mach/bf54x_keys.h>
46#include <linux/input.h>
47#include <linux/spi/ad7877.h>
41 48
42/* 49/*
43 * Name the Board for the /proc/cpuinfo 50 * Name the Board for the /proc/cpuinfo
@@ -48,6 +55,88 @@ char *bfin_board_name = "ADSP-BF548-EZKIT";
48 * Driver needs to know address, irq and flag pin. 55 * Driver needs to know address, irq and flag pin.
49 */ 56 */
50 57
58#if defined(CONFIG_FB_BF54X_LQ043) || defined(CONFIG_FB_BF54X_LQ043_MODULE)
59
60#include <asm/mach/bf54x-lq043.h>
61
62static struct bfin_bf54xfb_mach_info bf54x_lq043_data = {
63 .width = 480,
64 .height = 272,
65 .xres = {480, 480, 480},
66 .yres = {272, 272, 272},
67 .bpp = {24, 24, 24},
68 .disp = GPIO_PE3,
69};
70
71static struct resource bf54x_lq043_resources[] = {
72 {
73 .start = IRQ_EPPI0_ERR,
74 .end = IRQ_EPPI0_ERR,
75 .flags = IORESOURCE_IRQ,
76 },
77};
78
79static struct platform_device bf54x_lq043_device = {
80 .name = "bf54x-lq043",
81 .id = -1,
82 .num_resources = ARRAY_SIZE(bf54x_lq043_resources),
83 .resource = bf54x_lq043_resources,
84 .dev = {
85 .platform_data = &bf54x_lq043_data,
86 },
87};
88#endif
89
90#if defined(CONFIG_KEYBOARD_BFIN) || defined(CONFIG_KEYBOARD_BFIN_MODULE)
91static int bf548_keymap[] = {
92 KEYVAL(0, 0, KEY_ENTER),
93 KEYVAL(0, 1, KEY_HELP),
94 KEYVAL(0, 2, KEY_0),
95 KEYVAL(0, 3, KEY_BACKSPACE),
96 KEYVAL(1, 0, KEY_TAB),
97 KEYVAL(1, 1, KEY_9),
98 KEYVAL(1, 2, KEY_8),
99 KEYVAL(1, 3, KEY_7),
100 KEYVAL(2, 0, KEY_DOWN),
101 KEYVAL(2, 1, KEY_6),
102 KEYVAL(2, 2, KEY_5),
103 KEYVAL(2, 3, KEY_4),
104 KEYVAL(3, 0, KEY_UP),
105 KEYVAL(3, 1, KEY_3),
106 KEYVAL(3, 2, KEY_2),
107 KEYVAL(3, 3, KEY_1),
108};
109
110static struct bfin_kpad_platform_data bf54x_kpad_data = {
111 .rows = 4,
112 .cols = 4,
113 .keymap = bf548_keymap,
114 .keymapsize = ARRAY_SIZE(bf548_keymap),
115 .repeat = 0,
116 .debounce_time = 5000, /* ns (5ms) */
117 .coldrive_time = 1000, /* ns (1ms) */
118 .keyup_test_interval = 50, /* ms (50ms) */
119};
120
121static struct resource bf54x_kpad_resources[] = {
122 {
123 .start = IRQ_KEY,
124 .end = IRQ_KEY,
125 .flags = IORESOURCE_IRQ,
126 },
127};
128
129static struct platform_device bf54x_kpad_device = {
130 .name = "bf54x-keys",
131 .id = -1,
132 .num_resources = ARRAY_SIZE(bf54x_kpad_resources),
133 .resource = bf54x_kpad_resources,
134 .dev = {
135 .platform_data = &bf54x_kpad_data,
136 },
137};
138#endif
139
51#if defined(CONFIG_RTC_DRV_BFIN) || defined(CONFIG_RTC_DRV_BFIN_MODULE) 140#if defined(CONFIG_RTC_DRV_BFIN) || defined(CONFIG_RTC_DRV_BFIN_MODULE)
52static struct platform_device rtc_device = { 141static struct platform_device rtc_device = {
53 .name = "rtc-bfin", 142 .name = "rtc-bfin",
@@ -94,6 +183,344 @@ static struct platform_device bfin_uart_device = {
94}; 183};
95#endif 184#endif
96 185
186#if defined(CONFIG_SMSC911X) || defined(CONFIG_SMSC911X_MODULE)
187static struct resource smsc911x_resources[] = {
188 {
189 .name = "smsc911x-memory",
190 .start = 0x24000000,
191 .end = 0x24000000 + 0xFF,
192 .flags = IORESOURCE_MEM,
193 },
194 {
195 .start = IRQ_PE8,
196 .end = IRQ_PE8,
197 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
198 },
199};
200static struct platform_device smsc911x_device = {
201 .name = "smsc911x",
202 .id = 0,
203 .num_resources = ARRAY_SIZE(smsc911x_resources),
204 .resource = smsc911x_resources,
205};
206#endif
207
208#if defined(CONFIG_USB_BF54x_HCD) || defined(CONFIG_USB_BF54x_HCD_MODULE)
209static struct resource bf54x_hcd_resources[] = {
210 {
211 .start = 0xFFC03C00,
212 .end = 0xFFC040FF,
213 .flags = IORESOURCE_MEM,
214 },
215};
216
217static struct platform_device bf54x_hcd = {
218 .name = "bf54x-hcd",
219 .id = 0,
220 .num_resources = ARRAY_SIZE(bf54x_hcd_resources),
221 .resource = bf54x_hcd_resources,
222};
223#endif
224
225#if defined(CONFIG_USB_MUSB_HDRC) || defined(CONFIG_USB_MUSB_HDRC_MODULE)
226static struct resource musb_resources[] = {
227 [0] = {
228 .start = 0xFFC03C00,
229 .end = 0xFFC040FF,
230 .flags = IORESOURCE_MEM,
231 },
232 [1] = { /* general IRQ */
233 .start = IRQ_USB_INT0,
234 .end = IRQ_USB_INT0,
235 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL,
236 },
237 [2] = { /* DMA IRQ */
238 .start = IRQ_USB_DMA,
239 .end = IRQ_USB_DMA,
240 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL,
241 },
242};
243
244static struct musb_hdrc_platform_data musb_plat = {
245#ifdef CONFIG_USB_MUSB_OTG
246 .mode = MUSB_OTG,
247#elif CONFIG_USB_MUSB_HDRC_HCD
248 .mode = MUSB_HOST,
249#elif CONFIG_USB_GADGET_MUSB_HDRC
250 .mode = MUSB_PERIPHERAL,
251#endif
252 .multipoint = 1,
253};
254
255static u64 musb_dmamask = ~(u32)0;
256
257static struct platform_device musb_device = {
258 .name = "musb_hdrc",
259 .id = 0,
260 .dev = {
261 .dma_mask = &musb_dmamask,
262 .coherent_dma_mask = 0xffffffff,
263 .platform_data = &musb_plat,
264 },
265 .num_resources = ARRAY_SIZE(musb_resources),
266 .resource = musb_resources,
267};
268#endif
269
270#if defined(CONFIG_PATA_BF54X) || defined(CONFIG_PATA_BF54X_MODULE)
271static struct resource bfin_atapi_resources[] = {
272 {
273 .start = 0xFFC03800,
274 .end = 0xFFC0386F,
275 .flags = IORESOURCE_MEM,
276 },
277 {
278 .start = IRQ_ATAPI_ERR,
279 .end = IRQ_ATAPI_ERR,
280 .flags = IORESOURCE_IRQ,
281 },
282};
283
284static struct platform_device bfin_atapi_device = {
285 .name = "pata-bf54x",
286 .id = -1,
287 .num_resources = ARRAY_SIZE(bfin_atapi_resources),
288 .resource = bfin_atapi_resources,
289};
290#endif
291
292#if defined(CONFIG_MTD_NAND_BF5XX) || defined(CONFIG_MTD_NAND_BF5XX_MODULE)
293static struct mtd_partition partition_info[] = {
294 {
295 .name = "Linux Kernel",
296 .offset = 0,
297 .size = 4 * SIZE_1M,
298 },
299 {
300 .name = "File System",
301 .offset = 4 * SIZE_1M,
302 .size = (256 - 4) * SIZE_1M,
303 },
304};
305
306static struct bf5xx_nand_platform bf5xx_nand_platform = {
307 .page_size = NFC_PG_SIZE_256,
308 .data_width = NFC_NWIDTH_8,
309 .partitions = partition_info,
310 .nr_partitions = ARRAY_SIZE(partition_info),
311 .rd_dly = 3,
312 .wr_dly = 3,
313};
314
315static struct resource bf5xx_nand_resources[] = {
316 {
317 .start = 0xFFC03B00,
318 .end = 0xFFC03B4F,
319 .flags = IORESOURCE_MEM,
320 },
321 {
322 .start = CH_NFC,
323 .end = CH_NFC,
324 .flags = IORESOURCE_IRQ,
325 },
326};
327
328static struct platform_device bf5xx_nand_device = {
329 .name = "bf5xx-nand",
330 .id = 0,
331 .num_resources = ARRAY_SIZE(bf5xx_nand_resources),
332 .resource = bf5xx_nand_resources,
333 .dev = {
334 .platform_data = &bf5xx_nand_platform,
335 },
336};
337#endif
338
339#if defined(CONFIG_SDH_BFIN) || defined(CONFIG_SDH_BFIN)
340static struct platform_device bf54x_sdh_device = {
341 .name = "bfin-sdh",
342 .id = 0,
343};
344#endif
345
346#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
347/* all SPI peripherals info goes here */
348#if defined(CONFIG_MTD_M25P80) \
349 || defined(CONFIG_MTD_M25P80_MODULE)
350/* SPI flash chip (m25p16) */
351static struct mtd_partition bfin_spi_flash_partitions[] = {
352 {
353 .name = "bootloader",
354 .size = 0x00040000,
355 .offset = 0,
356 .mask_flags = MTD_CAP_ROM
357 }, {
358 .name = "linux kernel",
359 .size = 0x1c0000,
360 .offset = 0x40000
361 }
362};
363
364static struct flash_platform_data bfin_spi_flash_data = {
365 .name = "m25p80",
366 .parts = bfin_spi_flash_partitions,
367 .nr_parts = ARRAY_SIZE(bfin_spi_flash_partitions),
368 .type = "m25p16",
369};
370
371static struct bfin5xx_spi_chip spi_flash_chip_info = {
372 .enable_dma = 0, /* use dma transfer with this chip*/
373 .bits_per_word = 8,
374 .cs_change_per_word = 0,
375};
376#endif
377
378#if defined(CONFIG_TOUCHSCREEN_AD7877) || defined(CONFIG_TOUCHSCREEN_AD7877_MODULE)
379static struct bfin5xx_spi_chip spi_ad7877_chip_info = {
380 .cs_change_per_word = 1,
381 .enable_dma = 0,
382 .bits_per_word = 16,
383};
384
385static const struct ad7877_platform_data bfin_ad7877_ts_info = {
386 .model = 7877,
387 .vref_delay_usecs = 50, /* internal, no capacitor */
388 .x_plate_ohms = 419,
389 .y_plate_ohms = 486,
390 .pressure_max = 1000,
391 .pressure_min = 0,
392 .stopacq_polarity = 1,
393 .first_conversion_delay = 3,
394 .acquisition_time = 1,
395 .averaging = 1,
396 .pen_down_acc_interval = 1,
397};
398#endif
399
400static struct spi_board_info bf54x_spi_board_info[] __initdata = {
401#if defined(CONFIG_MTD_M25P80) \
402 || defined(CONFIG_MTD_M25P80_MODULE)
403 {
404 /* the modalias must be the same as spi device driver name */
405 .modalias = "m25p80", /* Name of spi_driver for this device */
406 .max_speed_hz = 25000000, /* max spi clock (SCK) speed in HZ */
407 .bus_num = 0, /* Framework bus number */
408 .chip_select = 1, /* SPI_SSEL1*/
409 .platform_data = &bfin_spi_flash_data,
410 .controller_data = &spi_flash_chip_info,
411 .mode = SPI_MODE_3,
412 },
413#endif
414#if defined(CONFIG_TOUCHSCREEN_AD7877) || defined(CONFIG_TOUCHSCREEN_AD7877_MODULE)
415{
416 .modalias = "ad7877",
417 .platform_data = &bfin_ad7877_ts_info,
418 .irq = IRQ_PJ11,
419 .max_speed_hz = 12500000, /* max spi clock (SCK) speed in HZ */
420 .bus_num = 0,
421 .chip_select = 2,
422 .controller_data = &spi_ad7877_chip_info,
423},
424#endif
425};
426
427/* SPI (0) */
428static struct resource bfin_spi0_resource[] = {
429 [0] = {
430 .start = SPI0_REGBASE,
431 .end = SPI0_REGBASE + 0xFF,
432 .flags = IORESOURCE_MEM,
433 },
434 [1] = {
435 .start = CH_SPI0,
436 .end = CH_SPI0,
437 .flags = IORESOURCE_IRQ,
438 }
439};
440
441/* SPI (1) */
442static struct resource bfin_spi1_resource[] = {
443 [0] = {
444 .start = SPI1_REGBASE,
445 .end = SPI1_REGBASE + 0xFF,
446 .flags = IORESOURCE_MEM,
447 },
448 [1] = {
449 .start = CH_SPI1,
450 .end = CH_SPI1,
451 .flags = IORESOURCE_IRQ,
452 }
453};
454
455/* SPI controller data */
456static struct bfin5xx_spi_master bf54x_spi_master_info = {
457 .num_chipselect = 8,
458 .enable_dma = 1, /* master has the ability to do dma transfer */
459};
460
461static struct platform_device bf54x_spi_master0 = {
462 .name = "bfin-spi",
463 .id = 0, /* Bus number */
464 .num_resources = ARRAY_SIZE(bfin_spi0_resource),
465 .resource = bfin_spi0_resource,
466 .dev = {
467 .platform_data = &bf54x_spi_master_info, /* Passed to driver */
468 },
469};
470
471static struct platform_device bf54x_spi_master1 = {
472 .name = "bfin-spi",
473 .id = 1, /* Bus number */
474 .num_resources = ARRAY_SIZE(bfin_spi1_resource),
475 .resource = bfin_spi1_resource,
476 .dev = {
477 .platform_data = &bf54x_spi_master_info, /* Passed to driver */
478 },
479};
480#endif /* spi master and devices */
481
482#if defined(CONFIG_I2C_BLACKFIN_TWI) || defined(CONFIG_I2C_BLACKFIN_TWI_MODULE)
483static struct resource bfin_twi0_resource[] = {
484 [0] = {
485 .start = TWI0_REGBASE,
486 .end = TWI0_REGBASE + 0xFF,
487 .flags = IORESOURCE_MEM,
488 },
489 [1] = {
490 .start = IRQ_TWI0,
491 .end = IRQ_TWI0,
492 .flags = IORESOURCE_IRQ,
493 },
494};
495
496static struct platform_device i2c_bfin_twi0_device = {
497 .name = "i2c-bfin-twi",
498 .id = 0,
499 .num_resources = ARRAY_SIZE(bfin_twi0_resource),
500 .resource = bfin_twi0_resource,
501};
502
503static struct resource bfin_twi1_resource[] = {
504 [0] = {
505 .start = TWI1_REGBASE,
506 .end = TWI1_REGBASE + 0xFF,
507 .flags = IORESOURCE_MEM,
508 },
509 [1] = {
510 .start = IRQ_TWI1,
511 .end = IRQ_TWI1,
512 .flags = IORESOURCE_IRQ,
513 },
514};
515
516static struct platform_device i2c_bfin_twi1_device = {
517 .name = "i2c-bfin-twi",
518 .id = 1,
519 .num_resources = ARRAY_SIZE(bfin_twi1_resource),
520 .resource = bfin_twi1_resource,
521};
522#endif
523
97static struct platform_device *ezkit_devices[] __initdata = { 524static struct platform_device *ezkit_devices[] __initdata = {
98#if defined(CONFIG_RTC_DRV_BFIN) || defined(CONFIG_RTC_DRV_BFIN_MODULE) 525#if defined(CONFIG_RTC_DRV_BFIN) || defined(CONFIG_RTC_DRV_BFIN_MODULE)
99 &rtc_device, 526 &rtc_device,
@@ -102,12 +529,60 @@ static struct platform_device *ezkit_devices[] __initdata = {
102#if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE) 529#if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE)
103 &bfin_uart_device, 530 &bfin_uart_device,
104#endif 531#endif
532
533#if defined(CONFIG_FB_BF54X_LQ043) || defined(CONFIG_FB_BF54X_LQ043_MODULE)
534 &bf54x_lq043_device,
535#endif
536
537#if defined(CONFIG_SMSC911X) || defined(CONFIG_SMSC911X_MODULE)
538 &smsc911x_device,
539#endif
540
541#if defined(CONFIG_USB_BF54x_HCD) || defined(CONFIG_USB_BF54x_HCD_MODULE)
542 &bf54x_hcd,
543#endif
544
545#if defined(CONFIG_USB_MUSB_HDRC) || defined(CONFIG_USB_MUSB_HDRC_MODULE)
546 &musb_device,
547#endif
548
549#if defined(CONFIG_PATA_BF54X) || defined(CONFIG_PATA_BF54X_MODULE)
550 &bfin_atapi_device,
551#endif
552
553#if defined(CONFIG_MTD_NAND_BF5XX) || defined(CONFIG_MTD_NAND_BF5XX_MODULE)
554 &bf5xx_nand_device,
555#endif
556
557#if defined(CONFIG_SDH_BFIN) || defined(CONFIG_SDH_BFIN)
558 &bf54x_sdh_device,
559#endif
560
561#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
562 &bf54x_spi_master0,
563/* &bf54x_spi_master1,*/
564#endif
565
566#if defined(CONFIG_KEYBOARD_BFIN) || defined(CONFIG_KEYBOARD_BFIN_MODULE)
567 &bf54x_kpad_device,
568#endif
569
570#if defined(CONFIG_I2C_BLACKFIN_TWI) || defined(CONFIG_I2C_BLACKFIN_TWI_MODULE)
571 &i2c_bfin_twi0_device,
572 &i2c_bfin_twi1_device,
573#endif
105}; 574};
106 575
107static int __init stamp_init(void) 576static int __init stamp_init(void)
108{ 577{
109 printk(KERN_INFO "%s(): registering device resources\n", __FUNCTION__); 578 printk(KERN_INFO "%s(): registering device resources\n", __FUNCTION__);
110 platform_add_devices(ezkit_devices, ARRAY_SIZE(ezkit_devices)); 579 platform_add_devices(ezkit_devices, ARRAY_SIZE(ezkit_devices));
580
581#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
582 spi_register_board_info(bf54x_spi_board_info,
583 ARRAY_SIZE(bf54x_spi_board_info));
584#endif
585
111 return 0; 586 return 0;
112} 587}
113 588
diff --git a/arch/blackfin/mach-bf548/gpio.c b/arch/blackfin/mach-bf548/gpio.c
deleted file mode 100644
index 0da5f0003b8c..000000000000
--- a/arch/blackfin/mach-bf548/gpio.c
+++ /dev/null
@@ -1,323 +0,0 @@
1/*
2 * File: arch/blackfin/mach-bf548/gpio.c
3 * Based on:
4 * Author: Michael Hennerich (hennerich@blackfin.uclinux.org)
5 *
6 * Created:
7 * Description: GPIO Abstraction Layer
8 *
9 * Modified:
10 * Copyright 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/module.h>
31#include <linux/err.h>
32#include <asm/blackfin.h>
33#include <asm/gpio.h>
34#include <asm/portmux.h>
35#include <linux/irq.h>
36
37static struct gpio_port_t *gpio_array[gpio_bank(MAX_BLACKFIN_GPIOS)] = {
38 (struct gpio_port_t *)PORTA_FER,
39 (struct gpio_port_t *)PORTB_FER,
40 (struct gpio_port_t *)PORTC_FER,
41 (struct gpio_port_t *)PORTD_FER,
42 (struct gpio_port_t *)PORTE_FER,
43 (struct gpio_port_t *)PORTF_FER,
44 (struct gpio_port_t *)PORTG_FER,
45 (struct gpio_port_t *)PORTH_FER,
46 (struct gpio_port_t *)PORTI_FER,
47 (struct gpio_port_t *)PORTJ_FER,
48};
49
50static unsigned short reserved_gpio_map[gpio_bank(MAX_BLACKFIN_GPIOS)];
51static unsigned short reserved_peri_map[gpio_bank(MAX_BLACKFIN_GPIOS)];
52
53inline int check_gpio(unsigned short gpio)
54{
55 if (gpio == GPIO_PB15 || gpio == GPIO_PC14 || gpio == GPIO_PC15
56 || gpio == GPIO_PH14 || gpio == GPIO_PH15
57 || gpio == GPIO_PJ14 || gpio == GPIO_PJ15
58 || gpio > MAX_BLACKFIN_GPIOS)
59 return -EINVAL;
60 return 0;
61}
62
63inline void portmux_setup(unsigned short portno, unsigned short function)
64{
65 u32 pmux;
66
67 pmux = gpio_array[gpio_bank(portno)]->port_mux;
68
69 pmux &= ~(0x3 << (2 * gpio_sub_n(portno)));
70 pmux |= (function & 0x3) << (2 * gpio_sub_n(portno));
71
72 gpio_array[gpio_bank(portno)]->port_mux = pmux;
73
74}
75
76inline u16 get_portmux(unsigned short portno)
77{
78 u32 pmux;
79
80 pmux = gpio_array[gpio_bank(portno)]->port_mux;
81
82 return (pmux >> (2 * gpio_sub_n(portno)) & 0x3);
83
84}
85
86static void port_setup(unsigned short gpio, unsigned short usage)
87{
88 if (usage == GPIO_USAGE) {
89 if (gpio_array[gpio_bank(gpio)]->port_fer & gpio_bit(gpio))
90 printk(KERN_WARNING
91 "bfin-gpio: Possible Conflict with Peripheral "
92 "usage and GPIO %d detected!\n", gpio);
93 gpio_array[gpio_bank(gpio)]->port_fer &= ~gpio_bit(gpio);
94 } else
95 gpio_array[gpio_bank(gpio)]->port_fer |= gpio_bit(gpio);
96 SSYNC();
97}
98
99static int __init bfin_gpio_init(void)
100{
101 printk(KERN_INFO "Blackfin GPIO Controller\n");
102
103 return 0;
104}
105
106arch_initcall(bfin_gpio_init);
107
108int peripheral_request(unsigned short per, const char *label)
109{
110 unsigned long flags;
111 unsigned short ident = P_IDENT(per);
112
113 if (!(per & P_DEFINED))
114 return -ENODEV;
115
116 if (check_gpio(ident) < 0)
117 return -EINVAL;
118
119 local_irq_save(flags);
120
121 if (unlikely(reserved_gpio_map[gpio_bank(ident)] & gpio_bit(ident))) {
122 printk(KERN_ERR
123 "%s: Peripheral %d is already reserved as GPIO!\n",
124 __FUNCTION__, per);
125 dump_stack();
126 local_irq_restore(flags);
127 return -EBUSY;
128 }
129
130 if (unlikely(reserved_peri_map[gpio_bank(ident)] & gpio_bit(ident))) {
131
132 u16 funct = get_portmux(ident);
133
134 if (!((per & P_MAYSHARE) && (funct == P_FUNCT2MUX(per)))) {
135 printk(KERN_ERR
136 "%s: Peripheral %d is already reserved!\n",
137 __FUNCTION__, per);
138 dump_stack();
139 local_irq_restore(flags);
140 return -EBUSY;
141 }
142 }
143
144 reserved_peri_map[gpio_bank(ident)] |= gpio_bit(ident);
145
146 portmux_setup(ident, P_FUNCT2MUX(per));
147 port_setup(ident, PERIPHERAL_USAGE);
148
149 local_irq_restore(flags);
150
151 return 0;
152}
153EXPORT_SYMBOL(peripheral_request);
154
155int peripheral_request_list(unsigned short per[], const char *label)
156{
157
158 u16 cnt;
159 int ret;
160
161 for (cnt = 0; per[cnt] != 0; cnt++) {
162 ret = peripheral_request(per[cnt], label);
163 if (ret < 0)
164 return ret;
165 }
166
167 return 0;
168}
169EXPORT_SYMBOL(peripheral_request_list);
170
171void peripheral_free(unsigned short per)
172{
173 unsigned long flags;
174 unsigned short ident = P_IDENT(per);
175
176 if (!(per & P_DEFINED))
177 return;
178
179 if (check_gpio(ident) < 0)
180 return;
181
182 local_irq_save(flags);
183
184 if (unlikely(!(reserved_peri_map[gpio_bank(ident)] & gpio_bit(ident)))) {
185 printk(KERN_ERR "bfin-gpio: Peripheral %d wasn't reserved!\n", per);
186 dump_stack();
187 local_irq_restore(flags);
188 return;
189 }
190
191 if (!(per & P_MAYSHARE)) {
192 port_setup(ident, GPIO_USAGE);
193 }
194
195 reserved_peri_map[gpio_bank(ident)] &= ~gpio_bit(ident);
196
197 local_irq_restore(flags);
198}
199EXPORT_SYMBOL(peripheral_free);
200
201void peripheral_free_list(unsigned short per[])
202{
203 u16 cnt;
204
205 for (cnt = 0; per[cnt] != 0; cnt++) {
206 peripheral_free(per[cnt]);
207 }
208
209}
210EXPORT_SYMBOL(peripheral_free_list);
211
212/***********************************************************
213*
214* FUNCTIONS: Blackfin GPIO Driver
215*
216* INPUTS/OUTPUTS:
217* gpio - GPIO Number between 0 and MAX_BLACKFIN_GPIOS
218*
219*
220* DESCRIPTION: Blackfin GPIO Driver API
221*
222* CAUTION:
223*************************************************************
224* MODIFICATION HISTORY :
225**************************************************************/
226
227int gpio_request(unsigned short gpio, const char *label)
228{
229 unsigned long flags;
230
231 if (check_gpio(gpio) < 0)
232 return -EINVAL;
233
234 local_irq_save(flags);
235
236 if (unlikely(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
237 printk(KERN_ERR "bfin-gpio: GPIO %d is already reserved!\n", gpio);
238 dump_stack();
239 local_irq_restore(flags);
240 return -EBUSY;
241 }
242
243 if (unlikely(reserved_peri_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
244 printk(KERN_ERR
245 "bfin-gpio: GPIO %d is already reserved as Peripheral!\n", gpio);
246 dump_stack();
247 local_irq_restore(flags);
248 return -EBUSY;
249 }
250
251 reserved_gpio_map[gpio_bank(gpio)] |= gpio_bit(gpio);
252
253 local_irq_restore(flags);
254
255 port_setup(gpio, GPIO_USAGE);
256
257 return 0;
258}
259EXPORT_SYMBOL(gpio_request);
260
261void gpio_free(unsigned short gpio)
262{
263 unsigned long flags;
264
265 if (check_gpio(gpio) < 0)
266 return;
267
268 local_irq_save(flags);
269
270 if (unlikely(!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio)))) {
271 printk(KERN_ERR "bfin-gpio: GPIO %d wasn't reserved!\n", gpio);
272 dump_stack();
273 local_irq_restore(flags);
274 return;
275 }
276
277 reserved_gpio_map[gpio_bank(gpio)] &= ~gpio_bit(gpio);
278
279 local_irq_restore(flags);
280}
281EXPORT_SYMBOL(gpio_free);
282
283void gpio_direction_input(unsigned short gpio)
284{
285 unsigned long flags;
286
287 BUG_ON(!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio)));
288
289 local_irq_save(flags);
290 gpio_array[gpio_bank(gpio)]->port_dir_clear = gpio_bit(gpio);
291 gpio_array[gpio_bank(gpio)]->port_inen |= gpio_bit(gpio);
292 local_irq_restore(flags);
293}
294EXPORT_SYMBOL(gpio_direction_input);
295
296void gpio_direction_output(unsigned short gpio)
297{
298 unsigned long flags;
299
300 BUG_ON(!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio)));
301
302 local_irq_save(flags);
303 gpio_array[gpio_bank(gpio)]->port_inen &= ~gpio_bit(gpio);
304 gpio_array[gpio_bank(gpio)]->port_dir_set = gpio_bit(gpio);
305 local_irq_restore(flags);
306}
307EXPORT_SYMBOL(gpio_direction_output);
308
309void gpio_set_value(unsigned short gpio, unsigned short arg)
310{
311 if (arg)
312 gpio_array[gpio_bank(gpio)]->port_set = gpio_bit(gpio);
313 else
314 gpio_array[gpio_bank(gpio)]->port_clear = gpio_bit(gpio);
315
316}
317EXPORT_SYMBOL(gpio_set_value);
318
319unsigned short gpio_get_value(unsigned short gpio)
320{
321 return (1 & (gpio_array[gpio_bank(gpio)]->port_data >> gpio_sub_n(gpio)));
322}
323EXPORT_SYMBOL(gpio_get_value);
diff --git a/arch/blackfin/mach-bf548/head.S b/arch/blackfin/mach-bf548/head.S
index 06751ae8b857..3071c243d426 100644
--- a/arch/blackfin/mach-bf548/head.S
+++ b/arch/blackfin/mach-bf548/head.S
@@ -31,6 +31,7 @@
31#include <asm/blackfin.h> 31#include <asm/blackfin.h>
32#include <asm/trace.h> 32#include <asm/trace.h>
33#if CONFIG_BFIN_KERNEL_CLOCK 33#if CONFIG_BFIN_KERNEL_CLOCK
34#include <asm/mach-common/clocks.h>
34#include <asm/mach/mem_init.h> 35#include <asm/mach/mem_init.h>
35#endif 36#endif
36 37
@@ -49,9 +50,13 @@ ENTRY(__start)
49ENTRY(__stext) 50ENTRY(__stext)
50 /* R0: argument of command line string, passed from uboot, save it */ 51 /* R0: argument of command line string, passed from uboot, save it */
51 R7 = R0; 52 R7 = R0;
52 /* Set the SYSCFG register */ 53 /* Enable Cycle Counter and Nesting Of Interrupts */
53 R0 = 0x36; 54#ifdef CONFIG_BFIN_SCRATCH_REG_CYCLES
54 SYSCFG = R0; /*Enable Cycle Counter and Nesting Of Interrupts(3rd Bit)*/ 55 R0 = SYSCFG_SNEN;
56#else
57 R0 = SYSCFG_SNEN | SYSCFG_CCEN;
58#endif
59 SYSCFG = R0;
55 R0 = 0; 60 R0 = 0;
56 61
57 /* Clear Out All the data and pointer Registers*/ 62 /* Clear Out All the data and pointer Registers*/
@@ -92,13 +97,13 @@ ENTRY(__stext)
92 M2 = r0; 97 M2 = r0;
93 M3 = r0; 98 M3 = r0;
94 99
95 trace_buffer_start(p0,r0); 100 trace_buffer_init(p0,r0);
96 P0 = R1; 101 P0 = R1;
97 R0 = R1; 102 R0 = R1;
98 103
99 /* Turn off the icache */ 104 /* Turn off the icache */
100 p0.l = (IMEM_CONTROL & 0xFFFF); 105 p0.l = LO(IMEM_CONTROL);
101 p0.h = (IMEM_CONTROL >> 16); 106 p0.h = HI(IMEM_CONTROL);
102 R1 = [p0]; 107 R1 = [p0];
103 R0 = ~ENICPLB; 108 R0 = ~ENICPLB;
104 R0 = R0 & R1; 109 R0 = R0 & R1;
@@ -106,8 +111,8 @@ ENTRY(__stext)
106 SSYNC; 111 SSYNC;
107 112
108 /* Turn off the dcache */ 113 /* Turn off the dcache */
109 p0.l = (DMEM_CONTROL & 0xFFFF); 114 p0.l = LO(DMEM_CONTROL);
110 p0.h = (DMEM_CONTROL >> 16); 115 p0.h = HI(DMEM_CONTROL);
111 R1 = [p0]; 116 R1 = [p0];
112 R0 = ~ENDCPLB; 117 R0 = ~ENDCPLB;
113 R0 = R0 & R1; 118 R0 = R0 & R1;
@@ -120,6 +125,12 @@ ENTRY(__stext)
120 FP = SP; 125 FP = SP;
121 USP = SP; 126 USP = SP;
122 127
128#ifdef CONFIG_EARLY_PRINTK
129 SP += -12;
130 call _init_early_exception_vectors;
131 SP += 12;
132#endif
133
123 /* Put The Code for PLL Programming and SDRAM Programming in L1 ISRAM */ 134 /* Put The Code for PLL Programming and SDRAM Programming in L1 ISRAM */
124 call _bf53x_relocate_l1_mem; 135 call _bf53x_relocate_l1_mem;
125#if CONFIG_BFIN_KERNEL_CLOCK 136#if CONFIG_BFIN_KERNEL_CLOCK
@@ -172,7 +183,7 @@ ENTRY(__stext)
172 p0.l = .LWAIT_HERE; 183 p0.l = .LWAIT_HERE;
173 p0.h = .LWAIT_HERE; 184 p0.h = .LWAIT_HERE;
174 reti = p0; 185 reti = p0;
175#if defined (ANOMALY_05000281) 186#if ANOMALY_05000281
176 nop; 187 nop;
177 nop; 188 nop;
178 nop; 189 nop;
@@ -335,8 +346,8 @@ ENTRY(_start_dma_code)
335 w[p0] = r0.l; 346 w[p0] = r0.l;
336 ssync; 347 ssync;
337 348
338 p0.l = (EBIU_SDBCTL & 0xFFFF); 349 p0.l = LO(EBIU_SDBCTL);
339 p0.h = (EBIU_SDBCTL >> 16); /* SDRAM Memory Bank Control Register */ 350 p0.h = HI(EBIU_SDBCTL); /* SDRAM Memory Bank Control Register */
340 r0 = mem_SDBCTL; 351 r0 = mem_SDBCTL;
341 w[p0] = r0.l; 352 w[p0] = r0.l;
342 ssync; 353 ssync;
@@ -373,129 +384,6 @@ ENTRY(_start_dma_code)
373 RTS; 384 RTS;
374#endif /* CONFIG_BFIN_KERNEL_CLOCK */ 385#endif /* CONFIG_BFIN_KERNEL_CLOCK */
375 386
376ENTRY(_bfin_reset)
377 /* No more interrupts to be handled*/
378 CLI R6;
379 SSYNC;
380
381#if defined(CONFIG_MTD_M25P80)
382/*
383 * The following code fix the SPI flash reboot issue,
384 * /CS signal of the chip which is using PF10 return to GPIO mode
385 */
386 p0.h = hi(PORTF_FER);
387 p0.l = lo(PORTF_FER);
388 r0.l = 0x0000;
389 w[p0] = r0.l;
390 SSYNC;
391
392/* /CS return to high */
393 p0.h = hi(PORTFIO);
394 p0.l = lo(PORTFIO);
395 r0.l = 0xFFFF;
396 w[p0] = r0.l;
397 SSYNC;
398
399/* Delay some time, This is necessary */
400 r1.h = 0;
401 r1.l = 0x400;
402 p1 = r1;
403 lsetup (_delay_lab1,_delay_lab1_end ) lc1 = p1;
404_delay_lab1:
405 r0.h = 0;
406 r0.l = 0x8000;
407 p0 = r0;
408 lsetup (_delay_lab0,_delay_lab0_end ) lc0 = p0;
409_delay_lab0:
410 nop;
411_delay_lab0_end:
412 nop;
413_delay_lab1_end:
414 nop;
415#endif
416
417 /* Clear the bits 13-15 in SWRST if they werent cleared */
418 p0.h = hi(SWRST);
419 p0.l = lo(SWRST);
420 csync;
421 r0.l = w[p0];
422
423 /* Clear the IMASK register */
424 p0.h = hi(IMASK);
425 p0.l = lo(IMASK);
426 r0 = 0x0;
427 [p0] = r0;
428
429 /* Clear the ILAT register */
430 p0.h = hi(ILAT);
431 p0.l = lo(ILAT);
432 r0 = [p0];
433 [p0] = r0;
434 SSYNC;
435
436 /* Disable the WDOG TIMER */
437 p0.h = hi(WDOG_CTL);
438 p0.l = lo(WDOG_CTL);
439 r0.l = 0xAD6;
440 w[p0] = r0.l;
441 SSYNC;
442
443 /* Clear the sticky bit incase it is already set */
444 p0.h = hi(WDOG_CTL);
445 p0.l = lo(WDOG_CTL);
446 r0.l = 0x8AD6;
447 w[p0] = r0.l;
448 SSYNC;
449
450 /* Program the count value */
451 R0.l = 0x100;
452 R0.h = 0x0;
453 P0.h = hi(WDOG_CNT);
454 P0.l = lo(WDOG_CNT);
455 [P0] = R0;
456 SSYNC;
457
458 /* Program WDOG_STAT if necessary */
459 P0.h = hi(WDOG_CTL);
460 P0.l = lo(WDOG_CTL);
461 R0 = W[P0](Z);
462 CC = BITTST(R0,1);
463 if !CC JUMP .LWRITESTAT;
464 CC = BITTST(R0,2);
465 if !CC JUMP .LWRITESTAT;
466 JUMP .LSKIP_WRITE;
467
468.LWRITESTAT:
469 /* When watch dog timer is enabled,
470 * a write to STAT will load the contents of CNT to STAT
471 */
472 R0 = 0x0000(z);
473 P0.h = hi(WDOG_STAT);
474 P0.l = lo(WDOG_STAT)
475 [P0] = R0;
476 SSYNC;
477
478.LSKIP_WRITE:
479 /* Enable the reset event */
480 P0.h = hi(WDOG_CTL);
481 P0.l = lo(WDOG_CTL);
482 R0 = W[P0](Z);
483 BITCLR(R0,1);
484 BITCLR(R0,2);
485 W[P0] = R0.L;
486 SSYNC;
487 NOP;
488
489 /* Enable the wdog counter */
490 R0 = W[P0](Z);
491 BITCLR(R0,4);
492 W[P0] = R0.L;
493 SSYNC;
494
495 IDLE;
496
497 RTS;
498
499.data 387.data
500 388
501/* 389/*
diff --git a/arch/blackfin/mach-bf561/boards/cm_bf561.c b/arch/blackfin/mach-bf561/boards/cm_bf561.c
index 5b2b544529a1..cd827a1b6ba1 100644
--- a/arch/blackfin/mach-bf561/boards/cm_bf561.c
+++ b/arch/blackfin/mach-bf561/boards/cm_bf561.c
@@ -34,7 +34,9 @@
34#include <linux/spi/spi.h> 34#include <linux/spi/spi.h>
35#include <linux/spi/flash.h> 35#include <linux/spi/flash.h>
36#include <linux/usb_isp1362.h> 36#include <linux/usb_isp1362.h>
37#include <linux/pata_platform.h>
37#include <linux/irq.h> 38#include <linux/irq.h>
39#include <asm/dma.h>
38#include <asm/bfin5xx_spi.h> 40#include <asm/bfin5xx_spi.h>
39 41
40/* 42/*
@@ -112,7 +114,7 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
112 /* the modalias must be the same as spi device driver name */ 114 /* the modalias must be the same as spi device driver name */
113 .modalias = "m25p80", /* Name of spi_driver for this device */ 115 .modalias = "m25p80", /* Name of spi_driver for this device */
114 .max_speed_hz = 25000000, /* max spi clock (SCK) speed in HZ */ 116 .max_speed_hz = 25000000, /* max spi clock (SCK) speed in HZ */
115 .bus_num = 1, /* Framework bus number */ 117 .bus_num = 0, /* Framework bus number */
116 .chip_select = 1, /* Framework chip select. On STAMP537 it is SPISSEL1*/ 118 .chip_select = 1, /* Framework chip select. On STAMP537 it is SPISSEL1*/
117 .platform_data = &bfin_spi_flash_data, 119 .platform_data = &bfin_spi_flash_data,
118 .controller_data = &spi_flash_chip_info, 120 .controller_data = &spi_flash_chip_info,
@@ -124,7 +126,7 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
124 { 126 {
125 .modalias = "bfin_spi_adc", /* Name of spi_driver for this device */ 127 .modalias = "bfin_spi_adc", /* Name of spi_driver for this device */
126 .max_speed_hz = 6250000, /* max spi clock (SCK) speed in HZ */ 128 .max_speed_hz = 6250000, /* max spi clock (SCK) speed in HZ */
127 .bus_num = 1, /* Framework bus number */ 129 .bus_num = 0, /* Framework bus number */
128 .chip_select = 1, /* Framework chip select. */ 130 .chip_select = 1, /* Framework chip select. */
129 .platform_data = NULL, /* No spi_driver specific config */ 131 .platform_data = NULL, /* No spi_driver specific config */
130 .controller_data = &spi_adc_chip_info, 132 .controller_data = &spi_adc_chip_info,
@@ -135,7 +137,7 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
135 { 137 {
136 .modalias = "ad1836-spi", 138 .modalias = "ad1836-spi",
137 .max_speed_hz = 3125000, /* max spi clock (SCK) speed in HZ */ 139 .max_speed_hz = 3125000, /* max spi clock (SCK) speed in HZ */
138 .bus_num = 1, 140 .bus_num = 0,
139 .chip_select = CONFIG_SND_BLACKFIN_SPI_PFBIT, 141 .chip_select = CONFIG_SND_BLACKFIN_SPI_PFBIT,
140 .controller_data = &ad1836_spi_chip_info, 142 .controller_data = &ad1836_spi_chip_info,
141 }, 143 },
@@ -144,7 +146,7 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
144 { 146 {
145 .modalias = "ad9960-spi", 147 .modalias = "ad9960-spi",
146 .max_speed_hz = 10000000, /* max spi clock (SCK) speed in HZ */ 148 .max_speed_hz = 10000000, /* max spi clock (SCK) speed in HZ */
147 .bus_num = 1, 149 .bus_num = 0,
148 .chip_select = 1, 150 .chip_select = 1,
149 .controller_data = &ad9960_spi_chip_info, 151 .controller_data = &ad9960_spi_chip_info,
150 }, 152 },
@@ -153,7 +155,7 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
153 { 155 {
154 .modalias = "spi_mmc", 156 .modalias = "spi_mmc",
155 .max_speed_hz = 25000000, /* max spi clock (SCK) speed in HZ */ 157 .max_speed_hz = 25000000, /* max spi clock (SCK) speed in HZ */
156 .bus_num = 1, 158 .bus_num = 0,
157 .chip_select = CONFIG_SPI_MMC_CS_CHAN, 159 .chip_select = CONFIG_SPI_MMC_CS_CHAN,
158 .platform_data = NULL, 160 .platform_data = NULL,
159 .controller_data = &spi_mmc_chip_info, 161 .controller_data = &spi_mmc_chip_info,
@@ -162,17 +164,33 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
162#endif 164#endif
163}; 165};
164 166
167/* SPI (0) */
168static struct resource bfin_spi0_resource[] = {
169 [0] = {
170 .start = SPI0_REGBASE,
171 .end = SPI0_REGBASE + 0xFF,
172 .flags = IORESOURCE_MEM,
173 },
174 [1] = {
175 .start = CH_SPI,
176 .end = CH_SPI,
177 .flags = IORESOURCE_IRQ,
178 }
179};
180
165/* SPI controller data */ 181/* SPI controller data */
166static struct bfin5xx_spi_master spi_bfin_master_info = { 182static struct bfin5xx_spi_master bfin_spi0_info = {
167 .num_chipselect = 8, 183 .num_chipselect = 8,
168 .enable_dma = 1, /* master has the ability to do dma transfer */ 184 .enable_dma = 1, /* master has the ability to do dma transfer */
169}; 185};
170 186
171static struct platform_device spi_bfin_master_device = { 187static struct platform_device bfin_spi0_device = {
172 .name = "bfin-spi-master", 188 .name = "bfin-spi",
173 .id = 1, /* Bus number */ 189 .id = 0, /* Bus number */
190 .num_resources = ARRAY_SIZE(bfin_spi0_resource),
191 .resource = bfin_spi0_resource,
174 .dev = { 192 .dev = {
175 .platform_data = &spi_bfin_master_info, /* Passed to driver */ 193 .platform_data = &bfin_spi0_info, /* Passed to driver */
176 }, 194 },
177}; 195};
178#endif /* spi master and devices */ 196#endif /* spi master and devices */
@@ -256,6 +274,43 @@ static struct platform_device bfin_uart_device = {
256}; 274};
257#endif 275#endif
258 276
277#if defined(CONFIG_PATA_PLATFORM) || defined(CONFIG_PATA_PLATFORM_MODULE)
278#define PATA_INT 119
279
280static struct pata_platform_info bfin_pata_platform_data = {
281 .ioport_shift = 2,
282 .irq_type = IRQF_TRIGGER_HIGH | IRQF_DISABLED,
283};
284
285static struct resource bfin_pata_resources[] = {
286 {
287 .start = 0x2400C000,
288 .end = 0x2400C001F,
289 .flags = IORESOURCE_MEM,
290 },
291 {
292 .start = 0x2400D018,
293 .end = 0x2400D01B,
294 .flags = IORESOURCE_MEM,
295 },
296 {
297 .start = PATA_INT,
298 .end = PATA_INT,
299 .flags = IORESOURCE_IRQ,
300 },
301};
302
303static struct platform_device bfin_pata_device = {
304 .name = "pata_platform",
305 .id = -1,
306 .num_resources = ARRAY_SIZE(bfin_pata_resources),
307 .resource = bfin_pata_resources,
308 .dev = {
309 .platform_data = &bfin_pata_platform_data,
310 }
311};
312#endif
313
259static struct platform_device *cm_bf561_devices[] __initdata = { 314static struct platform_device *cm_bf561_devices[] __initdata = {
260 315
261#if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE) 316#if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE)
@@ -271,9 +326,12 @@ static struct platform_device *cm_bf561_devices[] __initdata = {
271#endif 326#endif
272 327
273#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE) 328#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
274 &spi_bfin_master_device, 329 &bfin_spi0_device,
275#endif 330#endif
276 331
332#if defined(CONFIG_PATA_PLATFORM) || defined(CONFIG_PATA_PLATFORM_MODULE)
333 &bfin_pata_device,
334#endif
277}; 335};
278 336
279static int __init cm_bf561_init(void) 337static int __init cm_bf561_init(void)
@@ -283,6 +341,10 @@ static int __init cm_bf561_init(void)
283#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE) 341#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
284 spi_register_board_info(bfin_spi_board_info, ARRAY_SIZE(bfin_spi_board_info)); 342 spi_register_board_info(bfin_spi_board_info, ARRAY_SIZE(bfin_spi_board_info));
285#endif 343#endif
344
345#if defined(CONFIG_PATA_PLATFORM) || defined(CONFIG_PATA_PLATFORM_MODULE)
346 irq_desc[PATA_INT].status |= IRQ_NOAUTOEN;
347#endif
286 return 0; 348 return 0;
287} 349}
288 350
diff --git a/arch/blackfin/mach-bf561/boards/ezkit.c b/arch/blackfin/mach-bf561/boards/ezkit.c
index 724191da20a2..57e14edca8b1 100644
--- a/arch/blackfin/mach-bf561/boards/ezkit.c
+++ b/arch/blackfin/mach-bf561/boards/ezkit.c
@@ -32,6 +32,8 @@
32#include <linux/spi/spi.h> 32#include <linux/spi/spi.h>
33#include <linux/irq.h> 33#include <linux/irq.h>
34#include <linux/interrupt.h> 34#include <linux/interrupt.h>
35#include <linux/pata_platform.h>
36#include <asm/dma.h>
35#include <asm/bfin5xx_spi.h> 37#include <asm/bfin5xx_spi.h>
36 38
37/* 39/*
@@ -140,17 +142,33 @@ static struct bfin5xx_spi_chip ad1836_spi_chip_info = {
140#endif 142#endif
141#endif 143#endif
142 144
145/* SPI (0) */
146static struct resource bfin_spi0_resource[] = {
147 [0] = {
148 .start = SPI0_REGBASE,
149 .end = SPI0_REGBASE + 0xFF,
150 .flags = IORESOURCE_MEM,
151 },
152 [1] = {
153 .start = CH_SPI,
154 .end = CH_SPI,
155 .flags = IORESOURCE_IRQ,
156 }
157};
158
143/* SPI controller data */ 159/* SPI controller data */
144static struct bfin5xx_spi_master spi_bfin_master_info = { 160static struct bfin5xx_spi_master bfin_spi0_info = {
145 .num_chipselect = 8, 161 .num_chipselect = 8,
146 .enable_dma = 1, /* master has the ability to do dma transfer */ 162 .enable_dma = 1, /* master has the ability to do dma transfer */
147}; 163};
148 164
149static struct platform_device spi_bfin_master_device = { 165static struct platform_device bfin_spi0_device = {
150 .name = "bfin-spi-master", 166 .name = "bfin-spi",
151 .id = 1, /* Bus number */ 167 .id = 0, /* Bus number */
168 .num_resources = ARRAY_SIZE(bfin_spi0_resource),
169 .resource = bfin_spi0_resource,
152 .dev = { 170 .dev = {
153 .platform_data = &spi_bfin_master_info, /* Passed to driver */ 171 .platform_data = &bfin_spi0_info, /* Passed to driver */
154 }, 172 },
155}; 173};
156 174
@@ -160,23 +178,63 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
160 { 178 {
161 .modalias = "ad1836-spi", 179 .modalias = "ad1836-spi",
162 .max_speed_hz = 3125000, /* max spi clock (SCK) speed in HZ */ 180 .max_speed_hz = 3125000, /* max spi clock (SCK) speed in HZ */
163 .bus_num = 1, 181 .bus_num = 0,
164 .chip_select = CONFIG_SND_BLACKFIN_SPI_PFBIT, 182 .chip_select = CONFIG_SND_BLACKFIN_SPI_PFBIT,
165 .controller_data = &ad1836_spi_chip_info, 183 .controller_data = &ad1836_spi_chip_info,
166 }, 184 },
167#endif 185#endif
168}; 186};
169 187
188#if defined(CONFIG_PATA_PLATFORM) || defined(CONFIG_PATA_PLATFORM_MODULE)
189#define PATA_INT 55
190
191static struct pata_platform_info bfin_pata_platform_data = {
192 .ioport_shift = 1,
193 .irq_type = IRQF_TRIGGER_HIGH | IRQF_DISABLED,
194};
195
196static struct resource bfin_pata_resources[] = {
197 {
198 .start = 0x20314020,
199 .end = 0x2031403F,
200 .flags = IORESOURCE_MEM,
201 },
202 {
203 .start = 0x2031401C,
204 .end = 0x2031401F,
205 .flags = IORESOURCE_MEM,
206 },
207 {
208 .start = PATA_INT,
209 .end = PATA_INT,
210 .flags = IORESOURCE_IRQ,
211 },
212};
213
214static struct platform_device bfin_pata_device = {
215 .name = "pata_platform",
216 .id = -1,
217 .num_resources = ARRAY_SIZE(bfin_pata_resources),
218 .resource = bfin_pata_resources,
219 .dev = {
220 .platform_data = &bfin_pata_platform_data,
221 }
222};
223#endif
224
170static struct platform_device *ezkit_devices[] __initdata = { 225static struct platform_device *ezkit_devices[] __initdata = {
171#if defined(CONFIG_SMC91X) || defined(CONFIG_SMC91X_MODULE) 226#if defined(CONFIG_SMC91X) || defined(CONFIG_SMC91X_MODULE)
172 &smc91x_device, 227 &smc91x_device,
173#endif 228#endif
174#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE) 229#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
175 &spi_bfin_master_device, 230 &bfin_spi0_device,
176#endif 231#endif
177#if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE) 232#if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE)
178 &bfin_uart_device, 233 &bfin_uart_device,
179#endif 234#endif
235#if defined(CONFIG_PATA_PLATFORM) || defined(CONFIG_PATA_PLATFORM_MODULE)
236 &bfin_pata_device,
237#endif
180}; 238};
181 239
182static int __init ezkit_init(void) 240static int __init ezkit_init(void)
@@ -194,7 +252,15 @@ static int __init ezkit_init(void)
194 SSYNC(); 252 SSYNC();
195#endif 253#endif
196 254
197 return spi_register_board_info(bfin_spi_board_info, ARRAY_SIZE(bfin_spi_board_info)); 255#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
256 spi_register_board_info(bfin_spi_board_info,
257 ARRAY_SIZE(bfin_spi_board_info));
258#endif
259
260#if defined(CONFIG_PATA_PLATFORM) || defined(CONFIG_PATA_PLATFORM_MODULE)
261 irq_desc[PATA_INT].status |= IRQ_NOAUTOEN;
262#endif
263 return 0;
198} 264}
199 265
200arch_initcall(ezkit_init); 266arch_initcall(ezkit_init);
diff --git a/arch/blackfin/mach-bf561/head.S b/arch/blackfin/mach-bf561/head.S
index 38650a628980..96a3d456fb6d 100644
--- a/arch/blackfin/mach-bf561/head.S
+++ b/arch/blackfin/mach-bf561/head.S
@@ -33,6 +33,7 @@
33#include <asm/trace.h> 33#include <asm/trace.h>
34 34
35#if CONFIG_BFIN_KERNEL_CLOCK 35#if CONFIG_BFIN_KERNEL_CLOCK
36#include <asm/mach-common/clocks.h>
36#include <asm/mach/mem_init.h> 37#include <asm/mach/mem_init.h>
37#endif 38#endif
38 39
@@ -50,10 +51,12 @@ __INIT
50ENTRY(__start) 51ENTRY(__start)
51 /* R0: argument of command line string, passed from uboot, save it */ 52 /* R0: argument of command line string, passed from uboot, save it */
52 R7 = R0; 53 R7 = R0;
53 /* Set the SYSCFG register: 54 /* Enable Cycle Counter and Nesting Of Interrupts */
54 * Enable Cycle Counter and Nesting Of Interrupts (3rd Bit) 55#ifdef CONFIG_BFIN_SCRATCH_REG_CYCLES
55 */ 56 R0 = SYSCFG_SNEN;
56 R0 = 0x36; 57#else
58 R0 = SYSCFG_SNEN | SYSCFG_CCEN;
59#endif
57 SYSCFG = R0; 60 SYSCFG = R0;
58 R0 = 0; 61 R0 = 0;
59 62
@@ -95,43 +98,42 @@ ENTRY(__start)
95 M2 = r0; 98 M2 = r0;
96 M3 = r0; 99 M3 = r0;
97 100
98 trace_buffer_start(p0,r0); 101 trace_buffer_init(p0,r0);
99 P0 = R1; 102 P0 = R1;
100 R0 = R1; 103 R0 = R1;
101 104
102 /* Turn off the icache */ 105 /* Turn off the icache */
103 p0.l = (IMEM_CONTROL & 0xFFFF); 106 p0.l = LO(IMEM_CONTROL);
104 p0.h = (IMEM_CONTROL >> 16); 107 p0.h = HI(IMEM_CONTROL);
105 R1 = [p0]; 108 R1 = [p0];
106 R0 = ~ENICPLB; 109 R0 = ~ENICPLB;
107 R0 = R0 & R1; 110 R0 = R0 & R1;
108 111
109 /* Anomaly 05000125 */ 112#if ANOMALY_05000125
110#ifdef ANOMALY_05000125
111 CLI R2; 113 CLI R2;
112 SSYNC; 114 SSYNC;
113#endif 115#endif
114 [p0] = R0; 116 [p0] = R0;
115 SSYNC; 117 SSYNC;
116#ifdef ANOMALY_05000125 118#if ANOMALY_05000125
117 STI R2; 119 STI R2;
118#endif 120#endif
119 121
120 /* Turn off the dcache */ 122 /* Turn off the dcache */
121 p0.l = (DMEM_CONTROL & 0xFFFF); 123 p0.l = LO(DMEM_CONTROL);
122 p0.h = (DMEM_CONTROL >> 16); 124 p0.h = HI(DMEM_CONTROL);
123 R1 = [p0]; 125 R1 = [p0];
124 R0 = ~ENDCPLB; 126 R0 = ~ENDCPLB;
125 R0 = R0 & R1; 127 R0 = R0 & R1;
126 128
127 /* Anomaly 05000125 */ 129 /* Anomaly 05000125 */
128#ifdef ANOMALY_05000125 130#if ANOMALY_05000125
129 CLI R2; 131 CLI R2;
130 SSYNC; 132 SSYNC;
131#endif 133#endif
132 [p0] = R0; 134 [p0] = R0;
133 SSYNC; 135 SSYNC;
134#ifdef ANOMALY_05000125 136#if ANOMALY_05000125
135 STI R2; 137 STI R2;
136#endif 138#endif
137 139
@@ -167,6 +169,12 @@ ENTRY(__start)
167 fp = sp; 169 fp = sp;
168 usp = sp; 170 usp = sp;
169 171
172#ifdef CONFIG_EARLY_PRINTK
173 SP += -12;
174 call _init_early_exception_vectors;
175 SP += 12;
176#endif
177
170 /* Put The Code for PLL Programming and SDRAM Programming in L1 ISRAM */ 178 /* Put The Code for PLL Programming and SDRAM Programming in L1 ISRAM */
171 call _bf53x_relocate_l1_mem; 179 call _bf53x_relocate_l1_mem;
172#if CONFIG_BFIN_KERNEL_CLOCK 180#if CONFIG_BFIN_KERNEL_CLOCK
@@ -220,7 +228,7 @@ ENTRY(__start)
220 p0.l = .LWAIT_HERE; 228 p0.l = .LWAIT_HERE;
221 p0.h = .LWAIT_HERE; 229 p0.h = .LWAIT_HERE;
222 reti = p0; 230 reti = p0;
223#if defined(ANOMALY_05000281) 231#if ANOMALY_05000281
224 nop; nop; nop; 232 nop; nop; nop;
225#endif 233#endif
226 rti; 234 rti;
@@ -372,8 +380,8 @@ ENTRY(_start_dma_code)
372 w[p0] = r0.l; 380 w[p0] = r0.l;
373 ssync; 381 ssync;
374 382
375 p0.l = (EBIU_SDBCTL & 0xFFFF); 383 p0.l = LO(EBIU_SDBCTL);
376 p0.h = (EBIU_SDBCTL >> 16); /* SDRAM Memory Bank Control Register */ 384 p0.h = HI(EBIU_SDBCTL); /* SDRAM Memory Bank Control Register */
377 r0 = mem_SDBCTL; 385 r0 = mem_SDBCTL;
378 w[p0] = r0.l; 386 w[p0] = r0.l;
379 ssync; 387 ssync;
@@ -404,66 +412,6 @@ ENTRY(_start_dma_code)
404ENDPROC(_start_dma_code) 412ENDPROC(_start_dma_code)
405#endif /* CONFIG_BFIN_KERNEL_CLOCK */ 413#endif /* CONFIG_BFIN_KERNEL_CLOCK */
406 414
407ENTRY(_bfin_reset)
408 /* No more interrupts to be handled*/
409 CLI R6;
410 SSYNC;
411
412#if defined(CONFIG_BFIN_SHARED_FLASH_ENET)
413 p0.h = hi(FIO_INEN);
414 p0.l = lo(FIO_INEN);
415 r0.l = ~(PF1 | PF0);
416 w[p0] = r0.l;
417
418 p0.h = hi(FIO_DIR);
419 p0.l = lo(FIO_DIR);
420 r0.l = (PF1 | PF0);
421 w[p0] = r0.l;
422
423 p0.h = hi(FIO_FLAG_C);
424 p0.l = lo(FIO_FLAG_C);
425 r0.l = (PF1 | PF0);
426 w[p0] = r0.l;
427#endif
428
429 /* Clear the IMASK register */
430 p0.h = hi(IMASK);
431 p0.l = lo(IMASK);
432 r0 = 0x0;
433 [p0] = r0;
434
435 /* Clear the ILAT register */
436 p0.h = hi(ILAT);
437 p0.l = lo(ILAT);
438 r0 = [p0];
439 [p0] = r0;
440 SSYNC;
441
442 /* make sure SYSCR is set to use BMODE */
443 P0.h = hi(SYSCR);
444 P0.l = lo(SYSCR);
445 R0.l = 0x20; /* on BF561, disable core b */
446 W[P0] = R0.l;
447 SSYNC;
448
449 /* issue a system soft reset */
450 P1.h = hi(SWRST);
451 P1.l = lo(SWRST);
452 R1.l = 0x0007;
453 W[P1] = R1;
454 SSYNC;
455
456 /* clear system soft reset */
457 R0.l = 0x0000;
458 W[P0] = R0;
459 SSYNC;
460
461 /* issue core reset */
462 raise 1;
463
464 RTS;
465ENDPROC(_bfin_reset)
466
467.data 415.data
468 416
469/* 417/*
diff --git a/arch/blackfin/mach-common/Makefile b/arch/blackfin/mach-common/Makefile
index 0279ede70392..4d7733dfd5de 100644
--- a/arch/blackfin/mach-common/Makefile
+++ b/arch/blackfin/mach-common/Makefile
@@ -4,7 +4,7 @@
4 4
5obj-y := \ 5obj-y := \
6 cache.o cacheinit.o cplbhdlr.o cplbmgr.o entry.o \ 6 cache.o cacheinit.o cplbhdlr.o cplbmgr.o entry.o \
7 interrupt.o lock.o irqpanic.o 7 interrupt.o lock.o irqpanic.o arch_checks.o
8 8
9obj-$(CONFIG_CPLB_INFO) += cplbinfo.o 9obj-$(CONFIG_CPLB_INFO) += cplbinfo.o
10obj-$(CONFIG_BFIN_SINGLE_CORE) += ints-priority-sc.o 10obj-$(CONFIG_BFIN_SINGLE_CORE) += ints-priority-sc.o
diff --git a/arch/blackfin/mach-common/arch_checks.c b/arch/blackfin/mach-common/arch_checks.c
new file mode 100644
index 000000000000..2f6ce397780f
--- /dev/null
+++ b/arch/blackfin/mach-common/arch_checks.c
@@ -0,0 +1,60 @@
1/*
2 * File: arch/blackfin/mach-common/arch_checks.c
3 * Based on:
4 * Author: Robin Getz <rgetz@blackfin.uclinux.org>
5 *
6 * Created: 25Jul07
7 * Description: Do some checking to make sure things are OK
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 <asm/mach/anomaly.h>
31#include <asm/mach-common/clocks.h>
32
33#ifdef CONFIG_BFIN_KERNEL_CLOCK
34
35# if (CONFIG_VCO_HZ > CONFIG_MAX_VCO_HZ)
36# error "VCO selected is more than maximum value. Please change the VCO multipler"
37# endif
38
39# if (CONFIG_SCLK_HZ > CONFIG_MAX_SCLK_HZ)
40# error "Sclk value selected is more than maximum. Please select a proper value for SCLK multiplier"
41# endif
42
43# if (CONFIG_SCLK_HZ < CONFIG_MIN_SCLK_HZ)
44# error "Sclk value selected is less than minimum. Please select a proper value for SCLK multiplier"
45# endif
46
47# if (ANOMALY_05000273) && (CONFIG_SCLK_HZ * 2 > CONFIG_CCLK_HZ)
48# error "ANOMALY 05000273, please make sure CCLK is at least 2x SCLK"
49# endif
50
51# if (CONFIG_SCLK_HZ > CONFIG_CCLK_HZ) && (CONFIG_SCLK_HZ != CONFIG_CLKIN_HZ) && (CONFIG_CCLK_HZ != CONFIG_CLKIN_HZ)
52# error "Please select sclk less than cclk"
53# endif
54
55#endif /* CONFIG_BFIN_KERNEL_CLOCK */
56
57#if (CONFIG_MEM_SIZE % 4)
58#error "SDRAM mem size must be multible of 4MB"
59#endif
60
diff --git a/arch/blackfin/mach-common/cache.S b/arch/blackfin/mach-common/cache.S
index 7063795eb7c0..0521b1588204 100644
--- a/arch/blackfin/mach-common/cache.S
+++ b/arch/blackfin/mach-common/cache.S
@@ -79,8 +79,8 @@ ENTRY(_icache_invalidate)
79ENTRY(_invalidate_entire_icache) 79ENTRY(_invalidate_entire_icache)
80 [--SP] = ( R7:5); 80 [--SP] = ( R7:5);
81 81
82 P0.L = (IMEM_CONTROL & 0xFFFF); 82 P0.L = LO(IMEM_CONTROL);
83 P0.H = (IMEM_CONTROL >> 16); 83 P0.H = HI(IMEM_CONTROL);
84 R7 = [P0]; 84 R7 = [P0];
85 85
86 /* Clear the IMC bit , All valid bits in the instruction 86 /* Clear the IMC bit , All valid bits in the instruction
@@ -197,8 +197,8 @@ ENTRY(_invalidate_entire_dcache)
197ENTRY(_dcache_invalidate) 197ENTRY(_dcache_invalidate)
198 [--SP] = ( R7:6); 198 [--SP] = ( R7:6);
199 199
200 P0.L = (DMEM_CONTROL & 0xFFFF); 200 P0.L = LO(DMEM_CONTROL);
201 P0.H = (DMEM_CONTROL >> 16); 201 P0.H = HI(DMEM_CONTROL);
202 R7 = [P0]; 202 R7 = [P0];
203 203
204 /* Clear the DMC[1:0] bits, All valid bits in the data 204 /* Clear the DMC[1:0] bits, All valid bits in the data
diff --git a/arch/blackfin/mach-common/cacheinit.S b/arch/blackfin/mach-common/cacheinit.S
index 5be6b975ae4a..22fada0c1cb3 100644
--- a/arch/blackfin/mach-common/cacheinit.S
+++ b/arch/blackfin/mach-common/cacheinit.S
@@ -38,13 +38,13 @@
38 38
39.text 39.text
40 40
41#ifdef ANOMALY_05000125 41#if ANOMALY_05000125
42#if defined(CONFIG_BLKFIN_CACHE) 42#if defined(CONFIG_BFIN_ICACHE)
43ENTRY(_bfin_write_IMEM_CONTROL) 43ENTRY(_bfin_write_IMEM_CONTROL)
44 44
45 /* Enable Instruction Cache */ 45 /* Enable Instruction Cache */
46 P0.l = (IMEM_CONTROL & 0xFFFF); 46 P0.l = LO(IMEM_CONTROL);
47 P0.h = (IMEM_CONTROL >> 16); 47 P0.h = HI(IMEM_CONTROL);
48 48
49 /* Anomaly 05000125 */ 49 /* Anomaly 05000125 */
50 CLI R1; 50 CLI R1;
@@ -58,10 +58,10 @@ ENTRY(_bfin_write_IMEM_CONTROL)
58ENDPROC(_bfin_write_IMEM_CONTROL) 58ENDPROC(_bfin_write_IMEM_CONTROL)
59#endif 59#endif
60 60
61#if defined(CONFIG_BLKFIN_DCACHE) 61#if defined(CONFIG_BFIN_DCACHE)
62ENTRY(_bfin_write_DMEM_CONTROL) 62ENTRY(_bfin_write_DMEM_CONTROL)
63 P0.l = (DMEM_CONTROL & 0xFFFF); 63 P0.l = LO(DMEM_CONTROL);
64 P0.h = (DMEM_CONTROL >> 16); 64 P0.h = HI(DMEM_CONTROL);
65 65
66 CLI R1; 66 CLI R1;
67 SSYNC; /* SSYNC required before writing to DMEM_CONTROL. */ 67 SSYNC; /* SSYNC required before writing to DMEM_CONTROL. */
diff --git a/arch/blackfin/mach-common/cplbhdlr.S b/arch/blackfin/mach-common/cplbhdlr.S
index 2f3c72c23997..2788532de72b 100644
--- a/arch/blackfin/mach-common/cplbhdlr.S
+++ b/arch/blackfin/mach-common/cplbhdlr.S
@@ -69,14 +69,14 @@ ENTRY(__cplb_hdr)
69 69
70.Lis_icplb_miss: 70.Lis_icplb_miss:
71 71
72#if defined(CONFIG_BLKFIN_CACHE) || defined(CONFIG_BLKFIN_DCACHE) 72#if defined(CONFIG_BFIN_ICACHE) || defined(CONFIG_BFIN_DCACHE)
73# if defined(CONFIG_BLKFIN_CACHE) && !defined(CONFIG_BLKFIN_DCACHE) 73# if defined(CONFIG_BFIN_ICACHE) && !defined(CONFIG_BFIN_DCACHE)
74 R1 = CPLB_ENABLE_ICACHE; 74 R1 = CPLB_ENABLE_ICACHE;
75# endif 75# endif
76# if !defined(CONFIG_BLKFIN_CACHE) && defined(CONFIG_BLKFIN_DCACHE) 76# if !defined(CONFIG_BFIN_ICACHE) && defined(CONFIG_BFIN_DCACHE)
77 R1 = CPLB_ENABLE_DCACHE; 77 R1 = CPLB_ENABLE_DCACHE;
78# endif 78# endif
79# if defined(CONFIG_BLKFIN_CACHE) && defined(CONFIG_BLKFIN_DCACHE) 79# if defined(CONFIG_BFIN_ICACHE) && defined(CONFIG_BFIN_DCACHE)
80 R1 = CPLB_ENABLE_DCACHE | CPLB_ENABLE_ICACHE; 80 R1 = CPLB_ENABLE_DCACHE | CPLB_ENABLE_ICACHE;
81# endif 81# endif
82#else 82#else
diff --git a/arch/blackfin/mach-common/cplbmgr.S b/arch/blackfin/mach-common/cplbmgr.S
index e4b47e09cf13..946703ef48ff 100644
--- a/arch/blackfin/mach-common/cplbmgr.S
+++ b/arch/blackfin/mach-common/cplbmgr.S
@@ -75,15 +75,15 @@ ENTRY(_cplb_mgr)
75 * from the configuration table. 75 * from the configuration table.
76 */ 76 */
77 77
78 P4.L = (ICPLB_FAULT_ADDR & 0xFFFF); 78 P4.L = LO(ICPLB_FAULT_ADDR);
79 P4.H = (ICPLB_FAULT_ADDR >> 16); 79 P4.H = HI(ICPLB_FAULT_ADDR);
80 80
81 P1 = 16; 81 P1 = 16;
82 P5.L = _page_size_table; 82 P5.L = _page_size_table;
83 P5.H = _page_size_table; 83 P5.H = _page_size_table;
84 84
85 P0.L = (ICPLB_DATA0 & 0xFFFF); 85 P0.L = LO(ICPLB_DATA0);
86 P0.H = (ICPLB_DATA0 >> 16); 86 P0.H = HI(ICPLB_DATA0);
87 R4 = [P4]; /* Get faulting address*/ 87 R4 = [P4]; /* Get faulting address*/
88 R6 = 64; /* Advance past the fault address, which*/ 88 R6 = 64; /* Advance past the fault address, which*/
89 R6 = R6 + R4; /* we'll use if we find a match*/ 89 R6 = R6 + R4; /* we'll use if we find a match*/
@@ -117,13 +117,13 @@ ENTRY(_cplb_mgr)
117 I0 = R4; /* Fault address we'll search for*/ 117 I0 = R4; /* Fault address we'll search for*/
118 118
119 /* set up pointers */ 119 /* set up pointers */
120 P0.L = (ICPLB_DATA0 & 0xFFFF); 120 P0.L = LO(ICPLB_DATA0);
121 P0.H = (ICPLB_DATA0 >> 16); 121 P0.H = HI(ICPLB_DATA0);
122 122
123 /* The replacement procedure for ICPLBs */ 123 /* The replacement procedure for ICPLBs */
124 124
125 P4.L = (IMEM_CONTROL & 0xFFFF); 125 P4.L = LO(IMEM_CONTROL);
126 P4.H = (IMEM_CONTROL >> 16); 126 P4.H = HI(IMEM_CONTROL);
127 127
128 /* disable cplbs */ 128 /* disable cplbs */
129 R5 = [P4]; /* Control Register*/ 129 R5 = [P4]; /* Control Register*/
@@ -243,8 +243,8 @@ ENTRY(_cplb_mgr)
243 * last entry of the table. 243 * last entry of the table.
244 */ 244 */
245 245
246 P1.L = (ICPLB_DATA15 & 0xFFFF); /* ICPLB_DATA15 */ 246 P1.L = LO(ICPLB_DATA15); /* ICPLB_DATA15 */
247 P1.H = (ICPLB_DATA15 >> 16); 247 P1.H = HI(ICPLB_DATA15);
248 [P1] = R2; 248 [P1] = R2;
249 [P1-0x100] = R4; 249 [P1-0x100] = R4;
250#ifdef CONFIG_CPLB_INFO 250#ifdef CONFIG_CPLB_INFO
@@ -292,10 +292,10 @@ ENTRY(_cplb_mgr)
292 * pending writes associated with the CPLB. 292 * pending writes associated with the CPLB.
293 */ 293 */
294 294
295 P4.L = (DCPLB_STATUS & 0xFFFF); 295 P4.L = LO(DCPLB_STATUS);
296 P4.H = (DCPLB_STATUS >> 16); 296 P4.H = HI(DCPLB_STATUS);
297 P3.L = (DCPLB_DATA0 & 0xFFFF); 297 P3.L = LO(DCPLB_DATA0);
298 P3.H = (DCPLB_DATA0 >> 16); 298 P3.H = HI(DCPLB_DATA0);
299 R5 = [P4]; 299 R5 = [P4];
300 300
301 /* A protection violation can be caused by more than just writes 301 /* A protection violation can be caused by more than just writes
@@ -355,11 +355,11 @@ ENTRY(_cplb_mgr)
355 * config table, that covers the faulting address. 355 * config table, that covers the faulting address.
356 */ 356 */
357 357
358 P1.L = (DCPLB_DATA15 & 0xFFFF); 358 P1.L = LO(DCPLB_DATA15);
359 P1.H = (DCPLB_DATA15 >> 16); 359 P1.H = HI(DCPLB_DATA15);
360 360
361 P4.L = (DCPLB_FAULT_ADDR & 0xFFFF); 361 P4.L = LO(DCPLB_FAULT_ADDR);
362 P4.H = (DCPLB_FAULT_ADDR >> 16); 362 P4.H = HI(DCPLB_FAULT_ADDR);
363 R4 = [P4]; 363 R4 = [P4];
364 I0 = R4; 364 I0 = R4;
365 365
@@ -368,8 +368,8 @@ ENTRY(_cplb_mgr)
368 R6 = R1; /* Save for later*/ 368 R6 = R1; /* Save for later*/
369 369
370 /* Turn off CPLBs while we work.*/ 370 /* Turn off CPLBs while we work.*/
371 P4.L = (DMEM_CONTROL & 0xFFFF); 371 P4.L = LO(DMEM_CONTROL);
372 P4.H = (DMEM_CONTROL >> 16); 372 P4.H = HI(DMEM_CONTROL);
373 R5 = [P4]; 373 R5 = [P4];
374 BITCLR(R5,ENDCPLB_P); 374 BITCLR(R5,ENDCPLB_P);
375 CLI R0; 375 CLI R0;
@@ -384,8 +384,8 @@ ENTRY(_cplb_mgr)
384 * are no good. 384 * are no good.
385 */ 385 */
386 386
387 I1.L = (DCPLB_DATA0 & 0xFFFF); 387 I1.L = LO(DCPLB_DATA0);
388 I1.H = (DCPLB_DATA0 >> 16); 388 I1.H = HI(DCPLB_DATA0);
389 P1 = 2; 389 P1 = 2;
390 P2 = 16; 390 P2 = 16;
391 I2.L = _dcplb_preference; 391 I2.L = _dcplb_preference;
@@ -405,7 +405,7 @@ ENTRY(_cplb_mgr)
405 P3.L = _page_size_table; /* retrieve end address */ 405 P3.L = _page_size_table; /* retrieve end address */
406 P3.H = _page_size_table; /* retrieve end address */ 406 P3.H = _page_size_table; /* retrieve end address */
407 R3 = 0x1002; /* 16th - position, 2 bits -length */ 407 R3 = 0x1002; /* 16th - position, 2 bits -length */
408#ifdef ANOMALY_05000209 408#if ANOMALY_05000209
409 nop; /* Anomaly 05000209 */ 409 nop; /* Anomaly 05000209 */
410#endif 410#endif
411 R7 = EXTRACT(R1,R3.l); 411 R7 = EXTRACT(R1,R3.l);
@@ -475,8 +475,8 @@ ENTRY(_cplb_mgr)
475 * one space closer to the start. 475 * one space closer to the start.
476 */ 476 */
477 477
478 R1.L = (DCPLB_DATA16 & 0xFFFF); /* DCPLB_DATA15 + 4 */ 478 R1.L = LO(DCPLB_DATA16); /* DCPLB_DATA15 + 4 */
479 R1.H = (DCPLB_DATA16 >> 16); 479 R1.H = HI(DCPLB_DATA16);
480 R0 = P0; 480 R0 = P0;
481 481
482 /* If the victim happens to be in DCPLB15, 482 /* If the victim happens to be in DCPLB15,
@@ -549,8 +549,8 @@ ENTRY(_cplb_mgr)
549 * if necessary. 549 * if necessary.
550 */ 550 */
551 551
552 P1.L = (DCPLB_DATA15 & 0xFFFF); 552 P1.L = LO(DCPLB_DATA15);
553 P1.H = (DCPLB_DATA15 >> 16); 553 P1.H = HI(DCPLB_DATA15);
554 554
555 /* If the DCPLB has cache bits set, but caching hasn't 555 /* If the DCPLB has cache bits set, but caching hasn't
556 * been enabled, then we want to mask off the cache-in-L1 556 * been enabled, then we want to mask off the cache-in-L1
@@ -565,7 +565,7 @@ ENTRY(_cplb_mgr)
565 * cost of first-write exceptions to mark the page as dirty. 565 * cost of first-write exceptions to mark the page as dirty.
566 */ 566 */
567 567
568#ifdef CONFIG_BLKFIN_WT 568#ifdef CONFIG_BFIN_WT
569 BITSET(R6, 14); /* Set WT*/ 569 BITSET(R6, 14); /* Set WT*/
570#endif 570#endif
571 571
diff --git a/arch/blackfin/mach-common/dpmc.S b/arch/blackfin/mach-common/dpmc.S
index 97cdcd6a00d4..39fbc2861107 100644
--- a/arch/blackfin/mach-common/dpmc.S
+++ b/arch/blackfin/mach-common/dpmc.S
@@ -39,8 +39,8 @@ ENTRY(_unmask_wdog_wakeup_evt)
39 P0.H = hi(SICA_IWR1); 39 P0.H = hi(SICA_IWR1);
40 P0.L = lo(SICA_IWR1); 40 P0.L = lo(SICA_IWR1);
41#else 41#else
42 P0.h = (SIC_IWR >> 16); 42 P0.h = HI(SIC_IWR);
43 P0.l = (SIC_IWR & 0xFFFF); 43 P0.l = LO(SIC_IWR);
44#endif 44#endif
45 R7 = [P0]; 45 R7 = [P0];
46#if defined(CONFIG_BF561) 46#if defined(CONFIG_BF561)
@@ -60,11 +60,11 @@ ENTRY(_unmask_wdog_wakeup_evt)
60 */ 60 */
61 R7 = 0x0000(z); 61 R7 = 0x0000(z);
62#if defined(CONFIG_BF561) 62#if defined(CONFIG_BF561)
63 P0.h = (WDOGA_STAT >> 16); 63 P0.h = HI(WDOGA_STAT);
64 P0.l = (WDOGA_STAT & 0xFFFF); 64 P0.l = LO(WDOGA_STAT);
65#else 65#else
66 P0.h = (WDOG_STAT >> 16); 66 P0.h = HI(WDOG_STAT);
67 P0.l = (WDOG_STAT & 0xFFFF); 67 P0.l = LO(WDOG_STAT);
68#endif 68#endif
69 [P0] = R7; 69 [P0] = R7;
70 SSYNC; 70 SSYNC;
@@ -73,21 +73,21 @@ ENTRY(_unmask_wdog_wakeup_evt)
73ENTRY(_program_wdog_timer) 73ENTRY(_program_wdog_timer)
74 [--SP] = ( R7:0, P5:0 ); 74 [--SP] = ( R7:0, P5:0 );
75#if defined(CONFIG_BF561) 75#if defined(CONFIG_BF561)
76 P0.h = (WDOGA_CNT >> 16); 76 P0.h = HI(WDOGA_CNT);
77 P0.l = (WDOGA_CNT & 0xFFFF); 77 P0.l = LO(WDOGA_CNT);
78#else 78#else
79 P0.h = (WDOG_CNT >> 16); 79 P0.h = HI(WDOG_CNT);
80 P0.l = (WDOG_CNT & 0xFFFF); 80 P0.l = LO(WDOG_CNT);
81#endif 81#endif
82 [P0] = R0; 82 [P0] = R0;
83 SSYNC; 83 SSYNC;
84 84
85#if defined(CONFIG_BF561) 85#if defined(CONFIG_BF561)
86 P0.h = (WDOGA_CTL >> 16); 86 P0.h = HI(WDOGA_CTL);
87 P0.l = (WDOGA_CTL & 0xFFFF); 87 P0.l = LO(WDOGA_CTL);
88#else 88#else
89 P0.h = (WDOG_CTL >> 16); 89 P0.h = HI(WDOG_CTL);
90 P0.l = (WDOG_CTL & 0xFFFF); 90 P0.l = LO(WDOG_CTL);
91#endif 91#endif
92 R7 = W[P0](Z); 92 R7 = W[P0](Z);
93 CC = BITTST(R7,1); 93 CC = BITTST(R7,1);
@@ -97,11 +97,11 @@ ENTRY(_program_wdog_timer)
97 97
98.LSKIP_WRITE_TO_STAT: 98.LSKIP_WRITE_TO_STAT:
99#if defined(CONFIG_BF561) 99#if defined(CONFIG_BF561)
100 P0.h = (WDOGA_CTL >> 16); 100 P0.h = HI(WDOGA_CTL);
101 P0.l = (WDOGA_CTL & 0xFFFF); 101 P0.l = LO(WDOGA_CTL);
102#else 102#else
103 P0.h = (WDOG_CTL >> 16); 103 P0.h = HI(WDOG_CTL);
104 P0.l = (WDOG_CTL & 0xFFFF); 104 P0.l = LO(WDOG_CTL);
105#endif 105#endif
106 R7 = W[P0](Z); 106 R7 = W[P0](Z);
107 BITCLR(R7,1); /* Enable GP event */ 107 BITCLR(R7,1); /* Enable GP event */
@@ -122,11 +122,11 @@ ENTRY(_clear_wdog_wakeup_evt)
122 [--SP] = ( R7:0, P5:0 ); 122 [--SP] = ( R7:0, P5:0 );
123 123
124#if defined(CONFIG_BF561) 124#if defined(CONFIG_BF561)
125 P0.h = (WDOGA_CTL >> 16); 125 P0.h = HI(WDOGA_CTL);
126 P0.l = (WDOGA_CTL & 0xFFFF); 126 P0.l = LO(WDOGA_CTL);
127#else 127#else
128 P0.h = (WDOG_CTL >> 16); 128 P0.h = HI(WDOG_CTL);
129 P0.l = (WDOG_CTL & 0xFFFF); 129 P0.l = LO(WDOG_CTL);
130#endif 130#endif
131 R7 = 0x0AD6(Z); 131 R7 = 0x0AD6(Z);
132 W[P0] = R7.L; 132 W[P0] = R7.L;
@@ -149,11 +149,11 @@ ENTRY(_clear_wdog_wakeup_evt)
149ENTRY(_disable_wdog_timer) 149ENTRY(_disable_wdog_timer)
150 [--SP] = ( R7:0, P5:0 ); 150 [--SP] = ( R7:0, P5:0 );
151#if defined(CONFIG_BF561) 151#if defined(CONFIG_BF561)
152 P0.h = (WDOGA_CTL >> 16); 152 P0.h = HI(WDOGA_CTL);
153 P0.l = (WDOGA_CTL & 0xFFFF); 153 P0.l = LO(WDOGA_CTL);
154#else 154#else
155 P0.h = (WDOG_CTL >> 16); 155 P0.h = HI(WDOG_CTL);
156 P0.l = (WDOG_CTL & 0xFFFF); 156 P0.l = LO(WDOG_CTL);
157#endif 157#endif
158 R7 = 0xAD6(Z); 158 R7 = 0xAD6(Z);
159 W[P0] = R7.L; 159 W[P0] = R7.L;
@@ -300,7 +300,7 @@ ENTRY(_sleep_deeper)
300 P0.H = hi(PLL_CTL); 300 P0.H = hi(PLL_CTL);
301 P0.L = lo(PLL_CTL); 301 P0.L = lo(PLL_CTL);
302 R5 = W[P0](z); 302 R5 = W[P0](z);
303 R0.L = (MIN_VC/CONFIG_CLKIN_HZ) << 9; 303 R0.L = (CONFIG_MIN_VCO_HZ/CONFIG_CLKIN_HZ) << 9;
304 W[P0] = R0.l; 304 W[P0] = R0.l;
305 305
306 SSYNC; 306 SSYNC;
diff --git a/arch/blackfin/mach-common/entry.S b/arch/blackfin/mach-common/entry.S
index 960458808344..e3ad5802868a 100644
--- a/arch/blackfin/mach-common/entry.S
+++ b/arch/blackfin/mach-common/entry.S
@@ -29,21 +29,7 @@
29 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 29 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 */ 30 */
31 31
32/* 32/* NOTE: This code handles signal-recognition, which happens every time
33 * 25-Dec-2004 - LG Soft India
34 * 1. Fix in return_from_int, to make sure any pending
35 * system call in ILAT for this process to get
36 * executed, otherwise in case context switch happens,
37 * system call of first process (i.e in ILAT) will be
38 * carried forward to the switched process.
39 * 2. Removed Constant references for the following
40 * a. IPEND
41 * b. EXCAUSE mask
42 * c. PAGE Mask
43 */
44
45/*
46 * NOTE: This code handles signal-recognition, which happens every time
47 * after a timer-interrupt and after each system call. 33 * after a timer-interrupt and after each system call.
48 */ 34 */
49 35
@@ -58,6 +44,23 @@
58 44
59#include <asm/mach-common/context.S> 45#include <asm/mach-common/context.S>
60 46
47#if defined(CONFIG_BFIN_SCRATCH_REG_RETN)
48# define EX_SCRATCH_REG RETN
49#elif defined(CONFIG_BFIN_SCRATCH_REG_RETE)
50# define EX_SCRATCH_REG RETE
51#else
52# define EX_SCRATCH_REG CYCLES
53#endif
54
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
61#ifdef CONFIG_EXCPT_IRQ_SYSC_L1 64#ifdef CONFIG_EXCPT_IRQ_SYSC_L1
62.section .l1.text 65.section .l1.text
63#else 66#else
@@ -69,7 +72,7 @@
69 * patch up CPLB misses on the kernel stack. 72 * patch up CPLB misses on the kernel stack.
70 */ 73 */
71ENTRY(_ex_dcplb) 74ENTRY(_ex_dcplb)
72#if defined(ANOMALY_05000261) 75#if ANOMALY_05000261
73 /* 76 /*
74 * Work around an anomaly: if we see a new DCPLB fault, return 77 * Work around an anomaly: if we see a new DCPLB fault, return
75 * without doing anything. Then, if we get the same fault again, 78 * without doing anything. Then, if we get the same fault again,
@@ -93,7 +96,7 @@ ENTRY(_ex_icplb)
93 call __cplb_hdr; 96 call __cplb_hdr;
94 DEBUG_START_HWTRACE(p5, r7) 97 DEBUG_START_HWTRACE(p5, r7)
95 RESTORE_ALL_SYS 98 RESTORE_ALL_SYS
96 SP = RETN; 99 SP = EX_SCRATCH_REG;
97 rtx; 100 rtx;
98ENDPROC(_ex_icplb) 101ENDPROC(_ex_icplb)
99 102
@@ -102,7 +105,7 @@ ENTRY(_ex_syscall)
102 (R7:6,P5:4) = [sp++]; 105 (R7:6,P5:4) = [sp++];
103 ASTAT = [sp++]; 106 ASTAT = [sp++];
104 raise 15; /* invoked by TRAP #0, for sys call */ 107 raise 15; /* invoked by TRAP #0, for sys call */
105 sp = retn; 108 sp = EX_SCRATCH_REG;
106 rtx 109 rtx
107ENDPROC(_ex_syscall) 110ENDPROC(_ex_syscall)
108 111
@@ -135,9 +138,9 @@ ENTRY(_ex_single_step)
135 cc = r6 == r7; 138 cc = r6 == r7;
136 if !cc jump _ex_trap_c; 139 if !cc jump _ex_trap_c;
137 140
138_return_from_exception: 141ENTRY(_return_from_exception)
139 DEBUG_START_HWTRACE(p5, r7) 142 DEBUG_START_HWTRACE(p5, r7)
140#ifdef ANOMALY_05000257 143#if ANOMALY_05000257
141 R7=LC0; 144 R7=LC0;
142 LC0=R7; 145 LC0=R7;
143 R7=LC1; 146 R7=LC1;
@@ -145,7 +148,7 @@ _return_from_exception:
145#endif 148#endif
146 (R7:6,P5:4) = [sp++]; 149 (R7:6,P5:4) = [sp++];
147 ASTAT = [sp++]; 150 ASTAT = [sp++];
148 sp = retn; 151 sp = EX_SCRATCH_REG;
149 rtx; 152 rtx;
150ENDPROC(_ex_soft_bp) 153ENDPROC(_ex_soft_bp)
151 154
@@ -163,7 +166,17 @@ ENTRY(_handle_bad_cplb)
163 [--sp] = ASTAT; 166 [--sp] = ASTAT;
164 [--sp] = (R7:6, P5:4); 167 [--sp] = (R7:6, P5:4);
165 168
169ENTRY(_ex_replaceable)
170 nop;
171
166ENTRY(_ex_trap_c) 172ENTRY(_ex_trap_c)
173 /* Make sure we are not in a double fault */
174 p4.l = lo(IPEND);
175 p4.h = hi(IPEND);
176 r7 = [p4];
177 CC = BITTST (r7, 5);
178 if CC jump _double_fault;
179
167 /* Call C code (trap_c) to handle the exception, which most 180 /* Call C code (trap_c) to handle the exception, which most
168 * likely involves sending a signal to the current process. 181 * likely involves sending a signal to the current process.
169 * To avoid double faults, lower our priority to IRQ5 first. 182 * To avoid double faults, lower our priority to IRQ5 first.
@@ -204,11 +217,57 @@ ENTRY(_ex_trap_c)
204 DEBUG_START_HWTRACE(p5, r7) 217 DEBUG_START_HWTRACE(p5, r7)
205 (R7:6,P5:4) = [sp++]; 218 (R7:6,P5:4) = [sp++];
206 ASTAT = [sp++]; 219 ASTAT = [sp++];
207 SP = RETN; 220 SP = EX_SCRATCH_REG;
208 raise 5; 221 raise 5;
209 rtx; 222 rtx;
210ENDPROC(_ex_trap_c) 223ENDPROC(_ex_trap_c)
211 224
225/* We just realized we got an exception, while we were processing a different
226 * exception. This is a unrecoverable event, so crash
227 */
228ENTRY(_double_fault)
229 /* Turn caches & protection off, to ensure we don't get any more
230 * double exceptions
231 */
232
233 P4.L = LO(IMEM_CONTROL);
234 P4.H = HI(IMEM_CONTROL);
235
236 R5 = [P4]; /* Control Register*/
237 BITCLR(R5,ENICPLB_P);
238 SSYNC; /* SSYNC required before writing to IMEM_CONTROL. */
239 .align 8;
240 [P4] = R5;
241 SSYNC;
242
243 P4.L = LO(DMEM_CONTROL);
244 P4.H = HI(DMEM_CONTROL);
245 R5 = [P4];
246 BITCLR(R5,ENDCPLB_P);
247 SSYNC; /* SSYNC required before writing to DMEM_CONTROL. */
248 .align 8;
249 [P4] = R5;
250 SSYNC;
251
252 /* Fix up the stack */
253 (R7:6,P5:4) = [sp++];
254 ASTAT = [sp++];
255 SP = EX_SCRATCH_REG;
256
257 /* We should be out of the exception stack, and back down into
258 * kernel or user space stack
259 */
260 SAVE_ALL_SYS
261
262 r0 = sp; /* stack frame pt_regs pointer argument ==> r0 */
263 SP += -12;
264 call _double_fault_c;
265 SP += 12;
266.L_double_fault_panic:
267 JUMP .L_double_fault_panic
268
269ENDPROC(_double_fault)
270
212ENTRY(_exception_to_level5) 271ENTRY(_exception_to_level5)
213 SAVE_ALL_SYS 272 SAVE_ALL_SYS
214 273
@@ -279,7 +338,7 @@ ENTRY(_trap) /* Exception: 4th entry into system event table(supervisor mode)*/
279 * covered by a CPLB. Switch to an exception stack; use RETN as a 338 * covered by a CPLB. Switch to an exception stack; use RETN as a
280 * scratch register (for want of a better option). 339 * scratch register (for want of a better option).
281 */ 340 */
282 retn = sp; 341 EX_SCRATCH_REG = sp;
283 sp.l = _exception_stack_top; 342 sp.l = _exception_stack_top;
284 sp.h = _exception_stack_top; 343 sp.h = _exception_stack_top;
285 /* Try to deal with syscalls quickly. */ 344 /* Try to deal with syscalls quickly. */
@@ -290,8 +349,8 @@ ENTRY(_trap) /* Exception: 4th entry into system event table(supervisor mode)*/
290 r6.l = lo(SEQSTAT_EXCAUSE); 349 r6.l = lo(SEQSTAT_EXCAUSE);
291 r6.h = hi(SEQSTAT_EXCAUSE); 350 r6.h = hi(SEQSTAT_EXCAUSE);
292 r7 = r7 & r6; 351 r7 = r7 & r6;
293 p5.h = _extable; 352 p5.h = _ex_table;
294 p5.l = _extable; 353 p5.l = _ex_table;
295 p4 = r7; 354 p4 = r7;
296 p5 = p5 + (p4 << 2); 355 p5 = p5 + (p4 << 2);
297 p4 = [p5]; 356 p4 = [p5];
@@ -634,9 +693,9 @@ ENTRY(_return_from_int)
634 p1.h = _schedule_and_signal_from_int; 693 p1.h = _schedule_and_signal_from_int;
635 [p0] = p1; 694 [p0] = p1;
636 csync; 695 csync;
637#if defined(ANOMALY_05000281) 696#if ANOMALY_05000281
638 r0.l = lo(CONFIG_BOOT_LOAD); 697 r0.l = _safe_speculative_execution;
639 r0.h = hi(CONFIG_BOOT_LOAD); 698 r0.h = _safe_speculative_execution;
640 reti = r0; 699 reti = r0;
641#endif 700#endif
642 r0 = 0x801f (z); 701 r0 = 0x801f (z);
@@ -648,9 +707,9 @@ ENTRY(_return_from_int)
648ENDPROC(_return_from_int) 707ENDPROC(_return_from_int)
649 708
650ENTRY(_lower_to_irq14) 709ENTRY(_lower_to_irq14)
651#if defined(ANOMALY_05000281) 710#if ANOMALY_05000281
652 r0.l = lo(CONFIG_BOOT_LOAD); 711 r0.l = _safe_speculative_execution;
653 r0.h = hi(CONFIG_BOOT_LOAD); 712 r0.h = _safe_speculative_execution;
654 reti = r0; 713 reti = r0;
655#endif 714#endif
656 r0 = 0x401f; 715 r0 = 0x401f;
@@ -731,6 +790,114 @@ ENTRY(_init_exception_buff)
731 rts; 790 rts;
732ENDPROC(_init_exception_buff) 791ENDPROC(_init_exception_buff)
733 792
793/* We handle this 100% in exception space - to reduce overhead
794 * Only potiential problem is if the software buffer gets swapped out of the
795 * CPLB table - then double fault. - so we don't let this happen in other places
796 */
797#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
798ENTRY(_ex_trace_buff_full)
799 [--sp] = P3;
800 [--sp] = P2;
801 [--sp] = LC0;
802 [--sp] = LT0;
803 [--sp] = LB0;
804 P5.L = _trace_buff_offset;
805 P5.H = _trace_buff_offset;
806 P3 = [P5]; /* trace_buff_offset */
807 P5.L = lo(TBUFSTAT);
808 P5.H = hi(TBUFSTAT);
809 R7 = [P5];
810 R7 <<= 1; /* double, since we need to read twice */
811 LC0 = R7;
812 R7 <<= 2; /* need to shift over again,
813 * to get the number of bytes */
814 P5.L = lo(TBUF);
815 P5.H = hi(TBUF);
816 R6 = ((1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN)*1024) - 1;
817
818 P2 = R7;
819 P3 = P3 + P2;
820 R7 = P3;
821 R7 = R7 & R6;
822 P3 = R7;
823 P2.L = _trace_buff_offset;
824 P2.H = _trace_buff_offset;
825 [P2] = P3;
826
827 P2.L = _software_trace_buff;
828 P2.H = _software_trace_buff;
829
830 LSETUP (.Lstart, .Lend) LC0;
831.Lstart:
832 R7 = [P5]; /* read TBUF */
833 P4 = P3 + P2;
834 [P4] = R7;
835 P3 += -4;
836 R7 = P3;
837 R7 = R7 & R6;
838.Lend:
839 P3 = R7;
840
841 LB0 = [sp++];
842 LT0 = [sp++];
843 LC0 = [sp++];
844 P2 = [sp++];
845 P3 = [sp++];
846 jump _return_from_exception;
847ENDPROC(_ex_trace_buff_full)
848
849#if CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN == 4
850.data
851#else
852.section .l1.data.B
853#endif /* CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN */
854ENTRY(_trace_buff_offset)
855 .long 0;
856ALIGN
857ENTRY(_software_trace_buff)
858 .rept ((1 << CONFIG_DEBUG_BFIN_HWTRACE_EXPAND_LEN)*256);
859 .long 0
860 .endr
861#endif /* CONFIG_DEBUG_BFIN_HWTRACE_EXPAND */
862
863#if CONFIG_EARLY_PRINTK
864.section .init.text
865ENTRY(_early_trap)
866 SAVE_ALL_SYS
867 trace_buffer_stop(p0,r0);
868
869 /* Turn caches off, to ensure we don't get double exceptions */
870
871 P4.L = LO(IMEM_CONTROL);
872 P4.H = HI(IMEM_CONTROL);
873
874 R5 = [P4]; /* Control Register*/
875 BITCLR(R5,ENICPLB_P);
876 CLI R1;
877 SSYNC; /* SSYNC required before writing to IMEM_CONTROL. */
878 .align 8;
879 [P4] = R5;
880 SSYNC;
881
882 P4.L = LO(DMEM_CONTROL);
883 P4.H = HI(DMEM_CONTROL);
884 R5 = [P4];
885 BITCLR(R5,ENDCPLB_P);
886 SSYNC; /* SSYNC required before writing to DMEM_CONTROL. */
887 .align 8;
888 [P4] = R5;
889 SSYNC;
890 STI R1;
891
892 r0 = sp; /* stack frame pt_regs pointer argument ==> r0 */
893 r1 = RETX;
894
895 SP += -12;
896 call _early_trap_c;
897 SP += 12;
898ENDPROC(_early_trap)
899#endif /* CONFIG_EARLY_PRINTK */
900
734/* 901/*
735 * Put these in the kernel data section - that should always be covered by 902 * Put these in the kernel data section - that should always be covered by
736 * a CPLB. This is needed to ensure we don't get double fault conditions 903 * a CPLB. This is needed to ensure we don't get double fault conditions
@@ -741,30 +908,33 @@ ENDPROC(_init_exception_buff)
741#else 908#else
742.data 909.data
743#endif 910#endif
744ALIGN 911ENTRY(_ex_table)
745_extable:
746 /* entry for each EXCAUSE[5:0] 912 /* entry for each EXCAUSE[5:0]
747 * This table must be in sync with the table in ./kernel/traps.c 913 * This table must be in sync with the table in ./kernel/traps.c
748 * EXCPT instruction can provide 4 bits of EXCAUSE, allowing 16 to be user defined 914 * EXCPT instruction can provide 4 bits of EXCAUSE, allowing 16 to be user defined
749 */ 915 */
750 .long _ex_syscall; /* 0x00 - User Defined - Linux Syscall */ 916 .long _ex_syscall /* 0x00 - User Defined - Linux Syscall */
751 .long _ex_soft_bp /* 0x01 - User Defined - Software breakpoint */ 917 .long _ex_soft_bp /* 0x01 - User Defined - Software breakpoint */
752 .long _ex_trap_c /* 0x02 - User Defined */ 918 .long _ex_replaceable /* 0x02 - User Defined */
753 .long _ex_trap_c /* 0x03 - User Defined - userspace stack overflow */ 919 .long _ex_trap_c /* 0x03 - User Defined - userspace stack overflow */
754 .long _ex_trap_c /* 0x04 - User Defined */ 920 .long _ex_replaceable /* 0x04 - User Defined */
755 .long _ex_trap_c /* 0x05 - User Defined */ 921 .long _ex_replaceable /* 0x05 - User Defined */
756 .long _ex_trap_c /* 0x06 - User Defined */ 922 .long _ex_replaceable /* 0x06 - User Defined */
757 .long _ex_trap_c /* 0x07 - User Defined */ 923 .long _ex_replaceable /* 0x07 - User Defined */
758 .long _ex_trap_c /* 0x08 - User Defined */ 924 .long _ex_replaceable /* 0x08 - User Defined */
759 .long _ex_trap_c /* 0x09 - User Defined */ 925 .long _ex_replaceable /* 0x09 - User Defined */
760 .long _ex_trap_c /* 0x0A - User Defined */ 926 .long _ex_replaceable /* 0x0A - User Defined */
761 .long _ex_trap_c /* 0x0B - User Defined */ 927 .long _ex_replaceable /* 0x0B - User Defined */
762 .long _ex_trap_c /* 0x0C - User Defined */ 928 .long _ex_replaceable /* 0x0C - User Defined */
763 .long _ex_trap_c /* 0x0D - User Defined */ 929 .long _ex_replaceable /* 0x0D - User Defined */
764 .long _ex_trap_c /* 0x0E - User Defined */ 930 .long _ex_replaceable /* 0x0E - User Defined */
765 .long _ex_trap_c /* 0x0F - User Defined */ 931 .long _ex_replaceable /* 0x0F - User Defined */
766 .long _ex_single_step /* 0x10 - HW Single step */ 932 .long _ex_single_step /* 0x10 - HW Single step */
933#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
934 .long _ex_trace_buff_full /* 0x11 - Trace Buffer Full */
935#else
767 .long _ex_trap_c /* 0x11 - Trace Buffer Full */ 936 .long _ex_trap_c /* 0x11 - Trace Buffer Full */
937#endif
768 .long _ex_trap_c /* 0x12 - Reserved */ 938 .long _ex_trap_c /* 0x12 - Reserved */
769 .long _ex_trap_c /* 0x13 - Reserved */ 939 .long _ex_trap_c /* 0x13 - Reserved */
770 .long _ex_trap_c /* 0x14 - Reserved */ 940 .long _ex_trap_c /* 0x14 - Reserved */
@@ -812,8 +982,8 @@ _extable:
812 .long _ex_trap_c /* 0x3D - Reserved */ 982 .long _ex_trap_c /* 0x3D - Reserved */
813 .long _ex_trap_c /* 0x3E - Reserved */ 983 .long _ex_trap_c /* 0x3E - Reserved */
814 .long _ex_trap_c /* 0x3F - Reserved */ 984 .long _ex_trap_c /* 0x3F - Reserved */
985END(_ex_table)
815 986
816ALIGN
817ENTRY(_sys_call_table) 987ENTRY(_sys_call_table)
818 .long _sys_restart_syscall /* 0 */ 988 .long _sys_restart_syscall /* 0 */
819 .long _sys_exit 989 .long _sys_exit
@@ -1184,7 +1354,7 @@ _exception_stack:
1184 .endr 1354 .endr
1185_exception_stack_top: 1355_exception_stack_top:
1186 1356
1187#if defined(ANOMALY_05000261) 1357#if ANOMALY_05000261
1188/* Used by the assembly entry point to work around an anomaly. */ 1358/* Used by the assembly entry point to work around an anomaly. */
1189_last_cplb_fault_retx: 1359_last_cplb_fault_retx:
1190 .long 0; 1360 .long 0;
diff --git a/arch/blackfin/mach-common/interrupt.S b/arch/blackfin/mach-common/interrupt.S
index 203e20709163..c6b32fe0f6e9 100644
--- a/arch/blackfin/mach-common/interrupt.S
+++ b/arch/blackfin/mach-common/interrupt.S
@@ -46,30 +46,6 @@
46 46
47.align 4 /* just in case */ 47.align 4 /* just in case */
48 48
49/*
50 * initial interrupt handlers
51 */
52
53#ifndef CONFIG_KGDB
54 /* interrupt routine for emulation - 0 */
55 /* Currently used only if GDB stub is not in - invalid */
56 /* gdb-stub set the evt itself */
57 /* save registers for post-mortem only */
58ENTRY(_evt_emulation)
59 SAVE_ALL_SYS
60#ifdef CONFIG_FRAME_POINTER
61 fp = 0;
62#endif
63 r0 = IRQ_EMU;
64 r1 = sp;
65 SP += -12;
66 call _irq_panic;
67 SP += 12;
68 /* - GDB stub fills this in by itself (if defined) */
69 rte;
70ENDPROC(_evt_emulation)
71#endif
72
73/* Common interrupt entry code. First we do CLI, then push 49/* Common interrupt entry code. First we do CLI, then push
74 * RETI, to keep interrupts disabled, but to allow this state to be changed 50 * RETI, to keep interrupts disabled, but to allow this state to be changed
75 * by local_bh_enable. 51 * by local_bh_enable.
@@ -140,7 +116,7 @@ __common_int_entry:
140 fp = 0; 116 fp = 0;
141#endif 117#endif
142 118
143#if defined (ANOMALY_05000283) || defined (ANOMALY_05000315) 119#if ANOMALY_05000283 || ANOMALY_05000315
144 cc = r7 == r7; 120 cc = r7 == r7;
145 p5.h = 0xffc0; 121 p5.h = 0xffc0;
146 p5.l = 0x0014; 122 p5.l = 0x0014;
@@ -163,7 +139,7 @@ ENTRY(_evt_ivhw)
163#ifdef CONFIG_FRAME_POINTER 139#ifdef CONFIG_FRAME_POINTER
164 fp = 0; 140 fp = 0;
165#endif 141#endif
166#ifdef ANOMALY_05000283 142#if ANOMALY_05000283
167 cc = r7 == r7; 143 cc = r7 == r7;
168 p5.h = 0xffc0; 144 p5.h = 0xffc0;
169 p5.l = 0x0014; 145 p5.l = 0x0014;
@@ -201,27 +177,15 @@ ENTRY(_evt_ivhw)
201 jump .Lcommon_restore_context; 177 jump .Lcommon_restore_context;
202#endif 178#endif
203 179
204/* interrupt routine for evt2 - 2. This is NMI. */ 180/* Interrupt routine for evt2 (NMI).
205ENTRY(_evt_evt2) 181 * We don't actually use this, so just return.
206 SAVE_CONTEXT 182 * For inner circle type details, please see:
207#ifdef CONFIG_FRAME_POINTER 183 * http://docs.blackfin.uclinux.org/doku.php?id=linux:nmi
208 fp = 0; 184 */
209#endif 185ENTRY(_evt_nmi)
210#ifdef ANOMALY_05000283 186.weak _evt_nmi
211 cc = r7 == r7;
212 p5.h = 0xffc0;
213 p5.l = 0x0014;
214 if cc jump 1f;
215 r7.l = W[p5];
2161:
217#endif
218 r0 = IRQ_NMI;
219 r1 = sp;
220 SP += -12;
221 call _asm_do_IRQ;
222 SP += 12;
223 RESTORE_CONTEXT
224 rtn; 187 rtn;
188ENDPROC(_evt_nmi)
225 189
226/* interrupt routine for core timer - 6 */ 190/* interrupt routine for core timer - 6 */
227ENTRY(_evt_timer) 191ENTRY(_evt_timer)
diff --git a/arch/blackfin/mach-common/ints-priority-dc.c b/arch/blackfin/mach-common/ints-priority-dc.c
index 660f881b620a..2db3546fc874 100644
--- a/arch/blackfin/mach-common/ints-priority-dc.c
+++ b/arch/blackfin/mach-common/ints-priority-dc.c
@@ -221,7 +221,7 @@ static unsigned int bf561_gpio_irq_startup(unsigned int irq)
221 221
222 if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr))) { 222 if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr))) {
223 223
224 ret = gpio_request(gpionr, NULL); 224 ret = gpio_request(gpionr, "IRQ");
225 if (ret) 225 if (ret)
226 return ret; 226 return ret;
227 227
@@ -261,7 +261,7 @@ static int bf561_gpio_irq_type(unsigned int irq, unsigned int type)
261 261
262 if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr))) { 262 if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr))) {
263 263
264 ret = gpio_request(gpionr, NULL); 264 ret = gpio_request(gpionr, "IRQ");
265 if (ret) 265 if (ret)
266 return ret; 266 return ret;
267 267
@@ -362,10 +362,11 @@ void __init init_exception_vectors(void)
362{ 362{
363 SSYNC(); 363 SSYNC();
364 364
365#ifndef CONFIG_KGDB 365 /* cannot program in software:
366 bfin_write_EVT0(evt_emulation); 366 * evt0 - emulation (jtag)
367#endif 367 * evt1 - reset
368 bfin_write_EVT2(evt_evt2); 368 */
369 bfin_write_EVT2(evt_nmi);
369 bfin_write_EVT3(trap); 370 bfin_write_EVT3(trap);
370 bfin_write_EVT5(evt_ivhw); 371 bfin_write_EVT5(evt_ivhw);
371 bfin_write_EVT6(evt_timer); 372 bfin_write_EVT6(evt_timer);
diff --git a/arch/blackfin/mach-common/ints-priority-sc.c b/arch/blackfin/mach-common/ints-priority-sc.c
index 4708023fe716..d3b7672b2b94 100644
--- a/arch/blackfin/mach-common/ints-priority-sc.c
+++ b/arch/blackfin/mach-common/ints-priority-sc.c
@@ -343,7 +343,7 @@ static unsigned int bfin_gpio_irq_startup(unsigned int irq)
343 u16 gpionr = irq - IRQ_PF0; 343 u16 gpionr = irq - IRQ_PF0;
344 344
345 if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr))) { 345 if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr))) {
346 ret = gpio_request(gpionr, NULL); 346 ret = gpio_request(gpionr, "IRQ");
347 if (ret) 347 if (ret)
348 return ret; 348 return ret;
349 } 349 }
@@ -377,7 +377,7 @@ static int bfin_gpio_irq_type(unsigned int irq, unsigned int type)
377 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING | 377 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
378 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) { 378 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
379 if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr))) { 379 if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr))) {
380 ret = gpio_request(gpionr, NULL); 380 ret = gpio_request(gpionr, "IRQ");
381 if (ret) 381 if (ret)
382 return ret; 382 return ret;
383 } 383 }
@@ -587,7 +587,7 @@ static unsigned int bfin_gpio_irq_startup(unsigned int irq)
587 } 587 }
588 588
589 if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr))) { 589 if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr))) {
590 ret = gpio_request(gpionr, NULL); 590 ret = gpio_request(gpionr, "IRQ");
591 if (ret) 591 if (ret)
592 return ret; 592 return ret;
593 } 593 }
@@ -627,7 +627,7 @@ static int bfin_gpio_irq_type(unsigned int irq, unsigned int type)
627 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING | 627 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
628 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) { 628 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
629 if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr))) { 629 if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr))) {
630 ret = gpio_request(gpionr, NULL); 630 ret = gpio_request(gpionr, "IRQ");
631 if (ret) 631 if (ret)
632 return ret; 632 return ret;
633 } 633 }
@@ -721,10 +721,11 @@ void __init init_exception_vectors(void)
721{ 721{
722 SSYNC(); 722 SSYNC();
723 723
724#ifndef CONFIG_KGDB 724 /* cannot program in software:
725 bfin_write_EVT0(evt_emulation); 725 * evt0 - emulation (jtag)
726#endif 726 * evt1 - reset
727 bfin_write_EVT2(evt_evt2); 727 */
728 bfin_write_EVT2(evt_nmi);
728 bfin_write_EVT3(trap); 729 bfin_write_EVT3(trap);
729 bfin_write_EVT5(evt_ivhw); 730 bfin_write_EVT5(evt_ivhw);
730 bfin_write_EVT6(evt_timer); 731 bfin_write_EVT6(evt_timer);
diff --git a/arch/blackfin/mach-common/lock.S b/arch/blackfin/mach-common/lock.S
index 386ac8dda076..28b87fe9ce3c 100644
--- a/arch/blackfin/mach-common/lock.S
+++ b/arch/blackfin/mach-common/lock.S
@@ -33,7 +33,7 @@
33 33
34.text 34.text
35 35
36#ifdef CONFIG_BLKFIN_CACHE_LOCK 36#ifdef CONFIG_BFIN_ICACHE_LOCK
37 37
38/* When you come here, it is assumed that 38/* When you come here, it is assumed that
39 * R0 - Which way to be locked 39 * R0 - Which way to be locked
@@ -43,12 +43,12 @@ ENTRY(_cache_grab_lock)
43 43
44 [--SP]=( R7:0,P5:0 ); 44 [--SP]=( R7:0,P5:0 );
45 45
46 P1.H = (IMEM_CONTROL >> 16); 46 P1.H = HI(IMEM_CONTROL);
47 P1.L = (IMEM_CONTROL & 0xFFFF); 47 P1.L = LO(IMEM_CONTROL);
48 P5.H = (ICPLB_ADDR0 >> 16); 48 P5.H = HI(ICPLB_ADDR0);
49 P5.L = (ICPLB_ADDR0 & 0xFFFF); 49 P5.L = LO(ICPLB_ADDR0);
50 P4.H = (ICPLB_DATA0 >> 16); 50 P4.H = HI(ICPLB_DATA0);
51 P4.L = (ICPLB_DATA0 & 0xFFFF); 51 P4.L = LO(ICPLB_DATA0);
52 R7 = R0; 52 R7 = R0;
53 53
54 /* If the code of interest already resides in the cache 54 /* If the code of interest already resides in the cache
@@ -167,8 +167,8 @@ ENTRY(_cache_lock)
167 167
168 [--SP]=( R7:0,P5:0 ); 168 [--SP]=( R7:0,P5:0 );
169 169
170 P1.H = (IMEM_CONTROL >> 16); 170 P1.H = HI(IMEM_CONTROL);
171 P1.L = (IMEM_CONTROL & 0xFFFF); 171 P1.L = LO(IMEM_CONTROL);
172 172
173 /* Disable the Interrupts*/ 173 /* Disable the Interrupts*/
174 CLI R3; 174 CLI R3;
@@ -189,14 +189,14 @@ ENTRY(_cache_lock)
189 RTS; 189 RTS;
190ENDPROC(_cache_lock) 190ENDPROC(_cache_lock)
191 191
192#endif /* BLKFIN_CACHE_LOCK */ 192#endif /* BFIN_ICACHE_LOCK */
193 193
194/* Return the ILOC bits of IMEM_CONTROL 194/* Return the ILOC bits of IMEM_CONTROL
195 */ 195 */
196 196
197ENTRY(_read_iloc) 197ENTRY(_read_iloc)
198 P1.H = (IMEM_CONTROL >> 16); 198 P1.H = HI(IMEM_CONTROL);
199 P1.L = (IMEM_CONTROL & 0xFFFF); 199 P1.L = LO(IMEM_CONTROL);
200 R1 = 0xF; 200 R1 = 0xF;
201 R0 = [P1]; 201 R0 = [P1];
202 R0 = R0 >> 3; 202 R0 = R0 >> 3;
diff --git a/arch/blackfin/mm/init.c b/arch/blackfin/mm/init.c
index 68459cc052a1..e97ea8fc8dc4 100644
--- a/arch/blackfin/mm/init.c
+++ b/arch/blackfin/mm/init.c
@@ -53,7 +53,7 @@ static unsigned long empty_bad_page;
53 53
54unsigned long empty_zero_page; 54unsigned long empty_zero_page;
55 55
56void __init show_mem(void) 56void show_mem(void)
57{ 57{
58 unsigned long i; 58 unsigned long i;
59 int free = 0, total = 0, reserved = 0, shared = 0; 59 int free = 0, total = 0, reserved = 0, shared = 0;
diff --git a/arch/blackfin/oprofile/op_blackfin.h b/arch/blackfin/oprofile/op_blackfin.h
index f88f446c814f..05dd08c9d154 100644
--- a/arch/blackfin/oprofile/op_blackfin.h
+++ b/arch/blackfin/oprofile/op_blackfin.h
@@ -68,7 +68,7 @@ static inline unsigned int ctr_read(void)
68 unsigned int tmp; 68 unsigned int tmp;
69 69
70 tmp = bfin_read_PFCTL(); 70 tmp = bfin_read_PFCTL();
71 __builtin_bfin_csync(); 71 CSYNC();
72 72
73 return tmp; 73 return tmp;
74} 74}
@@ -76,21 +76,21 @@ static inline unsigned int ctr_read(void)
76static inline void ctr_write(unsigned int val) 76static inline void ctr_write(unsigned int val)
77{ 77{
78 bfin_write_PFCTL(val); 78 bfin_write_PFCTL(val);
79 __builtin_bfin_csync(); 79 CSYNC();
80} 80}
81 81
82static inline void count_read(unsigned int *count) 82static inline void count_read(unsigned int *count)
83{ 83{
84 count[0] = bfin_read_PFCNTR0(); 84 count[0] = bfin_read_PFCNTR0();
85 count[1] = bfin_read_PFCNTR1(); 85 count[1] = bfin_read_PFCNTR1();
86 __builtin_bfin_csync(); 86 CSYNC();
87} 87}
88 88
89static inline void count_write(unsigned int *count) 89static inline void count_write(unsigned int *count)
90{ 90{
91 bfin_write_PFCNTR0(count[0]); 91 bfin_write_PFCNTR0(count[0]);
92 bfin_write_PFCNTR1(count[1]); 92 bfin_write_PFCNTR1(count[1]);
93 __builtin_bfin_csync(); 93 CSYNC();
94} 94}
95 95
96extern int pm_overflow_handler(int irq, struct pt_regs *regs); 96extern int pm_overflow_handler(int irq, struct pt_regs *regs);
diff --git a/arch/i386/Kconfig b/arch/i386/Kconfig
index 97b64d7d6bf6..2d85e4b87307 100644
--- a/arch/i386/Kconfig
+++ b/arch/i386/Kconfig
@@ -226,7 +226,7 @@ config PARAVIRT
226 However, when run without a hypervisor the kernel is 226 However, when run without a hypervisor the kernel is
227 theoretically slower. If in doubt, say N. 227 theoretically slower. If in doubt, say N.
228 228
229source "arch/i386/xen/Kconfig" 229source "arch/x86/xen/Kconfig"
230 230
231config VMI 231config VMI
232 bool "VMI Paravirt-ops support" 232 bool "VMI Paravirt-ops support"
@@ -707,7 +707,7 @@ config MATH_EMULATION
707 intend to use this kernel on different machines. 707 intend to use this kernel on different machines.
708 708
709 More information about the internals of the Linux math coprocessor 709 More information about the internals of the Linux math coprocessor
710 emulation can be found in <file:arch/i386/math-emu/README>. 710 emulation can be found in <file:arch/x86/math-emu/README>.
711 711
712 If you are not sure, say Y; apart from resulting in a 66 KB bigger 712 If you are not sure, say Y; apart from resulting in a 66 KB bigger
713 kernel, it won't hurt. 713 kernel, it won't hurt.
@@ -1067,7 +1067,7 @@ config APM_REAL_MODE_POWER_OFF
1067 1067
1068endif # APM 1068endif # APM
1069 1069
1070source "arch/i386/kernel/cpu/cpufreq/Kconfig" 1070source "arch/x86/kernel/cpu/cpufreq/Kconfig"
1071 1071
1072endmenu 1072endmenu
1073 1073
@@ -1240,7 +1240,7 @@ menuconfig INSTRUMENTATION
1240 1240
1241if INSTRUMENTATION 1241if INSTRUMENTATION
1242 1242
1243source "arch/i386/oprofile/Kconfig" 1243source "arch/x86/oprofile/Kconfig"
1244 1244
1245config KPROBES 1245config KPROBES
1246 bool "Kprobes" 1246 bool "Kprobes"
diff --git a/arch/i386/Makefile b/arch/i386/Makefile
index 52b932478c6d..5e50dbf00f3e 100644
--- a/arch/i386/Makefile
+++ b/arch/i386/Makefile
@@ -17,6 +17,9 @@
17# 20050320 Kianusch Sayah Karadji <kianusch@sk-tech.net> 17# 20050320 Kianusch Sayah Karadji <kianusch@sk-tech.net>
18# Added support for GEODE CPU 18# Added support for GEODE CPU
19 19
20# Fill in SRCARCH
21SRCARCH := x86
22
20HAS_BIARCH := $(call cc-option-yn, -m32) 23HAS_BIARCH := $(call cc-option-yn, -m32)
21ifeq ($(HAS_BIARCH),y) 24ifeq ($(HAS_BIARCH),y)
22AS := $(AS) --32 25AS := $(AS) --32
@@ -61,62 +64,62 @@ AFLAGS += $(call as-instr,.cfi_startproc\n.cfi_signal_frame\n.cfi_endproc,-DCONF
61CFLAGS += $(cflags-y) 64CFLAGS += $(cflags-y)
62 65
63# Default subarch .c files 66# Default subarch .c files
64mcore-y := mach-default 67mcore-y := arch/x86/mach-default
65 68
66# Voyager subarch support 69# Voyager subarch support
67mflags-$(CONFIG_X86_VOYAGER) := -Iinclude/asm-i386/mach-voyager 70mflags-$(CONFIG_X86_VOYAGER) := -Iinclude/asm-x86/mach-voyager
68mcore-$(CONFIG_X86_VOYAGER) := mach-voyager 71mcore-$(CONFIG_X86_VOYAGER) := arch/x86/mach-voyager
69 72
70# VISWS subarch support 73# VISWS subarch support
71mflags-$(CONFIG_X86_VISWS) := -Iinclude/asm-i386/mach-visws 74mflags-$(CONFIG_X86_VISWS) := -Iinclude/asm-x86/mach-visws
72mcore-$(CONFIG_X86_VISWS) := mach-visws 75mcore-$(CONFIG_X86_VISWS) := arch/x86/mach-visws
73 76
74# NUMAQ subarch support 77# NUMAQ subarch support
75mflags-$(CONFIG_X86_NUMAQ) := -Iinclude/asm-i386/mach-numaq 78mflags-$(CONFIG_X86_NUMAQ) := -Iinclude/asm-x86/mach-numaq
76mcore-$(CONFIG_X86_NUMAQ) := mach-default 79mcore-$(CONFIG_X86_NUMAQ) := arch/x86/mach-default
77 80
78# BIGSMP subarch support 81# BIGSMP subarch support
79mflags-$(CONFIG_X86_BIGSMP) := -Iinclude/asm-i386/mach-bigsmp 82mflags-$(CONFIG_X86_BIGSMP) := -Iinclude/asm-x86/mach-bigsmp
80mcore-$(CONFIG_X86_BIGSMP) := mach-default 83mcore-$(CONFIG_X86_BIGSMP) := arch/x86/mach-default
81 84
82#Summit subarch support 85#Summit subarch support
83mflags-$(CONFIG_X86_SUMMIT) := -Iinclude/asm-i386/mach-summit 86mflags-$(CONFIG_X86_SUMMIT) := -Iinclude/asm-x86/mach-summit
84mcore-$(CONFIG_X86_SUMMIT) := mach-default 87mcore-$(CONFIG_X86_SUMMIT) := arch/x86/mach-default
85 88
86# generic subarchitecture 89# generic subarchitecture
87mflags-$(CONFIG_X86_GENERICARCH) := -Iinclude/asm-i386/mach-generic 90mflags-$(CONFIG_X86_GENERICARCH) := -Iinclude/asm-x86/mach-generic
88mcore-$(CONFIG_X86_GENERICARCH) := mach-default 91mcore-$(CONFIG_X86_GENERICARCH) := arch/x86/mach-default
89core-$(CONFIG_X86_GENERICARCH) += arch/i386/mach-generic/ 92core-$(CONFIG_X86_GENERICARCH) += arch/x86/mach-generic/
90 93
91# ES7000 subarch support 94# ES7000 subarch support
92mflags-$(CONFIG_X86_ES7000) := -Iinclude/asm-i386/mach-es7000 95mflags-$(CONFIG_X86_ES7000) := -Iinclude/asm-x86/mach-es7000
93mcore-$(CONFIG_X86_ES7000) := mach-default 96mcore-$(CONFIG_X86_ES7000) := arch/x86/mach-default
94core-$(CONFIG_X86_ES7000) := arch/i386/mach-es7000/ 97core-$(CONFIG_X86_ES7000) := arch/x86/mach-es7000/
95 98
96# Xen paravirtualization support 99# Xen paravirtualization support
97core-$(CONFIG_XEN) += arch/i386/xen/ 100core-$(CONFIG_XEN) += arch/x86/xen/
98 101
99# default subarch .h files 102# default subarch .h files
100mflags-y += -Iinclude/asm-i386/mach-default 103mflags-y += -Iinclude/asm-x86/mach-default
101 104
102head-y := arch/i386/kernel/head.o arch/i386/kernel/init_task.o 105head-y := arch/x86/kernel/head_32.o arch/x86/kernel/init_task_32.o
103 106
104libs-y += arch/i386/lib/ 107libs-y += arch/x86/lib/
105core-y += arch/i386/kernel/ \ 108core-y += arch/x86/kernel/ \
106 arch/i386/mm/ \ 109 arch/x86/mm/ \
107 arch/i386/$(mcore-y)/ \ 110 $(mcore-y)/ \
108 arch/i386/crypto/ 111 arch/x86/crypto/
109drivers-$(CONFIG_MATH_EMULATION) += arch/i386/math-emu/ 112drivers-$(CONFIG_MATH_EMULATION) += arch/x86/math-emu/
110drivers-$(CONFIG_PCI) += arch/i386/pci/ 113drivers-$(CONFIG_PCI) += arch/x86/pci/
111# must be linked after kernel/ 114# must be linked after kernel/
112drivers-$(CONFIG_OPROFILE) += arch/i386/oprofile/ 115drivers-$(CONFIG_OPROFILE) += arch/x86/oprofile/
113drivers-$(CONFIG_PM) += arch/i386/power/ 116drivers-$(CONFIG_PM) += arch/x86/power/
114drivers-$(CONFIG_FB) += arch/i386/video/ 117drivers-$(CONFIG_FB) += arch/x86/video/
115 118
116CFLAGS += $(mflags-y) 119CFLAGS += $(mflags-y)
117AFLAGS += $(mflags-y) 120AFLAGS += $(mflags-y)
118 121
119boot := arch/i386/boot 122boot := arch/x86/boot
120 123
121PHONY += zImage bzImage compressed zlilo bzlilo \ 124PHONY += zImage bzImage compressed zlilo bzlilo \
122 zdisk bzdisk fdimage fdimage144 fdimage288 isoimage install 125 zdisk bzdisk fdimage fdimage144 fdimage288 isoimage install
@@ -125,9 +128,11 @@ all: bzImage
125 128
126# KBUILD_IMAGE specify target image being built 129# KBUILD_IMAGE specify target image being built
127 KBUILD_IMAGE := $(boot)/bzImage 130 KBUILD_IMAGE := $(boot)/bzImage
128zImage zlilo zdisk: KBUILD_IMAGE := arch/i386/boot/zImage 131zImage zlilo zdisk: KBUILD_IMAGE := arch/x86/boot/zImage
129 132
130zImage bzImage: vmlinux 133zImage bzImage: vmlinux
134 $(Q)mkdir -p $(objtree)/arch/i386/boot
135 $(Q)ln -fsn $(objtree)/arch/x86/boot/bzImage $(objtree)/arch/i386/boot/bzImage
131 $(Q)$(MAKE) $(build)=$(boot) $(KBUILD_IMAGE) 136 $(Q)$(MAKE) $(build)=$(boot) $(KBUILD_IMAGE)
132 137
133compressed: zImage 138compressed: zImage
@@ -145,7 +150,8 @@ install:
145 $(Q)$(MAKE) $(build)=$(boot) BOOTIMAGE=$(KBUILD_IMAGE) install 150 $(Q)$(MAKE) $(build)=$(boot) BOOTIMAGE=$(KBUILD_IMAGE) install
146 151
147archclean: 152archclean:
148 $(Q)$(MAKE) $(clean)=arch/i386/boot 153 $(Q)rm -rf $(objtree)/arch/i386/boot
154 $(Q)$(MAKE) $(clean)=arch/x86/boot
149 155
150define archhelp 156define archhelp
151 echo '* bzImage - Compressed kernel image (arch/$(ARCH)/boot/bzImage)' 157 echo '* bzImage - Compressed kernel image (arch/$(ARCH)/boot/bzImage)'
diff --git a/arch/i386/boot/Makefile b/arch/i386/boot/Makefile
deleted file mode 100644
index 93386a4e40b4..000000000000
--- a/arch/i386/boot/Makefile
+++ /dev/null
@@ -1,171 +0,0 @@
1#
2# arch/i386/boot/Makefile
3#
4# This file is subject to the terms and conditions of the GNU General Public
5# License. See the file "COPYING" in the main directory of this archive
6# for more details.
7#
8# Copyright (C) 1994 by Linus Torvalds
9#
10
11# ROOT_DEV specifies the default root-device when making the image.
12# This can be either FLOPPY, CURRENT, /dev/xxxx or empty, in which case
13# the default of FLOPPY is used by 'build'.
14
15ROOT_DEV := CURRENT
16
17# If you want to preset the SVGA mode, uncomment the next line and
18# set SVGA_MODE to whatever number you want.
19# Set it to -DSVGA_MODE=NORMAL_VGA if you just want the EGA/VGA mode.
20# The number is the same as you would ordinarily press at bootup.
21
22SVGA_MODE := -DSVGA_MODE=NORMAL_VGA
23
24# If you want the RAM disk device, define this to be the size in blocks.
25
26#RAMDISK := -DRAMDISK=512
27
28targets := vmlinux.bin setup.bin setup.elf zImage bzImage
29subdir- := compressed
30
31setup-y += a20.o apm.o cmdline.o copy.o cpu.o cpucheck.o edd.o
32setup-y += header.o main.o mca.o memory.o pm.o pmjump.o
33setup-y += printf.o string.o tty.o video.o version.o voyager.o
34
35# The link order of the video-*.o modules can matter. In particular,
36# video-vga.o *must* be listed first, followed by video-vesa.o.
37# Hardware-specific drivers should follow in the order they should be
38# probed, and video-bios.o should typically be last.
39setup-y += video-vga.o
40setup-y += video-vesa.o
41setup-y += video-bios.o
42targets += $(setup-y)
43hostprogs-y := tools/build
44
45HOSTCFLAGS_build.o := $(LINUXINCLUDE)
46
47# ---------------------------------------------------------------------------
48
49# How to compile the 16-bit code. Note we always compile for -march=i386,
50# that way we can complain to the user if the CPU is insufficient.
51cflags-i386 :=
52cflags-x86_64 := -m32
53CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
54 $(cflags-$(ARCH)) \
55 -Wall -Wstrict-prototypes \
56 -march=i386 -mregparm=3 \
57 -include $(srctree)/$(src)/code16gcc.h \
58 -fno-strict-aliasing -fomit-frame-pointer \
59 $(call cc-option, -ffreestanding) \
60 $(call cc-option, -fno-toplevel-reorder,\
61 $(call cc-option, -fno-unit-at-a-time)) \
62 $(call cc-option, -fno-stack-protector) \
63 $(call cc-option, -mpreferred-stack-boundary=2)
64AFLAGS := $(CFLAGS) -D__ASSEMBLY__
65
66$(obj)/zImage: IMAGE_OFFSET := 0x1000
67$(obj)/zImage: EXTRA_AFLAGS := $(SVGA_MODE) $(RAMDISK)
68$(obj)/bzImage: IMAGE_OFFSET := 0x100000
69$(obj)/bzImage: EXTRA_CFLAGS := -D__BIG_KERNEL__
70$(obj)/bzImage: EXTRA_AFLAGS := $(SVGA_MODE) $(RAMDISK) -D__BIG_KERNEL__
71$(obj)/bzImage: BUILDFLAGS := -b
72
73quiet_cmd_image = BUILD $@
74cmd_image = $(obj)/tools/build $(BUILDFLAGS) $(obj)/setup.bin \
75 $(obj)/vmlinux.bin $(ROOT_DEV) > $@
76
77$(obj)/zImage $(obj)/bzImage: $(obj)/setup.bin \
78 $(obj)/vmlinux.bin $(obj)/tools/build FORCE
79 $(call if_changed,image)
80 @echo 'Kernel: $@ is ready' ' (#'`cat .version`')'
81
82$(obj)/vmlinux.bin: $(obj)/compressed/vmlinux FORCE
83 $(call if_changed,objcopy)
84
85SETUP_OBJS = $(addprefix $(obj)/,$(setup-y))
86
87LDFLAGS_setup.elf := -T
88$(obj)/setup.elf: $(src)/setup.ld $(SETUP_OBJS) FORCE
89 $(call if_changed,ld)
90
91OBJCOPYFLAGS_setup.bin := -O binary
92
93$(obj)/setup.bin: $(obj)/setup.elf FORCE
94 $(call if_changed,objcopy)
95
96$(obj)/compressed/vmlinux: FORCE
97 $(Q)$(MAKE) $(build)=$(obj)/compressed IMAGE_OFFSET=$(IMAGE_OFFSET) $@
98
99# Set this if you want to pass append arguments to the zdisk/fdimage/isoimage kernel
100FDARGS =
101# Set this if you want an initrd included with the zdisk/fdimage/isoimage kernel
102FDINITRD =
103
104image_cmdline = default linux $(FDARGS) $(if $(FDINITRD),initrd=initrd.img,)
105
106$(obj)/mtools.conf: $(src)/mtools.conf.in
107 sed -e 's|@OBJ@|$(obj)|g' < $< > $@
108
109# This requires write access to /dev/fd0
110zdisk: $(BOOTIMAGE) $(obj)/mtools.conf
111 MTOOLSRC=$(obj)/mtools.conf mformat a: ; sync
112 syslinux /dev/fd0 ; sync
113 echo '$(image_cmdline)' | \
114 MTOOLSRC=$(src)/mtools.conf mcopy - a:syslinux.cfg
115 if [ -f '$(FDINITRD)' ] ; then \
116 MTOOLSRC=$(obj)/mtools.conf mcopy '$(FDINITRD)' a:initrd.img ; \
117 fi
118 MTOOLSRC=$(obj)/mtools.conf mcopy $(BOOTIMAGE) a:linux ; sync
119
120# These require being root or having syslinux 2.02 or higher installed
121fdimage fdimage144: $(BOOTIMAGE) $(obj)/mtools.conf
122 dd if=/dev/zero of=$(obj)/fdimage bs=1024 count=1440
123 MTOOLSRC=$(obj)/mtools.conf mformat v: ; sync
124 syslinux $(obj)/fdimage ; sync
125 echo '$(image_cmdline)' | \
126 MTOOLSRC=$(obj)/mtools.conf mcopy - v:syslinux.cfg
127 if [ -f '$(FDINITRD)' ] ; then \
128 MTOOLSRC=$(obj)/mtools.conf mcopy '$(FDINITRD)' v:initrd.img ; \
129 fi
130 MTOOLSRC=$(obj)/mtools.conf mcopy $(BOOTIMAGE) v:linux ; sync
131
132fdimage288: $(BOOTIMAGE) $(obj)/mtools.conf
133 dd if=/dev/zero of=$(obj)/fdimage bs=1024 count=2880
134 MTOOLSRC=$(obj)/mtools.conf mformat w: ; sync
135 syslinux $(obj)/fdimage ; sync
136 echo '$(image_cmdline)' | \
137 MTOOLSRC=$(obj)/mtools.conf mcopy - w:syslinux.cfg
138 if [ -f '$(FDINITRD)' ] ; then \
139 MTOOLSRC=$(obj)/mtools.conf mcopy '$(FDINITRD)' w:initrd.img ; \
140 fi
141 MTOOLSRC=$(obj)/mtools.conf mcopy $(BOOTIMAGE) w:linux ; sync
142
143isoimage: $(BOOTIMAGE)
144 -rm -rf $(obj)/isoimage
145 mkdir $(obj)/isoimage
146 for i in lib lib64 share end ; do \
147 if [ -f /usr/$$i/syslinux/isolinux.bin ] ; then \
148 cp /usr/$$i/syslinux/isolinux.bin $(obj)/isoimage ; \
149 break ; \
150 fi ; \
151 if [ $$i = end ] ; then exit 1 ; fi ; \
152 done
153 cp $(BOOTIMAGE) $(obj)/isoimage/linux
154 echo '$(image_cmdline)' > $(obj)/isoimage/isolinux.cfg
155 if [ -f '$(FDINITRD)' ] ; then \
156 cp '$(FDINITRD)' $(obj)/isoimage/initrd.img ; \
157 fi
158 mkisofs -J -r -o $(obj)/image.iso -b isolinux.bin -c boot.cat \
159 -no-emul-boot -boot-load-size 4 -boot-info-table \
160 $(obj)/isoimage
161 rm -rf $(obj)/isoimage
162
163zlilo: $(BOOTIMAGE)
164 if [ -f $(INSTALL_PATH)/vmlinuz ]; then mv $(INSTALL_PATH)/vmlinuz $(INSTALL_PATH)/vmlinuz.old; fi
165 if [ -f $(INSTALL_PATH)/System.map ]; then mv $(INSTALL_PATH)/System.map $(INSTALL_PATH)/System.old; fi
166 cat $(BOOTIMAGE) > $(INSTALL_PATH)/vmlinuz
167 cp System.map $(INSTALL_PATH)/
168 if [ -x /sbin/lilo ]; then /sbin/lilo; else /etc/lilo/install; fi
169
170install:
171 sh $(srctree)/$(src)/install.sh $(KERNELRELEASE) $(BOOTIMAGE) System.map "$(INSTALL_PATH)"
diff --git a/arch/i386/boot/compressed/Makefile b/arch/i386/boot/compressed/Makefile
deleted file mode 100644
index 189fa1dbefcc..000000000000
--- a/arch/i386/boot/compressed/Makefile
+++ /dev/null
@@ -1,50 +0,0 @@
1#
2# linux/arch/i386/boot/compressed/Makefile
3#
4# create a compressed vmlinux image from the original vmlinux
5#
6
7targets := vmlinux vmlinux.bin vmlinux.bin.gz head.o misc.o piggy.o \
8 vmlinux.bin.all vmlinux.relocs
9EXTRA_AFLAGS := -traditional
10
11LDFLAGS_vmlinux := -T
12hostprogs-y := relocs
13
14CFLAGS := -m32 -D__KERNEL__ $(LINUX_INCLUDE) -O2 \
15 -fno-strict-aliasing -fPIC \
16 $(call cc-option,-ffreestanding) \
17 $(call cc-option,-fno-stack-protector)
18LDFLAGS := -m elf_i386
19
20$(obj)/vmlinux: $(src)/vmlinux.lds $(obj)/head.o $(obj)/misc.o $(obj)/piggy.o FORCE
21 $(call if_changed,ld)
22 @:
23
24$(obj)/vmlinux.bin: vmlinux FORCE
25 $(call if_changed,objcopy)
26
27quiet_cmd_relocs = RELOCS $@
28 cmd_relocs = $(obj)/relocs $< > $@;$(obj)/relocs --abs-relocs $<
29$(obj)/vmlinux.relocs: vmlinux $(obj)/relocs FORCE
30 $(call if_changed,relocs)
31
32vmlinux.bin.all-y := $(obj)/vmlinux.bin
33vmlinux.bin.all-$(CONFIG_RELOCATABLE) += $(obj)/vmlinux.relocs
34quiet_cmd_relocbin = BUILD $@
35 cmd_relocbin = cat $(filter-out FORCE,$^) > $@
36$(obj)/vmlinux.bin.all: $(vmlinux.bin.all-y) FORCE
37 $(call if_changed,relocbin)
38
39ifdef CONFIG_RELOCATABLE
40$(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bin.all FORCE
41 $(call if_changed,gzip)
42else
43$(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bin FORCE
44 $(call if_changed,gzip)
45endif
46
47LDFLAGS_piggy.o := -r --format binary --oformat elf32-i386 -T
48
49$(obj)/piggy.o: $(src)/vmlinux.scr $(obj)/vmlinux.bin.gz FORCE
50 $(call if_changed,ld)
diff --git a/arch/i386/crypto/Makefile b/arch/i386/crypto/Makefile
deleted file mode 100644
index 3fd19af18e34..000000000000
--- a/arch/i386/crypto/Makefile
+++ /dev/null
@@ -1,12 +0,0 @@
1#
2# i386/crypto/Makefile
3#
4# Arch-specific CryptoAPI modules.
5#
6
7obj-$(CONFIG_CRYPTO_AES_586) += aes-i586.o
8obj-$(CONFIG_CRYPTO_TWOFISH_586) += twofish-i586.o
9
10aes-i586-y := aes-i586-asm.o aes.o
11twofish-i586-y := twofish-i586-asm.o twofish.o
12
diff --git a/arch/i386/kernel/Makefile b/arch/i386/kernel/Makefile
deleted file mode 100644
index 9d33b00de659..000000000000
--- a/arch/i386/kernel/Makefile
+++ /dev/null
@@ -1,88 +0,0 @@
1#
2# Makefile for the linux kernel.
3#
4
5extra-y := head.o init_task.o vmlinux.lds
6
7obj-y := process.o signal.o entry.o traps.o irq.o \
8 ptrace.o time.o ioport.o ldt.o setup.o i8259.o sys_i386.o \
9 pci-dma.o i386_ksyms.o i387.o bootflag.o e820.o\
10 quirks.o i8237.o topology.o alternative.o i8253.o tsc.o
11
12obj-$(CONFIG_STACKTRACE) += stacktrace.o
13obj-y += cpu/
14obj-y += acpi/
15obj-$(CONFIG_X86_BIOS_REBOOT) += reboot.o
16obj-$(CONFIG_MCA) += mca.o
17obj-$(CONFIG_X86_MSR) += msr.o
18obj-$(CONFIG_X86_CPUID) += cpuid.o
19obj-$(CONFIG_MICROCODE) += microcode.o
20obj-$(CONFIG_APM) += apm.o
21obj-$(CONFIG_X86_SMP) += smp.o smpboot.o tsc_sync.o
22obj-$(CONFIG_SMP) += smpcommon.o
23obj-$(CONFIG_X86_TRAMPOLINE) += trampoline.o
24obj-$(CONFIG_X86_MPPARSE) += mpparse.o
25obj-$(CONFIG_X86_LOCAL_APIC) += apic.o nmi.o
26obj-$(CONFIG_X86_IO_APIC) += io_apic.o
27obj-$(CONFIG_X86_REBOOTFIXUPS) += reboot_fixups.o
28obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o crash.o
29obj-$(CONFIG_CRASH_DUMP) += crash_dump.o
30obj-$(CONFIG_X86_NUMAQ) += numaq.o
31obj-$(CONFIG_X86_SUMMIT_NUMA) += summit.o
32obj-$(CONFIG_KPROBES) += kprobes.o
33obj-$(CONFIG_MODULES) += module.o
34obj-y += sysenter.o vsyscall.o
35obj-$(CONFIG_ACPI_SRAT) += srat.o
36obj-$(CONFIG_EFI) += efi.o efi_stub.o
37obj-$(CONFIG_DOUBLEFAULT) += doublefault.o
38obj-$(CONFIG_VM86) += vm86.o
39obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
40obj-$(CONFIG_HPET_TIMER) += hpet.o
41obj-$(CONFIG_K8_NB) += k8.o
42obj-$(CONFIG_MGEODE_LX) += geode.o
43
44obj-$(CONFIG_VMI) += vmi.o vmiclock.o
45obj-$(CONFIG_PARAVIRT) += paravirt.o
46obj-y += pcspeaker.o
47
48obj-$(CONFIG_SCx200) += scx200.o
49
50# vsyscall.o contains the vsyscall DSO images as __initdata.
51# We must build both images before we can assemble it.
52# Note: kbuild does not track this dependency due to usage of .incbin
53$(obj)/vsyscall.o: $(obj)/vsyscall-int80.so $(obj)/vsyscall-sysenter.so
54targets += $(foreach F,int80 sysenter,vsyscall-$F.o vsyscall-$F.so)
55targets += vsyscall-note.o vsyscall.lds
56
57# The DSO images are built using a special linker script.
58quiet_cmd_syscall = SYSCALL $@
59 cmd_syscall = $(CC) -m elf_i386 -nostdlib $(SYSCFLAGS_$(@F)) \
60 -Wl,-T,$(filter-out FORCE,$^) -o $@
61
62export CPPFLAGS_vsyscall.lds += -P -C -U$(ARCH)
63
64vsyscall-flags = -shared -s -Wl,-soname=linux-gate.so.1 \
65 $(call ld-option, -Wl$(comma)--hash-style=sysv)
66SYSCFLAGS_vsyscall-sysenter.so = $(vsyscall-flags)
67SYSCFLAGS_vsyscall-int80.so = $(vsyscall-flags)
68
69$(obj)/vsyscall-int80.so $(obj)/vsyscall-sysenter.so: \
70$(obj)/vsyscall-%.so: $(src)/vsyscall.lds \
71 $(obj)/vsyscall-%.o $(obj)/vsyscall-note.o FORCE
72 $(call if_changed,syscall)
73
74# We also create a special relocatable object that should mirror the symbol
75# table and layout of the linked DSO. With ld -R we can then refer to
76# these symbols in the kernel code rather than hand-coded addresses.
77extra-y += vsyscall-syms.o
78$(obj)/built-in.o: $(obj)/vsyscall-syms.o
79$(obj)/built-in.o: ld_flags += -R $(obj)/vsyscall-syms.o
80
81SYSCFLAGS_vsyscall-syms.o = -r
82$(obj)/vsyscall-syms.o: $(src)/vsyscall.lds \
83 $(obj)/vsyscall-sysenter.o $(obj)/vsyscall-note.o FORCE
84 $(call if_changed,syscall)
85
86k8-y += ../../x86_64/kernel/k8.o
87stacktrace-y += ../../x86_64/kernel/stacktrace.o
88
diff --git a/arch/i386/kernel/acpi/Makefile b/arch/i386/kernel/acpi/Makefile
deleted file mode 100644
index 7f7be01f44e6..000000000000
--- a/arch/i386/kernel/acpi/Makefile
+++ /dev/null
@@ -1,10 +0,0 @@
1obj-$(CONFIG_ACPI) += boot.o
2ifneq ($(CONFIG_PCI),)
3obj-$(CONFIG_X86_IO_APIC) += earlyquirk.o
4endif
5obj-$(CONFIG_ACPI_SLEEP) += sleep.o wakeup.o
6
7ifneq ($(CONFIG_ACPI_PROCESSOR),)
8obj-y += cstate.o processor.o
9endif
10
diff --git a/arch/i386/kernel/asm-offsets.c b/arch/i386/kernel/asm-offsets.c
deleted file mode 100644
index 7288ac88d746..000000000000
--- a/arch/i386/kernel/asm-offsets.c
+++ /dev/null
@@ -1,147 +0,0 @@
1/*
2 * Generate definitions needed by assembly language modules.
3 * This code generates raw asm output which is post-processed
4 * to extract and format the required data.
5 */
6
7#include <linux/crypto.h>
8#include <linux/sched.h>
9#include <linux/signal.h>
10#include <linux/personality.h>
11#include <linux/suspend.h>
12#include <asm/ucontext.h>
13#include "sigframe.h"
14#include <asm/pgtable.h>
15#include <asm/fixmap.h>
16#include <asm/processor.h>
17#include <asm/thread_info.h>
18#include <asm/elf.h>
19
20#include <xen/interface/xen.h>
21
22#ifdef CONFIG_LGUEST_GUEST
23#include <linux/lguest.h>
24#include "../../../drivers/lguest/lg.h"
25#endif
26
27#define DEFINE(sym, val) \
28 asm volatile("\n->" #sym " %0 " #val : : "i" (val))
29
30#define BLANK() asm volatile("\n->" : : )
31
32#define OFFSET(sym, str, mem) \
33 DEFINE(sym, offsetof(struct str, mem));
34
35/* workaround for a warning with -Wmissing-prototypes */
36void foo(void);
37
38void foo(void)
39{
40 OFFSET(SIGCONTEXT_eax, sigcontext, eax);
41 OFFSET(SIGCONTEXT_ebx, sigcontext, ebx);
42 OFFSET(SIGCONTEXT_ecx, sigcontext, ecx);
43 OFFSET(SIGCONTEXT_edx, sigcontext, edx);
44 OFFSET(SIGCONTEXT_esi, sigcontext, esi);
45 OFFSET(SIGCONTEXT_edi, sigcontext, edi);
46 OFFSET(SIGCONTEXT_ebp, sigcontext, ebp);
47 OFFSET(SIGCONTEXT_esp, sigcontext, esp);
48 OFFSET(SIGCONTEXT_eip, sigcontext, eip);
49 BLANK();
50
51 OFFSET(CPUINFO_x86, cpuinfo_x86, x86);
52 OFFSET(CPUINFO_x86_vendor, cpuinfo_x86, x86_vendor);
53 OFFSET(CPUINFO_x86_model, cpuinfo_x86, x86_model);
54 OFFSET(CPUINFO_x86_mask, cpuinfo_x86, x86_mask);
55 OFFSET(CPUINFO_hard_math, cpuinfo_x86, hard_math);
56 OFFSET(CPUINFO_cpuid_level, cpuinfo_x86, cpuid_level);
57 OFFSET(CPUINFO_x86_capability, cpuinfo_x86, x86_capability);
58 OFFSET(CPUINFO_x86_vendor_id, cpuinfo_x86, x86_vendor_id);
59 BLANK();
60
61 OFFSET(TI_task, thread_info, task);
62 OFFSET(TI_exec_domain, thread_info, exec_domain);
63 OFFSET(TI_flags, thread_info, flags);
64 OFFSET(TI_status, thread_info, status);
65 OFFSET(TI_preempt_count, thread_info, preempt_count);
66 OFFSET(TI_addr_limit, thread_info, addr_limit);
67 OFFSET(TI_restart_block, thread_info, restart_block);
68 OFFSET(TI_sysenter_return, thread_info, sysenter_return);
69 OFFSET(TI_cpu, thread_info, cpu);
70 BLANK();
71
72 OFFSET(GDS_size, Xgt_desc_struct, size);
73 OFFSET(GDS_address, Xgt_desc_struct, address);
74 OFFSET(GDS_pad, Xgt_desc_struct, pad);
75 BLANK();
76
77 OFFSET(PT_EBX, pt_regs, ebx);
78 OFFSET(PT_ECX, pt_regs, ecx);
79 OFFSET(PT_EDX, pt_regs, edx);
80 OFFSET(PT_ESI, pt_regs, esi);
81 OFFSET(PT_EDI, pt_regs, edi);
82 OFFSET(PT_EBP, pt_regs, ebp);
83 OFFSET(PT_EAX, pt_regs, eax);
84 OFFSET(PT_DS, pt_regs, xds);
85 OFFSET(PT_ES, pt_regs, xes);
86 OFFSET(PT_FS, pt_regs, xfs);
87 OFFSET(PT_ORIG_EAX, pt_regs, orig_eax);
88 OFFSET(PT_EIP, pt_regs, eip);
89 OFFSET(PT_CS, pt_regs, xcs);
90 OFFSET(PT_EFLAGS, pt_regs, eflags);
91 OFFSET(PT_OLDESP, pt_regs, esp);
92 OFFSET(PT_OLDSS, pt_regs, xss);
93 BLANK();
94
95 OFFSET(EXEC_DOMAIN_handler, exec_domain, handler);
96 OFFSET(RT_SIGFRAME_sigcontext, rt_sigframe, uc.uc_mcontext);
97 BLANK();
98
99 OFFSET(pbe_address, pbe, address);
100 OFFSET(pbe_orig_address, pbe, orig_address);
101 OFFSET(pbe_next, pbe, next);
102
103 /* Offset from the sysenter stack to tss.esp0 */
104 DEFINE(TSS_sysenter_esp0, offsetof(struct tss_struct, x86_tss.esp0) -
105 sizeof(struct tss_struct));
106
107 DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
108 DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
109 DEFINE(PTRS_PER_PTE, PTRS_PER_PTE);
110 DEFINE(PTRS_PER_PMD, PTRS_PER_PMD);
111 DEFINE(PTRS_PER_PGD, PTRS_PER_PGD);
112
113 DEFINE(VDSO_PRELINK_asm, VDSO_PRELINK);
114
115 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
116
117#ifdef CONFIG_PARAVIRT
118 BLANK();
119 OFFSET(PARAVIRT_enabled, paravirt_ops, paravirt_enabled);
120 OFFSET(PARAVIRT_irq_disable, paravirt_ops, irq_disable);
121 OFFSET(PARAVIRT_irq_enable, paravirt_ops, irq_enable);
122 OFFSET(PARAVIRT_irq_enable_sysexit, paravirt_ops, irq_enable_sysexit);
123 OFFSET(PARAVIRT_iret, paravirt_ops, iret);
124 OFFSET(PARAVIRT_read_cr0, paravirt_ops, read_cr0);
125#endif
126
127#ifdef CONFIG_XEN
128 BLANK();
129 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
130 OFFSET(XEN_vcpu_info_pending, vcpu_info, evtchn_upcall_pending);
131#endif
132
133#ifdef CONFIG_LGUEST_GUEST
134 BLANK();
135 OFFSET(LGUEST_DATA_irq_enabled, lguest_data, irq_enabled);
136 OFFSET(LGUEST_PAGES_host_gdt_desc, lguest_pages, state.host_gdt_desc);
137 OFFSET(LGUEST_PAGES_host_idt_desc, lguest_pages, state.host_idt_desc);
138 OFFSET(LGUEST_PAGES_host_cr3, lguest_pages, state.host_cr3);
139 OFFSET(LGUEST_PAGES_host_sp, lguest_pages, state.host_sp);
140 OFFSET(LGUEST_PAGES_guest_gdt_desc, lguest_pages,state.guest_gdt_desc);
141 OFFSET(LGUEST_PAGES_guest_idt_desc, lguest_pages,state.guest_idt_desc);
142 OFFSET(LGUEST_PAGES_guest_gdt, lguest_pages, state.guest_gdt);
143 OFFSET(LGUEST_PAGES_regs_trapnum, lguest_pages, regs.trapnum);
144 OFFSET(LGUEST_PAGES_regs_errcode, lguest_pages, regs.errcode);
145 OFFSET(LGUEST_PAGES_regs, lguest_pages, regs);
146#endif
147}
diff --git a/arch/i386/kernel/cpu/mtrr/state.c b/arch/i386/kernel/cpu/mtrr/state.c
deleted file mode 100644
index c9014ca4a575..000000000000
--- a/arch/i386/kernel/cpu/mtrr/state.c
+++ /dev/null
@@ -1,79 +0,0 @@
1#include <linux/mm.h>
2#include <linux/init.h>
3#include <asm/io.h>
4#include <asm/mtrr.h>
5#include <asm/msr.h>
6#include <asm-i386/processor-cyrix.h>
7#include "mtrr.h"
8
9
10/* Put the processor into a state where MTRRs can be safely set */
11void set_mtrr_prepare_save(struct set_mtrr_context *ctxt)
12{
13 unsigned int cr0;
14
15 /* Disable interrupts locally */
16 local_irq_save(ctxt->flags);
17
18 if (use_intel() || is_cpu(CYRIX)) {
19
20 /* Save value of CR4 and clear Page Global Enable (bit 7) */
21 if ( cpu_has_pge ) {
22 ctxt->cr4val = read_cr4();
23 write_cr4(ctxt->cr4val & ~X86_CR4_PGE);
24 }
25
26 /* Disable and flush caches. Note that wbinvd flushes the TLBs as
27 a side-effect */
28 cr0 = read_cr0() | 0x40000000;
29 wbinvd();
30 write_cr0(cr0);
31 wbinvd();
32
33 if (use_intel())
34 /* Save MTRR state */
35 rdmsr(MTRRdefType_MSR, ctxt->deftype_lo, ctxt->deftype_hi);
36 else
37 /* Cyrix ARRs - everything else were excluded at the top */
38 ctxt->ccr3 = getCx86(CX86_CCR3);
39 }
40}
41
42void set_mtrr_cache_disable(struct set_mtrr_context *ctxt)
43{
44 if (use_intel())
45 /* Disable MTRRs, and set the default type to uncached */
46 mtrr_wrmsr(MTRRdefType_MSR, ctxt->deftype_lo & 0xf300UL,
47 ctxt->deftype_hi);
48 else if (is_cpu(CYRIX))
49 /* Cyrix ARRs - everything else were excluded at the top */
50 setCx86(CX86_CCR3, (ctxt->ccr3 & 0x0f) | 0x10);
51}
52
53/* Restore the processor after a set_mtrr_prepare */
54void set_mtrr_done(struct set_mtrr_context *ctxt)
55{
56 if (use_intel() || is_cpu(CYRIX)) {
57
58 /* Flush caches and TLBs */
59 wbinvd();
60
61 /* Restore MTRRdefType */
62 if (use_intel())
63 /* Intel (P6) standard MTRRs */
64 mtrr_wrmsr(MTRRdefType_MSR, ctxt->deftype_lo, ctxt->deftype_hi);
65 else
66 /* Cyrix ARRs - everything else was excluded at the top */
67 setCx86(CX86_CCR3, ctxt->ccr3);
68
69 /* Enable caches */
70 write_cr0(read_cr0() & 0xbfffffff);
71
72 /* Restore value of CR4 */
73 if ( cpu_has_pge )
74 write_cr4(ctxt->cr4val);
75 }
76 /* Re-enable interrupts locally (if enabled previously) */
77 local_irq_restore(ctxt->flags);
78}
79
diff --git a/arch/i386/kernel/early_printk.c b/arch/i386/kernel/early_printk.c
deleted file mode 100644
index 92f812ba275c..000000000000
--- a/arch/i386/kernel/early_printk.c
+++ /dev/null
@@ -1,2 +0,0 @@
1
2#include "../../x86_64/kernel/early_printk.c"
diff --git a/arch/i386/kernel/entry.S b/arch/i386/kernel/entry.S
deleted file mode 100644
index a714d6b43506..000000000000
--- a/arch/i386/kernel/entry.S
+++ /dev/null
@@ -1,1112 +0,0 @@
1/*
2 * linux/arch/i386/entry.S
3 *
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 */
6
7/*
8 * entry.S contains the system-call and fault low-level handling routines.
9 * This also contains the timer-interrupt handler, as well as all interrupts
10 * and faults that can result in a task-switch.
11 *
12 * NOTE: This code handles signal-recognition, which happens every time
13 * after a timer-interrupt and after each system call.
14 *
15 * I changed all the .align's to 4 (16 byte alignment), as that's faster
16 * on a 486.
17 *
18 * Stack layout in 'syscall_exit':
19 * ptrace needs to have all regs on the stack.
20 * if the order here is changed, it needs to be
21 * updated in fork.c:copy_process, signal.c:do_signal,
22 * ptrace.c and ptrace.h
23 *
24 * 0(%esp) - %ebx
25 * 4(%esp) - %ecx
26 * 8(%esp) - %edx
27 * C(%esp) - %esi
28 * 10(%esp) - %edi
29 * 14(%esp) - %ebp
30 * 18(%esp) - %eax
31 * 1C(%esp) - %ds
32 * 20(%esp) - %es
33 * 24(%esp) - %fs
34 * 28(%esp) - orig_eax
35 * 2C(%esp) - %eip
36 * 30(%esp) - %cs
37 * 34(%esp) - %eflags
38 * 38(%esp) - %oldesp
39 * 3C(%esp) - %oldss
40 *
41 * "current" is in register %ebx during any slow entries.
42 */
43
44#include <linux/linkage.h>
45#include <asm/thread_info.h>
46#include <asm/irqflags.h>
47#include <asm/errno.h>
48#include <asm/segment.h>
49#include <asm/smp.h>
50#include <asm/page.h>
51#include <asm/desc.h>
52#include <asm/percpu.h>
53#include <asm/dwarf2.h>
54#include "irq_vectors.h"
55
56/*
57 * We use macros for low-level operations which need to be overridden
58 * for paravirtualization. The following will never clobber any registers:
59 * INTERRUPT_RETURN (aka. "iret")
60 * GET_CR0_INTO_EAX (aka. "movl %cr0, %eax")
61 * ENABLE_INTERRUPTS_SYSEXIT (aka "sti; sysexit").
62 *
63 * For DISABLE_INTERRUPTS/ENABLE_INTERRUPTS (aka "cli"/"sti"), you must
64 * specify what registers can be overwritten (CLBR_NONE, CLBR_EAX/EDX/ECX/ANY).
65 * Allowing a register to be clobbered can shrink the paravirt replacement
66 * enough to patch inline, increasing performance.
67 */
68
69#define nr_syscalls ((syscall_table_size)/4)
70
71CF_MASK = 0x00000001
72TF_MASK = 0x00000100
73IF_MASK = 0x00000200
74DF_MASK = 0x00000400
75NT_MASK = 0x00004000
76VM_MASK = 0x00020000
77
78#ifdef CONFIG_PREEMPT
79#define preempt_stop(clobbers) DISABLE_INTERRUPTS(clobbers); TRACE_IRQS_OFF
80#else
81#define preempt_stop(clobbers)
82#define resume_kernel restore_nocheck
83#endif
84
85.macro TRACE_IRQS_IRET
86#ifdef CONFIG_TRACE_IRQFLAGS
87 testl $IF_MASK,PT_EFLAGS(%esp) # interrupts off?
88 jz 1f
89 TRACE_IRQS_ON
901:
91#endif
92.endm
93
94#ifdef CONFIG_VM86
95#define resume_userspace_sig check_userspace
96#else
97#define resume_userspace_sig resume_userspace
98#endif
99
100#define SAVE_ALL \
101 cld; \
102 pushl %fs; \
103 CFI_ADJUST_CFA_OFFSET 4;\
104 /*CFI_REL_OFFSET fs, 0;*/\
105 pushl %es; \
106 CFI_ADJUST_CFA_OFFSET 4;\
107 /*CFI_REL_OFFSET es, 0;*/\
108 pushl %ds; \
109 CFI_ADJUST_CFA_OFFSET 4;\
110 /*CFI_REL_OFFSET ds, 0;*/\
111 pushl %eax; \
112 CFI_ADJUST_CFA_OFFSET 4;\
113 CFI_REL_OFFSET eax, 0;\
114 pushl %ebp; \
115 CFI_ADJUST_CFA_OFFSET 4;\
116 CFI_REL_OFFSET ebp, 0;\
117 pushl %edi; \
118 CFI_ADJUST_CFA_OFFSET 4;\
119 CFI_REL_OFFSET edi, 0;\
120 pushl %esi; \
121 CFI_ADJUST_CFA_OFFSET 4;\
122 CFI_REL_OFFSET esi, 0;\
123 pushl %edx; \
124 CFI_ADJUST_CFA_OFFSET 4;\
125 CFI_REL_OFFSET edx, 0;\
126 pushl %ecx; \
127 CFI_ADJUST_CFA_OFFSET 4;\
128 CFI_REL_OFFSET ecx, 0;\
129 pushl %ebx; \
130 CFI_ADJUST_CFA_OFFSET 4;\
131 CFI_REL_OFFSET ebx, 0;\
132 movl $(__USER_DS), %edx; \
133 movl %edx, %ds; \
134 movl %edx, %es; \
135 movl $(__KERNEL_PERCPU), %edx; \
136 movl %edx, %fs
137
138#define RESTORE_INT_REGS \
139 popl %ebx; \
140 CFI_ADJUST_CFA_OFFSET -4;\
141 CFI_RESTORE ebx;\
142 popl %ecx; \
143 CFI_ADJUST_CFA_OFFSET -4;\
144 CFI_RESTORE ecx;\
145 popl %edx; \
146 CFI_ADJUST_CFA_OFFSET -4;\
147 CFI_RESTORE edx;\
148 popl %esi; \
149 CFI_ADJUST_CFA_OFFSET -4;\
150 CFI_RESTORE esi;\
151 popl %edi; \
152 CFI_ADJUST_CFA_OFFSET -4;\
153 CFI_RESTORE edi;\
154 popl %ebp; \
155 CFI_ADJUST_CFA_OFFSET -4;\
156 CFI_RESTORE ebp;\
157 popl %eax; \
158 CFI_ADJUST_CFA_OFFSET -4;\
159 CFI_RESTORE eax
160
161#define RESTORE_REGS \
162 RESTORE_INT_REGS; \
1631: popl %ds; \
164 CFI_ADJUST_CFA_OFFSET -4;\
165 /*CFI_RESTORE ds;*/\
1662: popl %es; \
167 CFI_ADJUST_CFA_OFFSET -4;\
168 /*CFI_RESTORE es;*/\
1693: popl %fs; \
170 CFI_ADJUST_CFA_OFFSET -4;\
171 /*CFI_RESTORE fs;*/\
172.pushsection .fixup,"ax"; \
1734: movl $0,(%esp); \
174 jmp 1b; \
1755: movl $0,(%esp); \
176 jmp 2b; \
1776: movl $0,(%esp); \
178 jmp 3b; \
179.section __ex_table,"a";\
180 .align 4; \
181 .long 1b,4b; \
182 .long 2b,5b; \
183 .long 3b,6b; \
184.popsection
185
186#define RING0_INT_FRAME \
187 CFI_STARTPROC simple;\
188 CFI_SIGNAL_FRAME;\
189 CFI_DEF_CFA esp, 3*4;\
190 /*CFI_OFFSET cs, -2*4;*/\
191 CFI_OFFSET eip, -3*4
192
193#define RING0_EC_FRAME \
194 CFI_STARTPROC simple;\
195 CFI_SIGNAL_FRAME;\
196 CFI_DEF_CFA esp, 4*4;\
197 /*CFI_OFFSET cs, -2*4;*/\
198 CFI_OFFSET eip, -3*4
199
200#define RING0_PTREGS_FRAME \
201 CFI_STARTPROC simple;\
202 CFI_SIGNAL_FRAME;\
203 CFI_DEF_CFA esp, PT_OLDESP-PT_EBX;\
204 /*CFI_OFFSET cs, PT_CS-PT_OLDESP;*/\
205 CFI_OFFSET eip, PT_EIP-PT_OLDESP;\
206 /*CFI_OFFSET es, PT_ES-PT_OLDESP;*/\
207 /*CFI_OFFSET ds, PT_DS-PT_OLDESP;*/\
208 CFI_OFFSET eax, PT_EAX-PT_OLDESP;\
209 CFI_OFFSET ebp, PT_EBP-PT_OLDESP;\
210 CFI_OFFSET edi, PT_EDI-PT_OLDESP;\
211 CFI_OFFSET esi, PT_ESI-PT_OLDESP;\
212 CFI_OFFSET edx, PT_EDX-PT_OLDESP;\
213 CFI_OFFSET ecx, PT_ECX-PT_OLDESP;\
214 CFI_OFFSET ebx, PT_EBX-PT_OLDESP
215
216ENTRY(ret_from_fork)
217 CFI_STARTPROC
218 pushl %eax
219 CFI_ADJUST_CFA_OFFSET 4
220 call schedule_tail
221 GET_THREAD_INFO(%ebp)
222 popl %eax
223 CFI_ADJUST_CFA_OFFSET -4
224 pushl $0x0202 # Reset kernel eflags
225 CFI_ADJUST_CFA_OFFSET 4
226 popfl
227 CFI_ADJUST_CFA_OFFSET -4
228 jmp syscall_exit
229 CFI_ENDPROC
230END(ret_from_fork)
231
232/*
233 * Return to user mode is not as complex as all this looks,
234 * but we want the default path for a system call return to
235 * go as quickly as possible which is why some of this is
236 * less clear than it otherwise should be.
237 */
238
239 # userspace resumption stub bypassing syscall exit tracing
240 ALIGN
241 RING0_PTREGS_FRAME
242ret_from_exception:
243 preempt_stop(CLBR_ANY)
244ret_from_intr:
245 GET_THREAD_INFO(%ebp)
246check_userspace:
247 movl PT_EFLAGS(%esp), %eax # mix EFLAGS and CS
248 movb PT_CS(%esp), %al
249 andl $(VM_MASK | SEGMENT_RPL_MASK), %eax
250 cmpl $USER_RPL, %eax
251 jb resume_kernel # not returning to v8086 or userspace
252
253ENTRY(resume_userspace)
254 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
255 # setting need_resched or sigpending
256 # between sampling and the iret
257 movl TI_flags(%ebp), %ecx
258 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
259 # int/exception return?
260 jne work_pending
261 jmp restore_all
262END(ret_from_exception)
263
264#ifdef CONFIG_PREEMPT
265ENTRY(resume_kernel)
266 DISABLE_INTERRUPTS(CLBR_ANY)
267 cmpl $0,TI_preempt_count(%ebp) # non-zero preempt_count ?
268 jnz restore_nocheck
269need_resched:
270 movl TI_flags(%ebp), %ecx # need_resched set ?
271 testb $_TIF_NEED_RESCHED, %cl
272 jz restore_all
273 testl $IF_MASK,PT_EFLAGS(%esp) # interrupts off (exception path) ?
274 jz restore_all
275 call preempt_schedule_irq
276 jmp need_resched
277END(resume_kernel)
278#endif
279 CFI_ENDPROC
280
281/* SYSENTER_RETURN points to after the "sysenter" instruction in
282 the vsyscall page. See vsyscall-sysentry.S, which defines the symbol. */
283
284 # sysenter call handler stub
285ENTRY(sysenter_entry)
286 CFI_STARTPROC simple
287 CFI_SIGNAL_FRAME
288 CFI_DEF_CFA esp, 0
289 CFI_REGISTER esp, ebp
290 movl TSS_sysenter_esp0(%esp),%esp
291sysenter_past_esp:
292 /*
293 * No need to follow this irqs on/off section: the syscall
294 * disabled irqs and here we enable it straight after entry:
295 */
296 ENABLE_INTERRUPTS(CLBR_NONE)
297 pushl $(__USER_DS)
298 CFI_ADJUST_CFA_OFFSET 4
299 /*CFI_REL_OFFSET ss, 0*/
300 pushl %ebp
301 CFI_ADJUST_CFA_OFFSET 4
302 CFI_REL_OFFSET esp, 0
303 pushfl
304 CFI_ADJUST_CFA_OFFSET 4
305 pushl $(__USER_CS)
306 CFI_ADJUST_CFA_OFFSET 4
307 /*CFI_REL_OFFSET cs, 0*/
308 /*
309 * Push current_thread_info()->sysenter_return to the stack.
310 * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
311 * pushed above; +8 corresponds to copy_thread's esp0 setting.
312 */
313 pushl (TI_sysenter_return-THREAD_SIZE+8+4*4)(%esp)
314 CFI_ADJUST_CFA_OFFSET 4
315 CFI_REL_OFFSET eip, 0
316
317/*
318 * Load the potential sixth argument from user stack.
319 * Careful about security.
320 */
321 cmpl $__PAGE_OFFSET-3,%ebp
322 jae syscall_fault
3231: movl (%ebp),%ebp
324.section __ex_table,"a"
325 .align 4
326 .long 1b,syscall_fault
327.previous
328
329 pushl %eax
330 CFI_ADJUST_CFA_OFFSET 4
331 SAVE_ALL
332 GET_THREAD_INFO(%ebp)
333
334 /* Note, _TIF_SECCOMP is bit number 8, and so it needs testw and not testb */
335 testw $(_TIF_SYSCALL_EMU|_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT),TI_flags(%ebp)
336 jnz syscall_trace_entry
337 cmpl $(nr_syscalls), %eax
338 jae syscall_badsys
339 call *sys_call_table(,%eax,4)
340 movl %eax,PT_EAX(%esp)
341 DISABLE_INTERRUPTS(CLBR_ANY)
342 TRACE_IRQS_OFF
343 movl TI_flags(%ebp), %ecx
344 testw $_TIF_ALLWORK_MASK, %cx
345 jne syscall_exit_work
346/* if something modifies registers it must also disable sysexit */
347 movl PT_EIP(%esp), %edx
348 movl PT_OLDESP(%esp), %ecx
349 xorl %ebp,%ebp
350 TRACE_IRQS_ON
3511: mov PT_FS(%esp), %fs
352 ENABLE_INTERRUPTS_SYSEXIT
353 CFI_ENDPROC
354.pushsection .fixup,"ax"
3552: movl $0,PT_FS(%esp)
356 jmp 1b
357.section __ex_table,"a"
358 .align 4
359 .long 1b,2b
360.popsection
361ENDPROC(sysenter_entry)
362
363 # system call handler stub
364ENTRY(system_call)
365 RING0_INT_FRAME # can't unwind into user space anyway
366 pushl %eax # save orig_eax
367 CFI_ADJUST_CFA_OFFSET 4
368 SAVE_ALL
369 GET_THREAD_INFO(%ebp)
370 # system call tracing in operation / emulation
371 /* Note, _TIF_SECCOMP is bit number 8, and so it needs testw and not testb */
372 testw $(_TIF_SYSCALL_EMU|_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT),TI_flags(%ebp)
373 jnz syscall_trace_entry
374 cmpl $(nr_syscalls), %eax
375 jae syscall_badsys
376syscall_call:
377 call *sys_call_table(,%eax,4)
378 movl %eax,PT_EAX(%esp) # store the return value
379syscall_exit:
380 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
381 # setting need_resched or sigpending
382 # between sampling and the iret
383 TRACE_IRQS_OFF
384 testl $TF_MASK,PT_EFLAGS(%esp) # If tracing set singlestep flag on exit
385 jz no_singlestep
386 orl $_TIF_SINGLESTEP,TI_flags(%ebp)
387no_singlestep:
388 movl TI_flags(%ebp), %ecx
389 testw $_TIF_ALLWORK_MASK, %cx # current->work
390 jne syscall_exit_work
391
392restore_all:
393 movl PT_EFLAGS(%esp), %eax # mix EFLAGS, SS and CS
394 # Warning: PT_OLDSS(%esp) contains the wrong/random values if we
395 # are returning to the kernel.
396 # See comments in process.c:copy_thread() for details.
397 movb PT_OLDSS(%esp), %ah
398 movb PT_CS(%esp), %al
399 andl $(VM_MASK | (SEGMENT_TI_MASK << 8) | SEGMENT_RPL_MASK), %eax
400 cmpl $((SEGMENT_LDT << 8) | USER_RPL), %eax
401 CFI_REMEMBER_STATE
402 je ldt_ss # returning to user-space with LDT SS
403restore_nocheck:
404 TRACE_IRQS_IRET
405restore_nocheck_notrace:
406 RESTORE_REGS
407 addl $4, %esp # skip orig_eax/error_code
408 CFI_ADJUST_CFA_OFFSET -4
4091: INTERRUPT_RETURN
410.section .fixup,"ax"
411iret_exc:
412 pushl $0 # no error code
413 pushl $do_iret_error
414 jmp error_code
415.previous
416.section __ex_table,"a"
417 .align 4
418 .long 1b,iret_exc
419.previous
420
421 CFI_RESTORE_STATE
422ldt_ss:
423 larl PT_OLDSS(%esp), %eax
424 jnz restore_nocheck
425 testl $0x00400000, %eax # returning to 32bit stack?
426 jnz restore_nocheck # allright, normal return
427
428#ifdef CONFIG_PARAVIRT
429 /*
430 * The kernel can't run on a non-flat stack if paravirt mode
431 * is active. Rather than try to fixup the high bits of
432 * ESP, bypass this code entirely. This may break DOSemu
433 * and/or Wine support in a paravirt VM, although the option
434 * is still available to implement the setting of the high
435 * 16-bits in the INTERRUPT_RETURN paravirt-op.
436 */
437 cmpl $0, paravirt_ops+PARAVIRT_enabled
438 jne restore_nocheck
439#endif
440
441 /* If returning to userspace with 16bit stack,
442 * try to fix the higher word of ESP, as the CPU
443 * won't restore it.
444 * This is an "official" bug of all the x86-compatible
445 * CPUs, which we can try to work around to make
446 * dosemu and wine happy. */
447 movl PT_OLDESP(%esp), %eax
448 movl %esp, %edx
449 call patch_espfix_desc
450 pushl $__ESPFIX_SS
451 CFI_ADJUST_CFA_OFFSET 4
452 pushl %eax
453 CFI_ADJUST_CFA_OFFSET 4
454 DISABLE_INTERRUPTS(CLBR_EAX)
455 TRACE_IRQS_OFF
456 lss (%esp), %esp
457 CFI_ADJUST_CFA_OFFSET -8
458 jmp restore_nocheck
459 CFI_ENDPROC
460ENDPROC(system_call)
461
462 # perform work that needs to be done immediately before resumption
463 ALIGN
464 RING0_PTREGS_FRAME # can't unwind into user space anyway
465work_pending:
466 testb $_TIF_NEED_RESCHED, %cl
467 jz work_notifysig
468work_resched:
469 call schedule
470 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
471 # setting need_resched or sigpending
472 # between sampling and the iret
473 TRACE_IRQS_OFF
474 movl TI_flags(%ebp), %ecx
475 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
476 # than syscall tracing?
477 jz restore_all
478 testb $_TIF_NEED_RESCHED, %cl
479 jnz work_resched
480
481work_notifysig: # deal with pending signals and
482 # notify-resume requests
483#ifdef CONFIG_VM86
484 testl $VM_MASK, PT_EFLAGS(%esp)
485 movl %esp, %eax
486 jne work_notifysig_v86 # returning to kernel-space or
487 # vm86-space
488 xorl %edx, %edx
489 call do_notify_resume
490 jmp resume_userspace_sig
491
492 ALIGN
493work_notifysig_v86:
494 pushl %ecx # save ti_flags for do_notify_resume
495 CFI_ADJUST_CFA_OFFSET 4
496 call save_v86_state # %eax contains pt_regs pointer
497 popl %ecx
498 CFI_ADJUST_CFA_OFFSET -4
499 movl %eax, %esp
500#else
501 movl %esp, %eax
502#endif
503 xorl %edx, %edx
504 call do_notify_resume
505 jmp resume_userspace_sig
506END(work_pending)
507
508 # perform syscall exit tracing
509 ALIGN
510syscall_trace_entry:
511 movl $-ENOSYS,PT_EAX(%esp)
512 movl %esp, %eax
513 xorl %edx,%edx
514 call do_syscall_trace
515 cmpl $0, %eax
516 jne resume_userspace # ret != 0 -> running under PTRACE_SYSEMU,
517 # so must skip actual syscall
518 movl PT_ORIG_EAX(%esp), %eax
519 cmpl $(nr_syscalls), %eax
520 jnae syscall_call
521 jmp syscall_exit
522END(syscall_trace_entry)
523
524 # perform syscall exit tracing
525 ALIGN
526syscall_exit_work:
527 testb $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SINGLESTEP), %cl
528 jz work_pending
529 TRACE_IRQS_ON
530 ENABLE_INTERRUPTS(CLBR_ANY) # could let do_syscall_trace() call
531 # schedule() instead
532 movl %esp, %eax
533 movl $1, %edx
534 call do_syscall_trace
535 jmp resume_userspace
536END(syscall_exit_work)
537 CFI_ENDPROC
538
539 RING0_INT_FRAME # can't unwind into user space anyway
540syscall_fault:
541 pushl %eax # save orig_eax
542 CFI_ADJUST_CFA_OFFSET 4
543 SAVE_ALL
544 GET_THREAD_INFO(%ebp)
545 movl $-EFAULT,PT_EAX(%esp)
546 jmp resume_userspace
547END(syscall_fault)
548
549syscall_badsys:
550 movl $-ENOSYS,PT_EAX(%esp)
551 jmp resume_userspace
552END(syscall_badsys)
553 CFI_ENDPROC
554
555#define FIXUP_ESPFIX_STACK \
556 /* since we are on a wrong stack, we cant make it a C code :( */ \
557 PER_CPU(gdt_page, %ebx); \
558 GET_DESC_BASE(GDT_ENTRY_ESPFIX_SS, %ebx, %eax, %ax, %al, %ah); \
559 addl %esp, %eax; \
560 pushl $__KERNEL_DS; \
561 CFI_ADJUST_CFA_OFFSET 4; \
562 pushl %eax; \
563 CFI_ADJUST_CFA_OFFSET 4; \
564 lss (%esp), %esp; \
565 CFI_ADJUST_CFA_OFFSET -8;
566#define UNWIND_ESPFIX_STACK \
567 movl %ss, %eax; \
568 /* see if on espfix stack */ \
569 cmpw $__ESPFIX_SS, %ax; \
570 jne 27f; \
571 movl $__KERNEL_DS, %eax; \
572 movl %eax, %ds; \
573 movl %eax, %es; \
574 /* switch to normal stack */ \
575 FIXUP_ESPFIX_STACK; \
57627:;
577
578/*
579 * Build the entry stubs and pointer table with
580 * some assembler magic.
581 */
582.data
583ENTRY(interrupt)
584.text
585
586ENTRY(irq_entries_start)
587 RING0_INT_FRAME
588vector=0
589.rept NR_IRQS
590 ALIGN
591 .if vector
592 CFI_ADJUST_CFA_OFFSET -4
593 .endif
5941: pushl $~(vector)
595 CFI_ADJUST_CFA_OFFSET 4
596 jmp common_interrupt
597 .previous
598 .long 1b
599 .text
600vector=vector+1
601.endr
602END(irq_entries_start)
603
604.previous
605END(interrupt)
606.previous
607
608/*
609 * the CPU automatically disables interrupts when executing an IRQ vector,
610 * so IRQ-flags tracing has to follow that:
611 */
612 ALIGN
613common_interrupt:
614 SAVE_ALL
615 TRACE_IRQS_OFF
616 movl %esp,%eax
617 call do_IRQ
618 jmp ret_from_intr
619ENDPROC(common_interrupt)
620 CFI_ENDPROC
621
622#define BUILD_INTERRUPT(name, nr) \
623ENTRY(name) \
624 RING0_INT_FRAME; \
625 pushl $~(nr); \
626 CFI_ADJUST_CFA_OFFSET 4; \
627 SAVE_ALL; \
628 TRACE_IRQS_OFF \
629 movl %esp,%eax; \
630 call smp_##name; \
631 jmp ret_from_intr; \
632 CFI_ENDPROC; \
633ENDPROC(name)
634
635/* The include is where all of the SMP etc. interrupts come from */
636#include "entry_arch.h"
637
638KPROBE_ENTRY(page_fault)
639 RING0_EC_FRAME
640 pushl $do_page_fault
641 CFI_ADJUST_CFA_OFFSET 4
642 ALIGN
643error_code:
644 /* the function address is in %fs's slot on the stack */
645 pushl %es
646 CFI_ADJUST_CFA_OFFSET 4
647 /*CFI_REL_OFFSET es, 0*/
648 pushl %ds
649 CFI_ADJUST_CFA_OFFSET 4
650 /*CFI_REL_OFFSET ds, 0*/
651 pushl %eax
652 CFI_ADJUST_CFA_OFFSET 4
653 CFI_REL_OFFSET eax, 0
654 pushl %ebp
655 CFI_ADJUST_CFA_OFFSET 4
656 CFI_REL_OFFSET ebp, 0
657 pushl %edi
658 CFI_ADJUST_CFA_OFFSET 4
659 CFI_REL_OFFSET edi, 0
660 pushl %esi
661 CFI_ADJUST_CFA_OFFSET 4
662 CFI_REL_OFFSET esi, 0
663 pushl %edx
664 CFI_ADJUST_CFA_OFFSET 4
665 CFI_REL_OFFSET edx, 0
666 pushl %ecx
667 CFI_ADJUST_CFA_OFFSET 4
668 CFI_REL_OFFSET ecx, 0
669 pushl %ebx
670 CFI_ADJUST_CFA_OFFSET 4
671 CFI_REL_OFFSET ebx, 0
672 cld
673 pushl %fs
674 CFI_ADJUST_CFA_OFFSET 4
675 /*CFI_REL_OFFSET fs, 0*/
676 movl $(__KERNEL_PERCPU), %ecx
677 movl %ecx, %fs
678 UNWIND_ESPFIX_STACK
679 popl %ecx
680 CFI_ADJUST_CFA_OFFSET -4
681 /*CFI_REGISTER es, ecx*/
682 movl PT_FS(%esp), %edi # get the function address
683 movl PT_ORIG_EAX(%esp), %edx # get the error code
684 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
685 mov %ecx, PT_FS(%esp)
686 /*CFI_REL_OFFSET fs, ES*/
687 movl $(__USER_DS), %ecx
688 movl %ecx, %ds
689 movl %ecx, %es
690 movl %esp,%eax # pt_regs pointer
691 call *%edi
692 jmp ret_from_exception
693 CFI_ENDPROC
694KPROBE_END(page_fault)
695
696ENTRY(coprocessor_error)
697 RING0_INT_FRAME
698 pushl $0
699 CFI_ADJUST_CFA_OFFSET 4
700 pushl $do_coprocessor_error
701 CFI_ADJUST_CFA_OFFSET 4
702 jmp error_code
703 CFI_ENDPROC
704END(coprocessor_error)
705
706ENTRY(simd_coprocessor_error)
707 RING0_INT_FRAME
708 pushl $0
709 CFI_ADJUST_CFA_OFFSET 4
710 pushl $do_simd_coprocessor_error
711 CFI_ADJUST_CFA_OFFSET 4
712 jmp error_code
713 CFI_ENDPROC
714END(simd_coprocessor_error)
715
716ENTRY(device_not_available)
717 RING0_INT_FRAME
718 pushl $-1 # mark this as an int
719 CFI_ADJUST_CFA_OFFSET 4
720 SAVE_ALL
721 GET_CR0_INTO_EAX
722 testl $0x4, %eax # EM (math emulation bit)
723 jne device_not_available_emulate
724 preempt_stop(CLBR_ANY)
725 call math_state_restore
726 jmp ret_from_exception
727device_not_available_emulate:
728 pushl $0 # temporary storage for ORIG_EIP
729 CFI_ADJUST_CFA_OFFSET 4
730 call math_emulate
731 addl $4, %esp
732 CFI_ADJUST_CFA_OFFSET -4
733 jmp ret_from_exception
734 CFI_ENDPROC
735END(device_not_available)
736
737/*
738 * Debug traps and NMI can happen at the one SYSENTER instruction
739 * that sets up the real kernel stack. Check here, since we can't
740 * allow the wrong stack to be used.
741 *
742 * "TSS_sysenter_esp0+12" is because the NMI/debug handler will have
743 * already pushed 3 words if it hits on the sysenter instruction:
744 * eflags, cs and eip.
745 *
746 * We just load the right stack, and push the three (known) values
747 * by hand onto the new stack - while updating the return eip past
748 * the instruction that would have done it for sysenter.
749 */
750#define FIX_STACK(offset, ok, label) \
751 cmpw $__KERNEL_CS,4(%esp); \
752 jne ok; \
753label: \
754 movl TSS_sysenter_esp0+offset(%esp),%esp; \
755 CFI_DEF_CFA esp, 0; \
756 CFI_UNDEFINED eip; \
757 pushfl; \
758 CFI_ADJUST_CFA_OFFSET 4; \
759 pushl $__KERNEL_CS; \
760 CFI_ADJUST_CFA_OFFSET 4; \
761 pushl $sysenter_past_esp; \
762 CFI_ADJUST_CFA_OFFSET 4; \
763 CFI_REL_OFFSET eip, 0
764
765KPROBE_ENTRY(debug)
766 RING0_INT_FRAME
767 cmpl $sysenter_entry,(%esp)
768 jne debug_stack_correct
769 FIX_STACK(12, debug_stack_correct, debug_esp_fix_insn)
770debug_stack_correct:
771 pushl $-1 # mark this as an int
772 CFI_ADJUST_CFA_OFFSET 4
773 SAVE_ALL
774 xorl %edx,%edx # error code 0
775 movl %esp,%eax # pt_regs pointer
776 call do_debug
777 jmp ret_from_exception
778 CFI_ENDPROC
779KPROBE_END(debug)
780
781/*
782 * NMI is doubly nasty. It can happen _while_ we're handling
783 * a debug fault, and the debug fault hasn't yet been able to
784 * clear up the stack. So we first check whether we got an
785 * NMI on the sysenter entry path, but after that we need to
786 * check whether we got an NMI on the debug path where the debug
787 * fault happened on the sysenter path.
788 */
789KPROBE_ENTRY(nmi)
790 RING0_INT_FRAME
791 pushl %eax
792 CFI_ADJUST_CFA_OFFSET 4
793 movl %ss, %eax
794 cmpw $__ESPFIX_SS, %ax
795 popl %eax
796 CFI_ADJUST_CFA_OFFSET -4
797 je nmi_espfix_stack
798 cmpl $sysenter_entry,(%esp)
799 je nmi_stack_fixup
800 pushl %eax
801 CFI_ADJUST_CFA_OFFSET 4
802 movl %esp,%eax
803 /* Do not access memory above the end of our stack page,
804 * it might not exist.
805 */
806 andl $(THREAD_SIZE-1),%eax
807 cmpl $(THREAD_SIZE-20),%eax
808 popl %eax
809 CFI_ADJUST_CFA_OFFSET -4
810 jae nmi_stack_correct
811 cmpl $sysenter_entry,12(%esp)
812 je nmi_debug_stack_check
813nmi_stack_correct:
814 /* We have a RING0_INT_FRAME here */
815 pushl %eax
816 CFI_ADJUST_CFA_OFFSET 4
817 SAVE_ALL
818 xorl %edx,%edx # zero error code
819 movl %esp,%eax # pt_regs pointer
820 call do_nmi
821 jmp restore_nocheck_notrace
822 CFI_ENDPROC
823
824nmi_stack_fixup:
825 RING0_INT_FRAME
826 FIX_STACK(12,nmi_stack_correct, 1)
827 jmp nmi_stack_correct
828
829nmi_debug_stack_check:
830 /* We have a RING0_INT_FRAME here */
831 cmpw $__KERNEL_CS,16(%esp)
832 jne nmi_stack_correct
833 cmpl $debug,(%esp)
834 jb nmi_stack_correct
835 cmpl $debug_esp_fix_insn,(%esp)
836 ja nmi_stack_correct
837 FIX_STACK(24,nmi_stack_correct, 1)
838 jmp nmi_stack_correct
839
840nmi_espfix_stack:
841 /* We have a RING0_INT_FRAME here.
842 *
843 * create the pointer to lss back
844 */
845 pushl %ss
846 CFI_ADJUST_CFA_OFFSET 4
847 pushl %esp
848 CFI_ADJUST_CFA_OFFSET 4
849 addw $4, (%esp)
850 /* copy the iret frame of 12 bytes */
851 .rept 3
852 pushl 16(%esp)
853 CFI_ADJUST_CFA_OFFSET 4
854 .endr
855 pushl %eax
856 CFI_ADJUST_CFA_OFFSET 4
857 SAVE_ALL
858 FIXUP_ESPFIX_STACK # %eax == %esp
859 xorl %edx,%edx # zero error code
860 call do_nmi
861 RESTORE_REGS
862 lss 12+4(%esp), %esp # back to espfix stack
863 CFI_ADJUST_CFA_OFFSET -24
8641: INTERRUPT_RETURN
865 CFI_ENDPROC
866.section __ex_table,"a"
867 .align 4
868 .long 1b,iret_exc
869.previous
870KPROBE_END(nmi)
871
872#ifdef CONFIG_PARAVIRT
873ENTRY(native_iret)
8741: iret
875.section __ex_table,"a"
876 .align 4
877 .long 1b,iret_exc
878.previous
879END(native_iret)
880
881ENTRY(native_irq_enable_sysexit)
882 sti
883 sysexit
884END(native_irq_enable_sysexit)
885#endif
886
887KPROBE_ENTRY(int3)
888 RING0_INT_FRAME
889 pushl $-1 # mark this as an int
890 CFI_ADJUST_CFA_OFFSET 4
891 SAVE_ALL
892 xorl %edx,%edx # zero error code
893 movl %esp,%eax # pt_regs pointer
894 call do_int3
895 jmp ret_from_exception
896 CFI_ENDPROC
897KPROBE_END(int3)
898
899ENTRY(overflow)
900 RING0_INT_FRAME
901 pushl $0
902 CFI_ADJUST_CFA_OFFSET 4
903 pushl $do_overflow
904 CFI_ADJUST_CFA_OFFSET 4
905 jmp error_code
906 CFI_ENDPROC
907END(overflow)
908
909ENTRY(bounds)
910 RING0_INT_FRAME
911 pushl $0
912 CFI_ADJUST_CFA_OFFSET 4
913 pushl $do_bounds
914 CFI_ADJUST_CFA_OFFSET 4
915 jmp error_code
916 CFI_ENDPROC
917END(bounds)
918
919ENTRY(invalid_op)
920 RING0_INT_FRAME
921 pushl $0
922 CFI_ADJUST_CFA_OFFSET 4
923 pushl $do_invalid_op
924 CFI_ADJUST_CFA_OFFSET 4
925 jmp error_code
926 CFI_ENDPROC
927END(invalid_op)
928
929ENTRY(coprocessor_segment_overrun)
930 RING0_INT_FRAME
931 pushl $0
932 CFI_ADJUST_CFA_OFFSET 4
933 pushl $do_coprocessor_segment_overrun
934 CFI_ADJUST_CFA_OFFSET 4
935 jmp error_code
936 CFI_ENDPROC
937END(coprocessor_segment_overrun)
938
939ENTRY(invalid_TSS)
940 RING0_EC_FRAME
941 pushl $do_invalid_TSS
942 CFI_ADJUST_CFA_OFFSET 4
943 jmp error_code
944 CFI_ENDPROC
945END(invalid_TSS)
946
947ENTRY(segment_not_present)
948 RING0_EC_FRAME
949 pushl $do_segment_not_present
950 CFI_ADJUST_CFA_OFFSET 4
951 jmp error_code
952 CFI_ENDPROC
953END(segment_not_present)
954
955ENTRY(stack_segment)
956 RING0_EC_FRAME
957 pushl $do_stack_segment
958 CFI_ADJUST_CFA_OFFSET 4
959 jmp error_code
960 CFI_ENDPROC
961END(stack_segment)
962
963KPROBE_ENTRY(general_protection)
964 RING0_EC_FRAME
965 pushl $do_general_protection
966 CFI_ADJUST_CFA_OFFSET 4
967 jmp error_code
968 CFI_ENDPROC
969KPROBE_END(general_protection)
970
971ENTRY(alignment_check)
972 RING0_EC_FRAME
973 pushl $do_alignment_check
974 CFI_ADJUST_CFA_OFFSET 4
975 jmp error_code
976 CFI_ENDPROC
977END(alignment_check)
978
979ENTRY(divide_error)
980 RING0_INT_FRAME
981 pushl $0 # no error code
982 CFI_ADJUST_CFA_OFFSET 4
983 pushl $do_divide_error
984 CFI_ADJUST_CFA_OFFSET 4
985 jmp error_code
986 CFI_ENDPROC
987END(divide_error)
988
989#ifdef CONFIG_X86_MCE
990ENTRY(machine_check)
991 RING0_INT_FRAME
992 pushl $0
993 CFI_ADJUST_CFA_OFFSET 4
994 pushl machine_check_vector
995 CFI_ADJUST_CFA_OFFSET 4
996 jmp error_code
997 CFI_ENDPROC
998END(machine_check)
999#endif
1000
1001ENTRY(spurious_interrupt_bug)
1002 RING0_INT_FRAME
1003 pushl $0
1004 CFI_ADJUST_CFA_OFFSET 4
1005 pushl $do_spurious_interrupt_bug
1006 CFI_ADJUST_CFA_OFFSET 4
1007 jmp error_code
1008 CFI_ENDPROC
1009END(spurious_interrupt_bug)
1010
1011ENTRY(kernel_thread_helper)
1012 pushl $0 # fake return address for unwinder
1013 CFI_STARTPROC
1014 movl %edx,%eax
1015 push %edx
1016 CFI_ADJUST_CFA_OFFSET 4
1017 call *%ebx
1018 push %eax
1019 CFI_ADJUST_CFA_OFFSET 4
1020 call do_exit
1021 CFI_ENDPROC
1022ENDPROC(kernel_thread_helper)
1023
1024#ifdef CONFIG_XEN
1025ENTRY(xen_hypervisor_callback)
1026 CFI_STARTPROC
1027 pushl $0
1028 CFI_ADJUST_CFA_OFFSET 4
1029 SAVE_ALL
1030 TRACE_IRQS_OFF
1031
1032 /* Check to see if we got the event in the critical
1033 region in xen_iret_direct, after we've reenabled
1034 events and checked for pending events. This simulates
1035 iret instruction's behaviour where it delivers a
1036 pending interrupt when enabling interrupts. */
1037 movl PT_EIP(%esp),%eax
1038 cmpl $xen_iret_start_crit,%eax
1039 jb 1f
1040 cmpl $xen_iret_end_crit,%eax
1041 jae 1f
1042
1043 call xen_iret_crit_fixup
1044
10451: mov %esp, %eax
1046 call xen_evtchn_do_upcall
1047 jmp ret_from_intr
1048 CFI_ENDPROC
1049ENDPROC(xen_hypervisor_callback)
1050
1051# Hypervisor uses this for application faults while it executes.
1052# We get here for two reasons:
1053# 1. Fault while reloading DS, ES, FS or GS
1054# 2. Fault while executing IRET
1055# Category 1 we fix up by reattempting the load, and zeroing the segment
1056# register if the load fails.
1057# Category 2 we fix up by jumping to do_iret_error. We cannot use the
1058# normal Linux return path in this case because if we use the IRET hypercall
1059# to pop the stack frame we end up in an infinite loop of failsafe callbacks.
1060# We distinguish between categories by maintaining a status value in EAX.
1061ENTRY(xen_failsafe_callback)
1062 CFI_STARTPROC
1063 pushl %eax
1064 CFI_ADJUST_CFA_OFFSET 4
1065 movl $1,%eax
10661: mov 4(%esp),%ds
10672: mov 8(%esp),%es
10683: mov 12(%esp),%fs
10694: mov 16(%esp),%gs
1070 testl %eax,%eax
1071 popl %eax
1072 CFI_ADJUST_CFA_OFFSET -4
1073 lea 16(%esp),%esp
1074 CFI_ADJUST_CFA_OFFSET -16
1075 jz 5f
1076 addl $16,%esp
1077 jmp iret_exc # EAX != 0 => Category 2 (Bad IRET)
10785: pushl $0 # EAX == 0 => Category 1 (Bad segment)
1079 CFI_ADJUST_CFA_OFFSET 4
1080 SAVE_ALL
1081 jmp ret_from_exception
1082 CFI_ENDPROC
1083
1084.section .fixup,"ax"
10856: xorl %eax,%eax
1086 movl %eax,4(%esp)
1087 jmp 1b
10887: xorl %eax,%eax
1089 movl %eax,8(%esp)
1090 jmp 2b
10918: xorl %eax,%eax
1092 movl %eax,12(%esp)
1093 jmp 3b
10949: xorl %eax,%eax
1095 movl %eax,16(%esp)
1096 jmp 4b
1097.previous
1098.section __ex_table,"a"
1099 .align 4
1100 .long 1b,6b
1101 .long 2b,7b
1102 .long 3b,8b
1103 .long 4b,9b
1104.previous
1105ENDPROC(xen_failsafe_callback)
1106
1107#endif /* CONFIG_XEN */
1108
1109.section .rodata,"a"
1110#include "syscall_table.S"
1111
1112syscall_table_size=(.-sys_call_table)
diff --git a/arch/i386/kernel/head.S b/arch/i386/kernel/head.S
deleted file mode 100644
index 8f0382161c91..000000000000
--- a/arch/i386/kernel/head.S
+++ /dev/null
@@ -1,578 +0,0 @@
1/*
2 * linux/arch/i386/kernel/head.S -- the 32-bit startup code.
3 *
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 *
6 * Enhanced CPU detection and feature setting code by Mike Jagdis
7 * and Martin Mares, November 1997.
8 */
9
10.text
11#include <linux/threads.h>
12#include <linux/linkage.h>
13#include <asm/segment.h>
14#include <asm/page.h>
15#include <asm/pgtable.h>
16#include <asm/desc.h>
17#include <asm/cache.h>
18#include <asm/thread_info.h>
19#include <asm/asm-offsets.h>
20#include <asm/setup.h>
21
22/*
23 * References to members of the new_cpu_data structure.
24 */
25
26#define X86 new_cpu_data+CPUINFO_x86
27#define X86_VENDOR new_cpu_data+CPUINFO_x86_vendor
28#define X86_MODEL new_cpu_data+CPUINFO_x86_model
29#define X86_MASK new_cpu_data+CPUINFO_x86_mask
30#define X86_HARD_MATH new_cpu_data+CPUINFO_hard_math
31#define X86_CPUID new_cpu_data+CPUINFO_cpuid_level
32#define X86_CAPABILITY new_cpu_data+CPUINFO_x86_capability
33#define X86_VENDOR_ID new_cpu_data+CPUINFO_x86_vendor_id
34
35/*
36 * This is how much memory *in addition to the memory covered up to
37 * and including _end* we need mapped initially.
38 * We need:
39 * - one bit for each possible page, but only in low memory, which means
40 * 2^32/4096/8 = 128K worst case (4G/4G split.)
41 * - enough space to map all low memory, which means
42 * (2^32/4096) / 1024 pages (worst case, non PAE)
43 * (2^32/4096) / 512 + 4 pages (worst case for PAE)
44 * - a few pages for allocator use before the kernel pagetable has
45 * been set up
46 *
47 * Modulo rounding, each megabyte assigned here requires a kilobyte of
48 * memory, which is currently unreclaimed.
49 *
50 * This should be a multiple of a page.
51 */
52LOW_PAGES = 1<<(32-PAGE_SHIFT_asm)
53
54#if PTRS_PER_PMD > 1
55PAGE_TABLE_SIZE = (LOW_PAGES / PTRS_PER_PMD) + PTRS_PER_PGD
56#else
57PAGE_TABLE_SIZE = (LOW_PAGES / PTRS_PER_PGD)
58#endif
59BOOTBITMAP_SIZE = LOW_PAGES / 8
60ALLOCATOR_SLOP = 4
61
62INIT_MAP_BEYOND_END = BOOTBITMAP_SIZE + (PAGE_TABLE_SIZE + ALLOCATOR_SLOP)*PAGE_SIZE_asm
63
64/*
65 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
66 * %esi points to the real-mode code as a 32-bit pointer.
67 * CS and DS must be 4 GB flat segments, but we don't depend on
68 * any particular GDT layout, because we load our own as soon as we
69 * can.
70 */
71.section .text.head,"ax",@progbits
72ENTRY(startup_32)
73
74/*
75 * Set segments to known values.
76 */
77 cld
78 lgdt boot_gdt_descr - __PAGE_OFFSET
79 movl $(__BOOT_DS),%eax
80 movl %eax,%ds
81 movl %eax,%es
82 movl %eax,%fs
83 movl %eax,%gs
84
85/*
86 * Clear BSS first so that there are no surprises...
87 * No need to cld as DF is already clear from cld above...
88 */
89 xorl %eax,%eax
90 movl $__bss_start - __PAGE_OFFSET,%edi
91 movl $__bss_stop - __PAGE_OFFSET,%ecx
92 subl %edi,%ecx
93 shrl $2,%ecx
94 rep ; stosl
95/*
96 * Copy bootup parameters out of the way.
97 * Note: %esi still has the pointer to the real-mode data.
98 * With the kexec as boot loader, parameter segment might be loaded beyond
99 * kernel image and might not even be addressable by early boot page tables.
100 * (kexec on panic case). Hence copy out the parameters before initializing
101 * page tables.
102 */
103 movl $(boot_params - __PAGE_OFFSET),%edi
104 movl $(PARAM_SIZE/4),%ecx
105 cld
106 rep
107 movsl
108 movl boot_params - __PAGE_OFFSET + NEW_CL_POINTER,%esi
109 andl %esi,%esi
110 jnz 2f # New command line protocol
111 cmpw $(OLD_CL_MAGIC),OLD_CL_MAGIC_ADDR
112 jne 1f
113 movzwl OLD_CL_OFFSET,%esi
114 addl $(OLD_CL_BASE_ADDR),%esi
1152:
116 movl $(boot_command_line - __PAGE_OFFSET),%edi
117 movl $(COMMAND_LINE_SIZE/4),%ecx
118 rep
119 movsl
1201:
121
122/*
123 * Initialize page tables. This creates a PDE and a set of page
124 * tables, which are located immediately beyond _end. The variable
125 * init_pg_tables_end is set up to point to the first "safe" location.
126 * Mappings are created both at virtual address 0 (identity mapping)
127 * and PAGE_OFFSET for up to _end+sizeof(page tables)+INIT_MAP_BEYOND_END.
128 *
129 * Warning: don't use %esi or the stack in this code. However, %esp
130 * can be used as a GPR if you really need it...
131 */
132page_pde_offset = (__PAGE_OFFSET >> 20);
133
134 movl $(pg0 - __PAGE_OFFSET), %edi
135 movl $(swapper_pg_dir - __PAGE_OFFSET), %edx
136 movl $0x007, %eax /* 0x007 = PRESENT+RW+USER */
13710:
138 leal 0x007(%edi),%ecx /* Create PDE entry */
139 movl %ecx,(%edx) /* Store identity PDE entry */
140 movl %ecx,page_pde_offset(%edx) /* Store kernel PDE entry */
141 addl $4,%edx
142 movl $1024, %ecx
14311:
144 stosl
145 addl $0x1000,%eax
146 loop 11b
147 /* End condition: we must map up to and including INIT_MAP_BEYOND_END */
148 /* bytes beyond the end of our own page tables; the +0x007 is the attribute bits */
149 leal (INIT_MAP_BEYOND_END+0x007)(%edi),%ebp
150 cmpl %ebp,%eax
151 jb 10b
152 movl %edi,(init_pg_tables_end - __PAGE_OFFSET)
153
154 xorl %ebx,%ebx /* This is the boot CPU (BSP) */
155 jmp 3f
156/*
157 * Non-boot CPU entry point; entered from trampoline.S
158 * We can't lgdt here, because lgdt itself uses a data segment, but
159 * we know the trampoline has already loaded the boot_gdt for us.
160 *
161 * If cpu hotplug is not supported then this code can go in init section
162 * which will be freed later
163 */
164
165#ifndef CONFIG_HOTPLUG_CPU
166.section .init.text,"ax",@progbits
167#endif
168
169 /* Do an early initialization of the fixmap area */
170 movl $(swapper_pg_dir - __PAGE_OFFSET), %edx
171 movl $(swapper_pg_pmd - __PAGE_OFFSET), %eax
172 addl $0x007, %eax /* 0x007 = PRESENT+RW+USER */
173 movl %eax, 4092(%edx)
174
175#ifdef CONFIG_SMP
176ENTRY(startup_32_smp)
177 cld
178 movl $(__BOOT_DS),%eax
179 movl %eax,%ds
180 movl %eax,%es
181 movl %eax,%fs
182 movl %eax,%gs
183
184/*
185 * New page tables may be in 4Mbyte page mode and may
186 * be using the global pages.
187 *
188 * NOTE! If we are on a 486 we may have no cr4 at all!
189 * So we do not try to touch it unless we really have
190 * some bits in it to set. This won't work if the BSP
191 * implements cr4 but this AP does not -- very unlikely
192 * but be warned! The same applies to the pse feature
193 * if not equally supported. --macro
194 *
195 * NOTE! We have to correct for the fact that we're
196 * not yet offset PAGE_OFFSET..
197 */
198#define cr4_bits mmu_cr4_features-__PAGE_OFFSET
199 movl cr4_bits,%edx
200 andl %edx,%edx
201 jz 6f
202 movl %cr4,%eax # Turn on paging options (PSE,PAE,..)
203 orl %edx,%eax
204 movl %eax,%cr4
205
206 btl $5, %eax # check if PAE is enabled
207 jnc 6f
208
209 /* Check if extended functions are implemented */
210 movl $0x80000000, %eax
211 cpuid
212 cmpl $0x80000000, %eax
213 jbe 6f
214 mov $0x80000001, %eax
215 cpuid
216 /* Execute Disable bit supported? */
217 btl $20, %edx
218 jnc 6f
219
220 /* Setup EFER (Extended Feature Enable Register) */
221 movl $0xc0000080, %ecx
222 rdmsr
223
224 btsl $11, %eax
225 /* Make changes effective */
226 wrmsr
227
2286:
229 /* This is a secondary processor (AP) */
230 xorl %ebx,%ebx
231 incl %ebx
232
233#endif /* CONFIG_SMP */
2343:
235
236/*
237 * Enable paging
238 */
239 movl $swapper_pg_dir-__PAGE_OFFSET,%eax
240 movl %eax,%cr3 /* set the page table pointer.. */
241 movl %cr0,%eax
242 orl $0x80000000,%eax
243 movl %eax,%cr0 /* ..and set paging (PG) bit */
244 ljmp $__BOOT_CS,$1f /* Clear prefetch and normalize %eip */
2451:
246 /* Set up the stack pointer */
247 lss stack_start,%esp
248
249/*
250 * Initialize eflags. Some BIOS's leave bits like NT set. This would
251 * confuse the debugger if this code is traced.
252 * XXX - best to initialize before switching to protected mode.
253 */
254 pushl $0
255 popfl
256
257#ifdef CONFIG_SMP
258 andl %ebx,%ebx
259 jz 1f /* Initial CPU cleans BSS */
260 jmp checkCPUtype
2611:
262#endif /* CONFIG_SMP */
263
264/*
265 * start system 32-bit setup. We need to re-do some of the things done
266 * in 16-bit mode for the "real" operations.
267 */
268 call setup_idt
269
270checkCPUtype:
271
272 movl $-1,X86_CPUID # -1 for no CPUID initially
273
274/* check if it is 486 or 386. */
275/*
276 * XXX - this does a lot of unnecessary setup. Alignment checks don't
277 * apply at our cpl of 0 and the stack ought to be aligned already, and
278 * we don't need to preserve eflags.
279 */
280
281 movb $3,X86 # at least 386
282 pushfl # push EFLAGS
283 popl %eax # get EFLAGS
284 movl %eax,%ecx # save original EFLAGS
285 xorl $0x240000,%eax # flip AC and ID bits in EFLAGS
286 pushl %eax # copy to EFLAGS
287 popfl # set EFLAGS
288 pushfl # get new EFLAGS
289 popl %eax # put it in eax
290 xorl %ecx,%eax # change in flags
291 pushl %ecx # restore original EFLAGS
292 popfl
293 testl $0x40000,%eax # check if AC bit changed
294 je is386
295
296 movb $4,X86 # at least 486
297 testl $0x200000,%eax # check if ID bit changed
298 je is486
299
300 /* get vendor info */
301 xorl %eax,%eax # call CPUID with 0 -> return vendor ID
302 cpuid
303 movl %eax,X86_CPUID # save CPUID level
304 movl %ebx,X86_VENDOR_ID # lo 4 chars
305 movl %edx,X86_VENDOR_ID+4 # next 4 chars
306 movl %ecx,X86_VENDOR_ID+8 # last 4 chars
307
308 orl %eax,%eax # do we have processor info as well?
309 je is486
310
311 movl $1,%eax # Use the CPUID instruction to get CPU type
312 cpuid
313 movb %al,%cl # save reg for future use
314 andb $0x0f,%ah # mask processor family
315 movb %ah,X86
316 andb $0xf0,%al # mask model
317 shrb $4,%al
318 movb %al,X86_MODEL
319 andb $0x0f,%cl # mask mask revision
320 movb %cl,X86_MASK
321 movl %edx,X86_CAPABILITY
322
323is486: movl $0x50022,%ecx # set AM, WP, NE and MP
324 jmp 2f
325
326is386: movl $2,%ecx # set MP
3272: movl %cr0,%eax
328 andl $0x80000011,%eax # Save PG,PE,ET
329 orl %ecx,%eax
330 movl %eax,%cr0
331
332 call check_x87
333 lgdt early_gdt_descr
334 lidt idt_descr
335 ljmp $(__KERNEL_CS),$1f
3361: movl $(__KERNEL_DS),%eax # reload all the segment registers
337 movl %eax,%ss # after changing gdt.
338 movl %eax,%fs # gets reset once there's real percpu
339
340 movl $(__USER_DS),%eax # DS/ES contains default USER segment
341 movl %eax,%ds
342 movl %eax,%es
343
344 xorl %eax,%eax # Clear GS and LDT
345 movl %eax,%gs
346 lldt %ax
347
348 cld # gcc2 wants the direction flag cleared at all times
349 pushl $0 # fake return address for unwinder
350#ifdef CONFIG_SMP
351 movb ready, %cl
352 movb $1, ready
353 cmpb $0,%cl # the first CPU calls start_kernel
354 je 1f
355 movl $(__KERNEL_PERCPU), %eax
356 movl %eax,%fs # set this cpu's percpu
357 jmp initialize_secondary # all other CPUs call initialize_secondary
3581:
359#endif /* CONFIG_SMP */
360 jmp start_kernel
361
362/*
363 * We depend on ET to be correct. This checks for 287/387.
364 */
365check_x87:
366 movb $0,X86_HARD_MATH
367 clts
368 fninit
369 fstsw %ax
370 cmpb $0,%al
371 je 1f
372 movl %cr0,%eax /* no coprocessor: have to set bits */
373 xorl $4,%eax /* set EM */
374 movl %eax,%cr0
375 ret
376 ALIGN
3771: movb $1,X86_HARD_MATH
378 .byte 0xDB,0xE4 /* fsetpm for 287, ignored by 387 */
379 ret
380
381/*
382 * setup_idt
383 *
384 * sets up a idt with 256 entries pointing to
385 * ignore_int, interrupt gates. It doesn't actually load
386 * idt - that can be done only after paging has been enabled
387 * and the kernel moved to PAGE_OFFSET. Interrupts
388 * are enabled elsewhere, when we can be relatively
389 * sure everything is ok.
390 *
391 * Warning: %esi is live across this function.
392 */
393setup_idt:
394 lea ignore_int,%edx
395 movl $(__KERNEL_CS << 16),%eax
396 movw %dx,%ax /* selector = 0x0010 = cs */
397 movw $0x8E00,%dx /* interrupt gate - dpl=0, present */
398
399 lea idt_table,%edi
400 mov $256,%ecx
401rp_sidt:
402 movl %eax,(%edi)
403 movl %edx,4(%edi)
404 addl $8,%edi
405 dec %ecx
406 jne rp_sidt
407
408.macro set_early_handler handler,trapno
409 lea \handler,%edx
410 movl $(__KERNEL_CS << 16),%eax
411 movw %dx,%ax
412 movw $0x8E00,%dx /* interrupt gate - dpl=0, present */
413 lea idt_table,%edi
414 movl %eax,8*\trapno(%edi)
415 movl %edx,8*\trapno+4(%edi)
416.endm
417
418 set_early_handler handler=early_divide_err,trapno=0
419 set_early_handler handler=early_illegal_opcode,trapno=6
420 set_early_handler handler=early_protection_fault,trapno=13
421 set_early_handler handler=early_page_fault,trapno=14
422
423 ret
424
425early_divide_err:
426 xor %edx,%edx
427 pushl $0 /* fake errcode */
428 jmp early_fault
429
430early_illegal_opcode:
431 movl $6,%edx
432 pushl $0 /* fake errcode */
433 jmp early_fault
434
435early_protection_fault:
436 movl $13,%edx
437 jmp early_fault
438
439early_page_fault:
440 movl $14,%edx
441 jmp early_fault
442
443early_fault:
444 cld
445#ifdef CONFIG_PRINTK
446 movl $(__KERNEL_DS),%eax
447 movl %eax,%ds
448 movl %eax,%es
449 cmpl $2,early_recursion_flag
450 je hlt_loop
451 incl early_recursion_flag
452 movl %cr2,%eax
453 pushl %eax
454 pushl %edx /* trapno */
455 pushl $fault_msg
456#ifdef CONFIG_EARLY_PRINTK
457 call early_printk
458#else
459 call printk
460#endif
461#endif
462hlt_loop:
463 hlt
464 jmp hlt_loop
465
466/* This is the default interrupt "handler" :-) */
467 ALIGN
468ignore_int:
469 cld
470#ifdef CONFIG_PRINTK
471 pushl %eax
472 pushl %ecx
473 pushl %edx
474 pushl %es
475 pushl %ds
476 movl $(__KERNEL_DS),%eax
477 movl %eax,%ds
478 movl %eax,%es
479 cmpl $2,early_recursion_flag
480 je hlt_loop
481 incl early_recursion_flag
482 pushl 16(%esp)
483 pushl 24(%esp)
484 pushl 32(%esp)
485 pushl 40(%esp)
486 pushl $int_msg
487#ifdef CONFIG_EARLY_PRINTK
488 call early_printk
489#else
490 call printk
491#endif
492 addl $(5*4),%esp
493 popl %ds
494 popl %es
495 popl %edx
496 popl %ecx
497 popl %eax
498#endif
499 iret
500
501.section .text
502/*
503 * Real beginning of normal "text" segment
504 */
505ENTRY(stext)
506ENTRY(_stext)
507
508/*
509 * BSS section
510 */
511.section ".bss.page_aligned","wa"
512 .align PAGE_SIZE_asm
513ENTRY(swapper_pg_dir)
514 .fill 1024,4,0
515ENTRY(swapper_pg_pmd)
516 .fill 1024,4,0
517ENTRY(empty_zero_page)
518 .fill 4096,1,0
519
520/*
521 * This starts the data section.
522 */
523.data
524ENTRY(stack_start)
525 .long init_thread_union+THREAD_SIZE
526 .long __BOOT_DS
527
528ready: .byte 0
529
530early_recursion_flag:
531 .long 0
532
533int_msg:
534 .asciz "Unknown interrupt or fault at EIP %p %p %p\n"
535
536fault_msg:
537 .ascii "Int %d: CR2 %p err %p EIP %p CS %p flags %p\n"
538 .asciz "Stack: %p %p %p %p %p %p %p %p\n"
539
540#include "../xen/xen-head.S"
541
542/*
543 * The IDT and GDT 'descriptors' are a strange 48-bit object
544 * only used by the lidt and lgdt instructions. They are not
545 * like usual segment descriptors - they consist of a 16-bit
546 * segment size, and 32-bit linear address value:
547 */
548
549.globl boot_gdt_descr
550.globl idt_descr
551
552 ALIGN
553# early boot GDT descriptor (must use 1:1 address mapping)
554 .word 0 # 32 bit align gdt_desc.address
555boot_gdt_descr:
556 .word __BOOT_DS+7
557 .long boot_gdt - __PAGE_OFFSET
558
559 .word 0 # 32-bit align idt_desc.address
560idt_descr:
561 .word IDT_ENTRIES*8-1 # idt contains 256 entries
562 .long idt_table
563
564# boot GDT descriptor (later on used by CPU#0):
565 .word 0 # 32 bit align gdt_desc.address
566ENTRY(early_gdt_descr)
567 .word GDT_ENTRIES*8-1
568 .long per_cpu__gdt_page /* Overwritten for secondary CPUs */
569
570/*
571 * The boot_gdt must mirror the equivalent in setup.S and is
572 * used only for booting.
573 */
574 .align L1_CACHE_BYTES
575ENTRY(boot_gdt)
576 .fill GDT_ENTRY_BOOT_CS,8,0
577 .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
578 .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
diff --git a/arch/i386/kernel/signal.c b/arch/i386/kernel/signal.c
deleted file mode 100644
index f5dd85656c18..000000000000
--- a/arch/i386/kernel/signal.c
+++ /dev/null
@@ -1,667 +0,0 @@
1/*
2 * linux/arch/i386/kernel/signal.c
3 *
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 *
6 * 1997-11-28 Modified for POSIX.1b signals by Richard Henderson
7 * 2000-06-20 Pentium III FXSR, SSE support by Gareth Hughes
8 */
9
10#include <linux/sched.h>
11#include <linux/mm.h>
12#include <linux/smp.h>
13#include <linux/kernel.h>
14#include <linux/signal.h>
15#include <linux/errno.h>
16#include <linux/wait.h>
17#include <linux/unistd.h>
18#include <linux/stddef.h>
19#include <linux/personality.h>
20#include <linux/suspend.h>
21#include <linux/ptrace.h>
22#include <linux/elf.h>
23#include <linux/binfmts.h>
24#include <asm/processor.h>
25#include <asm/ucontext.h>
26#include <asm/uaccess.h>
27#include <asm/i387.h>
28#include "sigframe.h"
29
30#define DEBUG_SIG 0
31
32#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
33
34/*
35 * Atomically swap in the new signal mask, and wait for a signal.
36 */
37asmlinkage int
38sys_sigsuspend(int history0, int history1, old_sigset_t mask)
39{
40 mask &= _BLOCKABLE;
41 spin_lock_irq(&current->sighand->siglock);
42 current->saved_sigmask = current->blocked;
43 siginitset(&current->blocked, mask);
44 recalc_sigpending();
45 spin_unlock_irq(&current->sighand->siglock);
46
47 current->state = TASK_INTERRUPTIBLE;
48 schedule();
49 set_thread_flag(TIF_RESTORE_SIGMASK);
50 return -ERESTARTNOHAND;
51}
52
53asmlinkage int
54sys_sigaction(int sig, const struct old_sigaction __user *act,
55 struct old_sigaction __user *oact)
56{
57 struct k_sigaction new_ka, old_ka;
58 int ret;
59
60 if (act) {
61 old_sigset_t mask;
62 if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
63 __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
64 __get_user(new_ka.sa.sa_restorer, &act->sa_restorer))
65 return -EFAULT;
66 __get_user(new_ka.sa.sa_flags, &act->sa_flags);
67 __get_user(mask, &act->sa_mask);
68 siginitset(&new_ka.sa.sa_mask, mask);
69 }
70
71 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
72
73 if (!ret && oact) {
74 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
75 __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
76 __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer))
77 return -EFAULT;
78 __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
79 __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
80 }
81
82 return ret;
83}
84
85asmlinkage int
86sys_sigaltstack(unsigned long ebx)
87{
88 /* This is needed to make gcc realize it doesn't own the "struct pt_regs" */
89 struct pt_regs *regs = (struct pt_regs *)&ebx;
90 const stack_t __user *uss = (const stack_t __user *)ebx;
91 stack_t __user *uoss = (stack_t __user *)regs->ecx;
92
93 return do_sigaltstack(uss, uoss, regs->esp);
94}
95
96
97/*
98 * Do a signal return; undo the signal stack.
99 */
100
101static int
102restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc, int *peax)
103{
104 unsigned int err = 0;
105
106 /* Always make any pending restarted system calls return -EINTR */
107 current_thread_info()->restart_block.fn = do_no_restart_syscall;
108
109#define COPY(x) err |= __get_user(regs->x, &sc->x)
110
111#define COPY_SEG(seg) \
112 { unsigned short tmp; \
113 err |= __get_user(tmp, &sc->seg); \
114 regs->x##seg = tmp; }
115
116#define COPY_SEG_STRICT(seg) \
117 { unsigned short tmp; \
118 err |= __get_user(tmp, &sc->seg); \
119 regs->x##seg = tmp|3; }
120
121#define GET_SEG(seg) \
122 { unsigned short tmp; \
123 err |= __get_user(tmp, &sc->seg); \
124 loadsegment(seg,tmp); }
125
126#define FIX_EFLAGS (X86_EFLAGS_AC | X86_EFLAGS_RF | \
127 X86_EFLAGS_OF | X86_EFLAGS_DF | \
128 X86_EFLAGS_TF | X86_EFLAGS_SF | X86_EFLAGS_ZF | \
129 X86_EFLAGS_AF | X86_EFLAGS_PF | X86_EFLAGS_CF)
130
131 GET_SEG(gs);
132 COPY_SEG(fs);
133 COPY_SEG(es);
134 COPY_SEG(ds);
135 COPY(edi);
136 COPY(esi);
137 COPY(ebp);
138 COPY(esp);
139 COPY(ebx);
140 COPY(edx);
141 COPY(ecx);
142 COPY(eip);
143 COPY_SEG_STRICT(cs);
144 COPY_SEG_STRICT(ss);
145
146 {
147 unsigned int tmpflags;
148 err |= __get_user(tmpflags, &sc->eflags);
149 regs->eflags = (regs->eflags & ~FIX_EFLAGS) | (tmpflags & FIX_EFLAGS);
150 regs->orig_eax = -1; /* disable syscall checks */
151 }
152
153 {
154 struct _fpstate __user * buf;
155 err |= __get_user(buf, &sc->fpstate);
156 if (buf) {
157 if (!access_ok(VERIFY_READ, buf, sizeof(*buf)))
158 goto badframe;
159 err |= restore_i387(buf);
160 } else {
161 struct task_struct *me = current;
162 if (used_math()) {
163 clear_fpu(me);
164 clear_used_math();
165 }
166 }
167 }
168
169 err |= __get_user(*peax, &sc->eax);
170 return err;
171
172badframe:
173 return 1;
174}
175
176asmlinkage int sys_sigreturn(unsigned long __unused)
177{
178 struct pt_regs *regs = (struct pt_regs *) &__unused;
179 struct sigframe __user *frame = (struct sigframe __user *)(regs->esp - 8);
180 sigset_t set;
181 int eax;
182
183 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
184 goto badframe;
185 if (__get_user(set.sig[0], &frame->sc.oldmask)
186 || (_NSIG_WORDS > 1
187 && __copy_from_user(&set.sig[1], &frame->extramask,
188 sizeof(frame->extramask))))
189 goto badframe;
190
191 sigdelsetmask(&set, ~_BLOCKABLE);
192 spin_lock_irq(&current->sighand->siglock);
193 current->blocked = set;
194 recalc_sigpending();
195 spin_unlock_irq(&current->sighand->siglock);
196
197 if (restore_sigcontext(regs, &frame->sc, &eax))
198 goto badframe;
199 return eax;
200
201badframe:
202 if (show_unhandled_signals && printk_ratelimit())
203 printk("%s%s[%d] bad frame in sigreturn frame:%p eip:%lx"
204 " esp:%lx oeax:%lx\n",
205 current->pid > 1 ? KERN_INFO : KERN_EMERG,
206 current->comm, current->pid, frame, regs->eip,
207 regs->esp, regs->orig_eax);
208
209 force_sig(SIGSEGV, current);
210 return 0;
211}
212
213asmlinkage int sys_rt_sigreturn(unsigned long __unused)
214{
215 struct pt_regs *regs = (struct pt_regs *) &__unused;
216 struct rt_sigframe __user *frame = (struct rt_sigframe __user *)(regs->esp - 4);
217 sigset_t set;
218 int eax;
219
220 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
221 goto badframe;
222 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
223 goto badframe;
224
225 sigdelsetmask(&set, ~_BLOCKABLE);
226 spin_lock_irq(&current->sighand->siglock);
227 current->blocked = set;
228 recalc_sigpending();
229 spin_unlock_irq(&current->sighand->siglock);
230
231 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &eax))
232 goto badframe;
233
234 if (do_sigaltstack(&frame->uc.uc_stack, NULL, regs->esp) == -EFAULT)
235 goto badframe;
236
237 return eax;
238
239badframe:
240 force_sig(SIGSEGV, current);
241 return 0;
242}
243
244/*
245 * Set up a signal frame.
246 */
247
248static int
249setup_sigcontext(struct sigcontext __user *sc, struct _fpstate __user *fpstate,
250 struct pt_regs *regs, unsigned long mask)
251{
252 int tmp, err = 0;
253
254 err |= __put_user(regs->xfs, (unsigned int __user *)&sc->fs);
255 savesegment(gs, tmp);
256 err |= __put_user(tmp, (unsigned int __user *)&sc->gs);
257
258 err |= __put_user(regs->xes, (unsigned int __user *)&sc->es);
259 err |= __put_user(regs->xds, (unsigned int __user *)&sc->ds);
260 err |= __put_user(regs->edi, &sc->edi);
261 err |= __put_user(regs->esi, &sc->esi);
262 err |= __put_user(regs->ebp, &sc->ebp);
263 err |= __put_user(regs->esp, &sc->esp);
264 err |= __put_user(regs->ebx, &sc->ebx);
265 err |= __put_user(regs->edx, &sc->edx);
266 err |= __put_user(regs->ecx, &sc->ecx);
267 err |= __put_user(regs->eax, &sc->eax);
268 err |= __put_user(current->thread.trap_no, &sc->trapno);
269 err |= __put_user(current->thread.error_code, &sc->err);
270 err |= __put_user(regs->eip, &sc->eip);
271 err |= __put_user(regs->xcs, (unsigned int __user *)&sc->cs);
272 err |= __put_user(regs->eflags, &sc->eflags);
273 err |= __put_user(regs->esp, &sc->esp_at_signal);
274 err |= __put_user(regs->xss, (unsigned int __user *)&sc->ss);
275
276 tmp = save_i387(fpstate);
277 if (tmp < 0)
278 err = 1;
279 else
280 err |= __put_user(tmp ? fpstate : NULL, &sc->fpstate);
281
282 /* non-iBCS2 extensions.. */
283 err |= __put_user(mask, &sc->oldmask);
284 err |= __put_user(current->thread.cr2, &sc->cr2);
285
286 return err;
287}
288
289/*
290 * Determine which stack to use..
291 */
292static inline void __user *
293get_sigframe(struct k_sigaction *ka, struct pt_regs * regs, size_t frame_size)
294{
295 unsigned long esp;
296
297 /* Default to using normal stack */
298 esp = regs->esp;
299
300 /* This is the X/Open sanctioned signal stack switching. */
301 if (ka->sa.sa_flags & SA_ONSTACK) {
302 if (sas_ss_flags(esp) == 0)
303 esp = current->sas_ss_sp + current->sas_ss_size;
304 }
305
306 /* This is the legacy signal stack switching. */
307 else if ((regs->xss & 0xffff) != __USER_DS &&
308 !(ka->sa.sa_flags & SA_RESTORER) &&
309 ka->sa.sa_restorer) {
310 esp = (unsigned long) ka->sa.sa_restorer;
311 }
312
313 esp -= frame_size;
314 /* Align the stack pointer according to the i386 ABI,
315 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
316 esp = ((esp + 4) & -16ul) - 4;
317 return (void __user *) esp;
318}
319
320/* These symbols are defined with the addresses in the vsyscall page.
321 See vsyscall-sigreturn.S. */
322extern void __user __kernel_sigreturn;
323extern void __user __kernel_rt_sigreturn;
324
325static int setup_frame(int sig, struct k_sigaction *ka,
326 sigset_t *set, struct pt_regs * regs)
327{
328 void __user *restorer;
329 struct sigframe __user *frame;
330 int err = 0;
331 int usig;
332
333 frame = get_sigframe(ka, regs, sizeof(*frame));
334
335 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
336 goto give_sigsegv;
337
338 usig = current_thread_info()->exec_domain
339 && current_thread_info()->exec_domain->signal_invmap
340 && sig < 32
341 ? current_thread_info()->exec_domain->signal_invmap[sig]
342 : sig;
343
344 err = __put_user(usig, &frame->sig);
345 if (err)
346 goto give_sigsegv;
347
348 err = setup_sigcontext(&frame->sc, &frame->fpstate, regs, set->sig[0]);
349 if (err)
350 goto give_sigsegv;
351
352 if (_NSIG_WORDS > 1) {
353 err = __copy_to_user(&frame->extramask, &set->sig[1],
354 sizeof(frame->extramask));
355 if (err)
356 goto give_sigsegv;
357 }
358
359 if (current->binfmt->hasvdso)
360 restorer = (void *)VDSO_SYM(&__kernel_sigreturn);
361 else
362 restorer = (void *)&frame->retcode;
363 if (ka->sa.sa_flags & SA_RESTORER)
364 restorer = ka->sa.sa_restorer;
365
366 /* Set up to return from userspace. */
367 err |= __put_user(restorer, &frame->pretcode);
368
369 /*
370 * This is popl %eax ; movl $,%eax ; int $0x80
371 *
372 * WE DO NOT USE IT ANY MORE! It's only left here for historical
373 * reasons and because gdb uses it as a signature to notice
374 * signal handler stack frames.
375 */
376 err |= __put_user(0xb858, (short __user *)(frame->retcode+0));
377 err |= __put_user(__NR_sigreturn, (int __user *)(frame->retcode+2));
378 err |= __put_user(0x80cd, (short __user *)(frame->retcode+6));
379
380 if (err)
381 goto give_sigsegv;
382
383 /* Set up registers for signal handler */
384 regs->esp = (unsigned long) frame;
385 regs->eip = (unsigned long) ka->sa.sa_handler;
386 regs->eax = (unsigned long) sig;
387 regs->edx = (unsigned long) 0;
388 regs->ecx = (unsigned long) 0;
389
390 set_fs(USER_DS);
391 regs->xds = __USER_DS;
392 regs->xes = __USER_DS;
393 regs->xss = __USER_DS;
394 regs->xcs = __USER_CS;
395
396 /*
397 * Clear TF when entering the signal handler, but
398 * notify any tracer that was single-stepping it.
399 * The tracer may want to single-step inside the
400 * handler too.
401 */
402 regs->eflags &= ~TF_MASK;
403 if (test_thread_flag(TIF_SINGLESTEP))
404 ptrace_notify(SIGTRAP);
405
406#if DEBUG_SIG
407 printk("SIG deliver (%s:%d): sp=%p pc=%p ra=%p\n",
408 current->comm, current->pid, frame, regs->eip, frame->pretcode);
409#endif
410
411 return 0;
412
413give_sigsegv:
414 force_sigsegv(sig, current);
415 return -EFAULT;
416}
417
418static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
419 sigset_t *set, struct pt_regs * regs)
420{
421 void __user *restorer;
422 struct rt_sigframe __user *frame;
423 int err = 0;
424 int usig;
425
426 frame = get_sigframe(ka, regs, sizeof(*frame));
427
428 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
429 goto give_sigsegv;
430
431 usig = current_thread_info()->exec_domain
432 && current_thread_info()->exec_domain->signal_invmap
433 && sig < 32
434 ? current_thread_info()->exec_domain->signal_invmap[sig]
435 : sig;
436
437 err |= __put_user(usig, &frame->sig);
438 err |= __put_user(&frame->info, &frame->pinfo);
439 err |= __put_user(&frame->uc, &frame->puc);
440 err |= copy_siginfo_to_user(&frame->info, info);
441 if (err)
442 goto give_sigsegv;
443
444 /* Create the ucontext. */
445 err |= __put_user(0, &frame->uc.uc_flags);
446 err |= __put_user(0, &frame->uc.uc_link);
447 err |= __put_user(current->sas_ss_sp, &frame->uc.uc_stack.ss_sp);
448 err |= __put_user(sas_ss_flags(regs->esp),
449 &frame->uc.uc_stack.ss_flags);
450 err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
451 err |= setup_sigcontext(&frame->uc.uc_mcontext, &frame->fpstate,
452 regs, set->sig[0]);
453 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
454 if (err)
455 goto give_sigsegv;
456
457 /* Set up to return from userspace. */
458 restorer = (void *)VDSO_SYM(&__kernel_rt_sigreturn);
459 if (ka->sa.sa_flags & SA_RESTORER)
460 restorer = ka->sa.sa_restorer;
461 err |= __put_user(restorer, &frame->pretcode);
462
463 /*
464 * This is movl $,%eax ; int $0x80
465 *
466 * WE DO NOT USE IT ANY MORE! It's only left here for historical
467 * reasons and because gdb uses it as a signature to notice
468 * signal handler stack frames.
469 */
470 err |= __put_user(0xb8, (char __user *)(frame->retcode+0));
471 err |= __put_user(__NR_rt_sigreturn, (int __user *)(frame->retcode+1));
472 err |= __put_user(0x80cd, (short __user *)(frame->retcode+5));
473
474 if (err)
475 goto give_sigsegv;
476
477 /* Set up registers for signal handler */
478 regs->esp = (unsigned long) frame;
479 regs->eip = (unsigned long) ka->sa.sa_handler;
480 regs->eax = (unsigned long) usig;
481 regs->edx = (unsigned long) &frame->info;
482 regs->ecx = (unsigned long) &frame->uc;
483
484 set_fs(USER_DS);
485 regs->xds = __USER_DS;
486 regs->xes = __USER_DS;
487 regs->xss = __USER_DS;
488 regs->xcs = __USER_CS;
489
490 /*
491 * Clear TF when entering the signal handler, but
492 * notify any tracer that was single-stepping it.
493 * The tracer may want to single-step inside the
494 * handler too.
495 */
496 regs->eflags &= ~TF_MASK;
497 if (test_thread_flag(TIF_SINGLESTEP))
498 ptrace_notify(SIGTRAP);
499
500#if DEBUG_SIG
501 printk("SIG deliver (%s:%d): sp=%p pc=%p ra=%p\n",
502 current->comm, current->pid, frame, regs->eip, frame->pretcode);
503#endif
504
505 return 0;
506
507give_sigsegv:
508 force_sigsegv(sig, current);
509 return -EFAULT;
510}
511
512/*
513 * OK, we're invoking a handler
514 */
515
516static int
517handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
518 sigset_t *oldset, struct pt_regs * regs)
519{
520 int ret;
521
522 /* Are we from a system call? */
523 if (regs->orig_eax >= 0) {
524 /* If so, check system call restarting.. */
525 switch (regs->eax) {
526 case -ERESTART_RESTARTBLOCK:
527 case -ERESTARTNOHAND:
528 regs->eax = -EINTR;
529 break;
530
531 case -ERESTARTSYS:
532 if (!(ka->sa.sa_flags & SA_RESTART)) {
533 regs->eax = -EINTR;
534 break;
535 }
536 /* fallthrough */
537 case -ERESTARTNOINTR:
538 regs->eax = regs->orig_eax;
539 regs->eip -= 2;
540 }
541 }
542
543 /*
544 * If TF is set due to a debugger (PT_DTRACE), clear the TF flag so
545 * that register information in the sigcontext is correct.
546 */
547 if (unlikely(regs->eflags & TF_MASK)
548 && likely(current->ptrace & PT_DTRACE)) {
549 current->ptrace &= ~PT_DTRACE;
550 regs->eflags &= ~TF_MASK;
551 }
552
553 /* Set up the stack frame */
554 if (ka->sa.sa_flags & SA_SIGINFO)
555 ret = setup_rt_frame(sig, ka, info, oldset, regs);
556 else
557 ret = setup_frame(sig, ka, oldset, regs);
558
559 if (ret == 0) {
560 spin_lock_irq(&current->sighand->siglock);
561 sigorsets(&current->blocked,&current->blocked,&ka->sa.sa_mask);
562 if (!(ka->sa.sa_flags & SA_NODEFER))
563 sigaddset(&current->blocked,sig);
564 recalc_sigpending();
565 spin_unlock_irq(&current->sighand->siglock);
566 }
567
568 return ret;
569}
570
571/*
572 * Note that 'init' is a special process: it doesn't get signals it doesn't
573 * want to handle. Thus you cannot kill init even with a SIGKILL even by
574 * mistake.
575 */
576static void fastcall do_signal(struct pt_regs *regs)
577{
578 siginfo_t info;
579 int signr;
580 struct k_sigaction ka;
581 sigset_t *oldset;
582
583 /*
584 * We want the common case to go fast, which
585 * is why we may in certain cases get here from
586 * kernel mode. Just return without doing anything
587 * if so. vm86 regs switched out by assembly code
588 * before reaching here, so testing against kernel
589 * CS suffices.
590 */
591 if (!user_mode(regs))
592 return;
593
594 if (test_thread_flag(TIF_RESTORE_SIGMASK))
595 oldset = &current->saved_sigmask;
596 else
597 oldset = &current->blocked;
598
599 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
600 if (signr > 0) {
601 /* Reenable any watchpoints before delivering the
602 * signal to user space. The processor register will
603 * have been cleared if the watchpoint triggered
604 * inside the kernel.
605 */
606 if (unlikely(current->thread.debugreg[7]))
607 set_debugreg(current->thread.debugreg[7], 7);
608
609 /* Whee! Actually deliver the signal. */
610 if (handle_signal(signr, &info, &ka, oldset, regs) == 0) {
611 /* a signal was successfully delivered; the saved
612 * sigmask will have been stored in the signal frame,
613 * and will be restored by sigreturn, so we can simply
614 * clear the TIF_RESTORE_SIGMASK flag */
615 if (test_thread_flag(TIF_RESTORE_SIGMASK))
616 clear_thread_flag(TIF_RESTORE_SIGMASK);
617 }
618
619 return;
620 }
621
622 /* Did we come from a system call? */
623 if (regs->orig_eax >= 0) {
624 /* Restart the system call - no handlers present */
625 switch (regs->eax) {
626 case -ERESTARTNOHAND:
627 case -ERESTARTSYS:
628 case -ERESTARTNOINTR:
629 regs->eax = regs->orig_eax;
630 regs->eip -= 2;
631 break;
632
633 case -ERESTART_RESTARTBLOCK:
634 regs->eax = __NR_restart_syscall;
635 regs->eip -= 2;
636 break;
637 }
638 }
639
640 /* if there's no signal to deliver, we just put the saved sigmask
641 * back */
642 if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
643 clear_thread_flag(TIF_RESTORE_SIGMASK);
644 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
645 }
646}
647
648/*
649 * notification of userspace execution resumption
650 * - triggered by the TIF_WORK_MASK flags
651 */
652__attribute__((regparm(3)))
653void do_notify_resume(struct pt_regs *regs, void *_unused,
654 __u32 thread_info_flags)
655{
656 /* Pending single-step? */
657 if (thread_info_flags & _TIF_SINGLESTEP) {
658 regs->eflags |= TF_MASK;
659 clear_thread_flag(TIF_SINGLESTEP);
660 }
661
662 /* deal with pending signal delivery */
663 if (thread_info_flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK))
664 do_signal(regs);
665
666 clear_thread_flag(TIF_IRET);
667}
diff --git a/arch/i386/kernel/tsc_sync.c b/arch/i386/kernel/tsc_sync.c
deleted file mode 100644
index 12424629af87..000000000000
--- a/arch/i386/kernel/tsc_sync.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../x86_64/kernel/tsc_sync.c"
diff --git a/arch/i386/kernel/vsyscall-int80.S b/arch/i386/kernel/vsyscall-int80.S
deleted file mode 100644
index 530d0525e5e2..000000000000
--- a/arch/i386/kernel/vsyscall-int80.S
+++ /dev/null
@@ -1,53 +0,0 @@
1/*
2 * Code for the vsyscall page. This version uses the old int $0x80 method.
3 *
4 * NOTE:
5 * 1) __kernel_vsyscall _must_ be first in this page.
6 * 2) there are alignment constraints on this stub, see vsyscall-sigreturn.S
7 * for details.
8 */
9
10 .text
11 .globl __kernel_vsyscall
12 .type __kernel_vsyscall,@function
13__kernel_vsyscall:
14.LSTART_vsyscall:
15 int $0x80
16 ret
17.LEND_vsyscall:
18 .size __kernel_vsyscall,.-.LSTART_vsyscall
19 .previous
20
21 .section .eh_frame,"a",@progbits
22.LSTARTFRAMEDLSI:
23 .long .LENDCIEDLSI-.LSTARTCIEDLSI
24.LSTARTCIEDLSI:
25 .long 0 /* CIE ID */
26 .byte 1 /* Version number */
27 .string "zR" /* NUL-terminated augmentation string */
28 .uleb128 1 /* Code alignment factor */
29 .sleb128 -4 /* Data alignment factor */
30 .byte 8 /* Return address register column */
31 .uleb128 1 /* Augmentation value length */
32 .byte 0x1b /* DW_EH_PE_pcrel|DW_EH_PE_sdata4. */
33 .byte 0x0c /* DW_CFA_def_cfa */
34 .uleb128 4
35 .uleb128 4
36 .byte 0x88 /* DW_CFA_offset, column 0x8 */
37 .uleb128 1
38 .align 4
39.LENDCIEDLSI:
40 .long .LENDFDEDLSI-.LSTARTFDEDLSI /* Length FDE */
41.LSTARTFDEDLSI:
42 .long .LSTARTFDEDLSI-.LSTARTFRAMEDLSI /* CIE pointer */
43 .long .LSTART_vsyscall-. /* PC-relative start address */
44 .long .LEND_vsyscall-.LSTART_vsyscall
45 .uleb128 0
46 .align 4
47.LENDFDEDLSI:
48 .previous
49
50/*
51 * Get the common code for the sigreturn entry points.
52 */
53#include "vsyscall-sigreturn.S"
diff --git a/arch/i386/kernel/vsyscall-note.S b/arch/i386/kernel/vsyscall-note.S
deleted file mode 100644
index 07c0daf78237..000000000000
--- a/arch/i386/kernel/vsyscall-note.S
+++ /dev/null
@@ -1,45 +0,0 @@
1/*
2 * This supplies .note.* sections to go into the PT_NOTE inside the vDSO text.
3 * Here we can supply some information useful to userland.
4 */
5
6#include <linux/version.h>
7#include <linux/elfnote.h>
8
9/* Ideally this would use UTS_NAME, but using a quoted string here
10 doesn't work. Remember to change this when changing the
11 kernel's name. */
12ELFNOTE_START(Linux, 0, "a")
13 .long LINUX_VERSION_CODE
14ELFNOTE_END
15
16#ifdef CONFIG_XEN
17/*
18 * Add a special note telling glibc's dynamic linker a fake hardware
19 * flavor that it will use to choose the search path for libraries in the
20 * same way it uses real hardware capabilities like "mmx".
21 * We supply "nosegneg" as the fake capability, to indicate that we
22 * do not like negative offsets in instructions using segment overrides,
23 * since we implement those inefficiently. This makes it possible to
24 * install libraries optimized to avoid those access patterns in someplace
25 * like /lib/i686/tls/nosegneg. Note that an /etc/ld.so.conf.d/file
26 * corresponding to the bits here is needed to make ldconfig work right.
27 * It should contain:
28 * hwcap 1 nosegneg
29 * to match the mapping of bit to name that we give here.
30 *
31 * At runtime, the fake hardware feature will be considered to be present
32 * if its bit is set in the mask word. So, we start with the mask 0, and
33 * at boot time we set VDSO_NOTE_NONEGSEG_BIT if running under Xen.
34 */
35
36#include "../xen/vdso.h" /* Defines VDSO_NOTE_NONEGSEG_BIT. */
37
38 .globl VDSO_NOTE_MASK
39ELFNOTE_START(GNU, 2, "a")
40 .long 1 /* ncaps */
41VDSO_NOTE_MASK:
42 .long 0 /* mask */
43 .byte VDSO_NOTE_NONEGSEG_BIT; .asciz "nosegneg" /* bit, name */
44ELFNOTE_END
45#endif
diff --git a/arch/i386/kernel/vsyscall-sysenter.S b/arch/i386/kernel/vsyscall-sysenter.S
deleted file mode 100644
index 1a36d26e15eb..000000000000
--- a/arch/i386/kernel/vsyscall-sysenter.S
+++ /dev/null
@@ -1,122 +0,0 @@
1/*
2 * Code for the vsyscall page. This version uses the sysenter instruction.
3 *
4 * NOTE:
5 * 1) __kernel_vsyscall _must_ be first in this page.
6 * 2) there are alignment constraints on this stub, see vsyscall-sigreturn.S
7 * for details.
8 */
9
10/*
11 * The caller puts arg2 in %ecx, which gets pushed. The kernel will use
12 * %ecx itself for arg2. The pushing is because the sysexit instruction
13 * (found in entry.S) requires that we clobber %ecx with the desired %esp.
14 * User code might expect that %ecx is unclobbered though, as it would be
15 * for returning via the iret instruction, so we must push and pop.
16 *
17 * The caller puts arg3 in %edx, which the sysexit instruction requires
18 * for %eip. Thus, exactly as for arg2, we must push and pop.
19 *
20 * Arg6 is different. The caller puts arg6 in %ebp. Since the sysenter
21 * instruction clobbers %esp, the user's %esp won't even survive entry
22 * into the kernel. We store %esp in %ebp. Code in entry.S must fetch
23 * arg6 from the stack.
24 *
25 * You can not use this vsyscall for the clone() syscall because the
26 * three dwords on the parent stack do not get copied to the child.
27 */
28 .text
29 .globl __kernel_vsyscall
30 .type __kernel_vsyscall,@function
31__kernel_vsyscall:
32.LSTART_vsyscall:
33 push %ecx
34.Lpush_ecx:
35 push %edx
36.Lpush_edx:
37 push %ebp
38.Lenter_kernel:
39 movl %esp,%ebp
40 sysenter
41
42 /* 7: align return point with nop's to make disassembly easier */
43 .space 7,0x90
44
45 /* 14: System call restart point is here! (SYSENTER_RETURN-2) */
46 jmp .Lenter_kernel
47 /* 16: System call normal return point is here! */
48 .globl SYSENTER_RETURN /* Symbol used by sysenter.c */
49SYSENTER_RETURN:
50 pop %ebp
51.Lpop_ebp:
52 pop %edx
53.Lpop_edx:
54 pop %ecx
55.Lpop_ecx:
56 ret
57.LEND_vsyscall:
58 .size __kernel_vsyscall,.-.LSTART_vsyscall
59 .previous
60
61 .section .eh_frame,"a",@progbits
62.LSTARTFRAMEDLSI:
63 .long .LENDCIEDLSI-.LSTARTCIEDLSI
64.LSTARTCIEDLSI:
65 .long 0 /* CIE ID */
66 .byte 1 /* Version number */
67 .string "zR" /* NUL-terminated augmentation string */
68 .uleb128 1 /* Code alignment factor */
69 .sleb128 -4 /* Data alignment factor */
70 .byte 8 /* Return address register column */
71 .uleb128 1 /* Augmentation value length */
72 .byte 0x1b /* DW_EH_PE_pcrel|DW_EH_PE_sdata4. */
73 .byte 0x0c /* DW_CFA_def_cfa */
74 .uleb128 4
75 .uleb128 4
76 .byte 0x88 /* DW_CFA_offset, column 0x8 */
77 .uleb128 1
78 .align 4
79.LENDCIEDLSI:
80 .long .LENDFDEDLSI-.LSTARTFDEDLSI /* Length FDE */
81.LSTARTFDEDLSI:
82 .long .LSTARTFDEDLSI-.LSTARTFRAMEDLSI /* CIE pointer */
83 .long .LSTART_vsyscall-. /* PC-relative start address */
84 .long .LEND_vsyscall-.LSTART_vsyscall
85 .uleb128 0
86 /* What follows are the instructions for the table generation.
87 We have to record all changes of the stack pointer. */
88 .byte 0x04 /* DW_CFA_advance_loc4 */
89 .long .Lpush_ecx-.LSTART_vsyscall
90 .byte 0x0e /* DW_CFA_def_cfa_offset */
91 .byte 0x08 /* RA at offset 8 now */
92 .byte 0x04 /* DW_CFA_advance_loc4 */
93 .long .Lpush_edx-.Lpush_ecx
94 .byte 0x0e /* DW_CFA_def_cfa_offset */
95 .byte 0x0c /* RA at offset 12 now */
96 .byte 0x04 /* DW_CFA_advance_loc4 */
97 .long .Lenter_kernel-.Lpush_edx
98 .byte 0x0e /* DW_CFA_def_cfa_offset */
99 .byte 0x10 /* RA at offset 16 now */
100 .byte 0x85, 0x04 /* DW_CFA_offset %ebp -16 */
101 /* Finally the epilogue. */
102 .byte 0x04 /* DW_CFA_advance_loc4 */
103 .long .Lpop_ebp-.Lenter_kernel
104 .byte 0x0e /* DW_CFA_def_cfa_offset */
105 .byte 0x0c /* RA at offset 12 now */
106 .byte 0xc5 /* DW_CFA_restore %ebp */
107 .byte 0x04 /* DW_CFA_advance_loc4 */
108 .long .Lpop_edx-.Lpop_ebp
109 .byte 0x0e /* DW_CFA_def_cfa_offset */
110 .byte 0x08 /* RA at offset 8 now */
111 .byte 0x04 /* DW_CFA_advance_loc4 */
112 .long .Lpop_ecx-.Lpop_edx
113 .byte 0x0e /* DW_CFA_def_cfa_offset */
114 .byte 0x04 /* RA at offset 4 now */
115 .align 4
116.LENDFDEDLSI:
117 .previous
118
119/*
120 * Get the common code for the sigreturn entry points.
121 */
122#include "vsyscall-sigreturn.S"
diff --git a/arch/i386/kernel/vsyscall.S b/arch/i386/kernel/vsyscall.S
deleted file mode 100644
index b403890fe39b..000000000000
--- a/arch/i386/kernel/vsyscall.S
+++ /dev/null
@@ -1,15 +0,0 @@
1#include <linux/init.h>
2
3__INITDATA
4
5 .globl vsyscall_int80_start, vsyscall_int80_end
6vsyscall_int80_start:
7 .incbin "arch/i386/kernel/vsyscall-int80.so"
8vsyscall_int80_end:
9
10 .globl vsyscall_sysenter_start, vsyscall_sysenter_end
11vsyscall_sysenter_start:
12 .incbin "arch/i386/kernel/vsyscall-sysenter.so"
13vsyscall_sysenter_end:
14
15__FINIT
diff --git a/arch/i386/lib/Makefile b/arch/i386/lib/Makefile
deleted file mode 100644
index 4d105fdfe817..000000000000
--- a/arch/i386/lib/Makefile
+++ /dev/null
@@ -1,11 +0,0 @@
1#
2# Makefile for i386-specific library files..
3#
4
5
6lib-y = checksum.o delay.o usercopy.o getuser.o putuser.o memcpy.o strstr.o \
7 bitops.o semaphore.o string.o
8
9lib-$(CONFIG_X86_USE_3DNOW) += mmx.o
10
11obj-$(CONFIG_SMP) += msr-on-cpu.o
diff --git a/arch/i386/mach-generic/Makefile b/arch/i386/mach-generic/Makefile
deleted file mode 100644
index 6914485c0d85..000000000000
--- a/arch/i386/mach-generic/Makefile
+++ /dev/null
@@ -1,7 +0,0 @@
1#
2# Makefile for the generic architecture
3#
4
5EXTRA_CFLAGS := -Iarch/i386/kernel
6
7obj-y := probe.o summit.o bigsmp.o es7000.o default.o ../mach-es7000/
diff --git a/arch/i386/mach-voyager/Makefile b/arch/i386/mach-voyager/Makefile
deleted file mode 100644
index 33b74cf0dd22..000000000000
--- a/arch/i386/mach-voyager/Makefile
+++ /dev/null
@@ -1,8 +0,0 @@
1#
2# Makefile for the linux kernel.
3#
4
5EXTRA_CFLAGS := -Iarch/i386/kernel
6obj-y := setup.o voyager_basic.o voyager_thread.o
7
8obj-$(CONFIG_SMP) += voyager_smp.o voyager_cat.o
diff --git a/arch/i386/mm/Makefile b/arch/i386/mm/Makefile
deleted file mode 100644
index 80908b5aa60f..000000000000
--- a/arch/i386/mm/Makefile
+++ /dev/null
@@ -1,10 +0,0 @@
1#
2# Makefile for the linux i386-specific parts of the memory manager.
3#
4
5obj-y := init.o pgtable.o fault.o ioremap.o extable.o pageattr.o mmap.o
6
7obj-$(CONFIG_NUMA) += discontig.o
8obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o
9obj-$(CONFIG_HIGHMEM) += highmem.o
10obj-$(CONFIG_BOOT_IOREMAP) += boot_ioremap.o
diff --git a/arch/i386/pci/Makefile b/arch/i386/pci/Makefile
deleted file mode 100644
index 44650e03308b..000000000000
--- a/arch/i386/pci/Makefile
+++ /dev/null
@@ -1,14 +0,0 @@
1obj-y := i386.o init.o
2
3obj-$(CONFIG_PCI_BIOS) += pcbios.o
4obj-$(CONFIG_PCI_MMCONFIG) += mmconfig.o direct.o mmconfig-shared.o
5obj-$(CONFIG_PCI_DIRECT) += direct.o
6
7pci-y := fixup.o
8pci-$(CONFIG_ACPI) += acpi.o
9pci-y += legacy.o irq.o
10
11pci-$(CONFIG_X86_VISWS) := visws.o fixup.o
12pci-$(CONFIG_X86_NUMAQ) := numa.o irq.o
13
14obj-y += $(pci-y) common.o early.o
diff --git a/arch/ia64/ia32/audit.c b/arch/ia64/ia32/audit.c
index 8850fe40ea34..5e901c75df1b 100644
--- a/arch/ia64/ia32/audit.c
+++ b/arch/ia64/ia32/audit.c
@@ -1,4 +1,4 @@
1#include <asm-i386/unistd.h> 1#include <asm-x86/unistd_32.h>
2 2
3unsigned ia32_dir_class[] = { 3unsigned ia32_dir_class[] = {
4#include <asm-generic/audit_dir_write.h> 4#include <asm-generic/audit_dir_write.h>
diff --git a/arch/um/sys-i386/sys_call_table.S b/arch/um/sys-i386/sys_call_table.S
index 2497554b7b95..12d4148dba39 100644
--- a/arch/um/sys-i386/sys_call_table.S
+++ b/arch/um/sys-i386/sys_call_table.S
@@ -9,4 +9,4 @@
9 9
10#define old_mmap old_mmap_i386 10#define old_mmap old_mmap_i386
11 11
12#include "../../i386/kernel/syscall_table.S" 12#include "../../x86/kernel/syscall_table_32.S"
diff --git a/arch/um/sys-x86_64/syscall_table.c b/arch/um/sys-x86_64/syscall_table.c
index 5133988d3610..71b2ae4ad5de 100644
--- a/arch/um/sys-x86_64/syscall_table.c
+++ b/arch/um/sys-x86_64/syscall_table.c
@@ -36,7 +36,7 @@
36 36
37#define __SYSCALL(nr, sym) extern asmlinkage void sym(void) ; 37#define __SYSCALL(nr, sym) extern asmlinkage void sym(void) ;
38#undef _ASM_X86_64_UNISTD_H_ 38#undef _ASM_X86_64_UNISTD_H_
39#include <asm-x86_64/unistd.h> 39#include <asm-x86/unistd_64.h>
40 40
41#undef __SYSCALL 41#undef __SYSCALL
42#define __SYSCALL(nr, sym) [ nr ] = sym, 42#define __SYSCALL(nr, sym) [ nr ] = sym,
@@ -49,5 +49,5 @@ extern void sys_ni_syscall(void);
49sys_call_ptr_t sys_call_table[UM_NR_syscall_max+1] __cacheline_aligned = { 49sys_call_ptr_t sys_call_table[UM_NR_syscall_max+1] __cacheline_aligned = {
50 /* Smells like a like a compiler bug -- it doesn't work when the & below is removed. */ 50 /* Smells like a like a compiler bug -- it doesn't work when the & below is removed. */
51 [0 ... UM_NR_syscall_max] = &sys_ni_syscall, 51 [0 ... UM_NR_syscall_max] = &sys_ni_syscall,
52#include <asm-x86_64/unistd.h> 52#include <asm-x86/unistd_64.h>
53}; 53};
diff --git a/arch/i386/boot/.gitignore b/arch/x86/boot/.gitignore
index 18465143cfa2..18465143cfa2 100644
--- a/arch/i386/boot/.gitignore
+++ b/arch/x86/boot/.gitignore
diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
new file mode 100644
index 000000000000..cb1035f2b7e9
--- /dev/null
+++ b/arch/x86/boot/Makefile
@@ -0,0 +1,171 @@
1#
2# arch/x86/boot/Makefile
3#
4# This file is subject to the terms and conditions of the GNU General Public
5# License. See the file "COPYING" in the main directory of this archive
6# for more details.
7#
8# Copyright (C) 1994 by Linus Torvalds
9#
10
11# ROOT_DEV specifies the default root-device when making the image.
12# This can be either FLOPPY, CURRENT, /dev/xxxx or empty, in which case
13# the default of FLOPPY is used by 'build'.
14
15ROOT_DEV := CURRENT
16
17# If you want to preset the SVGA mode, uncomment the next line and
18# set SVGA_MODE to whatever number you want.
19# Set it to -DSVGA_MODE=NORMAL_VGA if you just want the EGA/VGA mode.
20# The number is the same as you would ordinarily press at bootup.
21
22SVGA_MODE := -DSVGA_MODE=NORMAL_VGA
23
24# If you want the RAM disk device, define this to be the size in blocks.
25
26#RAMDISK := -DRAMDISK=512
27
28targets := vmlinux.bin setup.bin setup.elf zImage bzImage
29subdir- := compressed
30
31setup-y += a20.o apm.o cmdline.o copy.o cpu.o cpucheck.o edd.o
32setup-y += header.o main.o mca.o memory.o pm.o pmjump.o
33setup-y += printf.o string.o tty.o video.o version.o voyager.o
34
35# The link order of the video-*.o modules can matter. In particular,
36# video-vga.o *must* be listed first, followed by video-vesa.o.
37# Hardware-specific drivers should follow in the order they should be
38# probed, and video-bios.o should typically be last.
39setup-y += video-vga.o
40setup-y += video-vesa.o
41setup-y += video-bios.o
42targets += $(setup-y)
43hostprogs-y := tools/build
44
45HOSTCFLAGS_build.o := $(LINUXINCLUDE)
46
47# ---------------------------------------------------------------------------
48
49# How to compile the 16-bit code. Note we always compile for -march=i386,
50# that way we can complain to the user if the CPU is insufficient.
51cflags-i386 :=
52cflags-x86_64 := -m32
53CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
54 $(cflags-$(ARCH)) \
55 -Wall -Wstrict-prototypes \
56 -march=i386 -mregparm=3 \
57 -include $(srctree)/$(src)/code16gcc.h \
58 -fno-strict-aliasing -fomit-frame-pointer \
59 $(call cc-option, -ffreestanding) \
60 $(call cc-option, -fno-toplevel-reorder,\
61 $(call cc-option, -fno-unit-at-a-time)) \
62 $(call cc-option, -fno-stack-protector) \
63 $(call cc-option, -mpreferred-stack-boundary=2)
64AFLAGS := $(CFLAGS) -D__ASSEMBLY__
65
66$(obj)/zImage: IMAGE_OFFSET := 0x1000
67$(obj)/zImage: EXTRA_AFLAGS := $(SVGA_MODE) $(RAMDISK)
68$(obj)/bzImage: IMAGE_OFFSET := 0x100000
69$(obj)/bzImage: EXTRA_CFLAGS := -D__BIG_KERNEL__
70$(obj)/bzImage: EXTRA_AFLAGS := $(SVGA_MODE) $(RAMDISK) -D__BIG_KERNEL__
71$(obj)/bzImage: BUILDFLAGS := -b
72
73quiet_cmd_image = BUILD $@
74cmd_image = $(obj)/tools/build $(BUILDFLAGS) $(obj)/setup.bin \
75 $(obj)/vmlinux.bin $(ROOT_DEV) > $@
76
77$(obj)/zImage $(obj)/bzImage: $(obj)/setup.bin \
78 $(obj)/vmlinux.bin $(obj)/tools/build FORCE
79 $(call if_changed,image)
80 @echo 'Kernel: $@ is ready' ' (#'`cat .version`')'
81
82$(obj)/vmlinux.bin: $(obj)/compressed/vmlinux FORCE
83 $(call if_changed,objcopy)
84
85SETUP_OBJS = $(addprefix $(obj)/,$(setup-y))
86
87LDFLAGS_setup.elf := -T
88$(obj)/setup.elf: $(src)/setup.ld $(SETUP_OBJS) FORCE
89 $(call if_changed,ld)
90
91OBJCOPYFLAGS_setup.bin := -O binary
92
93$(obj)/setup.bin: $(obj)/setup.elf FORCE
94 $(call if_changed,objcopy)
95
96$(obj)/compressed/vmlinux: FORCE
97 $(Q)$(MAKE) $(build)=$(obj)/compressed IMAGE_OFFSET=$(IMAGE_OFFSET) $@
98
99# Set this if you want to pass append arguments to the zdisk/fdimage/isoimage kernel
100FDARGS =
101# Set this if you want an initrd included with the zdisk/fdimage/isoimage kernel
102FDINITRD =
103
104image_cmdline = default linux $(FDARGS) $(if $(FDINITRD),initrd=initrd.img,)
105
106$(obj)/mtools.conf: $(src)/mtools.conf.in
107 sed -e 's|@OBJ@|$(obj)|g' < $< > $@
108
109# This requires write access to /dev/fd0
110zdisk: $(BOOTIMAGE) $(obj)/mtools.conf
111 MTOOLSRC=$(obj)/mtools.conf mformat a: ; sync
112 syslinux /dev/fd0 ; sync
113 echo '$(image_cmdline)' | \
114 MTOOLSRC=$(src)/mtools.conf mcopy - a:syslinux.cfg
115 if [ -f '$(FDINITRD)' ] ; then \
116 MTOOLSRC=$(obj)/mtools.conf mcopy '$(FDINITRD)' a:initrd.img ; \
117 fi
118 MTOOLSRC=$(obj)/mtools.conf mcopy $(BOOTIMAGE) a:linux ; sync
119
120# These require being root or having syslinux 2.02 or higher installed
121fdimage fdimage144: $(BOOTIMAGE) $(obj)/mtools.conf
122 dd if=/dev/zero of=$(obj)/fdimage bs=1024 count=1440
123 MTOOLSRC=$(obj)/mtools.conf mformat v: ; sync
124 syslinux $(obj)/fdimage ; sync
125 echo '$(image_cmdline)' | \
126 MTOOLSRC=$(obj)/mtools.conf mcopy - v:syslinux.cfg
127 if [ -f '$(FDINITRD)' ] ; then \
128 MTOOLSRC=$(obj)/mtools.conf mcopy '$(FDINITRD)' v:initrd.img ; \
129 fi
130 MTOOLSRC=$(obj)/mtools.conf mcopy $(BOOTIMAGE) v:linux ; sync
131
132fdimage288: $(BOOTIMAGE) $(obj)/mtools.conf
133 dd if=/dev/zero of=$(obj)/fdimage bs=1024 count=2880
134 MTOOLSRC=$(obj)/mtools.conf mformat w: ; sync
135 syslinux $(obj)/fdimage ; sync
136 echo '$(image_cmdline)' | \
137 MTOOLSRC=$(obj)/mtools.conf mcopy - w:syslinux.cfg
138 if [ -f '$(FDINITRD)' ] ; then \
139 MTOOLSRC=$(obj)/mtools.conf mcopy '$(FDINITRD)' w:initrd.img ; \
140 fi
141 MTOOLSRC=$(obj)/mtools.conf mcopy $(BOOTIMAGE) w:linux ; sync
142
143isoimage: $(BOOTIMAGE)
144 -rm -rf $(obj)/isoimage
145 mkdir $(obj)/isoimage
146 for i in lib lib64 share end ; do \
147 if [ -f /usr/$$i/syslinux/isolinux.bin ] ; then \
148 cp /usr/$$i/syslinux/isolinux.bin $(obj)/isoimage ; \
149 break ; \
150 fi ; \
151 if [ $$i = end ] ; then exit 1 ; fi ; \
152 done
153 cp $(BOOTIMAGE) $(obj)/isoimage/linux
154 echo '$(image_cmdline)' > $(obj)/isoimage/isolinux.cfg
155 if [ -f '$(FDINITRD)' ] ; then \
156 cp '$(FDINITRD)' $(obj)/isoimage/initrd.img ; \
157 fi
158 mkisofs -J -r -o $(obj)/image.iso -b isolinux.bin -c boot.cat \
159 -no-emul-boot -boot-load-size 4 -boot-info-table \
160 $(obj)/isoimage
161 rm -rf $(obj)/isoimage
162
163zlilo: $(BOOTIMAGE)
164 if [ -f $(INSTALL_PATH)/vmlinuz ]; then mv $(INSTALL_PATH)/vmlinuz $(INSTALL_PATH)/vmlinuz.old; fi
165 if [ -f $(INSTALL_PATH)/System.map ]; then mv $(INSTALL_PATH)/System.map $(INSTALL_PATH)/System.old; fi
166 cat $(BOOTIMAGE) > $(INSTALL_PATH)/vmlinuz
167 cp System.map $(INSTALL_PATH)/
168 if [ -x /sbin/lilo ]; then /sbin/lilo; else /etc/lilo/install; fi
169
170install:
171 sh $(srctree)/$(src)/install.sh $(KERNELRELEASE) $(BOOTIMAGE) System.map "$(INSTALL_PATH)"
diff --git a/arch/i386/boot/a20.c b/arch/x86/boot/a20.c
index 31348d054fca..31348d054fca 100644
--- a/arch/i386/boot/a20.c
+++ b/arch/x86/boot/a20.c
diff --git a/arch/i386/boot/apm.c b/arch/x86/boot/apm.c
index eab50c55a3a5..eab50c55a3a5 100644
--- a/arch/i386/boot/apm.c
+++ b/arch/x86/boot/apm.c
diff --git a/arch/i386/boot/bitops.h b/arch/x86/boot/bitops.h
index 8dcc8dc7db88..8dcc8dc7db88 100644
--- a/arch/i386/boot/bitops.h
+++ b/arch/x86/boot/bitops.h
diff --git a/arch/i386/boot/boot.h b/arch/x86/boot/boot.h
index 20bab9431acb..20bab9431acb 100644
--- a/arch/i386/boot/boot.h
+++ b/arch/x86/boot/boot.h
diff --git a/arch/i386/boot/cmdline.c b/arch/x86/boot/cmdline.c
index 34bb778c4357..34bb778c4357 100644
--- a/arch/i386/boot/cmdline.c
+++ b/arch/x86/boot/cmdline.c
diff --git a/arch/i386/boot/code16gcc.h b/arch/x86/boot/code16gcc.h
index d93e48010b61..d93e48010b61 100644
--- a/arch/i386/boot/code16gcc.h
+++ b/arch/x86/boot/code16gcc.h
diff --git a/arch/i386/boot/compressed/.gitignore b/arch/x86/boot/compressed/.gitignore
index be0ed065249b..be0ed065249b 100644
--- a/arch/i386/boot/compressed/.gitignore
+++ b/arch/x86/boot/compressed/.gitignore
diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
new file mode 100644
index 000000000000..52c1db854520
--- /dev/null
+++ b/arch/x86/boot/compressed/Makefile
@@ -0,0 +1,5 @@
1ifeq ($(CONFIG_X86_32),y)
2include ${srctree}/arch/x86/boot/compressed/Makefile_32
3else
4include ${srctree}/arch/x86/boot/compressed/Makefile_64
5endif
diff --git a/arch/x86/boot/compressed/Makefile_32 b/arch/x86/boot/compressed/Makefile_32
new file mode 100644
index 000000000000..22613c652d22
--- /dev/null
+++ b/arch/x86/boot/compressed/Makefile_32
@@ -0,0 +1,50 @@
1#
2# linux/arch/x86/boot/compressed/Makefile
3#
4# create a compressed vmlinux image from the original vmlinux
5#
6
7targets := vmlinux vmlinux.bin vmlinux.bin.gz head_32.o misc_32.o piggy.o \
8 vmlinux.bin.all vmlinux.relocs
9EXTRA_AFLAGS := -traditional
10
11LDFLAGS_vmlinux := -T
12hostprogs-y := relocs
13
14CFLAGS := -m32 -D__KERNEL__ $(LINUX_INCLUDE) -O2 \
15 -fno-strict-aliasing -fPIC \
16 $(call cc-option,-ffreestanding) \
17 $(call cc-option,-fno-stack-protector)
18LDFLAGS := -m elf_i386
19
20$(obj)/vmlinux: $(src)/vmlinux_32.lds $(obj)/head_32.o $(obj)/misc_32.o $(obj)/piggy.o FORCE
21 $(call if_changed,ld)
22 @:
23
24$(obj)/vmlinux.bin: vmlinux FORCE
25 $(call if_changed,objcopy)
26
27quiet_cmd_relocs = RELOCS $@
28 cmd_relocs = $(obj)/relocs $< > $@;$(obj)/relocs --abs-relocs $<
29$(obj)/vmlinux.relocs: vmlinux $(obj)/relocs FORCE
30 $(call if_changed,relocs)
31
32vmlinux.bin.all-y := $(obj)/vmlinux.bin
33vmlinux.bin.all-$(CONFIG_RELOCATABLE) += $(obj)/vmlinux.relocs
34quiet_cmd_relocbin = BUILD $@
35 cmd_relocbin = cat $(filter-out FORCE,$^) > $@
36$(obj)/vmlinux.bin.all: $(vmlinux.bin.all-y) FORCE
37 $(call if_changed,relocbin)
38
39ifdef CONFIG_RELOCATABLE
40$(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bin.all FORCE
41 $(call if_changed,gzip)
42else
43$(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bin FORCE
44 $(call if_changed,gzip)
45endif
46
47LDFLAGS_piggy.o := -r --format binary --oformat elf32-i386 -T
48
49$(obj)/piggy.o: $(src)/vmlinux_32.scr $(obj)/vmlinux.bin.gz FORCE
50 $(call if_changed,ld)
diff --git a/arch/x86/boot/compressed/Makefile_64 b/arch/x86/boot/compressed/Makefile_64
new file mode 100644
index 000000000000..dc6b3380cc45
--- /dev/null
+++ b/arch/x86/boot/compressed/Makefile_64
@@ -0,0 +1,30 @@
1#
2# linux/arch/x86/boot/compressed/Makefile
3#
4# create a compressed vmlinux image from the original vmlinux
5#
6
7targets := vmlinux vmlinux.bin vmlinux.bin.gz head_64.o misc_64.o piggy.o
8
9CFLAGS := -m64 -D__KERNEL__ $(LINUXINCLUDE) -O2 \
10 -fno-strict-aliasing -fPIC -mcmodel=small \
11 $(call cc-option, -ffreestanding) \
12 $(call cc-option, -fno-stack-protector)
13AFLAGS := $(CFLAGS) -D__ASSEMBLY__
14LDFLAGS := -m elf_x86_64
15
16LDFLAGS_vmlinux := -T
17$(obj)/vmlinux: $(src)/vmlinux_64.lds $(obj)/head_64.o $(obj)/misc_64.o $(obj)/piggy.o FORCE
18 $(call if_changed,ld)
19 @:
20
21$(obj)/vmlinux.bin: vmlinux FORCE
22 $(call if_changed,objcopy)
23
24$(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bin FORCE
25 $(call if_changed,gzip)
26
27LDFLAGS_piggy.o := -r --format binary --oformat elf64-x86-64 -T
28
29$(obj)/piggy.o: $(obj)/vmlinux_64.scr $(obj)/vmlinux.bin.gz FORCE
30 $(call if_changed,ld)
diff --git a/arch/i386/boot/compressed/head.S b/arch/x86/boot/compressed/head_32.S
index f35ea2237522..f35ea2237522 100644
--- a/arch/i386/boot/compressed/head.S
+++ b/arch/x86/boot/compressed/head_32.S
diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
new file mode 100644
index 000000000000..49467640751f
--- /dev/null
+++ b/arch/x86/boot/compressed/head_64.S
@@ -0,0 +1,311 @@
1/*
2 * linux/boot/head.S
3 *
4 * Copyright (C) 1991, 1992, 1993 Linus Torvalds
5 */
6
7/*
8 * head.S contains the 32-bit startup code.
9 *
10 * NOTE!!! Startup happens at absolute address 0x00001000, which is also where
11 * the page directory will exist. The startup code will be overwritten by
12 * the page directory. [According to comments etc elsewhere on a compressed
13 * kernel it will end up at 0x1000 + 1Mb I hope so as I assume this. - AC]
14 *
15 * Page 0 is deliberately kept safe, since System Management Mode code in
16 * laptops may need to access the BIOS data stored there. This is also
17 * useful for future device drivers that either access the BIOS via VM86
18 * mode.
19 */
20
21/*
22 * High loaded stuff by Hans Lermen & Werner Almesberger, Feb. 1996
23 */
24.code32
25.text
26
27#include <linux/linkage.h>
28#include <asm/segment.h>
29#include <asm/pgtable.h>
30#include <asm/page.h>
31#include <asm/msr.h>
32
33.section ".text.head"
34 .code32
35 .globl startup_32
36
37startup_32:
38 cld
39 cli
40 movl $(__KERNEL_DS), %eax
41 movl %eax, %ds
42 movl %eax, %es
43 movl %eax, %ss
44
45/* Calculate the delta between where we were compiled to run
46 * at and where we were actually loaded at. This can only be done
47 * with a short local call on x86. Nothing else will tell us what
48 * address we are running at. The reserved chunk of the real-mode
49 * data at 0x1e4 (defined as a scratch field) are used as the stack
50 * for this calculation. Only 4 bytes are needed.
51 */
52 leal (0x1e4+4)(%esi), %esp
53 call 1f
541: popl %ebp
55 subl $1b, %ebp
56
57/* setup a stack and make sure cpu supports long mode. */
58 movl $user_stack_end, %eax
59 addl %ebp, %eax
60 movl %eax, %esp
61
62 call verify_cpu
63 testl %eax, %eax
64 jnz no_longmode
65
66/* Compute the delta between where we were compiled to run at
67 * and where the code will actually run at.
68 */
69/* %ebp contains the address we are loaded at by the boot loader and %ebx
70 * contains the address where we should move the kernel image temporarily
71 * for safe in-place decompression.
72 */
73
74#ifdef CONFIG_RELOCATABLE
75 movl %ebp, %ebx
76 addl $(LARGE_PAGE_SIZE -1), %ebx
77 andl $LARGE_PAGE_MASK, %ebx
78#else
79 movl $CONFIG_PHYSICAL_START, %ebx
80#endif
81
82 /* Replace the compressed data size with the uncompressed size */
83 subl input_len(%ebp), %ebx
84 movl output_len(%ebp), %eax
85 addl %eax, %ebx
86 /* Add 8 bytes for every 32K input block */
87 shrl $12, %eax
88 addl %eax, %ebx
89 /* Add 32K + 18 bytes of extra slack and align on a 4K boundary */
90 addl $(32768 + 18 + 4095), %ebx
91 andl $~4095, %ebx
92
93/*
94 * Prepare for entering 64 bit mode
95 */
96
97 /* Load new GDT with the 64bit segments using 32bit descriptor */
98 leal gdt(%ebp), %eax
99 movl %eax, gdt+2(%ebp)
100 lgdt gdt(%ebp)
101
102 /* Enable PAE mode */
103 xorl %eax, %eax
104 orl $(1 << 5), %eax
105 movl %eax, %cr4
106
107 /*
108 * Build early 4G boot pagetable
109 */
110 /* Initialize Page tables to 0*/
111 leal pgtable(%ebx), %edi
112 xorl %eax, %eax
113 movl $((4096*6)/4), %ecx
114 rep stosl
115
116 /* Build Level 4 */
117 leal pgtable + 0(%ebx), %edi
118 leal 0x1007 (%edi), %eax
119 movl %eax, 0(%edi)
120
121 /* Build Level 3 */
122 leal pgtable + 0x1000(%ebx), %edi
123 leal 0x1007(%edi), %eax
124 movl $4, %ecx
1251: movl %eax, 0x00(%edi)
126 addl $0x00001000, %eax
127 addl $8, %edi
128 decl %ecx
129 jnz 1b
130
131 /* Build Level 2 */
132 leal pgtable + 0x2000(%ebx), %edi
133 movl $0x00000183, %eax
134 movl $2048, %ecx
1351: movl %eax, 0(%edi)
136 addl $0x00200000, %eax
137 addl $8, %edi
138 decl %ecx
139 jnz 1b
140
141 /* Enable the boot page tables */
142 leal pgtable(%ebx), %eax
143 movl %eax, %cr3
144
145 /* Enable Long mode in EFER (Extended Feature Enable Register) */
146 movl $MSR_EFER, %ecx
147 rdmsr
148 btsl $_EFER_LME, %eax
149 wrmsr
150
151 /* Setup for the jump to 64bit mode
152 *
153 * When the jump is performend we will be in long mode but
154 * in 32bit compatibility mode with EFER.LME = 1, CS.L = 0, CS.D = 1
155 * (and in turn EFER.LMA = 1). To jump into 64bit mode we use
156 * the new gdt/idt that has __KERNEL_CS with CS.L = 1.
157 * We place all of the values on our mini stack so lret can
158 * used to perform that far jump.
159 */
160 pushl $__KERNEL_CS
161 leal startup_64(%ebp), %eax
162 pushl %eax
163
164 /* Enter paged protected Mode, activating Long Mode */
165 movl $0x80000001, %eax /* Enable Paging and Protected mode */
166 movl %eax, %cr0
167
168 /* Jump from 32bit compatibility mode into 64bit mode. */
169 lret
170
171no_longmode:
172 /* This isn't an x86-64 CPU so hang */
1731:
174 hlt
175 jmp 1b
176
177#include "../../kernel/verify_cpu_64.S"
178
179 /* Be careful here startup_64 needs to be at a predictable
180 * address so I can export it in an ELF header. Bootloaders
181 * should look at the ELF header to find this address, as
182 * it may change in the future.
183 */
184 .code64
185 .org 0x200
186ENTRY(startup_64)
187 /* We come here either from startup_32 or directly from a
188 * 64bit bootloader. If we come here from a bootloader we depend on
189 * an identity mapped page table being provied that maps our
190 * entire text+data+bss and hopefully all of memory.
191 */
192
193 /* Setup data segments. */
194 xorl %eax, %eax
195 movl %eax, %ds
196 movl %eax, %es
197 movl %eax, %ss
198 movl %eax, %fs
199 movl %eax, %gs
200 lldt %ax
201 movl $0x20, %eax
202 ltr %ax
203
204 /* Compute the decompressed kernel start address. It is where
205 * we were loaded at aligned to a 2M boundary. %rbp contains the
206 * decompressed kernel start address.
207 *
208 * If it is a relocatable kernel then decompress and run the kernel
209 * from load address aligned to 2MB addr, otherwise decompress and
210 * run the kernel from CONFIG_PHYSICAL_START
211 */
212
213 /* Start with the delta to where the kernel will run at. */
214#ifdef CONFIG_RELOCATABLE
215 leaq startup_32(%rip) /* - $startup_32 */, %rbp
216 addq $(LARGE_PAGE_SIZE - 1), %rbp
217 andq $LARGE_PAGE_MASK, %rbp
218 movq %rbp, %rbx
219#else
220 movq $CONFIG_PHYSICAL_START, %rbp
221 movq %rbp, %rbx
222#endif
223
224 /* Replace the compressed data size with the uncompressed size */
225 movl input_len(%rip), %eax
226 subq %rax, %rbx
227 movl output_len(%rip), %eax
228 addq %rax, %rbx
229 /* Add 8 bytes for every 32K input block */
230 shrq $12, %rax
231 addq %rax, %rbx
232 /* Add 32K + 18 bytes of extra slack and align on a 4K boundary */
233 addq $(32768 + 18 + 4095), %rbx
234 andq $~4095, %rbx
235
236/* Copy the compressed kernel to the end of our buffer
237 * where decompression in place becomes safe.
238 */
239 leaq _end(%rip), %r8
240 leaq _end(%rbx), %r9
241 movq $_end /* - $startup_32 */, %rcx
2421: subq $8, %r8
243 subq $8, %r9
244 movq 0(%r8), %rax
245 movq %rax, 0(%r9)
246 subq $8, %rcx
247 jnz 1b
248
249/*
250 * Jump to the relocated address.
251 */
252 leaq relocated(%rbx), %rax
253 jmp *%rax
254
255.section ".text"
256relocated:
257
258/*
259 * Clear BSS
260 */
261 xorq %rax, %rax
262 leaq _edata(%rbx), %rdi
263 leaq _end(%rbx), %rcx
264 subq %rdi, %rcx
265 cld
266 rep
267 stosb
268
269 /* Setup the stack */
270 leaq user_stack_end(%rip), %rsp
271
272 /* zero EFLAGS after setting rsp */
273 pushq $0
274 popfq
275
276/*
277 * Do the decompression, and jump to the new kernel..
278 */
279 pushq %rsi # Save the real mode argument
280 movq %rsi, %rdi # real mode address
281 leaq _heap(%rip), %rsi # _heap
282 leaq input_data(%rip), %rdx # input_data
283 movl input_len(%rip), %eax
284 movq %rax, %rcx # input_len
285 movq %rbp, %r8 # output
286 call decompress_kernel
287 popq %rsi
288
289
290/*
291 * Jump to the decompressed kernel.
292 */
293 jmp *%rbp
294
295 .data
296gdt:
297 .word gdt_end - gdt
298 .long gdt
299 .word 0
300 .quad 0x0000000000000000 /* NULL descriptor */
301 .quad 0x00af9a000000ffff /* __KERNEL_CS */
302 .quad 0x00cf92000000ffff /* __KERNEL_DS */
303 .quad 0x0080890000000000 /* TS descriptor */
304 .quad 0x0000000000000000 /* TS continued */
305gdt_end:
306 .bss
307/* Stack for uncompression */
308 .balign 4
309user_stack:
310 .fill 4096,4,0
311user_stack_end:
diff --git a/arch/i386/boot/compressed/misc.c b/arch/x86/boot/compressed/misc_32.c
index b28505c544c9..b28505c544c9 100644
--- a/arch/i386/boot/compressed/misc.c
+++ b/arch/x86/boot/compressed/misc_32.c
diff --git a/arch/x86_64/boot/compressed/misc.c b/arch/x86/boot/compressed/misc_64.c
index f932b0e89096..f932b0e89096 100644
--- a/arch/x86_64/boot/compressed/misc.c
+++ b/arch/x86/boot/compressed/misc_64.c
diff --git a/arch/i386/boot/compressed/relocs.c b/arch/x86/boot/compressed/relocs.c
index 2d77ee728f92..2d77ee728f92 100644
--- a/arch/i386/boot/compressed/relocs.c
+++ b/arch/x86/boot/compressed/relocs.c
diff --git a/arch/i386/boot/compressed/vmlinux.lds b/arch/x86/boot/compressed/vmlinux_32.lds
index cc4854f6c6c1..cc4854f6c6c1 100644
--- a/arch/i386/boot/compressed/vmlinux.lds
+++ b/arch/x86/boot/compressed/vmlinux_32.lds
diff --git a/arch/i386/boot/compressed/vmlinux.scr b/arch/x86/boot/compressed/vmlinux_32.scr
index 707a88f7f29e..707a88f7f29e 100644
--- a/arch/i386/boot/compressed/vmlinux.scr
+++ b/arch/x86/boot/compressed/vmlinux_32.scr
diff --git a/arch/x86_64/boot/compressed/vmlinux.lds b/arch/x86/boot/compressed/vmlinux_64.lds
index 94c13e557fb4..94c13e557fb4 100644
--- a/arch/x86_64/boot/compressed/vmlinux.lds
+++ b/arch/x86/boot/compressed/vmlinux_64.lds
diff --git a/arch/x86_64/boot/compressed/vmlinux.scr b/arch/x86/boot/compressed/vmlinux_64.scr
index bd1429ce193e..bd1429ce193e 100644
--- a/arch/x86_64/boot/compressed/vmlinux.scr
+++ b/arch/x86/boot/compressed/vmlinux_64.scr
diff --git a/arch/i386/boot/copy.S b/arch/x86/boot/copy.S
index ef127e56a3cf..ef127e56a3cf 100644
--- a/arch/i386/boot/copy.S
+++ b/arch/x86/boot/copy.S
diff --git a/arch/i386/boot/cpu.c b/arch/x86/boot/cpu.c
index 2a5c32da5852..2a5c32da5852 100644
--- a/arch/i386/boot/cpu.c
+++ b/arch/x86/boot/cpu.c
diff --git a/arch/i386/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
index e655a89c5510..e655a89c5510 100644
--- a/arch/i386/boot/cpucheck.c
+++ b/arch/x86/boot/cpucheck.c
diff --git a/arch/i386/boot/edd.c b/arch/x86/boot/edd.c
index bd138e442ec2..bd138e442ec2 100644
--- a/arch/i386/boot/edd.c
+++ b/arch/x86/boot/edd.c
diff --git a/arch/i386/boot/header.S b/arch/x86/boot/header.S
index f3140e596d40..f3140e596d40 100644
--- a/arch/i386/boot/header.S
+++ b/arch/x86/boot/header.S
diff --git a/arch/i386/boot/install.sh b/arch/x86/boot/install.sh
index 88d77761d01b..88d77761d01b 100644
--- a/arch/i386/boot/install.sh
+++ b/arch/x86/boot/install.sh
diff --git a/arch/i386/boot/main.c b/arch/x86/boot/main.c
index 0eeef3989a17..0eeef3989a17 100644
--- a/arch/i386/boot/main.c
+++ b/arch/x86/boot/main.c
diff --git a/arch/i386/boot/mca.c b/arch/x86/boot/mca.c
index 68222f2d4b67..68222f2d4b67 100644
--- a/arch/i386/boot/mca.c
+++ b/arch/x86/boot/mca.c
diff --git a/arch/i386/boot/memory.c b/arch/x86/boot/memory.c
index 378353956b5d..378353956b5d 100644
--- a/arch/i386/boot/memory.c
+++ b/arch/x86/boot/memory.c
diff --git a/arch/i386/boot/mtools.conf.in b/arch/x86/boot/mtools.conf.in
index efd6d2490c1d..efd6d2490c1d 100644
--- a/arch/i386/boot/mtools.conf.in
+++ b/arch/x86/boot/mtools.conf.in
diff --git a/arch/i386/boot/pm.c b/arch/x86/boot/pm.c
index 09fb342cc62e..09fb342cc62e 100644
--- a/arch/i386/boot/pm.c
+++ b/arch/x86/boot/pm.c
diff --git a/arch/i386/boot/pmjump.S b/arch/x86/boot/pmjump.S
index 2e559233725a..2e559233725a 100644
--- a/arch/i386/boot/pmjump.S
+++ b/arch/x86/boot/pmjump.S
diff --git a/arch/i386/boot/printf.c b/arch/x86/boot/printf.c
index 1a09f9309d3c..1a09f9309d3c 100644
--- a/arch/i386/boot/printf.c
+++ b/arch/x86/boot/printf.c
diff --git a/arch/i386/boot/setup.ld b/arch/x86/boot/setup.ld
index df9234b3a5e0..df9234b3a5e0 100644
--- a/arch/i386/boot/setup.ld
+++ b/arch/x86/boot/setup.ld
diff --git a/arch/i386/boot/string.c b/arch/x86/boot/string.c
index 481a22097781..481a22097781 100644
--- a/arch/i386/boot/string.c
+++ b/arch/x86/boot/string.c
diff --git a/arch/i386/boot/tools/.gitignore b/arch/x86/boot/tools/.gitignore
index 378eac25d311..378eac25d311 100644
--- a/arch/i386/boot/tools/.gitignore
+++ b/arch/x86/boot/tools/.gitignore
diff --git a/arch/i386/boot/tools/build.c b/arch/x86/boot/tools/build.c
index b4248740ff0d..b4248740ff0d 100644
--- a/arch/i386/boot/tools/build.c
+++ b/arch/x86/boot/tools/build.c
diff --git a/arch/i386/boot/tty.c b/arch/x86/boot/tty.c
index f3f14bd26371..f3f14bd26371 100644
--- a/arch/i386/boot/tty.c
+++ b/arch/x86/boot/tty.c
diff --git a/arch/i386/boot/version.c b/arch/x86/boot/version.c
index c61462f7d9a7..c61462f7d9a7 100644
--- a/arch/i386/boot/version.c
+++ b/arch/x86/boot/version.c
diff --git a/arch/i386/boot/vesa.h b/arch/x86/boot/vesa.h
index ff5b73cd406f..ff5b73cd406f 100644
--- a/arch/i386/boot/vesa.h
+++ b/arch/x86/boot/vesa.h
diff --git a/arch/i386/boot/video-bios.c b/arch/x86/boot/video-bios.c
index 68e65d95cdfd..68e65d95cdfd 100644
--- a/arch/i386/boot/video-bios.c
+++ b/arch/x86/boot/video-bios.c
diff --git a/arch/i386/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
index 192190710710..192190710710 100644
--- a/arch/i386/boot/video-vesa.c
+++ b/arch/x86/boot/video-vesa.c
diff --git a/arch/i386/boot/video-vga.c b/arch/x86/boot/video-vga.c
index aef02f9ec0c1..aef02f9ec0c1 100644
--- a/arch/i386/boot/video-vga.c
+++ b/arch/x86/boot/video-vga.c
diff --git a/arch/i386/boot/video.c b/arch/x86/boot/video.c
index e4ba897bf9a3..e4ba897bf9a3 100644
--- a/arch/i386/boot/video.c
+++ b/arch/x86/boot/video.c
diff --git a/arch/i386/boot/video.h b/arch/x86/boot/video.h
index b92447d51213..b92447d51213 100644
--- a/arch/i386/boot/video.h
+++ b/arch/x86/boot/video.h
diff --git a/arch/i386/boot/voyager.c b/arch/x86/boot/voyager.c
index 61c8fe0453be..61c8fe0453be 100644
--- a/arch/i386/boot/voyager.c
+++ b/arch/x86/boot/voyager.c
diff --git a/arch/x86/crypto/Makefile b/arch/x86/crypto/Makefile
new file mode 100644
index 000000000000..18dcdc6fb7aa
--- /dev/null
+++ b/arch/x86/crypto/Makefile
@@ -0,0 +1,5 @@
1ifeq ($(CONFIG_X86_32),y)
2include ${srctree}/arch/x86/crypto/Makefile_32
3else
4include ${srctree}/arch/x86/crypto/Makefile_64
5endif
diff --git a/arch/x86/crypto/Makefile_32 b/arch/x86/crypto/Makefile_32
new file mode 100644
index 000000000000..2d873a2388ed
--- /dev/null
+++ b/arch/x86/crypto/Makefile_32
@@ -0,0 +1,12 @@
1#
2# x86/crypto/Makefile
3#
4# Arch-specific CryptoAPI modules.
5#
6
7obj-$(CONFIG_CRYPTO_AES_586) += aes-i586.o
8obj-$(CONFIG_CRYPTO_TWOFISH_586) += twofish-i586.o
9
10aes-i586-y := aes-i586-asm_32.o aes_32.o
11twofish-i586-y := twofish-i586-asm_32.o twofish_32.o
12
diff --git a/arch/x86/crypto/Makefile_64 b/arch/x86/crypto/Makefile_64
new file mode 100644
index 000000000000..b40896276e93
--- /dev/null
+++ b/arch/x86/crypto/Makefile_64
@@ -0,0 +1,12 @@
1#
2# x86/crypto/Makefile
3#
4# Arch-specific CryptoAPI modules.
5#
6
7obj-$(CONFIG_CRYPTO_AES_X86_64) += aes-x86_64.o
8obj-$(CONFIG_CRYPTO_TWOFISH_X86_64) += twofish-x86_64.o
9
10aes-x86_64-y := aes-x86_64-asm_64.o aes_64.o
11twofish-x86_64-y := twofish-x86_64-asm_64.o twofish_64.o
12
diff --git a/arch/i386/crypto/aes-i586-asm.S b/arch/x86/crypto/aes-i586-asm_32.S
index f942f0c8f630..f942f0c8f630 100644
--- a/arch/i386/crypto/aes-i586-asm.S
+++ b/arch/x86/crypto/aes-i586-asm_32.S
diff --git a/arch/x86_64/crypto/aes-x86_64-asm.S b/arch/x86/crypto/aes-x86_64-asm_64.S
index 26b40de4d0b0..26b40de4d0b0 100644
--- a/arch/x86_64/crypto/aes-x86_64-asm.S
+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
diff --git a/arch/i386/crypto/aes.c b/arch/x86/crypto/aes_32.c
index 49aad9397f10..49aad9397f10 100644
--- a/arch/i386/crypto/aes.c
+++ b/arch/x86/crypto/aes_32.c
diff --git a/arch/x86_64/crypto/aes.c b/arch/x86/crypto/aes_64.c
index 5cdb13ea5cc2..5cdb13ea5cc2 100644
--- a/arch/x86_64/crypto/aes.c
+++ b/arch/x86/crypto/aes_64.c
diff --git a/arch/i386/crypto/twofish-i586-asm.S b/arch/x86/crypto/twofish-i586-asm_32.S
index 39b98ed2c1b9..39b98ed2c1b9 100644
--- a/arch/i386/crypto/twofish-i586-asm.S
+++ b/arch/x86/crypto/twofish-i586-asm_32.S
diff --git a/arch/x86_64/crypto/twofish-x86_64-asm.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
index 35974a586615..35974a586615 100644
--- a/arch/x86_64/crypto/twofish-x86_64-asm.S
+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
diff --git a/arch/i386/crypto/twofish.c b/arch/x86/crypto/twofish_32.c
index e3004dfe9c7a..e3004dfe9c7a 100644
--- a/arch/i386/crypto/twofish.c
+++ b/arch/x86/crypto/twofish_32.c
diff --git a/arch/x86_64/crypto/twofish.c b/arch/x86/crypto/twofish_64.c
index 182d91d5cfb9..182d91d5cfb9 100644
--- a/arch/x86_64/crypto/twofish.c
+++ b/arch/x86/crypto/twofish_64.c
diff --git a/arch/x86_64/ia32/Makefile b/arch/x86/ia32/Makefile
index cdae36435e21..cdae36435e21 100644
--- a/arch/x86_64/ia32/Makefile
+++ b/arch/x86/ia32/Makefile
diff --git a/arch/x86/ia32/audit.c b/arch/x86/ia32/audit.c
new file mode 100644
index 000000000000..91b7b5922dfa
--- /dev/null
+++ b/arch/x86/ia32/audit.c
@@ -0,0 +1,42 @@
1#include <asm/unistd_32.h>
2
3unsigned ia32_dir_class[] = {
4#include <asm-generic/audit_dir_write.h>
5~0U
6};
7
8unsigned ia32_chattr_class[] = {
9#include <asm-generic/audit_change_attr.h>
10~0U
11};
12
13unsigned ia32_write_class[] = {
14#include <asm-generic/audit_write.h>
15~0U
16};
17
18unsigned ia32_read_class[] = {
19#include <asm-generic/audit_read.h>
20~0U
21};
22
23unsigned ia32_signal_class[] = {
24#include <asm-generic/audit_signal.h>
25~0U
26};
27
28int ia32_classify_syscall(unsigned syscall)
29{
30 switch(syscall) {
31 case __NR_open:
32 return 2;
33 case __NR_openat:
34 return 3;
35 case __NR_socketcall:
36 return 4;
37 case __NR_execve:
38 return 5;
39 default:
40 return 1;
41 }
42}
diff --git a/arch/x86_64/ia32/fpu32.c b/arch/x86/ia32/fpu32.c
index 2c8209a3605a..2c8209a3605a 100644
--- a/arch/x86_64/ia32/fpu32.c
+++ b/arch/x86/ia32/fpu32.c
diff --git a/arch/x86_64/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
index 08781370256d..08781370256d 100644
--- a/arch/x86_64/ia32/ia32_aout.c
+++ b/arch/x86/ia32/ia32_aout.c
diff --git a/arch/x86_64/ia32/ia32_binfmt.c b/arch/x86/ia32/ia32_binfmt.c
index dffd2ac72747..dffd2ac72747 100644
--- a/arch/x86_64/ia32/ia32_binfmt.c
+++ b/arch/x86/ia32/ia32_binfmt.c
diff --git a/arch/x86_64/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
index 6ea19c25f90d..6ea19c25f90d 100644
--- a/arch/x86_64/ia32/ia32_signal.c
+++ b/arch/x86/ia32/ia32_signal.c
diff --git a/arch/x86_64/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
index 18b231810908..18b231810908 100644
--- a/arch/x86_64/ia32/ia32entry.S
+++ b/arch/x86/ia32/ia32entry.S
diff --git a/arch/x86/ia32/ipc32.c b/arch/x86/ia32/ipc32.c
new file mode 100644
index 000000000000..2e1869ec4db4
--- /dev/null
+++ b/arch/x86/ia32/ipc32.c
@@ -0,0 +1,57 @@
1#include <linux/kernel.h>
2#include <linux/spinlock.h>
3#include <linux/list.h>
4#include <linux/syscalls.h>
5#include <linux/time.h>
6#include <linux/sem.h>
7#include <linux/msg.h>
8#include <linux/shm.h>
9#include <linux/ipc.h>
10#include <linux/compat.h>
11
12#include <asm/ipc.h>
13
14asmlinkage long
15sys32_ipc(u32 call, int first, int second, int third,
16 compat_uptr_t ptr, u32 fifth)
17{
18 int version;
19
20 version = call >> 16; /* hack for backward compatibility */
21 call &= 0xffff;
22
23 switch (call) {
24 case SEMOP:
25 /* struct sembuf is the same on 32 and 64bit :)) */
26 return sys_semtimedop(first, compat_ptr(ptr), second, NULL);
27 case SEMTIMEDOP:
28 return compat_sys_semtimedop(first, compat_ptr(ptr), second,
29 compat_ptr(fifth));
30 case SEMGET:
31 return sys_semget(first, second, third);
32 case SEMCTL:
33 return compat_sys_semctl(first, second, third, compat_ptr(ptr));
34
35 case MSGSND:
36 return compat_sys_msgsnd(first, second, third, compat_ptr(ptr));
37 case MSGRCV:
38 return compat_sys_msgrcv(first, second, fifth, third,
39 version, compat_ptr(ptr));
40 case MSGGET:
41 return sys_msgget((key_t) first, second);
42 case MSGCTL:
43 return compat_sys_msgctl(first, second, compat_ptr(ptr));
44
45 case SHMAT:
46 return compat_sys_shmat(first, second, third, version,
47 compat_ptr(ptr));
48 break;
49 case SHMDT:
50 return sys_shmdt(compat_ptr(ptr));
51 case SHMGET:
52 return sys_shmget(first, (unsigned)second, third);
53 case SHMCTL:
54 return compat_sys_shmctl(first, second, compat_ptr(ptr));
55 }
56 return -ENOSYS;
57}
diff --git a/arch/x86_64/ia32/mmap32.c b/arch/x86/ia32/mmap32.c
index e4b84b4a417a..e4b84b4a417a 100644
--- a/arch/x86_64/ia32/mmap32.c
+++ b/arch/x86/ia32/mmap32.c
diff --git a/arch/x86_64/ia32/ptrace32.c b/arch/x86/ia32/ptrace32.c
index 4a233ad6269c..4a233ad6269c 100644
--- a/arch/x86_64/ia32/ptrace32.c
+++ b/arch/x86/ia32/ptrace32.c
diff --git a/arch/x86_64/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
index bee96d614432..bee96d614432 100644
--- a/arch/x86_64/ia32/sys_ia32.c
+++ b/arch/x86/ia32/sys_ia32.c
diff --git a/arch/x86_64/ia32/syscall32.c b/arch/x86/ia32/syscall32.c
index 15013bac181c..15013bac181c 100644
--- a/arch/x86_64/ia32/syscall32.c
+++ b/arch/x86/ia32/syscall32.c
diff --git a/arch/x86/ia32/syscall32_syscall.S b/arch/x86/ia32/syscall32_syscall.S
new file mode 100644
index 000000000000..933f0f08b1cf
--- /dev/null
+++ b/arch/x86/ia32/syscall32_syscall.S
@@ -0,0 +1,17 @@
1/* 32bit VDSOs mapped into user space. */
2
3 .section ".init.data","aw"
4
5 .globl syscall32_syscall
6 .globl syscall32_syscall_end
7
8syscall32_syscall:
9 .incbin "arch/x86/ia32/vsyscall-syscall.so"
10syscall32_syscall_end:
11
12 .globl syscall32_sysenter
13 .globl syscall32_sysenter_end
14
15syscall32_sysenter:
16 .incbin "arch/x86/ia32/vsyscall-sysenter.so"
17syscall32_sysenter_end:
diff --git a/arch/x86_64/ia32/tls32.c b/arch/x86/ia32/tls32.c
index 1cc4340de3ca..1cc4340de3ca 100644
--- a/arch/x86_64/ia32/tls32.c
+++ b/arch/x86/ia32/tls32.c
diff --git a/arch/x86/ia32/vsyscall-sigreturn.S b/arch/x86/ia32/vsyscall-sigreturn.S
new file mode 100644
index 000000000000..b383be00baec
--- /dev/null
+++ b/arch/x86/ia32/vsyscall-sigreturn.S
@@ -0,0 +1,143 @@
1/*
2 * Common code for the sigreturn entry points on the vsyscall page.
3 * This code uses SYSCALL_ENTER_KERNEL (either syscall or int $0x80)
4 * to enter the kernel.
5 * This file is #include'd by vsyscall-*.S to define them after the
6 * vsyscall entry point. The addresses we get for these entry points
7 * by doing ".balign 32" must match in both versions of the page.
8 */
9
10 .code32
11 .section .text.sigreturn,"ax"
12 .balign 32
13 .globl __kernel_sigreturn
14 .type __kernel_sigreturn,@function
15__kernel_sigreturn:
16.LSTART_sigreturn:
17 popl %eax
18 movl $__NR_ia32_sigreturn, %eax
19 SYSCALL_ENTER_KERNEL
20.LEND_sigreturn:
21 .size __kernel_sigreturn,.-.LSTART_sigreturn
22
23 .section .text.rtsigreturn,"ax"
24 .balign 32
25 .globl __kernel_rt_sigreturn
26 .type __kernel_rt_sigreturn,@function
27__kernel_rt_sigreturn:
28.LSTART_rt_sigreturn:
29 movl $__NR_ia32_rt_sigreturn, %eax
30 SYSCALL_ENTER_KERNEL
31.LEND_rt_sigreturn:
32 .size __kernel_rt_sigreturn,.-.LSTART_rt_sigreturn
33
34 .section .eh_frame,"a",@progbits
35.LSTARTFRAMES:
36 .long .LENDCIES-.LSTARTCIES
37.LSTARTCIES:
38 .long 0 /* CIE ID */
39 .byte 1 /* Version number */
40 .string "zRS" /* NUL-terminated augmentation string */
41 .uleb128 1 /* Code alignment factor */
42 .sleb128 -4 /* Data alignment factor */
43 .byte 8 /* Return address register column */
44 .uleb128 1 /* Augmentation value length */
45 .byte 0x1b /* DW_EH_PE_pcrel|DW_EH_PE_sdata4. */
46 .byte 0x0c /* DW_CFA_def_cfa */
47 .uleb128 4
48 .uleb128 4
49 .byte 0x88 /* DW_CFA_offset, column 0x8 */
50 .uleb128 1
51 .align 4
52.LENDCIES:
53
54 .long .LENDFDE2-.LSTARTFDE2 /* Length FDE */
55.LSTARTFDE2:
56 .long .LSTARTFDE2-.LSTARTFRAMES /* CIE pointer */
57 /* HACK: The dwarf2 unwind routines will subtract 1 from the
58 return address to get an address in the middle of the
59 presumed call instruction. Since we didn't get here via
60 a call, we need to include the nop before the real start
61 to make up for it. */
62 .long .LSTART_sigreturn-1-. /* PC-relative start address */
63 .long .LEND_sigreturn-.LSTART_sigreturn+1
64 .uleb128 0 /* Augmentation length */
65 /* What follows are the instructions for the table generation.
66 We record the locations of each register saved. This is
67 complicated by the fact that the "CFA" is always assumed to
68 be the value of the stack pointer in the caller. This means
69 that we must define the CFA of this body of code to be the
70 saved value of the stack pointer in the sigcontext. Which
71 also means that there is no fixed relation to the other
72 saved registers, which means that we must use DW_CFA_expression
73 to compute their addresses. It also means that when we
74 adjust the stack with the popl, we have to do it all over again. */
75
76#define do_cfa_expr(offset) \
77 .byte 0x0f; /* DW_CFA_def_cfa_expression */ \
78 .uleb128 1f-0f; /* length */ \
790: .byte 0x74; /* DW_OP_breg4 */ \
80 .sleb128 offset; /* offset */ \
81 .byte 0x06; /* DW_OP_deref */ \
821:
83
84#define do_expr(regno, offset) \
85 .byte 0x10; /* DW_CFA_expression */ \
86 .uleb128 regno; /* regno */ \
87 .uleb128 1f-0f; /* length */ \
880: .byte 0x74; /* DW_OP_breg4 */ \
89 .sleb128 offset; /* offset */ \
901:
91
92 do_cfa_expr(IA32_SIGCONTEXT_esp+4)
93 do_expr(0, IA32_SIGCONTEXT_eax+4)
94 do_expr(1, IA32_SIGCONTEXT_ecx+4)
95 do_expr(2, IA32_SIGCONTEXT_edx+4)
96 do_expr(3, IA32_SIGCONTEXT_ebx+4)
97 do_expr(5, IA32_SIGCONTEXT_ebp+4)
98 do_expr(6, IA32_SIGCONTEXT_esi+4)
99 do_expr(7, IA32_SIGCONTEXT_edi+4)
100 do_expr(8, IA32_SIGCONTEXT_eip+4)
101
102 .byte 0x42 /* DW_CFA_advance_loc 2 -- nop; popl eax. */
103
104 do_cfa_expr(IA32_SIGCONTEXT_esp)
105 do_expr(0, IA32_SIGCONTEXT_eax)
106 do_expr(1, IA32_SIGCONTEXT_ecx)
107 do_expr(2, IA32_SIGCONTEXT_edx)
108 do_expr(3, IA32_SIGCONTEXT_ebx)
109 do_expr(5, IA32_SIGCONTEXT_ebp)
110 do_expr(6, IA32_SIGCONTEXT_esi)
111 do_expr(7, IA32_SIGCONTEXT_edi)
112 do_expr(8, IA32_SIGCONTEXT_eip)
113
114 .align 4
115.LENDFDE2:
116
117 .long .LENDFDE3-.LSTARTFDE3 /* Length FDE */
118.LSTARTFDE3:
119 .long .LSTARTFDE3-.LSTARTFRAMES /* CIE pointer */
120 /* HACK: See above wrt unwind library assumptions. */
121 .long .LSTART_rt_sigreturn-1-. /* PC-relative start address */
122 .long .LEND_rt_sigreturn-.LSTART_rt_sigreturn+1
123 .uleb128 0 /* Augmentation */
124 /* What follows are the instructions for the table generation.
125 We record the locations of each register saved. This is
126 slightly less complicated than the above, since we don't
127 modify the stack pointer in the process. */
128
129 do_cfa_expr(IA32_RT_SIGFRAME_sigcontext-4 + IA32_SIGCONTEXT_esp)
130 do_expr(0, IA32_RT_SIGFRAME_sigcontext-4 + IA32_SIGCONTEXT_eax)
131 do_expr(1, IA32_RT_SIGFRAME_sigcontext-4 + IA32_SIGCONTEXT_ecx)
132 do_expr(2, IA32_RT_SIGFRAME_sigcontext-4 + IA32_SIGCONTEXT_edx)
133 do_expr(3, IA32_RT_SIGFRAME_sigcontext-4 + IA32_SIGCONTEXT_ebx)
134 do_expr(5, IA32_RT_SIGFRAME_sigcontext-4 + IA32_SIGCONTEXT_ebp)
135 do_expr(6, IA32_RT_SIGFRAME_sigcontext-4 + IA32_SIGCONTEXT_esi)
136 do_expr(7, IA32_RT_SIGFRAME_sigcontext-4 + IA32_SIGCONTEXT_edi)
137 do_expr(8, IA32_RT_SIGFRAME_sigcontext-4 + IA32_SIGCONTEXT_eip)
138
139 .align 4
140.LENDFDE3:
141
142#include "../../x86/kernel/vsyscall-note_32.S"
143
diff --git a/arch/x86_64/ia32/vsyscall-syscall.S b/arch/x86/ia32/vsyscall-syscall.S
index cf9ef678de3e..cf9ef678de3e 100644
--- a/arch/x86_64/ia32/vsyscall-syscall.S
+++ b/arch/x86/ia32/vsyscall-syscall.S
diff --git a/arch/x86_64/ia32/vsyscall-sysenter.S b/arch/x86/ia32/vsyscall-sysenter.S
index ae056e553d13..ae056e553d13 100644
--- a/arch/x86_64/ia32/vsyscall-sysenter.S
+++ b/arch/x86/ia32/vsyscall-sysenter.S
diff --git a/arch/x86_64/ia32/vsyscall.lds b/arch/x86/ia32/vsyscall.lds
index 1dc86ff5bcb9..1dc86ff5bcb9 100644
--- a/arch/x86_64/ia32/vsyscall.lds
+++ b/arch/x86/ia32/vsyscall.lds
diff --git a/arch/i386/kernel/.gitignore b/arch/x86/kernel/.gitignore
index 40836ad9079c..40836ad9079c 100644
--- a/arch/i386/kernel/.gitignore
+++ b/arch/x86/kernel/.gitignore
diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
new file mode 100644
index 000000000000..45855c97923e
--- /dev/null
+++ b/arch/x86/kernel/Makefile
@@ -0,0 +1,5 @@
1ifeq ($(CONFIG_X86_32),y)
2include ${srctree}/arch/x86/kernel/Makefile_32
3else
4include ${srctree}/arch/x86/kernel/Makefile_64
5endif
diff --git a/arch/x86/kernel/Makefile_32 b/arch/x86/kernel/Makefile_32
new file mode 100644
index 000000000000..c624193740fd
--- /dev/null
+++ b/arch/x86/kernel/Makefile_32
@@ -0,0 +1,86 @@
1#
2# Makefile for the linux kernel.
3#
4
5extra-y := head_32.o init_task_32.o vmlinux.lds
6
7obj-y := process_32.o signal_32.o entry_32.o traps_32.o irq_32.o \
8 ptrace_32.o time_32.o ioport_32.o ldt_32.o setup_32.o i8259_32.o sys_i386_32.o \
9 pci-dma_32.o i386_ksyms_32.o i387_32.o bootflag.o e820_32.o\
10 quirks.o i8237.o topology.o alternative.o i8253_32.o tsc_32.o
11
12obj-$(CONFIG_STACKTRACE) += stacktrace.o
13obj-y += cpu/
14obj-y += acpi/
15obj-$(CONFIG_X86_BIOS_REBOOT) += reboot_32.o
16obj-$(CONFIG_MCA) += mca_32.o
17obj-$(CONFIG_X86_MSR) += msr.o
18obj-$(CONFIG_X86_CPUID) += cpuid.o
19obj-$(CONFIG_MICROCODE) += microcode.o
20obj-$(CONFIG_APM) += apm_32.o
21obj-$(CONFIG_X86_SMP) += smp_32.o smpboot_32.o tsc_sync.o
22obj-$(CONFIG_SMP) += smpcommon_32.o
23obj-$(CONFIG_X86_TRAMPOLINE) += trampoline_32.o
24obj-$(CONFIG_X86_MPPARSE) += mpparse_32.o
25obj-$(CONFIG_X86_LOCAL_APIC) += apic_32.o nmi_32.o
26obj-$(CONFIG_X86_IO_APIC) += io_apic_32.o
27obj-$(CONFIG_X86_REBOOTFIXUPS) += reboot_fixups_32.o
28obj-$(CONFIG_KEXEC) += machine_kexec_32.o relocate_kernel_32.o crash_32.o
29obj-$(CONFIG_CRASH_DUMP) += crash_dump_32.o
30obj-$(CONFIG_X86_NUMAQ) += numaq_32.o
31obj-$(CONFIG_X86_SUMMIT_NUMA) += summit_32.o
32obj-$(CONFIG_KPROBES) += kprobes_32.o
33obj-$(CONFIG_MODULES) += module_32.o
34obj-y += sysenter_32.o vsyscall_32.o
35obj-$(CONFIG_ACPI_SRAT) += srat_32.o
36obj-$(CONFIG_EFI) += efi_32.o efi_stub_32.o
37obj-$(CONFIG_DOUBLEFAULT) += doublefault_32.o
38obj-$(CONFIG_VM86) += vm86_32.o
39obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
40obj-$(CONFIG_HPET_TIMER) += hpet_32.o
41obj-$(CONFIG_K8_NB) += k8.o
42obj-$(CONFIG_MGEODE_LX) += geode_32.o
43
44obj-$(CONFIG_VMI) += vmi_32.o vmiclock_32.o
45obj-$(CONFIG_PARAVIRT) += paravirt_32.o
46obj-y += pcspeaker.o
47
48obj-$(CONFIG_SCx200) += scx200_32.o
49
50# vsyscall_32.o contains the vsyscall DSO images as __initdata.
51# We must build both images before we can assemble it.
52# Note: kbuild does not track this dependency due to usage of .incbin
53$(obj)/vsyscall_32.o: $(obj)/vsyscall-int80_32.so $(obj)/vsyscall-sysenter_32.so
54targets += $(foreach F,int80 sysenter,vsyscall-$F.o vsyscall-$F.so)
55targets += vsyscall-note_32.o vsyscall_32.lds
56
57# The DSO images are built using a special linker script.
58quiet_cmd_syscall = SYSCALL $@
59 cmd_syscall = $(CC) -m elf_i386 -nostdlib $(SYSCFLAGS_$(@F)) \
60 -Wl,-T,$(filter-out FORCE,$^) -o $@
61
62export CPPFLAGS_vsyscall_32.lds += -P -C -U$(ARCH)
63
64vsyscall-flags = -shared -s -Wl,-soname=linux-gate.so.1 \
65 $(call ld-option, -Wl$(comma)--hash-style=sysv)
66SYSCFLAGS_vsyscall-sysenter_32.so = $(vsyscall-flags)
67SYSCFLAGS_vsyscall-int80_32.so = $(vsyscall-flags)
68
69$(obj)/vsyscall-int80_32.so $(obj)/vsyscall-sysenter_32.so: \
70$(obj)/vsyscall-%.so: $(src)/vsyscall_32.lds \
71 $(obj)/vsyscall-%.o $(obj)/vsyscall-note_32.o FORCE
72 $(call if_changed,syscall)
73
74# We also create a special relocatable object that should mirror the symbol
75# table and layout of the linked DSO. With ld -R we can then refer to
76# these symbols in the kernel code rather than hand-coded addresses.
77extra-y += vsyscall-syms.o
78$(obj)/built-in.o: $(obj)/vsyscall-syms.o
79$(obj)/built-in.o: ld_flags += -R $(obj)/vsyscall-syms.o
80
81SYSCFLAGS_vsyscall-syms.o = -r
82$(obj)/vsyscall-syms.o: $(src)/vsyscall_32.lds \
83 $(obj)/vsyscall-sysenter_32.o $(obj)/vsyscall-note_32.o FORCE
84 $(call if_changed,syscall)
85
86
diff --git a/arch/x86/kernel/Makefile_64 b/arch/x86/kernel/Makefile_64
new file mode 100644
index 000000000000..3ab017a0a3b9
--- /dev/null
+++ b/arch/x86/kernel/Makefile_64
@@ -0,0 +1,54 @@
1#
2# Makefile for the linux kernel.
3#
4
5extra-y := head_64.o head64.o init_task_64.o vmlinux.lds
6EXTRA_AFLAGS := -traditional
7obj-y := process_64.o signal_64.o entry_64.o traps_64.o irq_64.o \
8 ptrace_64.o time_64.o ioport_64.o ldt_64.o setup_64.o i8259_64.o sys_x86_64.o \
9 x8664_ksyms_64.o i387_64.o syscall_64.o vsyscall_64.o \
10 setup64.o bootflag.o e820_64.o reboot_64.o quirks.o i8237.o \
11 pci-dma_64.o pci-nommu_64.o alternative.o hpet_64.o tsc_64.o bugs_64.o \
12 perfctr-watchdog.o
13
14obj-$(CONFIG_STACKTRACE) += stacktrace.o
15obj-$(CONFIG_X86_MCE) += mce_64.o therm_throt.o
16obj-$(CONFIG_X86_MCE_INTEL) += mce_intel_64.o
17obj-$(CONFIG_X86_MCE_AMD) += mce_amd_64.o
18obj-$(CONFIG_MTRR) += cpu/mtrr/
19obj-$(CONFIG_ACPI) += acpi/
20obj-$(CONFIG_X86_MSR) += msr.o
21obj-$(CONFIG_MICROCODE) += microcode.o
22obj-$(CONFIG_X86_CPUID) += cpuid.o
23obj-$(CONFIG_SMP) += smp_64.o smpboot_64.o trampoline_64.o tsc_sync.o
24obj-y += apic_64.o nmi_64.o
25obj-y += io_apic_64.o mpparse_64.o genapic_64.o genapic_flat_64.o
26obj-$(CONFIG_KEXEC) += machine_kexec_64.o relocate_kernel_64.o crash_64.o
27obj-$(CONFIG_CRASH_DUMP) += crash_dump_64.o
28obj-$(CONFIG_PM) += suspend_64.o
29obj-$(CONFIG_HIBERNATION) += suspend_asm_64.o
30obj-$(CONFIG_CPU_FREQ) += cpu/cpufreq/
31obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
32obj-$(CONFIG_IOMMU) += pci-gart_64.o aperture_64.o
33obj-$(CONFIG_CALGARY_IOMMU) += pci-calgary_64.o tce_64.o
34obj-$(CONFIG_SWIOTLB) += pci-swiotlb_64.o
35obj-$(CONFIG_KPROBES) += kprobes_64.o
36obj-$(CONFIG_X86_PM_TIMER) += pmtimer_64.o
37obj-$(CONFIG_X86_VSMP) += vsmp_64.o
38obj-$(CONFIG_K8_NB) += k8.o
39obj-$(CONFIG_AUDIT) += audit_64.o
40
41obj-$(CONFIG_MODULES) += module_64.o
42obj-$(CONFIG_PCI) += early-quirks_64.o
43
44obj-y += topology.o
45obj-y += intel_cacheinfo.o
46obj-y += addon_cpuid_features.o
47obj-y += pcspeaker.o
48
49CFLAGS_vsyscall_64.o := $(PROFILING) -g0
50
51therm_throt-y += cpu/mcheck/therm_throt.o
52intel_cacheinfo-y += cpu/intel_cacheinfo.o
53addon_cpuid_features-y += cpu/addon_cpuid_features.o
54perfctr-watchdog-y += cpu/perfctr-watchdog.o
diff --git a/arch/x86/kernel/acpi/Makefile b/arch/x86/kernel/acpi/Makefile
new file mode 100644
index 000000000000..3d5671939542
--- /dev/null
+++ b/arch/x86/kernel/acpi/Makefile
@@ -0,0 +1,5 @@
1ifeq ($(CONFIG_X86_32),y)
2include ${srctree}/arch/x86/kernel/acpi/Makefile_32
3else
4include ${srctree}/arch/x86/kernel/acpi/Makefile_64
5endif
diff --git a/arch/x86/kernel/acpi/Makefile_32 b/arch/x86/kernel/acpi/Makefile_32
new file mode 100644
index 000000000000..a4852a2e9190
--- /dev/null
+++ b/arch/x86/kernel/acpi/Makefile_32
@@ -0,0 +1,10 @@
1obj-$(CONFIG_ACPI) += boot.o
2ifneq ($(CONFIG_PCI),)
3obj-$(CONFIG_X86_IO_APIC) += earlyquirk_32.o
4endif
5obj-$(CONFIG_ACPI_SLEEP) += sleep_32.o wakeup_32.o
6
7ifneq ($(CONFIG_ACPI_PROCESSOR),)
8obj-y += cstate.o processor.o
9endif
10
diff --git a/arch/x86/kernel/acpi/Makefile_64 b/arch/x86/kernel/acpi/Makefile_64
new file mode 100644
index 000000000000..629425bc002d
--- /dev/null
+++ b/arch/x86/kernel/acpi/Makefile_64
@@ -0,0 +1,7 @@
1obj-y := boot.o
2obj-$(CONFIG_ACPI_SLEEP) += sleep_64.o wakeup_64.o
3
4ifneq ($(CONFIG_ACPI_PROCESSOR),)
5obj-y += processor.o cstate.o
6endif
7
diff --git a/arch/i386/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
index afd2afe9102d..afd2afe9102d 100644
--- a/arch/i386/kernel/acpi/boot.c
+++ b/arch/x86/kernel/acpi/boot.c
diff --git a/arch/i386/kernel/acpi/cstate.c b/arch/x86/kernel/acpi/cstate.c
index 2d39f55d29a8..2d39f55d29a8 100644
--- a/arch/i386/kernel/acpi/cstate.c
+++ b/arch/x86/kernel/acpi/cstate.c
diff --git a/arch/i386/kernel/acpi/earlyquirk.c b/arch/x86/kernel/acpi/earlyquirk_32.c
index 23f78efc577d..23f78efc577d 100644
--- a/arch/i386/kernel/acpi/earlyquirk.c
+++ b/arch/x86/kernel/acpi/earlyquirk_32.c
diff --git a/arch/i386/kernel/acpi/processor.c b/arch/x86/kernel/acpi/processor.c
index b54fded49834..b54fded49834 100644
--- a/arch/i386/kernel/acpi/processor.c
+++ b/arch/x86/kernel/acpi/processor.c
diff --git a/arch/i386/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep_32.c
index 10699489cfe7..10699489cfe7 100644
--- a/arch/i386/kernel/acpi/sleep.c
+++ b/arch/x86/kernel/acpi/sleep_32.c
diff --git a/arch/x86_64/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep_64.c
index 79475d237071..79475d237071 100644
--- a/arch/x86_64/kernel/acpi/sleep.c
+++ b/arch/x86/kernel/acpi/sleep_64.c
diff --git a/arch/i386/kernel/acpi/wakeup.S b/arch/x86/kernel/acpi/wakeup_32.S
index f22ba8534d26..f22ba8534d26 100644
--- a/arch/i386/kernel/acpi/wakeup.S
+++ b/arch/x86/kernel/acpi/wakeup_32.S
diff --git a/arch/x86/kernel/acpi/wakeup_64.S b/arch/x86/kernel/acpi/wakeup_64.S
new file mode 100644
index 000000000000..8b4357e1efe0
--- /dev/null
+++ b/arch/x86/kernel/acpi/wakeup_64.S
@@ -0,0 +1,456 @@
1.text
2#include <linux/linkage.h>
3#include <asm/segment.h>
4#include <asm/pgtable.h>
5#include <asm/page.h>
6#include <asm/msr.h>
7
8# Copyright 2003 Pavel Machek <pavel@suse.cz>, distribute under GPLv2
9#
10# wakeup_code runs in real mode, and at unknown address (determined at run-time).
11# Therefore it must only use relative jumps/calls.
12#
13# Do we need to deal with A20? It is okay: ACPI specs says A20 must be enabled
14#
15# If physical address of wakeup_code is 0x12345, BIOS should call us with
16# cs = 0x1234, eip = 0x05
17#
18
19#define BEEP \
20 inb $97, %al; \
21 outb %al, $0x80; \
22 movb $3, %al; \
23 outb %al, $97; \
24 outb %al, $0x80; \
25 movb $-74, %al; \
26 outb %al, $67; \
27 outb %al, $0x80; \
28 movb $-119, %al; \
29 outb %al, $66; \
30 outb %al, $0x80; \
31 movb $15, %al; \
32 outb %al, $66;
33
34
35ALIGN
36 .align 16
37ENTRY(wakeup_start)
38wakeup_code:
39 wakeup_code_start = .
40 .code16
41
42# Running in *copy* of this code, somewhere in low 1MB.
43
44 movb $0xa1, %al ; outb %al, $0x80
45 cli
46 cld
47 # setup data segment
48 movw %cs, %ax
49 movw %ax, %ds # Make ds:0 point to wakeup_start
50 movw %ax, %ss
51
52 # Data segment must be set up before we can see whether to beep.
53 testl $4, realmode_flags - wakeup_code
54 jz 1f
55 BEEP
561:
57
58 # Private stack is needed for ASUS board
59 mov $(wakeup_stack - wakeup_code), %sp
60
61 pushl $0 # Kill any dangerous flags
62 popfl
63
64 movl real_magic - wakeup_code, %eax
65 cmpl $0x12345678, %eax
66 jne bogus_real_magic
67
68 call verify_cpu # Verify the cpu supports long
69 # mode
70 testl %eax, %eax
71 jnz no_longmode
72
73 testl $1, realmode_flags - wakeup_code
74 jz 1f
75 lcall $0xc000,$3
76 movw %cs, %ax
77 movw %ax, %ds # Bios might have played with that
78 movw %ax, %ss
791:
80
81 testl $2, realmode_flags - wakeup_code
82 jz 1f
83 mov video_mode - wakeup_code, %ax
84 call mode_set
851:
86
87 movw $0xb800, %ax
88 movw %ax,%fs
89 movw $0x0e00 + 'L', %fs:(0x10)
90
91 movb $0xa2, %al ; outb %al, $0x80
92
93 mov %ds, %ax # Find 32bit wakeup_code addr
94 movzx %ax, %esi # (Convert %ds:gdt to a liner ptr)
95 shll $4, %esi
96 # Fix up the vectors
97 addl %esi, wakeup_32_vector - wakeup_code
98 addl %esi, wakeup_long64_vector - wakeup_code
99 addl %esi, gdt_48a + 2 - wakeup_code # Fixup the gdt pointer
100
101 lidtl %ds:idt_48a - wakeup_code
102 lgdtl %ds:gdt_48a - wakeup_code # load gdt with whatever is
103 # appropriate
104
105 movl $1, %eax # protected mode (PE) bit
106 lmsw %ax # This is it!
107 jmp 1f
1081:
109
110 ljmpl *(wakeup_32_vector - wakeup_code)
111
112 .balign 4
113wakeup_32_vector:
114 .long wakeup_32 - wakeup_code
115 .word __KERNEL32_CS, 0
116
117 .code32
118wakeup_32:
119# Running in this code, but at low address; paging is not yet turned on.
120 movb $0xa5, %al ; outb %al, $0x80
121
122 movl $__KERNEL_DS, %eax
123 movl %eax, %ds
124
125 movw $0x0e00 + 'i', %ds:(0xb8012)
126 movb $0xa8, %al ; outb %al, $0x80;
127
128 /*
129 * Prepare for entering 64bits mode
130 */
131
132 /* Enable PAE */
133 xorl %eax, %eax
134 btsl $5, %eax
135 movl %eax, %cr4
136
137 /* Setup early boot stage 4 level pagetables */
138 leal (wakeup_level4_pgt - wakeup_code)(%esi), %eax
139 movl %eax, %cr3
140
141 /* Check if nx is implemented */
142 movl $0x80000001, %eax
143 cpuid
144 movl %edx,%edi
145
146 /* Enable Long Mode */
147 xorl %eax, %eax
148 btsl $_EFER_LME, %eax
149
150 /* No Execute supported? */
151 btl $20,%edi
152 jnc 1f
153 btsl $_EFER_NX, %eax
154
155 /* Make changes effective */
1561: movl $MSR_EFER, %ecx
157 xorl %edx, %edx
158 wrmsr
159
160 xorl %eax, %eax
161 btsl $31, %eax /* Enable paging and in turn activate Long Mode */
162 btsl $0, %eax /* Enable protected mode */
163
164 /* Make changes effective */
165 movl %eax, %cr0
166
167 /* At this point:
168 CR4.PAE must be 1
169 CS.L must be 0
170 CR3 must point to PML4
171 Next instruction must be a branch
172 This must be on identity-mapped page
173 */
174 /*
175 * At this point we're in long mode but in 32bit compatibility mode
176 * with EFER.LME = 1, CS.L = 0, CS.D = 1 (and in turn
177 * EFER.LMA = 1). Now we want to jump in 64bit mode, to do that we load
178 * the new gdt/idt that has __KERNEL_CS with CS.L = 1.
179 */
180
181 /* Finally jump in 64bit mode */
182 ljmp *(wakeup_long64_vector - wakeup_code)(%esi)
183
184 .balign 4
185wakeup_long64_vector:
186 .long wakeup_long64 - wakeup_code
187 .word __KERNEL_CS, 0
188
189.code64
190
191 /* Hooray, we are in Long 64-bit mode (but still running in
192 * low memory)
193 */
194wakeup_long64:
195 /*
196 * We must switch to a new descriptor in kernel space for the GDT
197 * because soon the kernel won't have access anymore to the userspace
198 * addresses where we're currently running on. We have to do that here
199 * because in 32bit we couldn't load a 64bit linear address.
200 */
201 lgdt cpu_gdt_descr
202
203 movw $0x0e00 + 'n', %ds:(0xb8014)
204 movb $0xa9, %al ; outb %al, $0x80
205
206 movq saved_magic, %rax
207 movq $0x123456789abcdef0, %rdx
208 cmpq %rdx, %rax
209 jne bogus_64_magic
210
211 movw $0x0e00 + 'u', %ds:(0xb8016)
212
213 nop
214 nop
215 movw $__KERNEL_DS, %ax
216 movw %ax, %ss
217 movw %ax, %ds
218 movw %ax, %es
219 movw %ax, %fs
220 movw %ax, %gs
221 movq saved_rsp, %rsp
222
223 movw $0x0e00 + 'x', %ds:(0xb8018)
224 movq saved_rbx, %rbx
225 movq saved_rdi, %rdi
226 movq saved_rsi, %rsi
227 movq saved_rbp, %rbp
228
229 movw $0x0e00 + '!', %ds:(0xb801a)
230 movq saved_rip, %rax
231 jmp *%rax
232
233.code32
234
235 .align 64
236gdta:
237 /* Its good to keep gdt in sync with one in trampoline.S */
238 .word 0, 0, 0, 0 # dummy
239 /* ??? Why I need the accessed bit set in order for this to work? */
240 .quad 0x00cf9b000000ffff # __KERNEL32_CS
241 .quad 0x00af9b000000ffff # __KERNEL_CS
242 .quad 0x00cf93000000ffff # __KERNEL_DS
243
244idt_48a:
245 .word 0 # idt limit = 0
246 .word 0, 0 # idt base = 0L
247
248gdt_48a:
249 .word 0x800 # gdt limit=2048,
250 # 256 GDT entries
251 .long gdta - wakeup_code # gdt base (relocated in later)
252
253real_magic: .quad 0
254video_mode: .quad 0
255realmode_flags: .quad 0
256
257.code16
258bogus_real_magic:
259 movb $0xba,%al ; outb %al,$0x80
260 jmp bogus_real_magic
261
262.code64
263bogus_64_magic:
264 movb $0xb3,%al ; outb %al,$0x80
265 jmp bogus_64_magic
266
267.code16
268no_longmode:
269 movb $0xbc,%al ; outb %al,$0x80
270 jmp no_longmode
271
272#include "../verify_cpu_64.S"
273
274/* This code uses an extended set of video mode numbers. These include:
275 * Aliases for standard modes
276 * NORMAL_VGA (-1)
277 * EXTENDED_VGA (-2)
278 * ASK_VGA (-3)
279 * Video modes numbered by menu position -- NOT RECOMMENDED because of lack
280 * of compatibility when extending the table. These are between 0x00 and 0xff.
281 */
282#define VIDEO_FIRST_MENU 0x0000
283
284/* Standard BIOS video modes (BIOS number + 0x0100) */
285#define VIDEO_FIRST_BIOS 0x0100
286
287/* VESA BIOS video modes (VESA number + 0x0200) */
288#define VIDEO_FIRST_VESA 0x0200
289
290/* Video7 special modes (BIOS number + 0x0900) */
291#define VIDEO_FIRST_V7 0x0900
292
293# Setting of user mode (AX=mode ID) => CF=success
294
295# For now, we only handle VESA modes (0x0200..0x03ff). To handle other
296# modes, we should probably compile in the video code from the boot
297# directory.
298.code16
299mode_set:
300 movw %ax, %bx
301 subb $VIDEO_FIRST_VESA>>8, %bh
302 cmpb $2, %bh
303 jb check_vesa
304
305setbad:
306 clc
307 ret
308
309check_vesa:
310 orw $0x4000, %bx # Use linear frame buffer
311 movw $0x4f02, %ax # VESA BIOS mode set call
312 int $0x10
313 cmpw $0x004f, %ax # AL=4f if implemented
314 jnz setbad # AH=0 if OK
315
316 stc
317 ret
318
319wakeup_stack_begin: # Stack grows down
320
321.org 0xff0
322wakeup_stack: # Just below end of page
323
324.org 0x1000
325ENTRY(wakeup_level4_pgt)
326 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
327 .fill 510,8,0
328 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
329 .quad level3_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
330
331ENTRY(wakeup_end)
332
333##
334# acpi_copy_wakeup_routine
335#
336# Copy the above routine to low memory.
337#
338# Parameters:
339# %rdi: place to copy wakeup routine to
340#
341# Returned address is location of code in low memory (past data and stack)
342#
343 .code64
344ENTRY(acpi_copy_wakeup_routine)
345 pushq %rax
346 pushq %rdx
347
348 movl saved_video_mode, %edx
349 movl %edx, video_mode - wakeup_start (,%rdi)
350 movl acpi_realmode_flags, %edx
351 movl %edx, realmode_flags - wakeup_start (,%rdi)
352 movq $0x12345678, real_magic - wakeup_start (,%rdi)
353 movq $0x123456789abcdef0, %rdx
354 movq %rdx, saved_magic
355
356 movq saved_magic, %rax
357 movq $0x123456789abcdef0, %rdx
358 cmpq %rdx, %rax
359 jne bogus_64_magic
360
361 # restore the regs we used
362 popq %rdx
363 popq %rax
364ENTRY(do_suspend_lowlevel_s4bios)
365 ret
366
367 .align 2
368 .p2align 4,,15
369.globl do_suspend_lowlevel
370 .type do_suspend_lowlevel,@function
371do_suspend_lowlevel:
372.LFB5:
373 subq $8, %rsp
374 xorl %eax, %eax
375 call save_processor_state
376
377 movq %rsp, saved_context_esp(%rip)
378 movq %rax, saved_context_eax(%rip)
379 movq %rbx, saved_context_ebx(%rip)
380 movq %rcx, saved_context_ecx(%rip)
381 movq %rdx, saved_context_edx(%rip)
382 movq %rbp, saved_context_ebp(%rip)
383 movq %rsi, saved_context_esi(%rip)
384 movq %rdi, saved_context_edi(%rip)
385 movq %r8, saved_context_r08(%rip)
386 movq %r9, saved_context_r09(%rip)
387 movq %r10, saved_context_r10(%rip)
388 movq %r11, saved_context_r11(%rip)
389 movq %r12, saved_context_r12(%rip)
390 movq %r13, saved_context_r13(%rip)
391 movq %r14, saved_context_r14(%rip)
392 movq %r15, saved_context_r15(%rip)
393 pushfq ; popq saved_context_eflags(%rip)
394
395 movq $.L97, saved_rip(%rip)
396
397 movq %rsp,saved_rsp
398 movq %rbp,saved_rbp
399 movq %rbx,saved_rbx
400 movq %rdi,saved_rdi
401 movq %rsi,saved_rsi
402
403 addq $8, %rsp
404 movl $3, %edi
405 xorl %eax, %eax
406 jmp acpi_enter_sleep_state
407.L97:
408 .p2align 4,,7
409.L99:
410 .align 4
411 movl $24, %eax
412 movw %ax, %ds
413 movq saved_context+58(%rip), %rax
414 movq %rax, %cr4
415 movq saved_context+50(%rip), %rax
416 movq %rax, %cr3
417 movq saved_context+42(%rip), %rax
418 movq %rax, %cr2
419 movq saved_context+34(%rip), %rax
420 movq %rax, %cr0
421 pushq saved_context_eflags(%rip) ; popfq
422 movq saved_context_esp(%rip), %rsp
423 movq saved_context_ebp(%rip), %rbp
424 movq saved_context_eax(%rip), %rax
425 movq saved_context_ebx(%rip), %rbx
426 movq saved_context_ecx(%rip), %rcx
427 movq saved_context_edx(%rip), %rdx
428 movq saved_context_esi(%rip), %rsi
429 movq saved_context_edi(%rip), %rdi
430 movq saved_context_r08(%rip), %r8
431 movq saved_context_r09(%rip), %r9
432 movq saved_context_r10(%rip), %r10
433 movq saved_context_r11(%rip), %r11
434 movq saved_context_r12(%rip), %r12
435 movq saved_context_r13(%rip), %r13
436 movq saved_context_r14(%rip), %r14
437 movq saved_context_r15(%rip), %r15
438
439 xorl %eax, %eax
440 addq $8, %rsp
441 jmp restore_processor_state
442.LFE5:
443.Lfe5:
444 .size do_suspend_lowlevel,.Lfe5-do_suspend_lowlevel
445
446.data
447ALIGN
448ENTRY(saved_rbp) .quad 0
449ENTRY(saved_rsi) .quad 0
450ENTRY(saved_rdi) .quad 0
451ENTRY(saved_rbx) .quad 0
452
453ENTRY(saved_rip) .quad 0
454ENTRY(saved_rsp) .quad 0
455
456ENTRY(saved_magic) .quad 0
diff --git a/arch/i386/kernel/alternative.c b/arch/x86/kernel/alternative.c
index bd72d94e713e..bd72d94e713e 100644
--- a/arch/i386/kernel/alternative.c
+++ b/arch/x86/kernel/alternative.c
diff --git a/arch/x86_64/kernel/aperture.c b/arch/x86/kernel/aperture_64.c
index 8f681cae7bf7..8f681cae7bf7 100644
--- a/arch/x86_64/kernel/aperture.c
+++ b/arch/x86/kernel/aperture_64.c
diff --git a/arch/i386/kernel/apic.c b/arch/x86/kernel/apic_32.c
index 3d67ae18d762..3d67ae18d762 100644
--- a/arch/i386/kernel/apic.c
+++ b/arch/x86/kernel/apic_32.c
diff --git a/arch/x86_64/kernel/apic.c b/arch/x86/kernel/apic_64.c
index 925758dbca0c..925758dbca0c 100644
--- a/arch/x86_64/kernel/apic.c
+++ b/arch/x86/kernel/apic_64.c
diff --git a/arch/i386/kernel/apm.c b/arch/x86/kernel/apm_32.c
index 32f2365c26ed..32f2365c26ed 100644
--- a/arch/i386/kernel/apm.c
+++ b/arch/x86/kernel/apm_32.c
diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
new file mode 100644
index 000000000000..cfa82c899f47
--- /dev/null
+++ b/arch/x86/kernel/asm-offsets.c
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "asm-offsets_32.c"
3#else
4# include "asm-offsets_64.c"
5#endif
diff --git a/arch/x86/kernel/asm-offsets_32.c b/arch/x86/kernel/asm-offsets_32.c
new file mode 100644
index 000000000000..8029742c0fc1
--- /dev/null
+++ b/arch/x86/kernel/asm-offsets_32.c
@@ -0,0 +1,147 @@
1/*
2 * Generate definitions needed by assembly language modules.
3 * This code generates raw asm output which is post-processed
4 * to extract and format the required data.
5 */
6
7#include <linux/crypto.h>
8#include <linux/sched.h>
9#include <linux/signal.h>
10#include <linux/personality.h>
11#include <linux/suspend.h>
12#include <asm/ucontext.h>
13#include "sigframe_32.h"
14#include <asm/pgtable.h>
15#include <asm/fixmap.h>
16#include <asm/processor.h>
17#include <asm/thread_info.h>
18#include <asm/elf.h>
19
20#include <xen/interface/xen.h>
21
22#ifdef CONFIG_LGUEST_GUEST
23#include <linux/lguest.h>
24#include "../../../drivers/lguest/lg.h"
25#endif
26
27#define DEFINE(sym, val) \
28 asm volatile("\n->" #sym " %0 " #val : : "i" (val))
29
30#define BLANK() asm volatile("\n->" : : )
31
32#define OFFSET(sym, str, mem) \
33 DEFINE(sym, offsetof(struct str, mem));
34
35/* workaround for a warning with -Wmissing-prototypes */
36void foo(void);
37
38void foo(void)
39{
40 OFFSET(SIGCONTEXT_eax, sigcontext, eax);
41 OFFSET(SIGCONTEXT_ebx, sigcontext, ebx);
42 OFFSET(SIGCONTEXT_ecx, sigcontext, ecx);
43 OFFSET(SIGCONTEXT_edx, sigcontext, edx);
44 OFFSET(SIGCONTEXT_esi, sigcontext, esi);
45 OFFSET(SIGCONTEXT_edi, sigcontext, edi);
46 OFFSET(SIGCONTEXT_ebp, sigcontext, ebp);
47 OFFSET(SIGCONTEXT_esp, sigcontext, esp);
48 OFFSET(SIGCONTEXT_eip, sigcontext, eip);
49 BLANK();
50
51 OFFSET(CPUINFO_x86, cpuinfo_x86, x86);
52 OFFSET(CPUINFO_x86_vendor, cpuinfo_x86, x86_vendor);
53 OFFSET(CPUINFO_x86_model, cpuinfo_x86, x86_model);
54 OFFSET(CPUINFO_x86_mask, cpuinfo_x86, x86_mask);
55 OFFSET(CPUINFO_hard_math, cpuinfo_x86, hard_math);
56 OFFSET(CPUINFO_cpuid_level, cpuinfo_x86, cpuid_level);
57 OFFSET(CPUINFO_x86_capability, cpuinfo_x86, x86_capability);
58 OFFSET(CPUINFO_x86_vendor_id, cpuinfo_x86, x86_vendor_id);
59 BLANK();
60
61 OFFSET(TI_task, thread_info, task);
62 OFFSET(TI_exec_domain, thread_info, exec_domain);
63 OFFSET(TI_flags, thread_info, flags);
64 OFFSET(TI_status, thread_info, status);
65 OFFSET(TI_preempt_count, thread_info, preempt_count);
66 OFFSET(TI_addr_limit, thread_info, addr_limit);
67 OFFSET(TI_restart_block, thread_info, restart_block);
68 OFFSET(TI_sysenter_return, thread_info, sysenter_return);
69 OFFSET(TI_cpu, thread_info, cpu);
70 BLANK();
71
72 OFFSET(GDS_size, Xgt_desc_struct, size);
73 OFFSET(GDS_address, Xgt_desc_struct, address);
74 OFFSET(GDS_pad, Xgt_desc_struct, pad);
75 BLANK();
76
77 OFFSET(PT_EBX, pt_regs, ebx);
78 OFFSET(PT_ECX, pt_regs, ecx);
79 OFFSET(PT_EDX, pt_regs, edx);
80 OFFSET(PT_ESI, pt_regs, esi);
81 OFFSET(PT_EDI, pt_regs, edi);
82 OFFSET(PT_EBP, pt_regs, ebp);
83 OFFSET(PT_EAX, pt_regs, eax);
84 OFFSET(PT_DS, pt_regs, xds);
85 OFFSET(PT_ES, pt_regs, xes);
86 OFFSET(PT_FS, pt_regs, xfs);
87 OFFSET(PT_ORIG_EAX, pt_regs, orig_eax);
88 OFFSET(PT_EIP, pt_regs, eip);
89 OFFSET(PT_CS, pt_regs, xcs);
90 OFFSET(PT_EFLAGS, pt_regs, eflags);
91 OFFSET(PT_OLDESP, pt_regs, esp);
92 OFFSET(PT_OLDSS, pt_regs, xss);
93 BLANK();
94
95 OFFSET(EXEC_DOMAIN_handler, exec_domain, handler);
96 OFFSET(RT_SIGFRAME_sigcontext, rt_sigframe, uc.uc_mcontext);
97 BLANK();
98
99 OFFSET(pbe_address, pbe, address);
100 OFFSET(pbe_orig_address, pbe, orig_address);
101 OFFSET(pbe_next, pbe, next);
102
103 /* Offset from the sysenter stack to tss.esp0 */
104 DEFINE(TSS_sysenter_esp0, offsetof(struct tss_struct, x86_tss.esp0) -
105 sizeof(struct tss_struct));
106
107 DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
108 DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
109 DEFINE(PTRS_PER_PTE, PTRS_PER_PTE);
110 DEFINE(PTRS_PER_PMD, PTRS_PER_PMD);
111 DEFINE(PTRS_PER_PGD, PTRS_PER_PGD);
112
113 DEFINE(VDSO_PRELINK_asm, VDSO_PRELINK);
114
115 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
116
117#ifdef CONFIG_PARAVIRT
118 BLANK();
119 OFFSET(PARAVIRT_enabled, paravirt_ops, paravirt_enabled);
120 OFFSET(PARAVIRT_irq_disable, paravirt_ops, irq_disable);
121 OFFSET(PARAVIRT_irq_enable, paravirt_ops, irq_enable);
122 OFFSET(PARAVIRT_irq_enable_sysexit, paravirt_ops, irq_enable_sysexit);
123 OFFSET(PARAVIRT_iret, paravirt_ops, iret);
124 OFFSET(PARAVIRT_read_cr0, paravirt_ops, read_cr0);
125#endif
126
127#ifdef CONFIG_XEN
128 BLANK();
129 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
130 OFFSET(XEN_vcpu_info_pending, vcpu_info, evtchn_upcall_pending);
131#endif
132
133#ifdef CONFIG_LGUEST_GUEST
134 BLANK();
135 OFFSET(LGUEST_DATA_irq_enabled, lguest_data, irq_enabled);
136 OFFSET(LGUEST_PAGES_host_gdt_desc, lguest_pages, state.host_gdt_desc);
137 OFFSET(LGUEST_PAGES_host_idt_desc, lguest_pages, state.host_idt_desc);
138 OFFSET(LGUEST_PAGES_host_cr3, lguest_pages, state.host_cr3);
139 OFFSET(LGUEST_PAGES_host_sp, lguest_pages, state.host_sp);
140 OFFSET(LGUEST_PAGES_guest_gdt_desc, lguest_pages,state.guest_gdt_desc);
141 OFFSET(LGUEST_PAGES_guest_idt_desc, lguest_pages,state.guest_idt_desc);
142 OFFSET(LGUEST_PAGES_guest_gdt, lguest_pages, state.guest_gdt);
143 OFFSET(LGUEST_PAGES_regs_trapnum, lguest_pages, regs.trapnum);
144 OFFSET(LGUEST_PAGES_regs_errcode, lguest_pages, regs.errcode);
145 OFFSET(LGUEST_PAGES_regs, lguest_pages, regs);
146#endif
147}
diff --git a/arch/x86_64/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets_64.c
index 778953bc636c..778953bc636c 100644
--- a/arch/x86_64/kernel/asm-offsets.c
+++ b/arch/x86/kernel/asm-offsets_64.c
diff --git a/arch/x86_64/kernel/audit.c b/arch/x86/kernel/audit_64.c
index 06d3e5a14d9d..06d3e5a14d9d 100644
--- a/arch/x86_64/kernel/audit.c
+++ b/arch/x86/kernel/audit_64.c
diff --git a/arch/i386/kernel/bootflag.c b/arch/x86/kernel/bootflag.c
index 0b9860530a6b..0b9860530a6b 100644
--- a/arch/i386/kernel/bootflag.c
+++ b/arch/x86/kernel/bootflag.c
diff --git a/arch/x86_64/kernel/bugs.c b/arch/x86/kernel/bugs_64.c
index 4e5e9d364d63..4e5e9d364d63 100644
--- a/arch/x86_64/kernel/bugs.c
+++ b/arch/x86/kernel/bugs_64.c
diff --git a/arch/i386/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
index 778396c78d65..778396c78d65 100644
--- a/arch/i386/kernel/cpu/Makefile
+++ b/arch/x86/kernel/cpu/Makefile
diff --git a/arch/i386/kernel/cpu/addon_cpuid_features.c b/arch/x86/kernel/cpu/addon_cpuid_features.c
index 3e91d3ee26ec..3e91d3ee26ec 100644
--- a/arch/i386/kernel/cpu/addon_cpuid_features.c
+++ b/arch/x86/kernel/cpu/addon_cpuid_features.c
diff --git a/arch/i386/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
index dcf6bbb1c7c0..dcf6bbb1c7c0 100644
--- a/arch/i386/kernel/cpu/amd.c
+++ b/arch/x86/kernel/cpu/amd.c
diff --git a/arch/i386/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
index 59266f03d1cd..59266f03d1cd 100644
--- a/arch/i386/kernel/cpu/bugs.c
+++ b/arch/x86/kernel/cpu/bugs.c
diff --git a/arch/i386/kernel/cpu/centaur.c b/arch/x86/kernel/cpu/centaur.c
index 473eac883c7b..473eac883c7b 100644
--- a/arch/i386/kernel/cpu/centaur.c
+++ b/arch/x86/kernel/cpu/centaur.c
diff --git a/arch/i386/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index d506201d397c..d506201d397c 100644
--- a/arch/i386/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
diff --git a/arch/i386/kernel/cpu/cpu.h b/arch/x86/kernel/cpu/cpu.h
index 2f6432cef6ff..2f6432cef6ff 100644
--- a/arch/i386/kernel/cpu/cpu.h
+++ b/arch/x86/kernel/cpu/cpu.h
diff --git a/arch/i386/kernel/cpu/cpufreq/Kconfig b/arch/x86/kernel/cpu/cpufreq/Kconfig
index d8c6f132dc7a..d8c6f132dc7a 100644
--- a/arch/i386/kernel/cpu/cpufreq/Kconfig
+++ b/arch/x86/kernel/cpu/cpufreq/Kconfig
diff --git a/arch/i386/kernel/cpu/cpufreq/Makefile b/arch/x86/kernel/cpu/cpufreq/Makefile
index 560f7760dae5..560f7760dae5 100644
--- a/arch/i386/kernel/cpu/cpufreq/Makefile
+++ b/arch/x86/kernel/cpu/cpufreq/Makefile
diff --git a/arch/i386/kernel/cpu/cpufreq/acpi-cpufreq.c b/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c
index b6434a7ef8b2..b6434a7ef8b2 100644
--- a/arch/i386/kernel/cpu/cpufreq/acpi-cpufreq.c
+++ b/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c
diff --git a/arch/i386/kernel/cpu/cpufreq/cpufreq-nforce2.c b/arch/x86/kernel/cpu/cpufreq/cpufreq-nforce2.c
index 66acd5039918..66acd5039918 100644
--- a/arch/i386/kernel/cpu/cpufreq/cpufreq-nforce2.c
+++ b/arch/x86/kernel/cpu/cpufreq/cpufreq-nforce2.c
diff --git a/arch/i386/kernel/cpu/cpufreq/e_powersaver.c b/arch/x86/kernel/cpu/cpufreq/e_powersaver.c
index f43d98e11cc7..f43d98e11cc7 100644
--- a/arch/i386/kernel/cpu/cpufreq/e_powersaver.c
+++ b/arch/x86/kernel/cpu/cpufreq/e_powersaver.c
diff --git a/arch/i386/kernel/cpu/cpufreq/elanfreq.c b/arch/x86/kernel/cpu/cpufreq/elanfreq.c
index f317276afa7a..f317276afa7a 100644
--- a/arch/i386/kernel/cpu/cpufreq/elanfreq.c
+++ b/arch/x86/kernel/cpu/cpufreq/elanfreq.c
diff --git a/arch/i386/kernel/cpu/cpufreq/gx-suspmod.c b/arch/x86/kernel/cpu/cpufreq/gx-suspmod.c
index 461dabc4e495..461dabc4e495 100644
--- a/arch/i386/kernel/cpu/cpufreq/gx-suspmod.c
+++ b/arch/x86/kernel/cpu/cpufreq/gx-suspmod.c
diff --git a/arch/i386/kernel/cpu/cpufreq/longhaul.c b/arch/x86/kernel/cpu/cpufreq/longhaul.c
index f0cce3c2dc3a..f0cce3c2dc3a 100644
--- a/arch/i386/kernel/cpu/cpufreq/longhaul.c
+++ b/arch/x86/kernel/cpu/cpufreq/longhaul.c
diff --git a/arch/i386/kernel/cpu/cpufreq/longhaul.h b/arch/x86/kernel/cpu/cpufreq/longhaul.h
index 4fcc320997df..4fcc320997df 100644
--- a/arch/i386/kernel/cpu/cpufreq/longhaul.h
+++ b/arch/x86/kernel/cpu/cpufreq/longhaul.h
diff --git a/arch/i386/kernel/cpu/cpufreq/longrun.c b/arch/x86/kernel/cpu/cpufreq/longrun.c
index b2689514295a..b2689514295a 100644
--- a/arch/i386/kernel/cpu/cpufreq/longrun.c
+++ b/arch/x86/kernel/cpu/cpufreq/longrun.c
diff --git a/arch/i386/kernel/cpu/cpufreq/p4-clockmod.c b/arch/x86/kernel/cpu/cpufreq/p4-clockmod.c
index 4c76b511e194..4c76b511e194 100644
--- a/arch/i386/kernel/cpu/cpufreq/p4-clockmod.c
+++ b/arch/x86/kernel/cpu/cpufreq/p4-clockmod.c
diff --git a/arch/i386/kernel/cpu/cpufreq/powernow-k6.c b/arch/x86/kernel/cpu/cpufreq/powernow-k6.c
index f89524051e4a..f89524051e4a 100644
--- a/arch/i386/kernel/cpu/cpufreq/powernow-k6.c
+++ b/arch/x86/kernel/cpu/cpufreq/powernow-k6.c
diff --git a/arch/i386/kernel/cpu/cpufreq/powernow-k7.c b/arch/x86/kernel/cpu/cpufreq/powernow-k7.c
index ca3e1d341889..ca3e1d341889 100644
--- a/arch/i386/kernel/cpu/cpufreq/powernow-k7.c
+++ b/arch/x86/kernel/cpu/cpufreq/powernow-k7.c
diff --git a/arch/i386/kernel/cpu/cpufreq/powernow-k7.h b/arch/x86/kernel/cpu/cpufreq/powernow-k7.h
index f8a63b3664e3..f8a63b3664e3 100644
--- a/arch/i386/kernel/cpu/cpufreq/powernow-k7.h
+++ b/arch/x86/kernel/cpu/cpufreq/powernow-k7.h
diff --git a/arch/i386/kernel/cpu/cpufreq/powernow-k8.c b/arch/x86/kernel/cpu/cpufreq/powernow-k8.c
index 34ed53a06730..34ed53a06730 100644
--- a/arch/i386/kernel/cpu/cpufreq/powernow-k8.c
+++ b/arch/x86/kernel/cpu/cpufreq/powernow-k8.c
diff --git a/arch/i386/kernel/cpu/cpufreq/powernow-k8.h b/arch/x86/kernel/cpu/cpufreq/powernow-k8.h
index b06c812208ca..b06c812208ca 100644
--- a/arch/i386/kernel/cpu/cpufreq/powernow-k8.h
+++ b/arch/x86/kernel/cpu/cpufreq/powernow-k8.h
diff --git a/arch/i386/kernel/cpu/cpufreq/sc520_freq.c b/arch/x86/kernel/cpu/cpufreq/sc520_freq.c
index b8fb4b521c62..b8fb4b521c62 100644
--- a/arch/i386/kernel/cpu/cpufreq/sc520_freq.c
+++ b/arch/x86/kernel/cpu/cpufreq/sc520_freq.c
diff --git a/arch/i386/kernel/cpu/cpufreq/speedstep-centrino.c b/arch/x86/kernel/cpu/cpufreq/speedstep-centrino.c
index 6c5dc2c85aeb..6c5dc2c85aeb 100644
--- a/arch/i386/kernel/cpu/cpufreq/speedstep-centrino.c
+++ b/arch/x86/kernel/cpu/cpufreq/speedstep-centrino.c
diff --git a/arch/i386/kernel/cpu/cpufreq/speedstep-ich.c b/arch/x86/kernel/cpu/cpufreq/speedstep-ich.c
index a5b2346faf1f..a5b2346faf1f 100644
--- a/arch/i386/kernel/cpu/cpufreq/speedstep-ich.c
+++ b/arch/x86/kernel/cpu/cpufreq/speedstep-ich.c
diff --git a/arch/i386/kernel/cpu/cpufreq/speedstep-lib.c b/arch/x86/kernel/cpu/cpufreq/speedstep-lib.c
index b1acc8ce3167..b1acc8ce3167 100644
--- a/arch/i386/kernel/cpu/cpufreq/speedstep-lib.c
+++ b/arch/x86/kernel/cpu/cpufreq/speedstep-lib.c
diff --git a/arch/i386/kernel/cpu/cpufreq/speedstep-lib.h b/arch/x86/kernel/cpu/cpufreq/speedstep-lib.h
index b11bcc608cac..b11bcc608cac 100644
--- a/arch/i386/kernel/cpu/cpufreq/speedstep-lib.h
+++ b/arch/x86/kernel/cpu/cpufreq/speedstep-lib.h
diff --git a/arch/i386/kernel/cpu/cpufreq/speedstep-smi.c b/arch/x86/kernel/cpu/cpufreq/speedstep-smi.c
index e1c509aa3054..e1c509aa3054 100644
--- a/arch/i386/kernel/cpu/cpufreq/speedstep-smi.c
+++ b/arch/x86/kernel/cpu/cpufreq/speedstep-smi.c
diff --git a/arch/i386/kernel/cpu/cyrix.c b/arch/x86/kernel/cpu/cyrix.c
index 122d2d75aa9f..122d2d75aa9f 100644
--- a/arch/i386/kernel/cpu/cyrix.c
+++ b/arch/x86/kernel/cpu/cyrix.c
diff --git a/arch/i386/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
index dc4e08147b1f..dc4e08147b1f 100644
--- a/arch/i386/kernel/cpu/intel.c
+++ b/arch/x86/kernel/cpu/intel.c
diff --git a/arch/i386/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
index db6c25aa5776..db6c25aa5776 100644
--- a/arch/i386/kernel/cpu/intel_cacheinfo.c
+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
diff --git a/arch/i386/kernel/cpu/mcheck/Makefile b/arch/x86/kernel/cpu/mcheck/Makefile
index f1ebe1c1c17a..f1ebe1c1c17a 100644
--- a/arch/i386/kernel/cpu/mcheck/Makefile
+++ b/arch/x86/kernel/cpu/mcheck/Makefile
diff --git a/arch/i386/kernel/cpu/mcheck/k7.c b/arch/x86/kernel/cpu/mcheck/k7.c
index eef63e3630c2..eef63e3630c2 100644
--- a/arch/i386/kernel/cpu/mcheck/k7.c
+++ b/arch/x86/kernel/cpu/mcheck/k7.c
diff --git a/arch/i386/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
index 34c781eddee4..34c781eddee4 100644
--- a/arch/i386/kernel/cpu/mcheck/mce.c
+++ b/arch/x86/kernel/cpu/mcheck/mce.c
diff --git a/arch/i386/kernel/cpu/mcheck/mce.h b/arch/x86/kernel/cpu/mcheck/mce.h
index 81fb6e2d35f3..81fb6e2d35f3 100644
--- a/arch/i386/kernel/cpu/mcheck/mce.h
+++ b/arch/x86/kernel/cpu/mcheck/mce.h
diff --git a/arch/i386/kernel/cpu/mcheck/non-fatal.c b/arch/x86/kernel/cpu/mcheck/non-fatal.c
index bf39409b3838..bf39409b3838 100644
--- a/arch/i386/kernel/cpu/mcheck/non-fatal.c
+++ b/arch/x86/kernel/cpu/mcheck/non-fatal.c
diff --git a/arch/i386/kernel/cpu/mcheck/p4.c b/arch/x86/kernel/cpu/mcheck/p4.c
index 1509edfb2313..1509edfb2313 100644
--- a/arch/i386/kernel/cpu/mcheck/p4.c
+++ b/arch/x86/kernel/cpu/mcheck/p4.c
diff --git a/arch/i386/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
index 94bc43d950cf..94bc43d950cf 100644
--- a/arch/i386/kernel/cpu/mcheck/p5.c
+++ b/arch/x86/kernel/cpu/mcheck/p5.c
diff --git a/arch/i386/kernel/cpu/mcheck/p6.c b/arch/x86/kernel/cpu/mcheck/p6.c
index deeae42ce199..deeae42ce199 100644
--- a/arch/i386/kernel/cpu/mcheck/p6.c
+++ b/arch/x86/kernel/cpu/mcheck/p6.c
diff --git a/arch/i386/kernel/cpu/mcheck/therm_throt.c b/arch/x86/kernel/cpu/mcheck/therm_throt.c
index 1203dc5ab87a..1203dc5ab87a 100644
--- a/arch/i386/kernel/cpu/mcheck/therm_throt.c
+++ b/arch/x86/kernel/cpu/mcheck/therm_throt.c
diff --git a/arch/i386/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
index 9e424b6c293d..9e424b6c293d 100644
--- a/arch/i386/kernel/cpu/mcheck/winchip.c
+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
diff --git a/arch/i386/kernel/cpu/mtrr/Makefile b/arch/x86/kernel/cpu/mtrr/Makefile
index 191fc0533649..191fc0533649 100644
--- a/arch/i386/kernel/cpu/mtrr/Makefile
+++ b/arch/x86/kernel/cpu/mtrr/Makefile
diff --git a/arch/i386/kernel/cpu/mtrr/amd.c b/arch/x86/kernel/cpu/mtrr/amd.c
index 0949cdbf848a..0949cdbf848a 100644
--- a/arch/i386/kernel/cpu/mtrr/amd.c
+++ b/arch/x86/kernel/cpu/mtrr/amd.c
diff --git a/arch/i386/kernel/cpu/mtrr/centaur.c b/arch/x86/kernel/cpu/mtrr/centaur.c
index cb9aa3a7a7ab..cb9aa3a7a7ab 100644
--- a/arch/i386/kernel/cpu/mtrr/centaur.c
+++ b/arch/x86/kernel/cpu/mtrr/centaur.c
diff --git a/arch/i386/kernel/cpu/mtrr/cyrix.c b/arch/x86/kernel/cpu/mtrr/cyrix.c
index 2287d4863a8a..2287d4863a8a 100644
--- a/arch/i386/kernel/cpu/mtrr/cyrix.c
+++ b/arch/x86/kernel/cpu/mtrr/cyrix.c
diff --git a/arch/i386/kernel/cpu/mtrr/generic.c b/arch/x86/kernel/cpu/mtrr/generic.c
index 56f64e34829f..56f64e34829f 100644
--- a/arch/i386/kernel/cpu/mtrr/generic.c
+++ b/arch/x86/kernel/cpu/mtrr/generic.c
diff --git a/arch/i386/kernel/cpu/mtrr/if.c b/arch/x86/kernel/cpu/mtrr/if.c
index c7d8f1756745..c7d8f1756745 100644
--- a/arch/i386/kernel/cpu/mtrr/if.c
+++ b/arch/x86/kernel/cpu/mtrr/if.c
diff --git a/arch/i386/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
index c48b6fea5ab4..c48b6fea5ab4 100644
--- a/arch/i386/kernel/cpu/mtrr/main.c
+++ b/arch/x86/kernel/cpu/mtrr/main.c
diff --git a/arch/i386/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
index 289dfe6030e3..289dfe6030e3 100644
--- a/arch/i386/kernel/cpu/mtrr/mtrr.h
+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
diff --git a/arch/x86/kernel/cpu/mtrr/state.c b/arch/x86/kernel/cpu/mtrr/state.c
new file mode 100644
index 000000000000..49e20c2afcdf
--- /dev/null
+++ b/arch/x86/kernel/cpu/mtrr/state.c
@@ -0,0 +1,79 @@
1#include <linux/mm.h>
2#include <linux/init.h>
3#include <asm/io.h>
4#include <asm/mtrr.h>
5#include <asm/msr.h>
6#include <asm/processor-cyrix.h>
7#include "mtrr.h"
8
9
10/* Put the processor into a state where MTRRs can be safely set */
11void set_mtrr_prepare_save(struct set_mtrr_context *ctxt)
12{
13 unsigned int cr0;
14
15 /* Disable interrupts locally */
16 local_irq_save(ctxt->flags);
17
18 if (use_intel() || is_cpu(CYRIX)) {
19
20 /* Save value of CR4 and clear Page Global Enable (bit 7) */
21 if ( cpu_has_pge ) {
22 ctxt->cr4val = read_cr4();
23 write_cr4(ctxt->cr4val & ~X86_CR4_PGE);
24 }
25
26 /* Disable and flush caches. Note that wbinvd flushes the TLBs as
27 a side-effect */
28 cr0 = read_cr0() | 0x40000000;
29 wbinvd();
30 write_cr0(cr0);
31 wbinvd();
32
33 if (use_intel())
34 /* Save MTRR state */
35 rdmsr(MTRRdefType_MSR, ctxt->deftype_lo, ctxt->deftype_hi);
36 else
37 /* Cyrix ARRs - everything else were excluded at the top */
38 ctxt->ccr3 = getCx86(CX86_CCR3);
39 }
40}
41
42void set_mtrr_cache_disable(struct set_mtrr_context *ctxt)
43{
44 if (use_intel())
45 /* Disable MTRRs, and set the default type to uncached */
46 mtrr_wrmsr(MTRRdefType_MSR, ctxt->deftype_lo & 0xf300UL,
47 ctxt->deftype_hi);
48 else if (is_cpu(CYRIX))
49 /* Cyrix ARRs - everything else were excluded at the top */
50 setCx86(CX86_CCR3, (ctxt->ccr3 & 0x0f) | 0x10);
51}
52
53/* Restore the processor after a set_mtrr_prepare */
54void set_mtrr_done(struct set_mtrr_context *ctxt)
55{
56 if (use_intel() || is_cpu(CYRIX)) {
57
58 /* Flush caches and TLBs */
59 wbinvd();
60
61 /* Restore MTRRdefType */
62 if (use_intel())
63 /* Intel (P6) standard MTRRs */
64 mtrr_wrmsr(MTRRdefType_MSR, ctxt->deftype_lo, ctxt->deftype_hi);
65 else
66 /* Cyrix ARRs - everything else was excluded at the top */
67 setCx86(CX86_CCR3, ctxt->ccr3);
68
69 /* Enable caches */
70 write_cr0(read_cr0() & 0xbfffffff);
71
72 /* Restore value of CR4 */
73 if ( cpu_has_pge )
74 write_cr4(ctxt->cr4val);
75 }
76 /* Re-enable interrupts locally (if enabled previously) */
77 local_irq_restore(ctxt->flags);
78}
79
diff --git a/arch/i386/kernel/cpu/nexgen.c b/arch/x86/kernel/cpu/nexgen.c
index 961fbe1a748f..961fbe1a748f 100644
--- a/arch/i386/kernel/cpu/nexgen.c
+++ b/arch/x86/kernel/cpu/nexgen.c
diff --git a/arch/i386/kernel/cpu/perfctr-watchdog.c b/arch/x86/kernel/cpu/perfctr-watchdog.c
index 93fecd4b03de..93fecd4b03de 100644
--- a/arch/i386/kernel/cpu/perfctr-watchdog.c
+++ b/arch/x86/kernel/cpu/perfctr-watchdog.c
diff --git a/arch/i386/kernel/cpu/proc.c b/arch/x86/kernel/cpu/proc.c
index 1e31b6caffb1..1e31b6caffb1 100644
--- a/arch/i386/kernel/cpu/proc.c
+++ b/arch/x86/kernel/cpu/proc.c
diff --git a/arch/i386/kernel/cpu/transmeta.c b/arch/x86/kernel/cpu/transmeta.c
index 200fb3f9ebfb..200fb3f9ebfb 100644
--- a/arch/i386/kernel/cpu/transmeta.c
+++ b/arch/x86/kernel/cpu/transmeta.c
diff --git a/arch/i386/kernel/cpu/umc.c b/arch/x86/kernel/cpu/umc.c
index a7a4e75bdcd7..a7a4e75bdcd7 100644
--- a/arch/i386/kernel/cpu/umc.c
+++ b/arch/x86/kernel/cpu/umc.c
diff --git a/arch/x86_64/kernel/cpufreq/Kconfig b/arch/x86/kernel/cpufreq/Kconfig
index a3fd51926cbd..a3fd51926cbd 100644
--- a/arch/x86_64/kernel/cpufreq/Kconfig
+++ b/arch/x86/kernel/cpufreq/Kconfig
diff --git a/arch/i386/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
index 5c2faa10e9fa..5c2faa10e9fa 100644
--- a/arch/i386/kernel/cpuid.c
+++ b/arch/x86/kernel/cpuid.c
diff --git a/arch/i386/kernel/crash.c b/arch/x86/kernel/crash_32.c
index 53589d1b1a05..53589d1b1a05 100644
--- a/arch/i386/kernel/crash.c
+++ b/arch/x86/kernel/crash_32.c
diff --git a/arch/x86_64/kernel/crash.c b/arch/x86/kernel/crash_64.c
index 13432a1ae904..13432a1ae904 100644
--- a/arch/x86_64/kernel/crash.c
+++ b/arch/x86/kernel/crash_64.c
diff --git a/arch/i386/kernel/crash_dump.c b/arch/x86/kernel/crash_dump_32.c
index 3f532df488bc..3f532df488bc 100644
--- a/arch/i386/kernel/crash_dump.c
+++ b/arch/x86/kernel/crash_dump_32.c
diff --git a/arch/x86_64/kernel/crash_dump.c b/arch/x86/kernel/crash_dump_64.c
index 942deac4d43a..942deac4d43a 100644
--- a/arch/x86_64/kernel/crash_dump.c
+++ b/arch/x86/kernel/crash_dump_64.c
diff --git a/arch/i386/kernel/doublefault.c b/arch/x86/kernel/doublefault_32.c
index 40978af630e7..40978af630e7 100644
--- a/arch/i386/kernel/doublefault.c
+++ b/arch/x86/kernel/doublefault_32.c
diff --git a/arch/i386/kernel/e820.c b/arch/x86/kernel/e820_32.c
index 3c86b979a40a..3c86b979a40a 100644
--- a/arch/i386/kernel/e820.c
+++ b/arch/x86/kernel/e820_32.c
diff --git a/arch/x86_64/kernel/e820.c b/arch/x86/kernel/e820_64.c
index 0f4d5e209e9b..0f4d5e209e9b 100644
--- a/arch/x86_64/kernel/e820.c
+++ b/arch/x86/kernel/e820_64.c
diff --git a/arch/x86_64/kernel/early-quirks.c b/arch/x86/kernel/early-quirks_64.c
index 13aa4fd728f3..13aa4fd728f3 100644
--- a/arch/x86_64/kernel/early-quirks.c
+++ b/arch/x86/kernel/early-quirks_64.c
diff --git a/arch/x86_64/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
index fd9aff3f3890..fd9aff3f3890 100644
--- a/arch/x86_64/kernel/early_printk.c
+++ b/arch/x86/kernel/early_printk.c
diff --git a/arch/i386/kernel/efi.c b/arch/x86/kernel/efi_32.c
index 2452c6fbe992..2452c6fbe992 100644
--- a/arch/i386/kernel/efi.c
+++ b/arch/x86/kernel/efi_32.c
diff --git a/arch/i386/kernel/efi_stub.S b/arch/x86/kernel/efi_stub_32.S
index ef00bb77d7e4..ef00bb77d7e4 100644
--- a/arch/i386/kernel/efi_stub.S
+++ b/arch/x86/kernel/efi_stub_32.S
diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
new file mode 100644
index 000000000000..290b7bc82da3
--- /dev/null
+++ b/arch/x86/kernel/entry_32.S
@@ -0,0 +1,1112 @@
1/*
2 * linux/arch/i386/entry.S
3 *
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 */
6
7/*
8 * entry.S contains the system-call and fault low-level handling routines.
9 * This also contains the timer-interrupt handler, as well as all interrupts
10 * and faults that can result in a task-switch.
11 *
12 * NOTE: This code handles signal-recognition, which happens every time
13 * after a timer-interrupt and after each system call.
14 *
15 * I changed all the .align's to 4 (16 byte alignment), as that's faster
16 * on a 486.
17 *
18 * Stack layout in 'syscall_exit':
19 * ptrace needs to have all regs on the stack.
20 * if the order here is changed, it needs to be
21 * updated in fork.c:copy_process, signal.c:do_signal,
22 * ptrace.c and ptrace.h
23 *
24 * 0(%esp) - %ebx
25 * 4(%esp) - %ecx
26 * 8(%esp) - %edx
27 * C(%esp) - %esi
28 * 10(%esp) - %edi
29 * 14(%esp) - %ebp
30 * 18(%esp) - %eax
31 * 1C(%esp) - %ds
32 * 20(%esp) - %es
33 * 24(%esp) - %fs
34 * 28(%esp) - orig_eax
35 * 2C(%esp) - %eip
36 * 30(%esp) - %cs
37 * 34(%esp) - %eflags
38 * 38(%esp) - %oldesp
39 * 3C(%esp) - %oldss
40 *
41 * "current" is in register %ebx during any slow entries.
42 */
43
44#include <linux/linkage.h>
45#include <asm/thread_info.h>
46#include <asm/irqflags.h>
47#include <asm/errno.h>
48#include <asm/segment.h>
49#include <asm/smp.h>
50#include <asm/page.h>
51#include <asm/desc.h>
52#include <asm/percpu.h>
53#include <asm/dwarf2.h>
54#include "irq_vectors.h"
55
56/*
57 * We use macros for low-level operations which need to be overridden
58 * for paravirtualization. The following will never clobber any registers:
59 * INTERRUPT_RETURN (aka. "iret")
60 * GET_CR0_INTO_EAX (aka. "movl %cr0, %eax")
61 * ENABLE_INTERRUPTS_SYSEXIT (aka "sti; sysexit").
62 *
63 * For DISABLE_INTERRUPTS/ENABLE_INTERRUPTS (aka "cli"/"sti"), you must
64 * specify what registers can be overwritten (CLBR_NONE, CLBR_EAX/EDX/ECX/ANY).
65 * Allowing a register to be clobbered can shrink the paravirt replacement
66 * enough to patch inline, increasing performance.
67 */
68
69#define nr_syscalls ((syscall_table_size)/4)
70
71CF_MASK = 0x00000001
72TF_MASK = 0x00000100
73IF_MASK = 0x00000200
74DF_MASK = 0x00000400
75NT_MASK = 0x00004000
76VM_MASK = 0x00020000
77
78#ifdef CONFIG_PREEMPT
79#define preempt_stop(clobbers) DISABLE_INTERRUPTS(clobbers); TRACE_IRQS_OFF
80#else
81#define preempt_stop(clobbers)
82#define resume_kernel restore_nocheck
83#endif
84
85.macro TRACE_IRQS_IRET
86#ifdef CONFIG_TRACE_IRQFLAGS
87 testl $IF_MASK,PT_EFLAGS(%esp) # interrupts off?
88 jz 1f
89 TRACE_IRQS_ON
901:
91#endif
92.endm
93
94#ifdef CONFIG_VM86
95#define resume_userspace_sig check_userspace
96#else
97#define resume_userspace_sig resume_userspace
98#endif
99
100#define SAVE_ALL \
101 cld; \
102 pushl %fs; \
103 CFI_ADJUST_CFA_OFFSET 4;\
104 /*CFI_REL_OFFSET fs, 0;*/\
105 pushl %es; \
106 CFI_ADJUST_CFA_OFFSET 4;\
107 /*CFI_REL_OFFSET es, 0;*/\
108 pushl %ds; \
109 CFI_ADJUST_CFA_OFFSET 4;\
110 /*CFI_REL_OFFSET ds, 0;*/\
111 pushl %eax; \
112 CFI_ADJUST_CFA_OFFSET 4;\
113 CFI_REL_OFFSET eax, 0;\
114 pushl %ebp; \
115 CFI_ADJUST_CFA_OFFSET 4;\
116 CFI_REL_OFFSET ebp, 0;\
117 pushl %edi; \
118 CFI_ADJUST_CFA_OFFSET 4;\
119 CFI_REL_OFFSET edi, 0;\
120 pushl %esi; \
121 CFI_ADJUST_CFA_OFFSET 4;\
122 CFI_REL_OFFSET esi, 0;\
123 pushl %edx; \
124 CFI_ADJUST_CFA_OFFSET 4;\
125 CFI_REL_OFFSET edx, 0;\
126 pushl %ecx; \
127 CFI_ADJUST_CFA_OFFSET 4;\
128 CFI_REL_OFFSET ecx, 0;\
129 pushl %ebx; \
130 CFI_ADJUST_CFA_OFFSET 4;\
131 CFI_REL_OFFSET ebx, 0;\
132 movl $(__USER_DS), %edx; \
133 movl %edx, %ds; \
134 movl %edx, %es; \
135 movl $(__KERNEL_PERCPU), %edx; \
136 movl %edx, %fs
137
138#define RESTORE_INT_REGS \
139 popl %ebx; \
140 CFI_ADJUST_CFA_OFFSET -4;\
141 CFI_RESTORE ebx;\
142 popl %ecx; \
143 CFI_ADJUST_CFA_OFFSET -4;\
144 CFI_RESTORE ecx;\
145 popl %edx; \
146 CFI_ADJUST_CFA_OFFSET -4;\
147 CFI_RESTORE edx;\
148 popl %esi; \
149 CFI_ADJUST_CFA_OFFSET -4;\
150 CFI_RESTORE esi;\
151 popl %edi; \
152 CFI_ADJUST_CFA_OFFSET -4;\
153 CFI_RESTORE edi;\
154 popl %ebp; \
155 CFI_ADJUST_CFA_OFFSET -4;\
156 CFI_RESTORE ebp;\
157 popl %eax; \
158 CFI_ADJUST_CFA_OFFSET -4;\
159 CFI_RESTORE eax
160
161#define RESTORE_REGS \
162 RESTORE_INT_REGS; \
1631: popl %ds; \
164 CFI_ADJUST_CFA_OFFSET -4;\
165 /*CFI_RESTORE ds;*/\
1662: popl %es; \
167 CFI_ADJUST_CFA_OFFSET -4;\
168 /*CFI_RESTORE es;*/\
1693: popl %fs; \
170 CFI_ADJUST_CFA_OFFSET -4;\
171 /*CFI_RESTORE fs;*/\
172.pushsection .fixup,"ax"; \
1734: movl $0,(%esp); \
174 jmp 1b; \
1755: movl $0,(%esp); \
176 jmp 2b; \
1776: movl $0,(%esp); \
178 jmp 3b; \
179.section __ex_table,"a";\
180 .align 4; \
181 .long 1b,4b; \
182 .long 2b,5b; \
183 .long 3b,6b; \
184.popsection
185
186#define RING0_INT_FRAME \
187 CFI_STARTPROC simple;\
188 CFI_SIGNAL_FRAME;\
189 CFI_DEF_CFA esp, 3*4;\
190 /*CFI_OFFSET cs, -2*4;*/\
191 CFI_OFFSET eip, -3*4
192
193#define RING0_EC_FRAME \
194 CFI_STARTPROC simple;\
195 CFI_SIGNAL_FRAME;\
196 CFI_DEF_CFA esp, 4*4;\
197 /*CFI_OFFSET cs, -2*4;*/\
198 CFI_OFFSET eip, -3*4
199
200#define RING0_PTREGS_FRAME \
201 CFI_STARTPROC simple;\
202 CFI_SIGNAL_FRAME;\
203 CFI_DEF_CFA esp, PT_OLDESP-PT_EBX;\
204 /*CFI_OFFSET cs, PT_CS-PT_OLDESP;*/\
205 CFI_OFFSET eip, PT_EIP-PT_OLDESP;\
206 /*CFI_OFFSET es, PT_ES-PT_OLDESP;*/\
207 /*CFI_OFFSET ds, PT_DS-PT_OLDESP;*/\
208 CFI_OFFSET eax, PT_EAX-PT_OLDESP;\
209 CFI_OFFSET ebp, PT_EBP-PT_OLDESP;\
210 CFI_OFFSET edi, PT_EDI-PT_OLDESP;\
211 CFI_OFFSET esi, PT_ESI-PT_OLDESP;\
212 CFI_OFFSET edx, PT_EDX-PT_OLDESP;\
213 CFI_OFFSET ecx, PT_ECX-PT_OLDESP;\
214 CFI_OFFSET ebx, PT_EBX-PT_OLDESP
215
216ENTRY(ret_from_fork)
217 CFI_STARTPROC
218 pushl %eax
219 CFI_ADJUST_CFA_OFFSET 4
220 call schedule_tail
221 GET_THREAD_INFO(%ebp)
222 popl %eax
223 CFI_ADJUST_CFA_OFFSET -4
224 pushl $0x0202 # Reset kernel eflags
225 CFI_ADJUST_CFA_OFFSET 4
226 popfl
227 CFI_ADJUST_CFA_OFFSET -4
228 jmp syscall_exit
229 CFI_ENDPROC
230END(ret_from_fork)
231
232/*
233 * Return to user mode is not as complex as all this looks,
234 * but we want the default path for a system call return to
235 * go as quickly as possible which is why some of this is
236 * less clear than it otherwise should be.
237 */
238
239 # userspace resumption stub bypassing syscall exit tracing
240 ALIGN
241 RING0_PTREGS_FRAME
242ret_from_exception:
243 preempt_stop(CLBR_ANY)
244ret_from_intr:
245 GET_THREAD_INFO(%ebp)
246check_userspace:
247 movl PT_EFLAGS(%esp), %eax # mix EFLAGS and CS
248 movb PT_CS(%esp), %al
249 andl $(VM_MASK | SEGMENT_RPL_MASK), %eax
250 cmpl $USER_RPL, %eax
251 jb resume_kernel # not returning to v8086 or userspace
252
253ENTRY(resume_userspace)
254 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
255 # setting need_resched or sigpending
256 # between sampling and the iret
257 movl TI_flags(%ebp), %ecx
258 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
259 # int/exception return?
260 jne work_pending
261 jmp restore_all
262END(ret_from_exception)
263
264#ifdef CONFIG_PREEMPT
265ENTRY(resume_kernel)
266 DISABLE_INTERRUPTS(CLBR_ANY)
267 cmpl $0,TI_preempt_count(%ebp) # non-zero preempt_count ?
268 jnz restore_nocheck
269need_resched:
270 movl TI_flags(%ebp), %ecx # need_resched set ?
271 testb $_TIF_NEED_RESCHED, %cl
272 jz restore_all
273 testl $IF_MASK,PT_EFLAGS(%esp) # interrupts off (exception path) ?
274 jz restore_all
275 call preempt_schedule_irq
276 jmp need_resched
277END(resume_kernel)
278#endif
279 CFI_ENDPROC
280
281/* SYSENTER_RETURN points to after the "sysenter" instruction in
282 the vsyscall page. See vsyscall-sysentry.S, which defines the symbol. */
283
284 # sysenter call handler stub
285ENTRY(sysenter_entry)
286 CFI_STARTPROC simple
287 CFI_SIGNAL_FRAME
288 CFI_DEF_CFA esp, 0
289 CFI_REGISTER esp, ebp
290 movl TSS_sysenter_esp0(%esp),%esp
291sysenter_past_esp:
292 /*
293 * No need to follow this irqs on/off section: the syscall
294 * disabled irqs and here we enable it straight after entry:
295 */
296 ENABLE_INTERRUPTS(CLBR_NONE)
297 pushl $(__USER_DS)
298 CFI_ADJUST_CFA_OFFSET 4
299 /*CFI_REL_OFFSET ss, 0*/
300 pushl %ebp
301 CFI_ADJUST_CFA_OFFSET 4
302 CFI_REL_OFFSET esp, 0
303 pushfl
304 CFI_ADJUST_CFA_OFFSET 4
305 pushl $(__USER_CS)
306 CFI_ADJUST_CFA_OFFSET 4
307 /*CFI_REL_OFFSET cs, 0*/
308 /*
309 * Push current_thread_info()->sysenter_return to the stack.
310 * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
311 * pushed above; +8 corresponds to copy_thread's esp0 setting.
312 */
313 pushl (TI_sysenter_return-THREAD_SIZE+8+4*4)(%esp)
314 CFI_ADJUST_CFA_OFFSET 4
315 CFI_REL_OFFSET eip, 0
316
317/*
318 * Load the potential sixth argument from user stack.
319 * Careful about security.
320 */
321 cmpl $__PAGE_OFFSET-3,%ebp
322 jae syscall_fault
3231: movl (%ebp),%ebp
324.section __ex_table,"a"
325 .align 4
326 .long 1b,syscall_fault
327.previous
328
329 pushl %eax
330 CFI_ADJUST_CFA_OFFSET 4
331 SAVE_ALL
332 GET_THREAD_INFO(%ebp)
333
334 /* Note, _TIF_SECCOMP is bit number 8, and so it needs testw and not testb */
335 testw $(_TIF_SYSCALL_EMU|_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT),TI_flags(%ebp)
336 jnz syscall_trace_entry
337 cmpl $(nr_syscalls), %eax
338 jae syscall_badsys
339 call *sys_call_table(,%eax,4)
340 movl %eax,PT_EAX(%esp)
341 DISABLE_INTERRUPTS(CLBR_ANY)
342 TRACE_IRQS_OFF
343 movl TI_flags(%ebp), %ecx
344 testw $_TIF_ALLWORK_MASK, %cx
345 jne syscall_exit_work
346/* if something modifies registers it must also disable sysexit */
347 movl PT_EIP(%esp), %edx
348 movl PT_OLDESP(%esp), %ecx
349 xorl %ebp,%ebp
350 TRACE_IRQS_ON
3511: mov PT_FS(%esp), %fs
352 ENABLE_INTERRUPTS_SYSEXIT
353 CFI_ENDPROC
354.pushsection .fixup,"ax"
3552: movl $0,PT_FS(%esp)
356 jmp 1b
357.section __ex_table,"a"
358 .align 4
359 .long 1b,2b
360.popsection
361ENDPROC(sysenter_entry)
362
363 # system call handler stub
364ENTRY(system_call)
365 RING0_INT_FRAME # can't unwind into user space anyway
366 pushl %eax # save orig_eax
367 CFI_ADJUST_CFA_OFFSET 4
368 SAVE_ALL
369 GET_THREAD_INFO(%ebp)
370 # system call tracing in operation / emulation
371 /* Note, _TIF_SECCOMP is bit number 8, and so it needs testw and not testb */
372 testw $(_TIF_SYSCALL_EMU|_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT),TI_flags(%ebp)
373 jnz syscall_trace_entry
374 cmpl $(nr_syscalls), %eax
375 jae syscall_badsys
376syscall_call:
377 call *sys_call_table(,%eax,4)
378 movl %eax,PT_EAX(%esp) # store the return value
379syscall_exit:
380 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
381 # setting need_resched or sigpending
382 # between sampling and the iret
383 TRACE_IRQS_OFF
384 testl $TF_MASK,PT_EFLAGS(%esp) # If tracing set singlestep flag on exit
385 jz no_singlestep
386 orl $_TIF_SINGLESTEP,TI_flags(%ebp)
387no_singlestep:
388 movl TI_flags(%ebp), %ecx
389 testw $_TIF_ALLWORK_MASK, %cx # current->work
390 jne syscall_exit_work
391
392restore_all:
393 movl PT_EFLAGS(%esp), %eax # mix EFLAGS, SS and CS
394 # Warning: PT_OLDSS(%esp) contains the wrong/random values if we
395 # are returning to the kernel.
396 # See comments in process.c:copy_thread() for details.
397 movb PT_OLDSS(%esp), %ah
398 movb PT_CS(%esp), %al
399 andl $(VM_MASK | (SEGMENT_TI_MASK << 8) | SEGMENT_RPL_MASK), %eax
400 cmpl $((SEGMENT_LDT << 8) | USER_RPL), %eax
401 CFI_REMEMBER_STATE
402 je ldt_ss # returning to user-space with LDT SS
403restore_nocheck:
404 TRACE_IRQS_IRET
405restore_nocheck_notrace:
406 RESTORE_REGS
407 addl $4, %esp # skip orig_eax/error_code
408 CFI_ADJUST_CFA_OFFSET -4
4091: INTERRUPT_RETURN
410.section .fixup,"ax"
411iret_exc:
412 pushl $0 # no error code
413 pushl $do_iret_error
414 jmp error_code
415.previous
416.section __ex_table,"a"
417 .align 4
418 .long 1b,iret_exc
419.previous
420
421 CFI_RESTORE_STATE
422ldt_ss:
423 larl PT_OLDSS(%esp), %eax
424 jnz restore_nocheck
425 testl $0x00400000, %eax # returning to 32bit stack?
426 jnz restore_nocheck # allright, normal return
427
428#ifdef CONFIG_PARAVIRT
429 /*
430 * The kernel can't run on a non-flat stack if paravirt mode
431 * is active. Rather than try to fixup the high bits of
432 * ESP, bypass this code entirely. This may break DOSemu
433 * and/or Wine support in a paravirt VM, although the option
434 * is still available to implement the setting of the high
435 * 16-bits in the INTERRUPT_RETURN paravirt-op.
436 */
437 cmpl $0, paravirt_ops+PARAVIRT_enabled
438 jne restore_nocheck
439#endif
440
441 /* If returning to userspace with 16bit stack,
442 * try to fix the higher word of ESP, as the CPU
443 * won't restore it.
444 * This is an "official" bug of all the x86-compatible
445 * CPUs, which we can try to work around to make
446 * dosemu and wine happy. */
447 movl PT_OLDESP(%esp), %eax
448 movl %esp, %edx
449 call patch_espfix_desc
450 pushl $__ESPFIX_SS
451 CFI_ADJUST_CFA_OFFSET 4
452 pushl %eax
453 CFI_ADJUST_CFA_OFFSET 4
454 DISABLE_INTERRUPTS(CLBR_EAX)
455 TRACE_IRQS_OFF
456 lss (%esp), %esp
457 CFI_ADJUST_CFA_OFFSET -8
458 jmp restore_nocheck
459 CFI_ENDPROC
460ENDPROC(system_call)
461
462 # perform work that needs to be done immediately before resumption
463 ALIGN
464 RING0_PTREGS_FRAME # can't unwind into user space anyway
465work_pending:
466 testb $_TIF_NEED_RESCHED, %cl
467 jz work_notifysig
468work_resched:
469 call schedule
470 DISABLE_INTERRUPTS(CLBR_ANY) # make sure we don't miss an interrupt
471 # setting need_resched or sigpending
472 # between sampling and the iret
473 TRACE_IRQS_OFF
474 movl TI_flags(%ebp), %ecx
475 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
476 # than syscall tracing?
477 jz restore_all
478 testb $_TIF_NEED_RESCHED, %cl
479 jnz work_resched
480
481work_notifysig: # deal with pending signals and
482 # notify-resume requests
483#ifdef CONFIG_VM86
484 testl $VM_MASK, PT_EFLAGS(%esp)
485 movl %esp, %eax
486 jne work_notifysig_v86 # returning to kernel-space or
487 # vm86-space
488 xorl %edx, %edx
489 call do_notify_resume
490 jmp resume_userspace_sig
491
492 ALIGN
493work_notifysig_v86:
494 pushl %ecx # save ti_flags for do_notify_resume
495 CFI_ADJUST_CFA_OFFSET 4
496 call save_v86_state # %eax contains pt_regs pointer
497 popl %ecx
498 CFI_ADJUST_CFA_OFFSET -4
499 movl %eax, %esp
500#else
501 movl %esp, %eax
502#endif
503 xorl %edx, %edx
504 call do_notify_resume
505 jmp resume_userspace_sig
506END(work_pending)
507
508 # perform syscall exit tracing
509 ALIGN
510syscall_trace_entry:
511 movl $-ENOSYS,PT_EAX(%esp)
512 movl %esp, %eax
513 xorl %edx,%edx
514 call do_syscall_trace
515 cmpl $0, %eax
516 jne resume_userspace # ret != 0 -> running under PTRACE_SYSEMU,
517 # so must skip actual syscall
518 movl PT_ORIG_EAX(%esp), %eax
519 cmpl $(nr_syscalls), %eax
520 jnae syscall_call
521 jmp syscall_exit
522END(syscall_trace_entry)
523
524 # perform syscall exit tracing
525 ALIGN
526syscall_exit_work:
527 testb $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SINGLESTEP), %cl
528 jz work_pending
529 TRACE_IRQS_ON
530 ENABLE_INTERRUPTS(CLBR_ANY) # could let do_syscall_trace() call
531 # schedule() instead
532 movl %esp, %eax
533 movl $1, %edx
534 call do_syscall_trace
535 jmp resume_userspace
536END(syscall_exit_work)
537 CFI_ENDPROC
538
539 RING0_INT_FRAME # can't unwind into user space anyway
540syscall_fault:
541 pushl %eax # save orig_eax
542 CFI_ADJUST_CFA_OFFSET 4
543 SAVE_ALL
544 GET_THREAD_INFO(%ebp)
545 movl $-EFAULT,PT_EAX(%esp)
546 jmp resume_userspace
547END(syscall_fault)
548
549syscall_badsys:
550 movl $-ENOSYS,PT_EAX(%esp)
551 jmp resume_userspace
552END(syscall_badsys)
553 CFI_ENDPROC
554
555#define FIXUP_ESPFIX_STACK \
556 /* since we are on a wrong stack, we cant make it a C code :( */ \
557 PER_CPU(gdt_page, %ebx); \
558 GET_DESC_BASE(GDT_ENTRY_ESPFIX_SS, %ebx, %eax, %ax, %al, %ah); \
559 addl %esp, %eax; \
560 pushl $__KERNEL_DS; \
561 CFI_ADJUST_CFA_OFFSET 4; \
562 pushl %eax; \
563 CFI_ADJUST_CFA_OFFSET 4; \
564 lss (%esp), %esp; \
565 CFI_ADJUST_CFA_OFFSET -8;
566#define UNWIND_ESPFIX_STACK \
567 movl %ss, %eax; \
568 /* see if on espfix stack */ \
569 cmpw $__ESPFIX_SS, %ax; \
570 jne 27f; \
571 movl $__KERNEL_DS, %eax; \
572 movl %eax, %ds; \
573 movl %eax, %es; \
574 /* switch to normal stack */ \
575 FIXUP_ESPFIX_STACK; \
57627:;
577
578/*
579 * Build the entry stubs and pointer table with
580 * some assembler magic.
581 */
582.data
583ENTRY(interrupt)
584.text
585
586ENTRY(irq_entries_start)
587 RING0_INT_FRAME
588vector=0
589.rept NR_IRQS
590 ALIGN
591 .if vector
592 CFI_ADJUST_CFA_OFFSET -4
593 .endif
5941: pushl $~(vector)
595 CFI_ADJUST_CFA_OFFSET 4
596 jmp common_interrupt
597 .previous
598 .long 1b
599 .text
600vector=vector+1
601.endr
602END(irq_entries_start)
603
604.previous
605END(interrupt)
606.previous
607
608/*
609 * the CPU automatically disables interrupts when executing an IRQ vector,
610 * so IRQ-flags tracing has to follow that:
611 */
612 ALIGN
613common_interrupt:
614 SAVE_ALL
615 TRACE_IRQS_OFF
616 movl %esp,%eax
617 call do_IRQ
618 jmp ret_from_intr
619ENDPROC(common_interrupt)
620 CFI_ENDPROC
621
622#define BUILD_INTERRUPT(name, nr) \
623ENTRY(name) \
624 RING0_INT_FRAME; \
625 pushl $~(nr); \
626 CFI_ADJUST_CFA_OFFSET 4; \
627 SAVE_ALL; \
628 TRACE_IRQS_OFF \
629 movl %esp,%eax; \
630 call smp_##name; \
631 jmp ret_from_intr; \
632 CFI_ENDPROC; \
633ENDPROC(name)
634
635/* The include is where all of the SMP etc. interrupts come from */
636#include "entry_arch.h"
637
638KPROBE_ENTRY(page_fault)
639 RING0_EC_FRAME
640 pushl $do_page_fault
641 CFI_ADJUST_CFA_OFFSET 4
642 ALIGN
643error_code:
644 /* the function address is in %fs's slot on the stack */
645 pushl %es
646 CFI_ADJUST_CFA_OFFSET 4
647 /*CFI_REL_OFFSET es, 0*/
648 pushl %ds
649 CFI_ADJUST_CFA_OFFSET 4
650 /*CFI_REL_OFFSET ds, 0*/
651 pushl %eax
652 CFI_ADJUST_CFA_OFFSET 4
653 CFI_REL_OFFSET eax, 0
654 pushl %ebp
655 CFI_ADJUST_CFA_OFFSET 4
656 CFI_REL_OFFSET ebp, 0
657 pushl %edi
658 CFI_ADJUST_CFA_OFFSET 4
659 CFI_REL_OFFSET edi, 0
660 pushl %esi
661 CFI_ADJUST_CFA_OFFSET 4
662 CFI_REL_OFFSET esi, 0
663 pushl %edx
664 CFI_ADJUST_CFA_OFFSET 4
665 CFI_REL_OFFSET edx, 0
666 pushl %ecx
667 CFI_ADJUST_CFA_OFFSET 4
668 CFI_REL_OFFSET ecx, 0
669 pushl %ebx
670 CFI_ADJUST_CFA_OFFSET 4
671 CFI_REL_OFFSET ebx, 0
672 cld
673 pushl %fs
674 CFI_ADJUST_CFA_OFFSET 4
675 /*CFI_REL_OFFSET fs, 0*/
676 movl $(__KERNEL_PERCPU), %ecx
677 movl %ecx, %fs
678 UNWIND_ESPFIX_STACK
679 popl %ecx
680 CFI_ADJUST_CFA_OFFSET -4
681 /*CFI_REGISTER es, ecx*/
682 movl PT_FS(%esp), %edi # get the function address
683 movl PT_ORIG_EAX(%esp), %edx # get the error code
684 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
685 mov %ecx, PT_FS(%esp)
686 /*CFI_REL_OFFSET fs, ES*/
687 movl $(__USER_DS), %ecx
688 movl %ecx, %ds
689 movl %ecx, %es
690 movl %esp,%eax # pt_regs pointer
691 call *%edi
692 jmp ret_from_exception
693 CFI_ENDPROC
694KPROBE_END(page_fault)
695
696ENTRY(coprocessor_error)
697 RING0_INT_FRAME
698 pushl $0
699 CFI_ADJUST_CFA_OFFSET 4
700 pushl $do_coprocessor_error
701 CFI_ADJUST_CFA_OFFSET 4
702 jmp error_code
703 CFI_ENDPROC
704END(coprocessor_error)
705
706ENTRY(simd_coprocessor_error)
707 RING0_INT_FRAME
708 pushl $0
709 CFI_ADJUST_CFA_OFFSET 4
710 pushl $do_simd_coprocessor_error
711 CFI_ADJUST_CFA_OFFSET 4
712 jmp error_code
713 CFI_ENDPROC
714END(simd_coprocessor_error)
715
716ENTRY(device_not_available)
717 RING0_INT_FRAME
718 pushl $-1 # mark this as an int
719 CFI_ADJUST_CFA_OFFSET 4
720 SAVE_ALL
721 GET_CR0_INTO_EAX
722 testl $0x4, %eax # EM (math emulation bit)
723 jne device_not_available_emulate
724 preempt_stop(CLBR_ANY)
725 call math_state_restore
726 jmp ret_from_exception
727device_not_available_emulate:
728 pushl $0 # temporary storage for ORIG_EIP
729 CFI_ADJUST_CFA_OFFSET 4
730 call math_emulate
731 addl $4, %esp
732 CFI_ADJUST_CFA_OFFSET -4
733 jmp ret_from_exception
734 CFI_ENDPROC
735END(device_not_available)
736
737/*
738 * Debug traps and NMI can happen at the one SYSENTER instruction
739 * that sets up the real kernel stack. Check here, since we can't
740 * allow the wrong stack to be used.
741 *
742 * "TSS_sysenter_esp0+12" is because the NMI/debug handler will have
743 * already pushed 3 words if it hits on the sysenter instruction:
744 * eflags, cs and eip.
745 *
746 * We just load the right stack, and push the three (known) values
747 * by hand onto the new stack - while updating the return eip past
748 * the instruction that would have done it for sysenter.
749 */
750#define FIX_STACK(offset, ok, label) \
751 cmpw $__KERNEL_CS,4(%esp); \
752 jne ok; \
753label: \
754 movl TSS_sysenter_esp0+offset(%esp),%esp; \
755 CFI_DEF_CFA esp, 0; \
756 CFI_UNDEFINED eip; \
757 pushfl; \
758 CFI_ADJUST_CFA_OFFSET 4; \
759 pushl $__KERNEL_CS; \
760 CFI_ADJUST_CFA_OFFSET 4; \
761 pushl $sysenter_past_esp; \
762 CFI_ADJUST_CFA_OFFSET 4; \
763 CFI_REL_OFFSET eip, 0
764
765KPROBE_ENTRY(debug)
766 RING0_INT_FRAME
767 cmpl $sysenter_entry,(%esp)
768 jne debug_stack_correct
769 FIX_STACK(12, debug_stack_correct, debug_esp_fix_insn)
770debug_stack_correct:
771 pushl $-1 # mark this as an int
772 CFI_ADJUST_CFA_OFFSET 4
773 SAVE_ALL
774 xorl %edx,%edx # error code 0
775 movl %esp,%eax # pt_regs pointer
776 call do_debug
777 jmp ret_from_exception
778 CFI_ENDPROC
779KPROBE_END(debug)
780
781/*
782 * NMI is doubly nasty. It can happen _while_ we're handling
783 * a debug fault, and the debug fault hasn't yet been able to
784 * clear up the stack. So we first check whether we got an
785 * NMI on the sysenter entry path, but after that we need to
786 * check whether we got an NMI on the debug path where the debug
787 * fault happened on the sysenter path.
788 */
789KPROBE_ENTRY(nmi)
790 RING0_INT_FRAME
791 pushl %eax
792 CFI_ADJUST_CFA_OFFSET 4
793 movl %ss, %eax
794 cmpw $__ESPFIX_SS, %ax
795 popl %eax
796 CFI_ADJUST_CFA_OFFSET -4
797 je nmi_espfix_stack
798 cmpl $sysenter_entry,(%esp)
799 je nmi_stack_fixup
800 pushl %eax
801 CFI_ADJUST_CFA_OFFSET 4
802 movl %esp,%eax
803 /* Do not access memory above the end of our stack page,
804 * it might not exist.
805 */
806 andl $(THREAD_SIZE-1),%eax
807 cmpl $(THREAD_SIZE-20),%eax
808 popl %eax
809 CFI_ADJUST_CFA_OFFSET -4
810 jae nmi_stack_correct
811 cmpl $sysenter_entry,12(%esp)
812 je nmi_debug_stack_check
813nmi_stack_correct:
814 /* We have a RING0_INT_FRAME here */
815 pushl %eax
816 CFI_ADJUST_CFA_OFFSET 4
817 SAVE_ALL
818 xorl %edx,%edx # zero error code
819 movl %esp,%eax # pt_regs pointer
820 call do_nmi
821 jmp restore_nocheck_notrace
822 CFI_ENDPROC
823
824nmi_stack_fixup:
825 RING0_INT_FRAME
826 FIX_STACK(12,nmi_stack_correct, 1)
827 jmp nmi_stack_correct
828
829nmi_debug_stack_check:
830 /* We have a RING0_INT_FRAME here */
831 cmpw $__KERNEL_CS,16(%esp)
832 jne nmi_stack_correct
833 cmpl $debug,(%esp)
834 jb nmi_stack_correct
835 cmpl $debug_esp_fix_insn,(%esp)
836 ja nmi_stack_correct
837 FIX_STACK(24,nmi_stack_correct, 1)
838 jmp nmi_stack_correct
839
840nmi_espfix_stack:
841 /* We have a RING0_INT_FRAME here.
842 *
843 * create the pointer to lss back
844 */
845 pushl %ss
846 CFI_ADJUST_CFA_OFFSET 4
847 pushl %esp
848 CFI_ADJUST_CFA_OFFSET 4
849 addw $4, (%esp)
850 /* copy the iret frame of 12 bytes */
851 .rept 3
852 pushl 16(%esp)
853 CFI_ADJUST_CFA_OFFSET 4
854 .endr
855 pushl %eax
856 CFI_ADJUST_CFA_OFFSET 4
857 SAVE_ALL
858 FIXUP_ESPFIX_STACK # %eax == %esp
859 xorl %edx,%edx # zero error code
860 call do_nmi
861 RESTORE_REGS
862 lss 12+4(%esp), %esp # back to espfix stack
863 CFI_ADJUST_CFA_OFFSET -24
8641: INTERRUPT_RETURN
865 CFI_ENDPROC
866.section __ex_table,"a"
867 .align 4
868 .long 1b,iret_exc
869.previous
870KPROBE_END(nmi)
871
872#ifdef CONFIG_PARAVIRT
873ENTRY(native_iret)
8741: iret
875.section __ex_table,"a"
876 .align 4
877 .long 1b,iret_exc
878.previous
879END(native_iret)
880
881ENTRY(native_irq_enable_sysexit)
882 sti
883 sysexit
884END(native_irq_enable_sysexit)
885#endif
886
887KPROBE_ENTRY(int3)
888 RING0_INT_FRAME
889 pushl $-1 # mark this as an int
890 CFI_ADJUST_CFA_OFFSET 4
891 SAVE_ALL
892 xorl %edx,%edx # zero error code
893 movl %esp,%eax # pt_regs pointer
894 call do_int3
895 jmp ret_from_exception
896 CFI_ENDPROC
897KPROBE_END(int3)
898
899ENTRY(overflow)
900 RING0_INT_FRAME
901 pushl $0
902 CFI_ADJUST_CFA_OFFSET 4
903 pushl $do_overflow
904 CFI_ADJUST_CFA_OFFSET 4
905 jmp error_code
906 CFI_ENDPROC
907END(overflow)
908
909ENTRY(bounds)
910 RING0_INT_FRAME
911 pushl $0
912 CFI_ADJUST_CFA_OFFSET 4
913 pushl $do_bounds
914 CFI_ADJUST_CFA_OFFSET 4
915 jmp error_code
916 CFI_ENDPROC
917END(bounds)
918
919ENTRY(invalid_op)
920 RING0_INT_FRAME
921 pushl $0
922 CFI_ADJUST_CFA_OFFSET 4
923 pushl $do_invalid_op
924 CFI_ADJUST_CFA_OFFSET 4
925 jmp error_code
926 CFI_ENDPROC
927END(invalid_op)
928
929ENTRY(coprocessor_segment_overrun)
930 RING0_INT_FRAME
931 pushl $0
932 CFI_ADJUST_CFA_OFFSET 4
933 pushl $do_coprocessor_segment_overrun
934 CFI_ADJUST_CFA_OFFSET 4
935 jmp error_code
936 CFI_ENDPROC
937END(coprocessor_segment_overrun)
938
939ENTRY(invalid_TSS)
940 RING0_EC_FRAME
941 pushl $do_invalid_TSS
942 CFI_ADJUST_CFA_OFFSET 4
943 jmp error_code
944 CFI_ENDPROC
945END(invalid_TSS)
946
947ENTRY(segment_not_present)
948 RING0_EC_FRAME
949 pushl $do_segment_not_present
950 CFI_ADJUST_CFA_OFFSET 4
951 jmp error_code
952 CFI_ENDPROC
953END(segment_not_present)
954
955ENTRY(stack_segment)
956 RING0_EC_FRAME
957 pushl $do_stack_segment
958 CFI_ADJUST_CFA_OFFSET 4
959 jmp error_code
960 CFI_ENDPROC
961END(stack_segment)
962
963KPROBE_ENTRY(general_protection)
964 RING0_EC_FRAME
965 pushl $do_general_protection
966 CFI_ADJUST_CFA_OFFSET 4
967 jmp error_code
968 CFI_ENDPROC
969KPROBE_END(general_protection)
970
971ENTRY(alignment_check)
972 RING0_EC_FRAME
973 pushl $do_alignment_check
974 CFI_ADJUST_CFA_OFFSET 4
975 jmp error_code
976 CFI_ENDPROC
977END(alignment_check)
978
979ENTRY(divide_error)
980 RING0_INT_FRAME
981 pushl $0 # no error code
982 CFI_ADJUST_CFA_OFFSET 4
983 pushl $do_divide_error
984 CFI_ADJUST_CFA_OFFSET 4
985 jmp error_code
986 CFI_ENDPROC
987END(divide_error)
988
989#ifdef CONFIG_X86_MCE
990ENTRY(machine_check)
991 RING0_INT_FRAME
992 pushl $0
993 CFI_ADJUST_CFA_OFFSET 4
994 pushl machine_check_vector
995 CFI_ADJUST_CFA_OFFSET 4
996 jmp error_code
997 CFI_ENDPROC
998END(machine_check)
999#endif
1000
1001ENTRY(spurious_interrupt_bug)
1002 RING0_INT_FRAME
1003 pushl $0
1004 CFI_ADJUST_CFA_OFFSET 4
1005 pushl $do_spurious_interrupt_bug
1006 CFI_ADJUST_CFA_OFFSET 4
1007 jmp error_code
1008 CFI_ENDPROC
1009END(spurious_interrupt_bug)
1010
1011ENTRY(kernel_thread_helper)
1012 pushl $0 # fake return address for unwinder
1013 CFI_STARTPROC
1014 movl %edx,%eax
1015 push %edx
1016 CFI_ADJUST_CFA_OFFSET 4
1017 call *%ebx
1018 push %eax
1019 CFI_ADJUST_CFA_OFFSET 4
1020 call do_exit
1021 CFI_ENDPROC
1022ENDPROC(kernel_thread_helper)
1023
1024#ifdef CONFIG_XEN
1025ENTRY(xen_hypervisor_callback)
1026 CFI_STARTPROC
1027 pushl $0
1028 CFI_ADJUST_CFA_OFFSET 4
1029 SAVE_ALL
1030 TRACE_IRQS_OFF
1031
1032 /* Check to see if we got the event in the critical
1033 region in xen_iret_direct, after we've reenabled
1034 events and checked for pending events. This simulates
1035 iret instruction's behaviour where it delivers a
1036 pending interrupt when enabling interrupts. */
1037 movl PT_EIP(%esp),%eax
1038 cmpl $xen_iret_start_crit,%eax
1039 jb 1f
1040 cmpl $xen_iret_end_crit,%eax
1041 jae 1f
1042
1043 call xen_iret_crit_fixup
1044
10451: mov %esp, %eax
1046 call xen_evtchn_do_upcall
1047 jmp ret_from_intr
1048 CFI_ENDPROC
1049ENDPROC(xen_hypervisor_callback)
1050
1051# Hypervisor uses this for application faults while it executes.
1052# We get here for two reasons:
1053# 1. Fault while reloading DS, ES, FS or GS
1054# 2. Fault while executing IRET
1055# Category 1 we fix up by reattempting the load, and zeroing the segment
1056# register if the load fails.
1057# Category 2 we fix up by jumping to do_iret_error. We cannot use the
1058# normal Linux return path in this case because if we use the IRET hypercall
1059# to pop the stack frame we end up in an infinite loop of failsafe callbacks.
1060# We distinguish between categories by maintaining a status value in EAX.
1061ENTRY(xen_failsafe_callback)
1062 CFI_STARTPROC
1063 pushl %eax
1064 CFI_ADJUST_CFA_OFFSET 4
1065 movl $1,%eax
10661: mov 4(%esp),%ds
10672: mov 8(%esp),%es
10683: mov 12(%esp),%fs
10694: mov 16(%esp),%gs
1070 testl %eax,%eax
1071 popl %eax
1072 CFI_ADJUST_CFA_OFFSET -4
1073 lea 16(%esp),%esp
1074 CFI_ADJUST_CFA_OFFSET -16
1075 jz 5f
1076 addl $16,%esp
1077 jmp iret_exc # EAX != 0 => Category 2 (Bad IRET)
10785: pushl $0 # EAX == 0 => Category 1 (Bad segment)
1079 CFI_ADJUST_CFA_OFFSET 4
1080 SAVE_ALL
1081 jmp ret_from_exception
1082 CFI_ENDPROC
1083
1084.section .fixup,"ax"
10856: xorl %eax,%eax
1086 movl %eax,4(%esp)
1087 jmp 1b
10887: xorl %eax,%eax
1089 movl %eax,8(%esp)
1090 jmp 2b
10918: xorl %eax,%eax
1092 movl %eax,12(%esp)
1093 jmp 3b
10949: xorl %eax,%eax
1095 movl %eax,16(%esp)
1096 jmp 4b
1097.previous
1098.section __ex_table,"a"
1099 .align 4
1100 .long 1b,6b
1101 .long 2b,7b
1102 .long 3b,8b
1103 .long 4b,9b
1104.previous
1105ENDPROC(xen_failsafe_callback)
1106
1107#endif /* CONFIG_XEN */
1108
1109.section .rodata,"a"
1110#include "syscall_table_32.S"
1111
1112syscall_table_size=(.-sys_call_table)
diff --git a/arch/x86_64/kernel/entry.S b/arch/x86/kernel/entry_64.S
index 1d232e5f5658..1d232e5f5658 100644
--- a/arch/x86_64/kernel/entry.S
+++ b/arch/x86/kernel/entry_64.S
diff --git a/arch/x86_64/kernel/genapic.c b/arch/x86/kernel/genapic_64.c
index 47496a40e84f..47496a40e84f 100644
--- a/arch/x86_64/kernel/genapic.c
+++ b/arch/x86/kernel/genapic_64.c
diff --git a/arch/x86_64/kernel/genapic_flat.c b/arch/x86/kernel/genapic_flat_64.c
index ecb01eefdd27..ecb01eefdd27 100644
--- a/arch/x86_64/kernel/genapic_flat.c
+++ b/arch/x86/kernel/genapic_flat_64.c
diff --git a/arch/i386/kernel/geode.c b/arch/x86/kernel/geode_32.c
index 41e8aec4c61d..41e8aec4c61d 100644
--- a/arch/i386/kernel/geode.c
+++ b/arch/x86/kernel/geode_32.c
diff --git a/arch/x86_64/kernel/head64.c b/arch/x86/kernel/head64.c
index 6c34bdd22e26..6c34bdd22e26 100644
--- a/arch/x86_64/kernel/head64.c
+++ b/arch/x86/kernel/head64.c
diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
new file mode 100644
index 000000000000..9150ca9b5f80
--- /dev/null
+++ b/arch/x86/kernel/head_32.S
@@ -0,0 +1,578 @@
1/*
2 * linux/arch/i386/kernel/head.S -- the 32-bit startup code.
3 *
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 *
6 * Enhanced CPU detection and feature setting code by Mike Jagdis
7 * and Martin Mares, November 1997.
8 */
9
10.text
11#include <linux/threads.h>
12#include <linux/linkage.h>
13#include <asm/segment.h>
14#include <asm/page.h>
15#include <asm/pgtable.h>
16#include <asm/desc.h>
17#include <asm/cache.h>
18#include <asm/thread_info.h>
19#include <asm/asm-offsets.h>
20#include <asm/setup.h>
21
22/*
23 * References to members of the new_cpu_data structure.
24 */
25
26#define X86 new_cpu_data+CPUINFO_x86
27#define X86_VENDOR new_cpu_data+CPUINFO_x86_vendor
28#define X86_MODEL new_cpu_data+CPUINFO_x86_model
29#define X86_MASK new_cpu_data+CPUINFO_x86_mask
30#define X86_HARD_MATH new_cpu_data+CPUINFO_hard_math
31#define X86_CPUID new_cpu_data+CPUINFO_cpuid_level
32#define X86_CAPABILITY new_cpu_data+CPUINFO_x86_capability
33#define X86_VENDOR_ID new_cpu_data+CPUINFO_x86_vendor_id
34
35/*
36 * This is how much memory *in addition to the memory covered up to
37 * and including _end* we need mapped initially.
38 * We need:
39 * - one bit for each possible page, but only in low memory, which means
40 * 2^32/4096/8 = 128K worst case (4G/4G split.)
41 * - enough space to map all low memory, which means
42 * (2^32/4096) / 1024 pages (worst case, non PAE)
43 * (2^32/4096) / 512 + 4 pages (worst case for PAE)
44 * - a few pages for allocator use before the kernel pagetable has
45 * been set up
46 *
47 * Modulo rounding, each megabyte assigned here requires a kilobyte of
48 * memory, which is currently unreclaimed.
49 *
50 * This should be a multiple of a page.
51 */
52LOW_PAGES = 1<<(32-PAGE_SHIFT_asm)
53
54#if PTRS_PER_PMD > 1
55PAGE_TABLE_SIZE = (LOW_PAGES / PTRS_PER_PMD) + PTRS_PER_PGD
56#else
57PAGE_TABLE_SIZE = (LOW_PAGES / PTRS_PER_PGD)
58#endif
59BOOTBITMAP_SIZE = LOW_PAGES / 8
60ALLOCATOR_SLOP = 4
61
62INIT_MAP_BEYOND_END = BOOTBITMAP_SIZE + (PAGE_TABLE_SIZE + ALLOCATOR_SLOP)*PAGE_SIZE_asm
63
64/*
65 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
66 * %esi points to the real-mode code as a 32-bit pointer.
67 * CS and DS must be 4 GB flat segments, but we don't depend on
68 * any particular GDT layout, because we load our own as soon as we
69 * can.
70 */
71.section .text.head,"ax",@progbits
72ENTRY(startup_32)
73
74/*
75 * Set segments to known values.
76 */
77 cld
78 lgdt boot_gdt_descr - __PAGE_OFFSET
79 movl $(__BOOT_DS),%eax
80 movl %eax,%ds
81 movl %eax,%es
82 movl %eax,%fs
83 movl %eax,%gs
84
85/*
86 * Clear BSS first so that there are no surprises...
87 * No need to cld as DF is already clear from cld above...
88 */
89 xorl %eax,%eax
90 movl $__bss_start - __PAGE_OFFSET,%edi
91 movl $__bss_stop - __PAGE_OFFSET,%ecx
92 subl %edi,%ecx
93 shrl $2,%ecx
94 rep ; stosl
95/*
96 * Copy bootup parameters out of the way.
97 * Note: %esi still has the pointer to the real-mode data.
98 * With the kexec as boot loader, parameter segment might be loaded beyond
99 * kernel image and might not even be addressable by early boot page tables.
100 * (kexec on panic case). Hence copy out the parameters before initializing
101 * page tables.
102 */
103 movl $(boot_params - __PAGE_OFFSET),%edi
104 movl $(PARAM_SIZE/4),%ecx
105 cld
106 rep
107 movsl
108 movl boot_params - __PAGE_OFFSET + NEW_CL_POINTER,%esi
109 andl %esi,%esi
110 jnz 2f # New command line protocol
111 cmpw $(OLD_CL_MAGIC),OLD_CL_MAGIC_ADDR
112 jne 1f
113 movzwl OLD_CL_OFFSET,%esi
114 addl $(OLD_CL_BASE_ADDR),%esi
1152:
116 movl $(boot_command_line - __PAGE_OFFSET),%edi
117 movl $(COMMAND_LINE_SIZE/4),%ecx
118 rep
119 movsl
1201:
121
122/*
123 * Initialize page tables. This creates a PDE and a set of page
124 * tables, which are located immediately beyond _end. The variable
125 * init_pg_tables_end is set up to point to the first "safe" location.
126 * Mappings are created both at virtual address 0 (identity mapping)
127 * and PAGE_OFFSET for up to _end+sizeof(page tables)+INIT_MAP_BEYOND_END.
128 *
129 * Warning: don't use %esi or the stack in this code. However, %esp
130 * can be used as a GPR if you really need it...
131 */
132page_pde_offset = (__PAGE_OFFSET >> 20);
133
134 movl $(pg0 - __PAGE_OFFSET), %edi
135 movl $(swapper_pg_dir - __PAGE_OFFSET), %edx
136 movl $0x007, %eax /* 0x007 = PRESENT+RW+USER */
13710:
138 leal 0x007(%edi),%ecx /* Create PDE entry */
139 movl %ecx,(%edx) /* Store identity PDE entry */
140 movl %ecx,page_pde_offset(%edx) /* Store kernel PDE entry */
141 addl $4,%edx
142 movl $1024, %ecx
14311:
144 stosl
145 addl $0x1000,%eax
146 loop 11b
147 /* End condition: we must map up to and including INIT_MAP_BEYOND_END */
148 /* bytes beyond the end of our own page tables; the +0x007 is the attribute bits */
149 leal (INIT_MAP_BEYOND_END+0x007)(%edi),%ebp
150 cmpl %ebp,%eax
151 jb 10b
152 movl %edi,(init_pg_tables_end - __PAGE_OFFSET)
153
154 xorl %ebx,%ebx /* This is the boot CPU (BSP) */
155 jmp 3f
156/*
157 * Non-boot CPU entry point; entered from trampoline.S
158 * We can't lgdt here, because lgdt itself uses a data segment, but
159 * we know the trampoline has already loaded the boot_gdt for us.
160 *
161 * If cpu hotplug is not supported then this code can go in init section
162 * which will be freed later
163 */
164
165#ifndef CONFIG_HOTPLUG_CPU
166.section .init.text,"ax",@progbits
167#endif
168
169 /* Do an early initialization of the fixmap area */
170 movl $(swapper_pg_dir - __PAGE_OFFSET), %edx
171 movl $(swapper_pg_pmd - __PAGE_OFFSET), %eax
172 addl $0x007, %eax /* 0x007 = PRESENT+RW+USER */
173 movl %eax, 4092(%edx)
174
175#ifdef CONFIG_SMP
176ENTRY(startup_32_smp)
177 cld
178 movl $(__BOOT_DS),%eax
179 movl %eax,%ds
180 movl %eax,%es
181 movl %eax,%fs
182 movl %eax,%gs
183
184/*
185 * New page tables may be in 4Mbyte page mode and may
186 * be using the global pages.
187 *
188 * NOTE! If we are on a 486 we may have no cr4 at all!
189 * So we do not try to touch it unless we really have
190 * some bits in it to set. This won't work if the BSP
191 * implements cr4 but this AP does not -- very unlikely
192 * but be warned! The same applies to the pse feature
193 * if not equally supported. --macro
194 *
195 * NOTE! We have to correct for the fact that we're
196 * not yet offset PAGE_OFFSET..
197 */
198#define cr4_bits mmu_cr4_features-__PAGE_OFFSET
199 movl cr4_bits,%edx
200 andl %edx,%edx
201 jz 6f
202 movl %cr4,%eax # Turn on paging options (PSE,PAE,..)
203 orl %edx,%eax
204 movl %eax,%cr4
205
206 btl $5, %eax # check if PAE is enabled
207 jnc 6f
208
209 /* Check if extended functions are implemented */
210 movl $0x80000000, %eax
211 cpuid
212 cmpl $0x80000000, %eax
213 jbe 6f
214 mov $0x80000001, %eax
215 cpuid
216 /* Execute Disable bit supported? */
217 btl $20, %edx
218 jnc 6f
219
220 /* Setup EFER (Extended Feature Enable Register) */
221 movl $0xc0000080, %ecx
222 rdmsr
223
224 btsl $11, %eax
225 /* Make changes effective */
226 wrmsr
227
2286:
229 /* This is a secondary processor (AP) */
230 xorl %ebx,%ebx
231 incl %ebx
232
233#endif /* CONFIG_SMP */
2343:
235
236/*
237 * Enable paging
238 */
239 movl $swapper_pg_dir-__PAGE_OFFSET,%eax
240 movl %eax,%cr3 /* set the page table pointer.. */
241 movl %cr0,%eax
242 orl $0x80000000,%eax
243 movl %eax,%cr0 /* ..and set paging (PG) bit */
244 ljmp $__BOOT_CS,$1f /* Clear prefetch and normalize %eip */
2451:
246 /* Set up the stack pointer */
247 lss stack_start,%esp
248
249/*
250 * Initialize eflags. Some BIOS's leave bits like NT set. This would
251 * confuse the debugger if this code is traced.
252 * XXX - best to initialize before switching to protected mode.
253 */
254 pushl $0
255 popfl
256
257#ifdef CONFIG_SMP
258 andl %ebx,%ebx
259 jz 1f /* Initial CPU cleans BSS */
260 jmp checkCPUtype
2611:
262#endif /* CONFIG_SMP */
263
264/*
265 * start system 32-bit setup. We need to re-do some of the things done
266 * in 16-bit mode for the "real" operations.
267 */
268 call setup_idt
269
270checkCPUtype:
271
272 movl $-1,X86_CPUID # -1 for no CPUID initially
273
274/* check if it is 486 or 386. */
275/*
276 * XXX - this does a lot of unnecessary setup. Alignment checks don't
277 * apply at our cpl of 0 and the stack ought to be aligned already, and
278 * we don't need to preserve eflags.
279 */
280
281 movb $3,X86 # at least 386
282 pushfl # push EFLAGS
283 popl %eax # get EFLAGS
284 movl %eax,%ecx # save original EFLAGS
285 xorl $0x240000,%eax # flip AC and ID bits in EFLAGS
286 pushl %eax # copy to EFLAGS
287 popfl # set EFLAGS
288 pushfl # get new EFLAGS
289 popl %eax # put it in eax
290 xorl %ecx,%eax # change in flags
291 pushl %ecx # restore original EFLAGS
292 popfl
293 testl $0x40000,%eax # check if AC bit changed
294 je is386
295
296 movb $4,X86 # at least 486
297 testl $0x200000,%eax # check if ID bit changed
298 je is486
299
300 /* get vendor info */
301 xorl %eax,%eax # call CPUID with 0 -> return vendor ID
302 cpuid
303 movl %eax,X86_CPUID # save CPUID level
304 movl %ebx,X86_VENDOR_ID # lo 4 chars
305 movl %edx,X86_VENDOR_ID+4 # next 4 chars
306 movl %ecx,X86_VENDOR_ID+8 # last 4 chars
307
308 orl %eax,%eax # do we have processor info as well?
309 je is486
310
311 movl $1,%eax # Use the CPUID instruction to get CPU type
312 cpuid
313 movb %al,%cl # save reg for future use
314 andb $0x0f,%ah # mask processor family
315 movb %ah,X86
316 andb $0xf0,%al # mask model
317 shrb $4,%al
318 movb %al,X86_MODEL
319 andb $0x0f,%cl # mask mask revision
320 movb %cl,X86_MASK
321 movl %edx,X86_CAPABILITY
322
323is486: movl $0x50022,%ecx # set AM, WP, NE and MP
324 jmp 2f
325
326is386: movl $2,%ecx # set MP
3272: movl %cr0,%eax
328 andl $0x80000011,%eax # Save PG,PE,ET
329 orl %ecx,%eax
330 movl %eax,%cr0
331
332 call check_x87
333 lgdt early_gdt_descr
334 lidt idt_descr
335 ljmp $(__KERNEL_CS),$1f
3361: movl $(__KERNEL_DS),%eax # reload all the segment registers
337 movl %eax,%ss # after changing gdt.
338 movl %eax,%fs # gets reset once there's real percpu
339
340 movl $(__USER_DS),%eax # DS/ES contains default USER segment
341 movl %eax,%ds
342 movl %eax,%es
343
344 xorl %eax,%eax # Clear GS and LDT
345 movl %eax,%gs
346 lldt %ax
347
348 cld # gcc2 wants the direction flag cleared at all times
349 pushl $0 # fake return address for unwinder
350#ifdef CONFIG_SMP
351 movb ready, %cl
352 movb $1, ready
353 cmpb $0,%cl # the first CPU calls start_kernel
354 je 1f
355 movl $(__KERNEL_PERCPU), %eax
356 movl %eax,%fs # set this cpu's percpu
357 jmp initialize_secondary # all other CPUs call initialize_secondary
3581:
359#endif /* CONFIG_SMP */
360 jmp start_kernel
361
362/*
363 * We depend on ET to be correct. This checks for 287/387.
364 */
365check_x87:
366 movb $0,X86_HARD_MATH
367 clts
368 fninit
369 fstsw %ax
370 cmpb $0,%al
371 je 1f
372 movl %cr0,%eax /* no coprocessor: have to set bits */
373 xorl $4,%eax /* set EM */
374 movl %eax,%cr0
375 ret
376 ALIGN
3771: movb $1,X86_HARD_MATH
378 .byte 0xDB,0xE4 /* fsetpm for 287, ignored by 387 */
379 ret
380
381/*
382 * setup_idt
383 *
384 * sets up a idt with 256 entries pointing to
385 * ignore_int, interrupt gates. It doesn't actually load
386 * idt - that can be done only after paging has been enabled
387 * and the kernel moved to PAGE_OFFSET. Interrupts
388 * are enabled elsewhere, when we can be relatively
389 * sure everything is ok.
390 *
391 * Warning: %esi is live across this function.
392 */
393setup_idt:
394 lea ignore_int,%edx
395 movl $(__KERNEL_CS << 16),%eax
396 movw %dx,%ax /* selector = 0x0010 = cs */
397 movw $0x8E00,%dx /* interrupt gate - dpl=0, present */
398
399 lea idt_table,%edi
400 mov $256,%ecx
401rp_sidt:
402 movl %eax,(%edi)
403 movl %edx,4(%edi)
404 addl $8,%edi
405 dec %ecx
406 jne rp_sidt
407
408.macro set_early_handler handler,trapno
409 lea \handler,%edx
410 movl $(__KERNEL_CS << 16),%eax
411 movw %dx,%ax
412 movw $0x8E00,%dx /* interrupt gate - dpl=0, present */
413 lea idt_table,%edi
414 movl %eax,8*\trapno(%edi)
415 movl %edx,8*\trapno+4(%edi)
416.endm
417
418 set_early_handler handler=early_divide_err,trapno=0
419 set_early_handler handler=early_illegal_opcode,trapno=6
420 set_early_handler handler=early_protection_fault,trapno=13
421 set_early_handler handler=early_page_fault,trapno=14
422
423 ret
424
425early_divide_err:
426 xor %edx,%edx
427 pushl $0 /* fake errcode */
428 jmp early_fault
429
430early_illegal_opcode:
431 movl $6,%edx
432 pushl $0 /* fake errcode */
433 jmp early_fault
434
435early_protection_fault:
436 movl $13,%edx
437 jmp early_fault
438
439early_page_fault:
440 movl $14,%edx
441 jmp early_fault
442
443early_fault:
444 cld
445#ifdef CONFIG_PRINTK
446 movl $(__KERNEL_DS),%eax
447 movl %eax,%ds
448 movl %eax,%es
449 cmpl $2,early_recursion_flag
450 je hlt_loop
451 incl early_recursion_flag
452 movl %cr2,%eax
453 pushl %eax
454 pushl %edx /* trapno */
455 pushl $fault_msg
456#ifdef CONFIG_EARLY_PRINTK
457 call early_printk
458#else
459 call printk
460#endif
461#endif
462hlt_loop:
463 hlt
464 jmp hlt_loop
465
466/* This is the default interrupt "handler" :-) */
467 ALIGN
468ignore_int:
469 cld
470#ifdef CONFIG_PRINTK
471 pushl %eax
472 pushl %ecx
473 pushl %edx
474 pushl %es
475 pushl %ds
476 movl $(__KERNEL_DS),%eax
477 movl %eax,%ds
478 movl %eax,%es
479 cmpl $2,early_recursion_flag
480 je hlt_loop
481 incl early_recursion_flag
482 pushl 16(%esp)
483 pushl 24(%esp)
484 pushl 32(%esp)
485 pushl 40(%esp)
486 pushl $int_msg
487#ifdef CONFIG_EARLY_PRINTK
488 call early_printk
489#else
490 call printk
491#endif
492 addl $(5*4),%esp
493 popl %ds
494 popl %es
495 popl %edx
496 popl %ecx
497 popl %eax
498#endif
499 iret
500
501.section .text
502/*
503 * Real beginning of normal "text" segment
504 */
505ENTRY(stext)
506ENTRY(_stext)
507
508/*
509 * BSS section
510 */
511.section ".bss.page_aligned","wa"
512 .align PAGE_SIZE_asm
513ENTRY(swapper_pg_dir)
514 .fill 1024,4,0
515ENTRY(swapper_pg_pmd)
516 .fill 1024,4,0
517ENTRY(empty_zero_page)
518 .fill 4096,1,0
519
520/*
521 * This starts the data section.
522 */
523.data
524ENTRY(stack_start)
525 .long init_thread_union+THREAD_SIZE
526 .long __BOOT_DS
527
528ready: .byte 0
529
530early_recursion_flag:
531 .long 0
532
533int_msg:
534 .asciz "Unknown interrupt or fault at EIP %p %p %p\n"
535
536fault_msg:
537 .ascii "Int %d: CR2 %p err %p EIP %p CS %p flags %p\n"
538 .asciz "Stack: %p %p %p %p %p %p %p %p\n"
539
540#include "../../x86/xen/xen-head.S"
541
542/*
543 * The IDT and GDT 'descriptors' are a strange 48-bit object
544 * only used by the lidt and lgdt instructions. They are not
545 * like usual segment descriptors - they consist of a 16-bit
546 * segment size, and 32-bit linear address value:
547 */
548
549.globl boot_gdt_descr
550.globl idt_descr
551
552 ALIGN
553# early boot GDT descriptor (must use 1:1 address mapping)
554 .word 0 # 32 bit align gdt_desc.address
555boot_gdt_descr:
556 .word __BOOT_DS+7
557 .long boot_gdt - __PAGE_OFFSET
558
559 .word 0 # 32-bit align idt_desc.address
560idt_descr:
561 .word IDT_ENTRIES*8-1 # idt contains 256 entries
562 .long idt_table
563
564# boot GDT descriptor (later on used by CPU#0):
565 .word 0 # 32 bit align gdt_desc.address
566ENTRY(early_gdt_descr)
567 .word GDT_ENTRIES*8-1
568 .long per_cpu__gdt_page /* Overwritten for secondary CPUs */
569
570/*
571 * The boot_gdt must mirror the equivalent in setup.S and is
572 * used only for booting.
573 */
574 .align L1_CACHE_BYTES
575ENTRY(boot_gdt)
576 .fill GDT_ENTRY_BOOT_CS,8,0
577 .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
578 .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
diff --git a/arch/x86_64/kernel/head.S b/arch/x86/kernel/head_64.S
index b6167fe3330e..b6167fe3330e 100644
--- a/arch/x86_64/kernel/head.S
+++ b/arch/x86/kernel/head_64.S
diff --git a/arch/i386/kernel/hpet.c b/arch/x86/kernel/hpet_32.c
index 533d4932bc79..533d4932bc79 100644
--- a/arch/i386/kernel/hpet.c
+++ b/arch/x86/kernel/hpet_32.c
diff --git a/arch/x86_64/kernel/hpet.c b/arch/x86/kernel/hpet_64.c
index e2d1b912e154..e2d1b912e154 100644
--- a/arch/x86_64/kernel/hpet.c
+++ b/arch/x86/kernel/hpet_64.c
diff --git a/arch/i386/kernel/i386_ksyms.c b/arch/x86/kernel/i386_ksyms_32.c
index e3d4b73bfdb0..e3d4b73bfdb0 100644
--- a/arch/i386/kernel/i386_ksyms.c
+++ b/arch/x86/kernel/i386_ksyms_32.c
diff --git a/arch/i386/kernel/i387.c b/arch/x86/kernel/i387_32.c
index 665847281ed2..665847281ed2 100644
--- a/arch/i386/kernel/i387.c
+++ b/arch/x86/kernel/i387_32.c
diff --git a/arch/x86_64/kernel/i387.c b/arch/x86/kernel/i387_64.c
index 1d58c13bc6bc..1d58c13bc6bc 100644
--- a/arch/x86_64/kernel/i387.c
+++ b/arch/x86/kernel/i387_64.c
diff --git a/arch/i386/kernel/i8237.c b/arch/x86/kernel/i8237.c
index 6f508e8d7c57..6f508e8d7c57 100644
--- a/arch/i386/kernel/i8237.c
+++ b/arch/x86/kernel/i8237.c
diff --git a/arch/i386/kernel/i8253.c b/arch/x86/kernel/i8253_32.c
index 6d839f2f1b1a..6d839f2f1b1a 100644
--- a/arch/i386/kernel/i8253.c
+++ b/arch/x86/kernel/i8253_32.c
diff --git a/arch/i386/kernel/i8259.c b/arch/x86/kernel/i8259_32.c
index 0499cbe9871a..0499cbe9871a 100644
--- a/arch/i386/kernel/i8259.c
+++ b/arch/x86/kernel/i8259_32.c
diff --git a/arch/x86_64/kernel/i8259.c b/arch/x86/kernel/i8259_64.c
index 948cae646099..948cae646099 100644
--- a/arch/x86_64/kernel/i8259.c
+++ b/arch/x86/kernel/i8259_64.c
diff --git a/arch/i386/kernel/init_task.c b/arch/x86/kernel/init_task_32.c
index d26fc063a760..d26fc063a760 100644
--- a/arch/i386/kernel/init_task.c
+++ b/arch/x86/kernel/init_task_32.c
diff --git a/arch/x86_64/kernel/init_task.c b/arch/x86/kernel/init_task_64.c
index 4ff33d4f8551..4ff33d4f8551 100644
--- a/arch/x86_64/kernel/init_task.c
+++ b/arch/x86/kernel/init_task_64.c
diff --git a/arch/i386/kernel/io_apic.c b/arch/x86/kernel/io_apic_32.c
index e2f4a1c68547..e2f4a1c68547 100644
--- a/arch/i386/kernel/io_apic.c
+++ b/arch/x86/kernel/io_apic_32.c
diff --git a/arch/x86_64/kernel/io_apic.c b/arch/x86/kernel/io_apic_64.c
index 966fa1062491..966fa1062491 100644
--- a/arch/x86_64/kernel/io_apic.c
+++ b/arch/x86/kernel/io_apic_64.c
diff --git a/arch/i386/kernel/ioport.c b/arch/x86/kernel/ioport_32.c
index 3d310a946d76..3d310a946d76 100644
--- a/arch/i386/kernel/ioport.c
+++ b/arch/x86/kernel/ioport_32.c
diff --git a/arch/x86_64/kernel/ioport.c b/arch/x86/kernel/ioport_64.c
index 653efa30b0f4..653efa30b0f4 100644
--- a/arch/x86_64/kernel/ioport.c
+++ b/arch/x86/kernel/ioport_64.c
diff --git a/arch/i386/kernel/irq.c b/arch/x86/kernel/irq_32.c
index dd2b97fc00b2..dd2b97fc00b2 100644
--- a/arch/i386/kernel/irq.c
+++ b/arch/x86/kernel/irq_32.c
diff --git a/arch/x86_64/kernel/irq.c b/arch/x86/kernel/irq_64.c
index 39cb3fa83ebb..39cb3fa83ebb 100644
--- a/arch/x86_64/kernel/irq.c
+++ b/arch/x86/kernel/irq_64.c
diff --git a/arch/x86_64/kernel/k8.c b/arch/x86/kernel/k8.c
index 7377ccb21335..7377ccb21335 100644
--- a/arch/x86_64/kernel/k8.c
+++ b/arch/x86/kernel/k8.c
diff --git a/arch/i386/kernel/kprobes.c b/arch/x86/kernel/kprobes_32.c
index 448a50b1324c..448a50b1324c 100644
--- a/arch/i386/kernel/kprobes.c
+++ b/arch/x86/kernel/kprobes_32.c
diff --git a/arch/x86_64/kernel/kprobes.c b/arch/x86/kernel/kprobes_64.c
index a30e004682e2..a30e004682e2 100644
--- a/arch/x86_64/kernel/kprobes.c
+++ b/arch/x86/kernel/kprobes_64.c
diff --git a/arch/i386/kernel/ldt.c b/arch/x86/kernel/ldt_32.c
index e0b2d17f4f10..e0b2d17f4f10 100644
--- a/arch/i386/kernel/ldt.c
+++ b/arch/x86/kernel/ldt_32.c
diff --git a/arch/x86_64/kernel/ldt.c b/arch/x86/kernel/ldt_64.c
index bc9ffd5c19cc..bc9ffd5c19cc 100644
--- a/arch/x86_64/kernel/ldt.c
+++ b/arch/x86/kernel/ldt_64.c
diff --git a/arch/i386/kernel/machine_kexec.c b/arch/x86/kernel/machine_kexec_32.c
index 91966bafb3dc..91966bafb3dc 100644
--- a/arch/i386/kernel/machine_kexec.c
+++ b/arch/x86/kernel/machine_kexec_32.c
diff --git a/arch/x86_64/kernel/machine_kexec.c b/arch/x86/kernel/machine_kexec_64.c
index c3a554703672..c3a554703672 100644
--- a/arch/x86_64/kernel/machine_kexec.c
+++ b/arch/x86/kernel/machine_kexec_64.c
diff --git a/arch/i386/kernel/mca.c b/arch/x86/kernel/mca_32.c
index b83672b89527..b83672b89527 100644
--- a/arch/i386/kernel/mca.c
+++ b/arch/x86/kernel/mca_32.c
diff --git a/arch/x86_64/kernel/mce.c b/arch/x86/kernel/mce_64.c
index a66d607f5b92..a66d607f5b92 100644
--- a/arch/x86_64/kernel/mce.c
+++ b/arch/x86/kernel/mce_64.c
diff --git a/arch/x86_64/kernel/mce_amd.c b/arch/x86/kernel/mce_amd_64.c
index 2f8a7f18b0fe..2f8a7f18b0fe 100644
--- a/arch/x86_64/kernel/mce_amd.c
+++ b/arch/x86/kernel/mce_amd_64.c
diff --git a/arch/x86_64/kernel/mce_intel.c b/arch/x86/kernel/mce_intel_64.c
index 6551505d8a2c..6551505d8a2c 100644
--- a/arch/x86_64/kernel/mce_intel.c
+++ b/arch/x86/kernel/mce_intel_64.c
diff --git a/arch/i386/kernel/microcode.c b/arch/x86/kernel/microcode.c
index 09cf78110358..09cf78110358 100644
--- a/arch/i386/kernel/microcode.c
+++ b/arch/x86/kernel/microcode.c
diff --git a/arch/i386/kernel/module.c b/arch/x86/kernel/module_32.c
index 3db0a5442eb1..3db0a5442eb1 100644
--- a/arch/i386/kernel/module.c
+++ b/arch/x86/kernel/module_32.c
diff --git a/arch/x86_64/kernel/module.c b/arch/x86/kernel/module_64.c
index a888e67f5874..a888e67f5874 100644
--- a/arch/x86_64/kernel/module.c
+++ b/arch/x86/kernel/module_64.c
diff --git a/arch/i386/kernel/mpparse.c b/arch/x86/kernel/mpparse_32.c
index 13abb4ebfb79..13abb4ebfb79 100644
--- a/arch/i386/kernel/mpparse.c
+++ b/arch/x86/kernel/mpparse_32.c
diff --git a/arch/x86_64/kernel/mpparse.c b/arch/x86/kernel/mpparse_64.c
index 8bf0ca03ac8e..8bf0ca03ac8e 100644
--- a/arch/x86_64/kernel/mpparse.c
+++ b/arch/x86/kernel/mpparse_64.c
diff --git a/arch/i386/kernel/msr.c b/arch/x86/kernel/msr.c
index 0c1069b8d638..0c1069b8d638 100644
--- a/arch/i386/kernel/msr.c
+++ b/arch/x86/kernel/msr.c
diff --git a/arch/i386/kernel/nmi.c b/arch/x86/kernel/nmi_32.c
index c7227e2180f8..c7227e2180f8 100644
--- a/arch/i386/kernel/nmi.c
+++ b/arch/x86/kernel/nmi_32.c
diff --git a/arch/x86_64/kernel/nmi.c b/arch/x86/kernel/nmi_64.c
index 0ec6d2ddb931..0ec6d2ddb931 100644
--- a/arch/x86_64/kernel/nmi.c
+++ b/arch/x86/kernel/nmi_64.c
diff --git a/arch/i386/kernel/numaq.c b/arch/x86/kernel/numaq_32.c
index 9000d82c6dc0..9000d82c6dc0 100644
--- a/arch/i386/kernel/numaq.c
+++ b/arch/x86/kernel/numaq_32.c
diff --git a/arch/i386/kernel/paravirt.c b/arch/x86/kernel/paravirt_32.c
index 739cfb207dd7..739cfb207dd7 100644
--- a/arch/i386/kernel/paravirt.c
+++ b/arch/x86/kernel/paravirt_32.c
diff --git a/arch/x86_64/kernel/pci-calgary.c b/arch/x86/kernel/pci-calgary_64.c
index 71da01e73f03..71da01e73f03 100644
--- a/arch/x86_64/kernel/pci-calgary.c
+++ b/arch/x86/kernel/pci-calgary_64.c
diff --git a/arch/i386/kernel/pci-dma.c b/arch/x86/kernel/pci-dma_32.c
index 048f09b62553..048f09b62553 100644
--- a/arch/i386/kernel/pci-dma.c
+++ b/arch/x86/kernel/pci-dma_32.c
diff --git a/arch/x86_64/kernel/pci-dma.c b/arch/x86/kernel/pci-dma_64.c
index 29711445c818..29711445c818 100644
--- a/arch/x86_64/kernel/pci-dma.c
+++ b/arch/x86/kernel/pci-dma_64.c
diff --git a/arch/x86_64/kernel/pci-gart.c b/arch/x86/kernel/pci-gart_64.c
index 4918c575d582..4918c575d582 100644
--- a/arch/x86_64/kernel/pci-gart.c
+++ b/arch/x86/kernel/pci-gart_64.c
diff --git a/arch/x86_64/kernel/pci-nommu.c b/arch/x86/kernel/pci-nommu_64.c
index 2a34c6c025a9..2a34c6c025a9 100644
--- a/arch/x86_64/kernel/pci-nommu.c
+++ b/arch/x86/kernel/pci-nommu_64.c
diff --git a/arch/x86_64/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb_64.c
index b2f405ea7c85..b2f405ea7c85 100644
--- a/arch/x86_64/kernel/pci-swiotlb.c
+++ b/arch/x86/kernel/pci-swiotlb_64.c
diff --git a/arch/i386/kernel/pcspeaker.c b/arch/x86/kernel/pcspeaker.c
index bc1f2d3ea277..bc1f2d3ea277 100644
--- a/arch/i386/kernel/pcspeaker.c
+++ b/arch/x86/kernel/pcspeaker.c
diff --git a/arch/x86_64/kernel/pmtimer.c b/arch/x86/kernel/pmtimer_64.c
index ae8f91214f15..ae8f91214f15 100644
--- a/arch/x86_64/kernel/pmtimer.c
+++ b/arch/x86/kernel/pmtimer_64.c
diff --git a/arch/i386/kernel/process.c b/arch/x86/kernel/process_32.c
index 84664710b784..84664710b784 100644
--- a/arch/i386/kernel/process.c
+++ b/arch/x86/kernel/process_32.c
diff --git a/arch/x86_64/kernel/process.c b/arch/x86/kernel/process_64.c
index 98956555450b..98956555450b 100644
--- a/arch/x86_64/kernel/process.c
+++ b/arch/x86/kernel/process_64.c
diff --git a/arch/i386/kernel/ptrace.c b/arch/x86/kernel/ptrace_32.c
index 7c1b92522e95..7c1b92522e95 100644
--- a/arch/i386/kernel/ptrace.c
+++ b/arch/x86/kernel/ptrace_32.c
diff --git a/arch/x86_64/kernel/ptrace.c b/arch/x86/kernel/ptrace_64.c
index eea3702427b4..eea3702427b4 100644
--- a/arch/x86_64/kernel/ptrace.c
+++ b/arch/x86/kernel/ptrace_64.c
diff --git a/arch/i386/kernel/quirks.c b/arch/x86/kernel/quirks.c
index 6722469c2633..6722469c2633 100644
--- a/arch/i386/kernel/quirks.c
+++ b/arch/x86/kernel/quirks.c
diff --git a/arch/i386/kernel/reboot.c b/arch/x86/kernel/reboot_32.c
index b37ed226830a..b37ed226830a 100644
--- a/arch/i386/kernel/reboot.c
+++ b/arch/x86/kernel/reboot_32.c
diff --git a/arch/x86_64/kernel/reboot.c b/arch/x86/kernel/reboot_64.c
index 368db2b9c5ac..368db2b9c5ac 100644
--- a/arch/x86_64/kernel/reboot.c
+++ b/arch/x86/kernel/reboot_64.c
diff --git a/arch/i386/kernel/reboot_fixups.c b/arch/x86/kernel/reboot_fixups_32.c
index 03e1cce58f49..03e1cce58f49 100644
--- a/arch/i386/kernel/reboot_fixups.c
+++ b/arch/x86/kernel/reboot_fixups_32.c
diff --git a/arch/i386/kernel/relocate_kernel.S b/arch/x86/kernel/relocate_kernel_32.S
index f151d6fae462..f151d6fae462 100644
--- a/arch/i386/kernel/relocate_kernel.S
+++ b/arch/x86/kernel/relocate_kernel_32.S
diff --git a/arch/x86_64/kernel/relocate_kernel.S b/arch/x86/kernel/relocate_kernel_64.S
index 14e95872c6a3..14e95872c6a3 100644
--- a/arch/x86_64/kernel/relocate_kernel.S
+++ b/arch/x86/kernel/relocate_kernel_64.S
diff --git a/arch/i386/kernel/scx200.c b/arch/x86/kernel/scx200_32.c
index c7d3df23f589..c7d3df23f589 100644
--- a/arch/i386/kernel/scx200.c
+++ b/arch/x86/kernel/scx200_32.c
diff --git a/arch/x86_64/kernel/setup64.c b/arch/x86/kernel/setup64.c
index 1200aaac403e..1200aaac403e 100644
--- a/arch/x86_64/kernel/setup64.c
+++ b/arch/x86/kernel/setup64.c
diff --git a/arch/i386/kernel/setup.c b/arch/x86/kernel/setup_32.c
index d474cd639bcb..d474cd639bcb 100644
--- a/arch/i386/kernel/setup.c
+++ b/arch/x86/kernel/setup_32.c
diff --git a/arch/x86_64/kernel/setup.c b/arch/x86/kernel/setup_64.c
index af838f6b0b7f..af838f6b0b7f 100644
--- a/arch/x86_64/kernel/setup.c
+++ b/arch/x86/kernel/setup_64.c
diff --git a/arch/i386/kernel/sigframe.h b/arch/x86/kernel/sigframe_32.h
index 0b2221711dad..0b2221711dad 100644
--- a/arch/i386/kernel/sigframe.h
+++ b/arch/x86/kernel/sigframe_32.h
diff --git a/arch/x86/kernel/signal_32.c b/arch/x86/kernel/signal_32.c
new file mode 100644
index 000000000000..c03570f7fe8e
--- /dev/null
+++ b/arch/x86/kernel/signal_32.c
@@ -0,0 +1,667 @@
1/*
2 * linux/arch/i386/kernel/signal.c
3 *
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 *
6 * 1997-11-28 Modified for POSIX.1b signals by Richard Henderson
7 * 2000-06-20 Pentium III FXSR, SSE support by Gareth Hughes
8 */
9
10#include <linux/sched.h>
11#include <linux/mm.h>
12#include <linux/smp.h>
13#include <linux/kernel.h>
14#include <linux/signal.h>
15#include <linux/errno.h>
16#include <linux/wait.h>
17#include <linux/unistd.h>
18#include <linux/stddef.h>
19#include <linux/personality.h>
20#include <linux/suspend.h>
21#include <linux/ptrace.h>
22#include <linux/elf.h>
23#include <linux/binfmts.h>
24#include <asm/processor.h>
25#include <asm/ucontext.h>
26#include <asm/uaccess.h>
27#include <asm/i387.h>
28#include "sigframe_32.h"
29
30#define DEBUG_SIG 0
31
32#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
33
34/*
35 * Atomically swap in the new signal mask, and wait for a signal.
36 */
37asmlinkage int
38sys_sigsuspend(int history0, int history1, old_sigset_t mask)
39{
40 mask &= _BLOCKABLE;
41 spin_lock_irq(&current->sighand->siglock);
42 current->saved_sigmask = current->blocked;
43 siginitset(&current->blocked, mask);
44 recalc_sigpending();
45 spin_unlock_irq(&current->sighand->siglock);
46
47 current->state = TASK_INTERRUPTIBLE;
48 schedule();
49 set_thread_flag(TIF_RESTORE_SIGMASK);
50 return -ERESTARTNOHAND;
51}
52
53asmlinkage int
54sys_sigaction(int sig, const struct old_sigaction __user *act,
55 struct old_sigaction __user *oact)
56{
57 struct k_sigaction new_ka, old_ka;
58 int ret;
59
60 if (act) {
61 old_sigset_t mask;
62 if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
63 __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
64 __get_user(new_ka.sa.sa_restorer, &act->sa_restorer))
65 return -EFAULT;
66 __get_user(new_ka.sa.sa_flags, &act->sa_flags);
67 __get_user(mask, &act->sa_mask);
68 siginitset(&new_ka.sa.sa_mask, mask);
69 }
70
71 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
72
73 if (!ret && oact) {
74 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
75 __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
76 __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer))
77 return -EFAULT;
78 __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
79 __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
80 }
81
82 return ret;
83}
84
85asmlinkage int
86sys_sigaltstack(unsigned long ebx)
87{
88 /* This is needed to make gcc realize it doesn't own the "struct pt_regs" */
89 struct pt_regs *regs = (struct pt_regs *)&ebx;
90 const stack_t __user *uss = (const stack_t __user *)ebx;
91 stack_t __user *uoss = (stack_t __user *)regs->ecx;
92
93 return do_sigaltstack(uss, uoss, regs->esp);
94}
95
96
97/*
98 * Do a signal return; undo the signal stack.
99 */
100
101static int
102restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc, int *peax)
103{
104 unsigned int err = 0;
105
106 /* Always make any pending restarted system calls return -EINTR */
107 current_thread_info()->restart_block.fn = do_no_restart_syscall;
108
109#define COPY(x) err |= __get_user(regs->x, &sc->x)
110
111#define COPY_SEG(seg) \
112 { unsigned short tmp; \
113 err |= __get_user(tmp, &sc->seg); \
114 regs->x##seg = tmp; }
115
116#define COPY_SEG_STRICT(seg) \
117 { unsigned short tmp; \
118 err |= __get_user(tmp, &sc->seg); \
119 regs->x##seg = tmp|3; }
120
121#define GET_SEG(seg) \
122 { unsigned short tmp; \
123 err |= __get_user(tmp, &sc->seg); \
124 loadsegment(seg,tmp); }
125
126#define FIX_EFLAGS (X86_EFLAGS_AC | X86_EFLAGS_RF | \
127 X86_EFLAGS_OF | X86_EFLAGS_DF | \
128 X86_EFLAGS_TF | X86_EFLAGS_SF | X86_EFLAGS_ZF | \
129 X86_EFLAGS_AF | X86_EFLAGS_PF | X86_EFLAGS_CF)
130
131 GET_SEG(gs);
132 COPY_SEG(fs);
133 COPY_SEG(es);
134 COPY_SEG(ds);
135 COPY(edi);
136 COPY(esi);
137 COPY(ebp);
138 COPY(esp);
139 COPY(ebx);
140 COPY(edx);
141 COPY(ecx);
142 COPY(eip);
143 COPY_SEG_STRICT(cs);
144 COPY_SEG_STRICT(ss);
145
146 {
147 unsigned int tmpflags;
148 err |= __get_user(tmpflags, &sc->eflags);
149 regs->eflags = (regs->eflags & ~FIX_EFLAGS) | (tmpflags & FIX_EFLAGS);
150 regs->orig_eax = -1; /* disable syscall checks */
151 }
152
153 {
154 struct _fpstate __user * buf;
155 err |= __get_user(buf, &sc->fpstate);
156 if (buf) {
157 if (!access_ok(VERIFY_READ, buf, sizeof(*buf)))
158 goto badframe;
159 err |= restore_i387(buf);
160 } else {
161 struct task_struct *me = current;
162 if (used_math()) {
163 clear_fpu(me);
164 clear_used_math();
165 }
166 }
167 }
168
169 err |= __get_user(*peax, &sc->eax);
170 return err;
171
172badframe:
173 return 1;
174}
175
176asmlinkage int sys_sigreturn(unsigned long __unused)
177{
178 struct pt_regs *regs = (struct pt_regs *) &__unused;
179 struct sigframe __user *frame = (struct sigframe __user *)(regs->esp - 8);
180 sigset_t set;
181 int eax;
182
183 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
184 goto badframe;
185 if (__get_user(set.sig[0], &frame->sc.oldmask)
186 || (_NSIG_WORDS > 1
187 && __copy_from_user(&set.sig[1], &frame->extramask,
188 sizeof(frame->extramask))))
189 goto badframe;
190
191 sigdelsetmask(&set, ~_BLOCKABLE);
192 spin_lock_irq(&current->sighand->siglock);
193 current->blocked = set;
194 recalc_sigpending();
195 spin_unlock_irq(&current->sighand->siglock);
196
197 if (restore_sigcontext(regs, &frame->sc, &eax))
198 goto badframe;
199 return eax;
200
201badframe:
202 if (show_unhandled_signals && printk_ratelimit())
203 printk("%s%s[%d] bad frame in sigreturn frame:%p eip:%lx"
204 " esp:%lx oeax:%lx\n",
205 current->pid > 1 ? KERN_INFO : KERN_EMERG,
206 current->comm, current->pid, frame, regs->eip,
207 regs->esp, regs->orig_eax);
208
209 force_sig(SIGSEGV, current);
210 return 0;
211}
212
213asmlinkage int sys_rt_sigreturn(unsigned long __unused)
214{
215 struct pt_regs *regs = (struct pt_regs *) &__unused;
216 struct rt_sigframe __user *frame = (struct rt_sigframe __user *)(regs->esp - 4);
217 sigset_t set;
218 int eax;
219
220 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
221 goto badframe;
222 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
223 goto badframe;
224
225 sigdelsetmask(&set, ~_BLOCKABLE);
226 spin_lock_irq(&current->sighand->siglock);
227 current->blocked = set;
228 recalc_sigpending();
229 spin_unlock_irq(&current->sighand->siglock);
230
231 if (restore_sigcontext(regs, &frame->uc.uc_mcontext, &eax))
232 goto badframe;
233
234 if (do_sigaltstack(&frame->uc.uc_stack, NULL, regs->esp) == -EFAULT)
235 goto badframe;
236
237 return eax;
238
239badframe:
240 force_sig(SIGSEGV, current);
241 return 0;
242}
243
244/*
245 * Set up a signal frame.
246 */
247
248static int
249setup_sigcontext(struct sigcontext __user *sc, struct _fpstate __user *fpstate,
250 struct pt_regs *regs, unsigned long mask)
251{
252 int tmp, err = 0;
253
254 err |= __put_user(regs->xfs, (unsigned int __user *)&sc->fs);
255 savesegment(gs, tmp);
256 err |= __put_user(tmp, (unsigned int __user *)&sc->gs);
257
258 err |= __put_user(regs->xes, (unsigned int __user *)&sc->es);
259 err |= __put_user(regs->xds, (unsigned int __user *)&sc->ds);
260 err |= __put_user(regs->edi, &sc->edi);
261 err |= __put_user(regs->esi, &sc->esi);
262 err |= __put_user(regs->ebp, &sc->ebp);
263 err |= __put_user(regs->esp, &sc->esp);
264 err |= __put_user(regs->ebx, &sc->ebx);
265 err |= __put_user(regs->edx, &sc->edx);
266 err |= __put_user(regs->ecx, &sc->ecx);
267 err |= __put_user(regs->eax, &sc->eax);
268 err |= __put_user(current->thread.trap_no, &sc->trapno);
269 err |= __put_user(current->thread.error_code, &sc->err);
270 err |= __put_user(regs->eip, &sc->eip);
271 err |= __put_user(regs->xcs, (unsigned int __user *)&sc->cs);
272 err |= __put_user(regs->eflags, &sc->eflags);
273 err |= __put_user(regs->esp, &sc->esp_at_signal);
274 err |= __put_user(regs->xss, (unsigned int __user *)&sc->ss);
275
276 tmp = save_i387(fpstate);
277 if (tmp < 0)
278 err = 1;
279 else
280 err |= __put_user(tmp ? fpstate : NULL, &sc->fpstate);
281
282 /* non-iBCS2 extensions.. */
283 err |= __put_user(mask, &sc->oldmask);
284 err |= __put_user(current->thread.cr2, &sc->cr2);
285
286 return err;
287}
288
289/*
290 * Determine which stack to use..
291 */
292static inline void __user *
293get_sigframe(struct k_sigaction *ka, struct pt_regs * regs, size_t frame_size)
294{
295 unsigned long esp;
296
297 /* Default to using normal stack */
298 esp = regs->esp;
299
300 /* This is the X/Open sanctioned signal stack switching. */
301 if (ka->sa.sa_flags & SA_ONSTACK) {
302 if (sas_ss_flags(esp) == 0)
303 esp = current->sas_ss_sp + current->sas_ss_size;
304 }
305
306 /* This is the legacy signal stack switching. */
307 else if ((regs->xss & 0xffff) != __USER_DS &&
308 !(ka->sa.sa_flags & SA_RESTORER) &&
309 ka->sa.sa_restorer) {
310 esp = (unsigned long) ka->sa.sa_restorer;
311 }
312
313 esp -= frame_size;
314 /* Align the stack pointer according to the i386 ABI,
315 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
316 esp = ((esp + 4) & -16ul) - 4;
317 return (void __user *) esp;
318}
319
320/* These symbols are defined with the addresses in the vsyscall page.
321 See vsyscall-sigreturn.S. */
322extern void __user __kernel_sigreturn;
323extern void __user __kernel_rt_sigreturn;
324
325static int setup_frame(int sig, struct k_sigaction *ka,
326 sigset_t *set, struct pt_regs * regs)
327{
328 void __user *restorer;
329 struct sigframe __user *frame;
330 int err = 0;
331 int usig;
332
333 frame = get_sigframe(ka, regs, sizeof(*frame));
334
335 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
336 goto give_sigsegv;
337
338 usig = current_thread_info()->exec_domain
339 && current_thread_info()->exec_domain->signal_invmap
340 && sig < 32
341 ? current_thread_info()->exec_domain->signal_invmap[sig]
342 : sig;
343
344 err = __put_user(usig, &frame->sig);
345 if (err)
346 goto give_sigsegv;
347
348 err = setup_sigcontext(&frame->sc, &frame->fpstate, regs, set->sig[0]);
349 if (err)
350 goto give_sigsegv;
351
352 if (_NSIG_WORDS > 1) {
353 err = __copy_to_user(&frame->extramask, &set->sig[1],
354 sizeof(frame->extramask));
355 if (err)
356 goto give_sigsegv;
357 }
358
359 if (current->binfmt->hasvdso)
360 restorer = (void *)VDSO_SYM(&__kernel_sigreturn);
361 else
362 restorer = (void *)&frame->retcode;
363 if (ka->sa.sa_flags & SA_RESTORER)
364 restorer = ka->sa.sa_restorer;
365
366 /* Set up to return from userspace. */
367 err |= __put_user(restorer, &frame->pretcode);
368
369 /*
370 * This is popl %eax ; movl $,%eax ; int $0x80
371 *
372 * WE DO NOT USE IT ANY MORE! It's only left here for historical
373 * reasons and because gdb uses it as a signature to notice
374 * signal handler stack frames.
375 */
376 err |= __put_user(0xb858, (short __user *)(frame->retcode+0));
377 err |= __put_user(__NR_sigreturn, (int __user *)(frame->retcode+2));
378 err |= __put_user(0x80cd, (short __user *)(frame->retcode+6));
379
380 if (err)
381 goto give_sigsegv;
382
383 /* Set up registers for signal handler */
384 regs->esp = (unsigned long) frame;
385 regs->eip = (unsigned long) ka->sa.sa_handler;
386 regs->eax = (unsigned long) sig;
387 regs->edx = (unsigned long) 0;
388 regs->ecx = (unsigned long) 0;
389
390 set_fs(USER_DS);
391 regs->xds = __USER_DS;
392 regs->xes = __USER_DS;
393 regs->xss = __USER_DS;
394 regs->xcs = __USER_CS;
395
396 /*
397 * Clear TF when entering the signal handler, but
398 * notify any tracer that was single-stepping it.
399 * The tracer may want to single-step inside the
400 * handler too.
401 */
402 regs->eflags &= ~TF_MASK;
403 if (test_thread_flag(TIF_SINGLESTEP))
404 ptrace_notify(SIGTRAP);
405
406#if DEBUG_SIG
407 printk("SIG deliver (%s:%d): sp=%p pc=%p ra=%p\n",
408 current->comm, current->pid, frame, regs->eip, frame->pretcode);
409#endif
410
411 return 0;
412
413give_sigsegv:
414 force_sigsegv(sig, current);
415 return -EFAULT;
416}
417
418static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
419 sigset_t *set, struct pt_regs * regs)
420{
421 void __user *restorer;
422 struct rt_sigframe __user *frame;
423 int err = 0;
424 int usig;
425
426 frame = get_sigframe(ka, regs, sizeof(*frame));
427
428 if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
429 goto give_sigsegv;
430
431 usig = current_thread_info()->exec_domain
432 && current_thread_info()->exec_domain->signal_invmap
433 && sig < 32
434 ? current_thread_info()->exec_domain->signal_invmap[sig]
435 : sig;
436
437 err |= __put_user(usig, &frame->sig);
438 err |= __put_user(&frame->info, &frame->pinfo);
439 err |= __put_user(&frame->uc, &frame->puc);
440 err |= copy_siginfo_to_user(&frame->info, info);
441 if (err)
442 goto give_sigsegv;
443
444 /* Create the ucontext. */
445 err |= __put_user(0, &frame->uc.uc_flags);
446 err |= __put_user(0, &frame->uc.uc_link);
447 err |= __put_user(current->sas_ss_sp, &frame->uc.uc_stack.ss_sp);
448 err |= __put_user(sas_ss_flags(regs->esp),
449 &frame->uc.uc_stack.ss_flags);
450 err |= __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
451 err |= setup_sigcontext(&frame->uc.uc_mcontext, &frame->fpstate,
452 regs, set->sig[0]);
453 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
454 if (err)
455 goto give_sigsegv;
456
457 /* Set up to return from userspace. */
458 restorer = (void *)VDSO_SYM(&__kernel_rt_sigreturn);
459 if (ka->sa.sa_flags & SA_RESTORER)
460 restorer = ka->sa.sa_restorer;
461 err |= __put_user(restorer, &frame->pretcode);
462
463 /*
464 * This is movl $,%eax ; int $0x80
465 *
466 * WE DO NOT USE IT ANY MORE! It's only left here for historical
467 * reasons and because gdb uses it as a signature to notice
468 * signal handler stack frames.
469 */
470 err |= __put_user(0xb8, (char __user *)(frame->retcode+0));
471 err |= __put_user(__NR_rt_sigreturn, (int __user *)(frame->retcode+1));
472 err |= __put_user(0x80cd, (short __user *)(frame->retcode+5));
473
474 if (err)
475 goto give_sigsegv;
476
477 /* Set up registers for signal handler */
478 regs->esp = (unsigned long) frame;
479 regs->eip = (unsigned long) ka->sa.sa_handler;
480 regs->eax = (unsigned long) usig;
481 regs->edx = (unsigned long) &frame->info;
482 regs->ecx = (unsigned long) &frame->uc;
483
484 set_fs(USER_DS);
485 regs->xds = __USER_DS;
486 regs->xes = __USER_DS;
487 regs->xss = __USER_DS;
488 regs->xcs = __USER_CS;
489
490 /*
491 * Clear TF when entering the signal handler, but
492 * notify any tracer that was single-stepping it.
493 * The tracer may want to single-step inside the
494 * handler too.
495 */
496 regs->eflags &= ~TF_MASK;
497 if (test_thread_flag(TIF_SINGLESTEP))
498 ptrace_notify(SIGTRAP);
499
500#if DEBUG_SIG
501 printk("SIG deliver (%s:%d): sp=%p pc=%p ra=%p\n",
502 current->comm, current->pid, frame, regs->eip, frame->pretcode);
503#endif
504
505 return 0;
506
507give_sigsegv:
508 force_sigsegv(sig, current);
509 return -EFAULT;
510}
511
512/*
513 * OK, we're invoking a handler
514 */
515
516static int
517handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,
518 sigset_t *oldset, struct pt_regs * regs)
519{
520 int ret;
521
522 /* Are we from a system call? */
523 if (regs->orig_eax >= 0) {
524 /* If so, check system call restarting.. */
525 switch (regs->eax) {
526 case -ERESTART_RESTARTBLOCK:
527 case -ERESTARTNOHAND:
528 regs->eax = -EINTR;
529 break;
530
531 case -ERESTARTSYS:
532 if (!(ka->sa.sa_flags & SA_RESTART)) {
533 regs->eax = -EINTR;
534 break;
535 }
536 /* fallthrough */
537 case -ERESTARTNOINTR:
538 regs->eax = regs->orig_eax;
539 regs->eip -= 2;
540 }
541 }
542
543 /*
544 * If TF is set due to a debugger (PT_DTRACE), clear the TF flag so
545 * that register information in the sigcontext is correct.
546 */
547 if (unlikely(regs->eflags & TF_MASK)
548 && likely(current->ptrace & PT_DTRACE)) {
549 current->ptrace &= ~PT_DTRACE;
550 regs->eflags &= ~TF_MASK;
551 }
552
553 /* Set up the stack frame */
554 if (ka->sa.sa_flags & SA_SIGINFO)
555 ret = setup_rt_frame(sig, ka, info, oldset, regs);
556 else
557 ret = setup_frame(sig, ka, oldset, regs);
558
559 if (ret == 0) {
560 spin_lock_irq(&current->sighand->siglock);
561 sigorsets(&current->blocked,&current->blocked,&ka->sa.sa_mask);
562 if (!(ka->sa.sa_flags & SA_NODEFER))
563 sigaddset(&current->blocked,sig);
564 recalc_sigpending();
565 spin_unlock_irq(&current->sighand->siglock);
566 }
567
568 return ret;
569}
570
571/*
572 * Note that 'init' is a special process: it doesn't get signals it doesn't
573 * want to handle. Thus you cannot kill init even with a SIGKILL even by
574 * mistake.
575 */
576static void fastcall do_signal(struct pt_regs *regs)
577{
578 siginfo_t info;
579 int signr;
580 struct k_sigaction ka;
581 sigset_t *oldset;
582
583 /*
584 * We want the common case to go fast, which
585 * is why we may in certain cases get here from
586 * kernel mode. Just return without doing anything
587 * if so. vm86 regs switched out by assembly code
588 * before reaching here, so testing against kernel
589 * CS suffices.
590 */
591 if (!user_mode(regs))
592 return;
593
594 if (test_thread_flag(TIF_RESTORE_SIGMASK))
595 oldset = &current->saved_sigmask;
596 else
597 oldset = &current->blocked;
598
599 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
600 if (signr > 0) {
601 /* Reenable any watchpoints before delivering the
602 * signal to user space. The processor register will
603 * have been cleared if the watchpoint triggered
604 * inside the kernel.
605 */
606 if (unlikely(current->thread.debugreg[7]))
607 set_debugreg(current->thread.debugreg[7], 7);
608
609 /* Whee! Actually deliver the signal. */
610 if (handle_signal(signr, &info, &ka, oldset, regs) == 0) {
611 /* a signal was successfully delivered; the saved
612 * sigmask will have been stored in the signal frame,
613 * and will be restored by sigreturn, so we can simply
614 * clear the TIF_RESTORE_SIGMASK flag */
615 if (test_thread_flag(TIF_RESTORE_SIGMASK))
616 clear_thread_flag(TIF_RESTORE_SIGMASK);
617 }
618
619 return;
620 }
621
622 /* Did we come from a system call? */
623 if (regs->orig_eax >= 0) {
624 /* Restart the system call - no handlers present */
625 switch (regs->eax) {
626 case -ERESTARTNOHAND:
627 case -ERESTARTSYS:
628 case -ERESTARTNOINTR:
629 regs->eax = regs->orig_eax;
630 regs->eip -= 2;
631 break;
632
633 case -ERESTART_RESTARTBLOCK:
634 regs->eax = __NR_restart_syscall;
635 regs->eip -= 2;
636 break;
637 }
638 }
639
640 /* if there's no signal to deliver, we just put the saved sigmask
641 * back */
642 if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
643 clear_thread_flag(TIF_RESTORE_SIGMASK);
644 sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
645 }
646}
647
648/*
649 * notification of userspace execution resumption
650 * - triggered by the TIF_WORK_MASK flags
651 */
652__attribute__((regparm(3)))
653void do_notify_resume(struct pt_regs *regs, void *_unused,
654 __u32 thread_info_flags)
655{
656 /* Pending single-step? */
657 if (thread_info_flags & _TIF_SINGLESTEP) {
658 regs->eflags |= TF_MASK;
659 clear_thread_flag(TIF_SINGLESTEP);
660 }
661
662 /* deal with pending signal delivery */
663 if (thread_info_flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK))
664 do_signal(regs);
665
666 clear_thread_flag(TIF_IRET);
667}
diff --git a/arch/x86_64/kernel/signal.c b/arch/x86/kernel/signal_64.c
index 739175b01e06..739175b01e06 100644
--- a/arch/x86_64/kernel/signal.c
+++ b/arch/x86/kernel/signal_64.c
diff --git a/arch/i386/kernel/smp.c b/arch/x86/kernel/smp_32.c
index 2d35d8502029..2d35d8502029 100644
--- a/arch/i386/kernel/smp.c
+++ b/arch/x86/kernel/smp_32.c
diff --git a/arch/x86_64/kernel/smp.c b/arch/x86/kernel/smp_64.c
index df4a82812adb..df4a82812adb 100644
--- a/arch/x86_64/kernel/smp.c
+++ b/arch/x86/kernel/smp_64.c
diff --git a/arch/i386/kernel/smpboot.c b/arch/x86/kernel/smpboot_32.c
index e4f61d1c6248..e4f61d1c6248 100644
--- a/arch/i386/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot_32.c
diff --git a/arch/x86_64/kernel/smpboot.c b/arch/x86/kernel/smpboot_64.c
index 32f50783edc8..32f50783edc8 100644
--- a/arch/x86_64/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot_64.c
diff --git a/arch/i386/kernel/smpcommon.c b/arch/x86/kernel/smpcommon_32.c
index bbfe85a0f699..bbfe85a0f699 100644
--- a/arch/i386/kernel/smpcommon.c
+++ b/arch/x86/kernel/smpcommon_32.c
diff --git a/arch/i386/kernel/srat.c b/arch/x86/kernel/srat_32.c
index 2a8713ec0f9a..2a8713ec0f9a 100644
--- a/arch/i386/kernel/srat.c
+++ b/arch/x86/kernel/srat_32.c
diff --git a/arch/x86_64/kernel/stacktrace.c b/arch/x86/kernel/stacktrace.c
index cb9109113584..cb9109113584 100644
--- a/arch/x86_64/kernel/stacktrace.c
+++ b/arch/x86/kernel/stacktrace.c
diff --git a/arch/i386/kernel/summit.c b/arch/x86/kernel/summit_32.c
index d0e01a3acf35..d0e01a3acf35 100644
--- a/arch/i386/kernel/summit.c
+++ b/arch/x86/kernel/summit_32.c
diff --git a/arch/x86_64/kernel/suspend.c b/arch/x86/kernel/suspend_64.c
index 573c0a6e0ac6..573c0a6e0ac6 100644
--- a/arch/x86_64/kernel/suspend.c
+++ b/arch/x86/kernel/suspend_64.c
diff --git a/arch/x86_64/kernel/suspend_asm.S b/arch/x86/kernel/suspend_asm_64.S
index 16d183f67bc1..16d183f67bc1 100644
--- a/arch/x86_64/kernel/suspend_asm.S
+++ b/arch/x86/kernel/suspend_asm_64.S
diff --git a/arch/i386/kernel/sys_i386.c b/arch/x86/kernel/sys_i386_32.c
index 42147304de88..42147304de88 100644
--- a/arch/i386/kernel/sys_i386.c
+++ b/arch/x86/kernel/sys_i386_32.c
diff --git a/arch/x86_64/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
index 4770b7a2052c..4770b7a2052c 100644
--- a/arch/x86_64/kernel/sys_x86_64.c
+++ b/arch/x86/kernel/sys_x86_64.c
diff --git a/arch/x86/kernel/syscall_64.c b/arch/x86/kernel/syscall_64.c
new file mode 100644
index 000000000000..9d498c2f8eea
--- /dev/null
+++ b/arch/x86/kernel/syscall_64.c
@@ -0,0 +1,26 @@
1/* System call table for x86-64. */
2
3#include <linux/linkage.h>
4#include <linux/sys.h>
5#include <linux/cache.h>
6#include <asm/asm-offsets.h>
7
8#define __NO_STUBS
9
10#define __SYSCALL(nr, sym) extern asmlinkage void sym(void) ;
11#undef _ASM_X86_64_UNISTD_H_
12#include <asm/unistd_64.h>
13
14#undef __SYSCALL
15#define __SYSCALL(nr, sym) [ nr ] = sym,
16#undef _ASM_X86_64_UNISTD_H_
17
18typedef void (*sys_call_ptr_t)(void);
19
20extern void sys_ni_syscall(void);
21
22const sys_call_ptr_t sys_call_table[__NR_syscall_max+1] = {
23 /* Smells like a like a compiler bug -- it doesn't work when the & below is removed. */
24 [0 ... __NR_syscall_max] = &sys_ni_syscall,
25#include <asm/unistd_64.h>
26};
diff --git a/arch/i386/kernel/syscall_table.S b/arch/x86/kernel/syscall_table_32.S
index 8344c70adf61..8344c70adf61 100644
--- a/arch/i386/kernel/syscall_table.S
+++ b/arch/x86/kernel/syscall_table_32.S
diff --git a/arch/i386/kernel/sysenter.c b/arch/x86/kernel/sysenter_32.c
index 4eb2e408764f..4eb2e408764f 100644
--- a/arch/i386/kernel/sysenter.c
+++ b/arch/x86/kernel/sysenter_32.c
diff --git a/arch/x86_64/kernel/tce.c b/arch/x86/kernel/tce_64.c
index e3f2569b2c44..e3f2569b2c44 100644
--- a/arch/x86_64/kernel/tce.c
+++ b/arch/x86/kernel/tce_64.c
diff --git a/arch/i386/kernel/time.c b/arch/x86/kernel/time_32.c
index 19a6c678d02e..19a6c678d02e 100644
--- a/arch/i386/kernel/time.c
+++ b/arch/x86/kernel/time_32.c
diff --git a/arch/x86_64/kernel/time.c b/arch/x86/kernel/time_64.c
index 6d48a4e826d9..6d48a4e826d9 100644
--- a/arch/x86_64/kernel/time.c
+++ b/arch/x86/kernel/time_64.c
diff --git a/arch/i386/kernel/topology.c b/arch/x86/kernel/topology.c
index 45782356a618..45782356a618 100644
--- a/arch/i386/kernel/topology.c
+++ b/arch/x86/kernel/topology.c
diff --git a/arch/i386/kernel/trampoline.S b/arch/x86/kernel/trampoline_32.S
index f62815f8d06a..f62815f8d06a 100644
--- a/arch/i386/kernel/trampoline.S
+++ b/arch/x86/kernel/trampoline_32.S
diff --git a/arch/x86/kernel/trampoline_64.S b/arch/x86/kernel/trampoline_64.S
new file mode 100644
index 000000000000..607983b0d27b
--- /dev/null
+++ b/arch/x86/kernel/trampoline_64.S
@@ -0,0 +1,166 @@
1/*
2 *
3 * Trampoline.S Derived from Setup.S by Linus Torvalds
4 *
5 * 4 Jan 1997 Michael Chastain: changed to gnu as.
6 * 15 Sept 2005 Eric Biederman: 64bit PIC support
7 *
8 * Entry: CS:IP point to the start of our code, we are
9 * in real mode with no stack, but the rest of the
10 * trampoline page to make our stack and everything else
11 * is a mystery.
12 *
13 * In fact we don't actually need a stack so we don't
14 * set one up.
15 *
16 * On entry to trampoline_data, the processor is in real mode
17 * with 16-bit addressing and 16-bit data. CS has some value
18 * and IP is zero. Thus, data addresses need to be absolute
19 * (no relocation) and are taken with regard to r_base.
20 *
21 * With the addition of trampoline_level4_pgt this code can
22 * now enter a 64bit kernel that lives at arbitrary 64bit
23 * physical addresses.
24 *
25 * If you work on this file, check the object module with objdump
26 * --full-contents --reloc to make sure there are no relocation
27 * entries.
28 */
29
30#include <linux/linkage.h>
31#include <asm/pgtable.h>
32#include <asm/page.h>
33#include <asm/msr.h>
34#include <asm/segment.h>
35
36.data
37
38.code16
39
40ENTRY(trampoline_data)
41r_base = .
42 cli # We should be safe anyway
43 wbinvd
44 mov %cs, %ax # Code and data in the same place
45 mov %ax, %ds
46 mov %ax, %es
47 mov %ax, %ss
48
49
50 movl $0xA5A5A5A5, trampoline_data - r_base
51 # write marker for master knows we're running
52
53 # Setup stack
54 movw $(trampoline_stack_end - r_base), %sp
55
56 call verify_cpu # Verify the cpu supports long mode
57 testl %eax, %eax # Check for return code
58 jnz no_longmode
59
60 mov %cs, %ax
61 movzx %ax, %esi # Find the 32bit trampoline location
62 shll $4, %esi
63
64 # Fixup the vectors
65 addl %esi, startup_32_vector - r_base
66 addl %esi, startup_64_vector - r_base
67 addl %esi, tgdt + 2 - r_base # Fixup the gdt pointer
68
69 /*
70 * GDT tables in non default location kernel can be beyond 16MB and
71 * lgdt will not be able to load the address as in real mode default
72 * operand size is 16bit. Use lgdtl instead to force operand size
73 * to 32 bit.
74 */
75
76 lidtl tidt - r_base # load idt with 0, 0
77 lgdtl tgdt - r_base # load gdt with whatever is appropriate
78
79 xor %ax, %ax
80 inc %ax # protected mode (PE) bit
81 lmsw %ax # into protected mode
82
83 # flush prefetch and jump to startup_32
84 ljmpl *(startup_32_vector - r_base)
85
86 .code32
87 .balign 4
88startup_32:
89 movl $__KERNEL_DS, %eax # Initialize the %ds segment register
90 movl %eax, %ds
91
92 xorl %eax, %eax
93 btsl $5, %eax # Enable PAE mode
94 movl %eax, %cr4
95
96 # Setup trampoline 4 level pagetables
97 leal (trampoline_level4_pgt - r_base)(%esi), %eax
98 movl %eax, %cr3
99
100 movl $MSR_EFER, %ecx
101 movl $(1 << _EFER_LME), %eax # Enable Long Mode
102 xorl %edx, %edx
103 wrmsr
104
105 xorl %eax, %eax
106 btsl $31, %eax # Enable paging and in turn activate Long Mode
107 btsl $0, %eax # Enable protected mode
108 movl %eax, %cr0
109
110 /*
111 * At this point we're in long mode but in 32bit compatibility mode
112 * with EFER.LME = 1, CS.L = 0, CS.D = 1 (and in turn
113 * EFER.LMA = 1). Now we want to jump in 64bit mode, to do that we use
114 * the new gdt/idt that has __KERNEL_CS with CS.L = 1.
115 */
116 ljmp *(startup_64_vector - r_base)(%esi)
117
118 .code64
119 .balign 4
120startup_64:
121 # Now jump into the kernel using virtual addresses
122 movq $secondary_startup_64, %rax
123 jmp *%rax
124
125 .code16
126no_longmode:
127 hlt
128 jmp no_longmode
129#include "verify_cpu_64.S"
130
131 # Careful these need to be in the same 64K segment as the above;
132tidt:
133 .word 0 # idt limit = 0
134 .word 0, 0 # idt base = 0L
135
136 # Duplicate the global descriptor table
137 # so the kernel can live anywhere
138 .balign 4
139tgdt:
140 .short tgdt_end - tgdt # gdt limit
141 .long tgdt - r_base
142 .short 0
143 .quad 0x00cf9b000000ffff # __KERNEL32_CS
144 .quad 0x00af9b000000ffff # __KERNEL_CS
145 .quad 0x00cf93000000ffff # __KERNEL_DS
146tgdt_end:
147
148 .balign 4
149startup_32_vector:
150 .long startup_32 - r_base
151 .word __KERNEL32_CS, 0
152
153 .balign 4
154startup_64_vector:
155 .long startup_64 - r_base
156 .word __KERNEL_CS, 0
157
158trampoline_stack:
159 .org 0x1000
160trampoline_stack_end:
161ENTRY(trampoline_level4_pgt)
162 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
163 .fill 510,8,0
164 .quad level3_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
165
166ENTRY(trampoline_end)
diff --git a/arch/i386/kernel/traps.c b/arch/x86/kernel/traps_32.c
index 47b0bef335bd..47b0bef335bd 100644
--- a/arch/i386/kernel/traps.c
+++ b/arch/x86/kernel/traps_32.c
diff --git a/arch/x86_64/kernel/traps.c b/arch/x86/kernel/traps_64.c
index 03888420775d..03888420775d 100644
--- a/arch/x86_64/kernel/traps.c
+++ b/arch/x86/kernel/traps_64.c
diff --git a/arch/i386/kernel/tsc.c b/arch/x86/kernel/tsc_32.c
index 3ed0ae8c918d..3ed0ae8c918d 100644
--- a/arch/i386/kernel/tsc.c
+++ b/arch/x86/kernel/tsc_32.c
diff --git a/arch/x86_64/kernel/tsc.c b/arch/x86/kernel/tsc_64.c
index 2a59bde663f2..2a59bde663f2 100644
--- a/arch/x86_64/kernel/tsc.c
+++ b/arch/x86/kernel/tsc_64.c
diff --git a/arch/x86_64/kernel/tsc_sync.c b/arch/x86/kernel/tsc_sync.c
index 355f5f506c81..355f5f506c81 100644
--- a/arch/x86_64/kernel/tsc_sync.c
+++ b/arch/x86/kernel/tsc_sync.c
diff --git a/arch/x86_64/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu_64.S
index 45b6f8a975a1..45b6f8a975a1 100644
--- a/arch/x86_64/kernel/verify_cpu.S
+++ b/arch/x86/kernel/verify_cpu_64.S
diff --git a/arch/i386/kernel/vm86.c b/arch/x86/kernel/vm86_32.c
index f2dcd1d27c0a..f2dcd1d27c0a 100644
--- a/arch/i386/kernel/vm86.c
+++ b/arch/x86/kernel/vm86_32.c
diff --git a/arch/i386/kernel/vmi.c b/arch/x86/kernel/vmi_32.c
index 18673e0f193b..18673e0f193b 100644
--- a/arch/i386/kernel/vmi.c
+++ b/arch/x86/kernel/vmi_32.c
diff --git a/arch/i386/kernel/vmiclock.c b/arch/x86/kernel/vmiclock_32.c
index b1b5ab08b26e..b1b5ab08b26e 100644
--- a/arch/i386/kernel/vmiclock.c
+++ b/arch/x86/kernel/vmiclock_32.c
diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
new file mode 100644
index 000000000000..849ee611f013
--- /dev/null
+++ b/arch/x86/kernel/vmlinux.lds.S
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "vmlinux_32.lds.S"
3#else
4# include "vmlinux_64.lds.S"
5#endif
diff --git a/arch/i386/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux_32.lds.S
index 7d72cce00529..7d72cce00529 100644
--- a/arch/i386/kernel/vmlinux.lds.S
+++ b/arch/x86/kernel/vmlinux_32.lds.S
diff --git a/arch/x86_64/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux_64.lds.S
index ba8ea97abd21..ba8ea97abd21 100644
--- a/arch/x86_64/kernel/vmlinux.lds.S
+++ b/arch/x86/kernel/vmlinux_64.lds.S
diff --git a/arch/x86_64/kernel/vsmp.c b/arch/x86/kernel/vsmp_64.c
index 414caf0c5f9a..414caf0c5f9a 100644
--- a/arch/x86_64/kernel/vsmp.c
+++ b/arch/x86/kernel/vsmp_64.c
diff --git a/arch/x86/kernel/vsyscall-int80_32.S b/arch/x86/kernel/vsyscall-int80_32.S
new file mode 100644
index 000000000000..103cab6aa7c0
--- /dev/null
+++ b/arch/x86/kernel/vsyscall-int80_32.S
@@ -0,0 +1,53 @@
1/*
2 * Code for the vsyscall page. This version uses the old int $0x80 method.
3 *
4 * NOTE:
5 * 1) __kernel_vsyscall _must_ be first in this page.
6 * 2) there are alignment constraints on this stub, see vsyscall-sigreturn.S
7 * for details.
8 */
9
10 .text
11 .globl __kernel_vsyscall
12 .type __kernel_vsyscall,@function
13__kernel_vsyscall:
14.LSTART_vsyscall:
15 int $0x80
16 ret
17.LEND_vsyscall:
18 .size __kernel_vsyscall,.-.LSTART_vsyscall
19 .previous
20
21 .section .eh_frame,"a",@progbits
22.LSTARTFRAMEDLSI:
23 .long .LENDCIEDLSI-.LSTARTCIEDLSI
24.LSTARTCIEDLSI:
25 .long 0 /* CIE ID */
26 .byte 1 /* Version number */
27 .string "zR" /* NUL-terminated augmentation string */
28 .uleb128 1 /* Code alignment factor */
29 .sleb128 -4 /* Data alignment factor */
30 .byte 8 /* Return address register column */
31 .uleb128 1 /* Augmentation value length */
32 .byte 0x1b /* DW_EH_PE_pcrel|DW_EH_PE_sdata4. */
33 .byte 0x0c /* DW_CFA_def_cfa */
34 .uleb128 4
35 .uleb128 4
36 .byte 0x88 /* DW_CFA_offset, column 0x8 */
37 .uleb128 1
38 .align 4
39.LENDCIEDLSI:
40 .long .LENDFDEDLSI-.LSTARTFDEDLSI /* Length FDE */
41.LSTARTFDEDLSI:
42 .long .LSTARTFDEDLSI-.LSTARTFRAMEDLSI /* CIE pointer */
43 .long .LSTART_vsyscall-. /* PC-relative start address */
44 .long .LEND_vsyscall-.LSTART_vsyscall
45 .uleb128 0
46 .align 4
47.LENDFDEDLSI:
48 .previous
49
50/*
51 * Get the common code for the sigreturn entry points.
52 */
53#include "vsyscall-sigreturn_32.S"
diff --git a/arch/x86/kernel/vsyscall-note_32.S b/arch/x86/kernel/vsyscall-note_32.S
new file mode 100644
index 000000000000..fcf376a37f79
--- /dev/null
+++ b/arch/x86/kernel/vsyscall-note_32.S
@@ -0,0 +1,45 @@
1/*
2 * This supplies .note.* sections to go into the PT_NOTE inside the vDSO text.
3 * Here we can supply some information useful to userland.
4 */
5
6#include <linux/version.h>
7#include <linux/elfnote.h>
8
9/* Ideally this would use UTS_NAME, but using a quoted string here
10 doesn't work. Remember to change this when changing the
11 kernel's name. */
12ELFNOTE_START(Linux, 0, "a")
13 .long LINUX_VERSION_CODE
14ELFNOTE_END
15
16#ifdef CONFIG_XEN
17/*
18 * Add a special note telling glibc's dynamic linker a fake hardware
19 * flavor that it will use to choose the search path for libraries in the
20 * same way it uses real hardware capabilities like "mmx".
21 * We supply "nosegneg" as the fake capability, to indicate that we
22 * do not like negative offsets in instructions using segment overrides,
23 * since we implement those inefficiently. This makes it possible to
24 * install libraries optimized to avoid those access patterns in someplace
25 * like /lib/i686/tls/nosegneg. Note that an /etc/ld.so.conf.d/file
26 * corresponding to the bits here is needed to make ldconfig work right.
27 * It should contain:
28 * hwcap 1 nosegneg
29 * to match the mapping of bit to name that we give here.
30 *
31 * At runtime, the fake hardware feature will be considered to be present
32 * if its bit is set in the mask word. So, we start with the mask 0, and
33 * at boot time we set VDSO_NOTE_NONEGSEG_BIT if running under Xen.
34 */
35
36#include "../../x86/xen/vdso.h" /* Defines VDSO_NOTE_NONEGSEG_BIT. */
37
38 .globl VDSO_NOTE_MASK
39ELFNOTE_START(GNU, 2, "a")
40 .long 1 /* ncaps */
41VDSO_NOTE_MASK:
42 .long 0 /* mask */
43 .byte VDSO_NOTE_NONEGSEG_BIT; .asciz "nosegneg" /* bit, name */
44ELFNOTE_END
45#endif
diff --git a/arch/i386/kernel/vsyscall-sigreturn.S b/arch/x86/kernel/vsyscall-sigreturn_32.S
index a92262f41659..a92262f41659 100644
--- a/arch/i386/kernel/vsyscall-sigreturn.S
+++ b/arch/x86/kernel/vsyscall-sigreturn_32.S
diff --git a/arch/x86/kernel/vsyscall-sysenter_32.S b/arch/x86/kernel/vsyscall-sysenter_32.S
new file mode 100644
index 000000000000..ed879bf42995
--- /dev/null
+++ b/arch/x86/kernel/vsyscall-sysenter_32.S
@@ -0,0 +1,122 @@
1/*
2 * Code for the vsyscall page. This version uses the sysenter instruction.
3 *
4 * NOTE:
5 * 1) __kernel_vsyscall _must_ be first in this page.
6 * 2) there are alignment constraints on this stub, see vsyscall-sigreturn.S
7 * for details.
8 */
9
10/*
11 * The caller puts arg2 in %ecx, which gets pushed. The kernel will use
12 * %ecx itself for arg2. The pushing is because the sysexit instruction
13 * (found in entry.S) requires that we clobber %ecx with the desired %esp.
14 * User code might expect that %ecx is unclobbered though, as it would be
15 * for returning via the iret instruction, so we must push and pop.
16 *
17 * The caller puts arg3 in %edx, which the sysexit instruction requires
18 * for %eip. Thus, exactly as for arg2, we must push and pop.
19 *
20 * Arg6 is different. The caller puts arg6 in %ebp. Since the sysenter
21 * instruction clobbers %esp, the user's %esp won't even survive entry
22 * into the kernel. We store %esp in %ebp. Code in entry.S must fetch
23 * arg6 from the stack.
24 *
25 * You can not use this vsyscall for the clone() syscall because the
26 * three dwords on the parent stack do not get copied to the child.
27 */
28 .text
29 .globl __kernel_vsyscall
30 .type __kernel_vsyscall,@function
31__kernel_vsyscall:
32.LSTART_vsyscall:
33 push %ecx
34.Lpush_ecx:
35 push %edx
36.Lpush_edx:
37 push %ebp
38.Lenter_kernel:
39 movl %esp,%ebp
40 sysenter
41
42 /* 7: align return point with nop's to make disassembly easier */
43 .space 7,0x90
44
45 /* 14: System call restart point is here! (SYSENTER_RETURN-2) */
46 jmp .Lenter_kernel
47 /* 16: System call normal return point is here! */
48 .globl SYSENTER_RETURN /* Symbol used by sysenter.c */
49SYSENTER_RETURN:
50 pop %ebp
51.Lpop_ebp:
52 pop %edx
53.Lpop_edx:
54 pop %ecx
55.Lpop_ecx:
56 ret
57.LEND_vsyscall:
58 .size __kernel_vsyscall,.-.LSTART_vsyscall
59 .previous
60
61 .section .eh_frame,"a",@progbits
62.LSTARTFRAMEDLSI:
63 .long .LENDCIEDLSI-.LSTARTCIEDLSI
64.LSTARTCIEDLSI:
65 .long 0 /* CIE ID */
66 .byte 1 /* Version number */
67 .string "zR" /* NUL-terminated augmentation string */
68 .uleb128 1 /* Code alignment factor */
69 .sleb128 -4 /* Data alignment factor */
70 .byte 8 /* Return address register column */
71 .uleb128 1 /* Augmentation value length */
72 .byte 0x1b /* DW_EH_PE_pcrel|DW_EH_PE_sdata4. */
73 .byte 0x0c /* DW_CFA_def_cfa */
74 .uleb128 4
75 .uleb128 4
76 .byte 0x88 /* DW_CFA_offset, column 0x8 */
77 .uleb128 1
78 .align 4
79.LENDCIEDLSI:
80 .long .LENDFDEDLSI-.LSTARTFDEDLSI /* Length FDE */
81.LSTARTFDEDLSI:
82 .long .LSTARTFDEDLSI-.LSTARTFRAMEDLSI /* CIE pointer */
83 .long .LSTART_vsyscall-. /* PC-relative start address */
84 .long .LEND_vsyscall-.LSTART_vsyscall
85 .uleb128 0
86 /* What follows are the instructions for the table generation.
87 We have to record all changes of the stack pointer. */
88 .byte 0x04 /* DW_CFA_advance_loc4 */
89 .long .Lpush_ecx-.LSTART_vsyscall
90 .byte 0x0e /* DW_CFA_def_cfa_offset */
91 .byte 0x08 /* RA at offset 8 now */
92 .byte 0x04 /* DW_CFA_advance_loc4 */
93 .long .Lpush_edx-.Lpush_ecx
94 .byte 0x0e /* DW_CFA_def_cfa_offset */
95 .byte 0x0c /* RA at offset 12 now */
96 .byte 0x04 /* DW_CFA_advance_loc4 */
97 .long .Lenter_kernel-.Lpush_edx
98 .byte 0x0e /* DW_CFA_def_cfa_offset */
99 .byte 0x10 /* RA at offset 16 now */
100 .byte 0x85, 0x04 /* DW_CFA_offset %ebp -16 */
101 /* Finally the epilogue. */
102 .byte 0x04 /* DW_CFA_advance_loc4 */
103 .long .Lpop_ebp-.Lenter_kernel
104 .byte 0x0e /* DW_CFA_def_cfa_offset */
105 .byte 0x0c /* RA at offset 12 now */
106 .byte 0xc5 /* DW_CFA_restore %ebp */
107 .byte 0x04 /* DW_CFA_advance_loc4 */
108 .long .Lpop_edx-.Lpop_ebp
109 .byte 0x0e /* DW_CFA_def_cfa_offset */
110 .byte 0x08 /* RA at offset 8 now */
111 .byte 0x04 /* DW_CFA_advance_loc4 */
112 .long .Lpop_ecx-.Lpop_edx
113 .byte 0x0e /* DW_CFA_def_cfa_offset */
114 .byte 0x04 /* RA at offset 4 now */
115 .align 4
116.LENDFDEDLSI:
117 .previous
118
119/*
120 * Get the common code for the sigreturn entry points.
121 */
122#include "vsyscall-sigreturn_32.S"
diff --git a/arch/x86/kernel/vsyscall_32.S b/arch/x86/kernel/vsyscall_32.S
new file mode 100644
index 000000000000..a5ab3dc4fd25
--- /dev/null
+++ b/arch/x86/kernel/vsyscall_32.S
@@ -0,0 +1,15 @@
1#include <linux/init.h>
2
3__INITDATA
4
5 .globl vsyscall_int80_start, vsyscall_int80_end
6vsyscall_int80_start:
7 .incbin "arch/x86/kernel/vsyscall-int80_32.so"
8vsyscall_int80_end:
9
10 .globl vsyscall_sysenter_start, vsyscall_sysenter_end
11vsyscall_sysenter_start:
12 .incbin "arch/x86/kernel/vsyscall-sysenter_32.so"
13vsyscall_sysenter_end:
14
15__FINIT
diff --git a/arch/i386/kernel/vsyscall.lds.S b/arch/x86/kernel/vsyscall_32.lds.S
index 4a8b0ed9b8fb..4a8b0ed9b8fb 100644
--- a/arch/i386/kernel/vsyscall.lds.S
+++ b/arch/x86/kernel/vsyscall_32.lds.S
diff --git a/arch/x86_64/kernel/vsyscall.c b/arch/x86/kernel/vsyscall_64.c
index 06c34949bfdc..06c34949bfdc 100644
--- a/arch/x86_64/kernel/vsyscall.c
+++ b/arch/x86/kernel/vsyscall_64.c
diff --git a/arch/x86_64/kernel/x8664_ksyms.c b/arch/x86/kernel/x8664_ksyms_64.c
index 77c25b307635..77c25b307635 100644
--- a/arch/x86_64/kernel/x8664_ksyms.c
+++ b/arch/x86/kernel/x8664_ksyms_64.c
diff --git a/arch/x86/lib/Makefile b/arch/x86/lib/Makefile
new file mode 100644
index 000000000000..329da276c6f1
--- /dev/null
+++ b/arch/x86/lib/Makefile
@@ -0,0 +1,5 @@
1ifeq ($(CONFIG_X86_32),y)
2include ${srctree}/arch/x86/lib/Makefile_32
3else
4include ${srctree}/arch/x86/lib/Makefile_64
5endif
diff --git a/arch/x86/lib/Makefile_32 b/arch/x86/lib/Makefile_32
new file mode 100644
index 000000000000..98d1f1e2e2ef
--- /dev/null
+++ b/arch/x86/lib/Makefile_32
@@ -0,0 +1,11 @@
1#
2# Makefile for i386-specific library files..
3#
4
5
6lib-y = checksum_32.o delay_32.o usercopy_32.o getuser_32.o putuser_32.o memcpy_32.o strstr_32.o \
7 bitops_32.o semaphore_32.o string_32.o
8
9lib-$(CONFIG_X86_USE_3DNOW) += mmx_32.o
10
11obj-$(CONFIG_SMP) += msr-on-cpu.o
diff --git a/arch/x86/lib/Makefile_64 b/arch/x86/lib/Makefile_64
new file mode 100644
index 000000000000..bbabad3c9335
--- /dev/null
+++ b/arch/x86/lib/Makefile_64
@@ -0,0 +1,13 @@
1#
2# Makefile for x86_64-specific library files.
3#
4
5CFLAGS_csum-partial_64.o := -funroll-loops
6
7obj-y := io_64.o iomap_copy_64.o
8obj-$(CONFIG_SMP) += msr-on-cpu.o
9
10lib-y := csum-partial_64.o csum-copy_64.o csum-wrappers_64.o delay_64.o \
11 usercopy_64.o getuser_64.o putuser_64.o \
12 thunk_64.o clear_page_64.o copy_page_64.o bitstr_64.o bitops_64.o
13lib-y += memcpy_64.o memmove_64.o memset_64.o copy_user_64.o rwlock_64.o copy_user_nocache_64.o
diff --git a/arch/i386/lib/bitops.c b/arch/x86/lib/bitops_32.c
index afd0045595d4..afd0045595d4 100644
--- a/arch/i386/lib/bitops.c
+++ b/arch/x86/lib/bitops_32.c
diff --git a/arch/x86_64/lib/bitops.c b/arch/x86/lib/bitops_64.c
index 95b6d9639fba..95b6d9639fba 100644
--- a/arch/x86_64/lib/bitops.c
+++ b/arch/x86/lib/bitops_64.c
diff --git a/arch/x86_64/lib/bitstr.c b/arch/x86/lib/bitstr_64.c
index 24676609a6ac..24676609a6ac 100644
--- a/arch/x86_64/lib/bitstr.c
+++ b/arch/x86/lib/bitstr_64.c
diff --git a/arch/i386/lib/checksum.S b/arch/x86/lib/checksum_32.S
index adbccd0bbb78..adbccd0bbb78 100644
--- a/arch/i386/lib/checksum.S
+++ b/arch/x86/lib/checksum_32.S
diff --git a/arch/x86_64/lib/clear_page.S b/arch/x86/lib/clear_page_64.S
index 9a10a78bb4a4..9a10a78bb4a4 100644
--- a/arch/x86_64/lib/clear_page.S
+++ b/arch/x86/lib/clear_page_64.S
diff --git a/arch/x86_64/lib/copy_page.S b/arch/x86/lib/copy_page_64.S
index 727a5d46d2fc..727a5d46d2fc 100644
--- a/arch/x86_64/lib/copy_page.S
+++ b/arch/x86/lib/copy_page_64.S
diff --git a/arch/x86_64/lib/copy_user.S b/arch/x86/lib/copy_user_64.S
index 70bebd310408..70bebd310408 100644
--- a/arch/x86_64/lib/copy_user.S
+++ b/arch/x86/lib/copy_user_64.S
diff --git a/arch/x86_64/lib/copy_user_nocache.S b/arch/x86/lib/copy_user_nocache_64.S
index 4620efb12f13..4620efb12f13 100644
--- a/arch/x86_64/lib/copy_user_nocache.S
+++ b/arch/x86/lib/copy_user_nocache_64.S
diff --git a/arch/x86_64/lib/csum-copy.S b/arch/x86/lib/csum-copy_64.S
index f0dba36578ea..f0dba36578ea 100644
--- a/arch/x86_64/lib/csum-copy.S
+++ b/arch/x86/lib/csum-copy_64.S
diff --git a/arch/x86_64/lib/csum-partial.c b/arch/x86/lib/csum-partial_64.c
index bc503f506903..bc503f506903 100644
--- a/arch/x86_64/lib/csum-partial.c
+++ b/arch/x86/lib/csum-partial_64.c
diff --git a/arch/x86_64/lib/csum-wrappers.c b/arch/x86/lib/csum-wrappers_64.c
index fd42a4a095fc..fd42a4a095fc 100644
--- a/arch/x86_64/lib/csum-wrappers.c
+++ b/arch/x86/lib/csum-wrappers_64.c
diff --git a/arch/i386/lib/delay.c b/arch/x86/lib/delay_32.c
index f6edb11364df..f6edb11364df 100644
--- a/arch/i386/lib/delay.c
+++ b/arch/x86/lib/delay_32.c
diff --git a/arch/x86_64/lib/delay.c b/arch/x86/lib/delay_64.c
index 2dbebd308347..2dbebd308347 100644
--- a/arch/x86_64/lib/delay.c
+++ b/arch/x86/lib/delay_64.c
diff --git a/arch/i386/lib/getuser.S b/arch/x86/lib/getuser_32.S
index 6d84b53f12a2..6d84b53f12a2 100644
--- a/arch/i386/lib/getuser.S
+++ b/arch/x86/lib/getuser_32.S
diff --git a/arch/x86_64/lib/getuser.S b/arch/x86/lib/getuser_64.S
index 5448876261f8..5448876261f8 100644
--- a/arch/x86_64/lib/getuser.S
+++ b/arch/x86/lib/getuser_64.S
diff --git a/arch/x86_64/lib/io.c b/arch/x86/lib/io_64.c
index 87b4a4e18039..87b4a4e18039 100644
--- a/arch/x86_64/lib/io.c
+++ b/arch/x86/lib/io_64.c
diff --git a/arch/x86_64/lib/iomap_copy.S b/arch/x86/lib/iomap_copy_64.S
index 05a95e713da8..05a95e713da8 100644
--- a/arch/x86_64/lib/iomap_copy.S
+++ b/arch/x86/lib/iomap_copy_64.S
diff --git a/arch/i386/lib/memcpy.c b/arch/x86/lib/memcpy_32.c
index 8ac51b82a632..8ac51b82a632 100644
--- a/arch/i386/lib/memcpy.c
+++ b/arch/x86/lib/memcpy_32.c
diff --git a/arch/x86_64/lib/memcpy.S b/arch/x86/lib/memcpy_64.S
index c22981fa2f3a..c22981fa2f3a 100644
--- a/arch/x86_64/lib/memcpy.S
+++ b/arch/x86/lib/memcpy_64.S
diff --git a/arch/x86_64/lib/memmove.c b/arch/x86/lib/memmove_64.c
index 751ebae8ec42..751ebae8ec42 100644
--- a/arch/x86_64/lib/memmove.c
+++ b/arch/x86/lib/memmove_64.c
diff --git a/arch/x86_64/lib/memset.S b/arch/x86/lib/memset_64.S
index 2c5948116bd2..2c5948116bd2 100644
--- a/arch/x86_64/lib/memset.S
+++ b/arch/x86/lib/memset_64.S
diff --git a/arch/i386/lib/mmx.c b/arch/x86/lib/mmx_32.c
index 28084d2e8dd4..28084d2e8dd4 100644
--- a/arch/i386/lib/mmx.c
+++ b/arch/x86/lib/mmx_32.c
diff --git a/arch/i386/lib/msr-on-cpu.c b/arch/x86/lib/msr-on-cpu.c
index 7767962f25d3..7767962f25d3 100644
--- a/arch/i386/lib/msr-on-cpu.c
+++ b/arch/x86/lib/msr-on-cpu.c
diff --git a/arch/i386/lib/putuser.S b/arch/x86/lib/putuser_32.S
index f58fba109d18..f58fba109d18 100644
--- a/arch/i386/lib/putuser.S
+++ b/arch/x86/lib/putuser_32.S
diff --git a/arch/x86_64/lib/putuser.S b/arch/x86/lib/putuser_64.S
index 4989f5a8fa9b..4989f5a8fa9b 100644
--- a/arch/x86_64/lib/putuser.S
+++ b/arch/x86/lib/putuser_64.S
diff --git a/arch/x86_64/lib/rwlock.S b/arch/x86/lib/rwlock_64.S
index 0cde1f807314..0cde1f807314 100644
--- a/arch/x86_64/lib/rwlock.S
+++ b/arch/x86/lib/rwlock_64.S
diff --git a/arch/i386/lib/semaphore.S b/arch/x86/lib/semaphore_32.S
index c01eb39c0b43..c01eb39c0b43 100644
--- a/arch/i386/lib/semaphore.S
+++ b/arch/x86/lib/semaphore_32.S
diff --git a/arch/i386/lib/string.c b/arch/x86/lib/string_32.c
index 2c773fefa3dd..2c773fefa3dd 100644
--- a/arch/i386/lib/string.c
+++ b/arch/x86/lib/string_32.c
diff --git a/arch/i386/lib/strstr.c b/arch/x86/lib/strstr_32.c
index a3dafbf59dae..a3dafbf59dae 100644
--- a/arch/i386/lib/strstr.c
+++ b/arch/x86/lib/strstr_32.c
diff --git a/arch/x86_64/lib/thunk.S b/arch/x86/lib/thunk_64.S
index 55e586d352d3..55e586d352d3 100644
--- a/arch/x86_64/lib/thunk.S
+++ b/arch/x86/lib/thunk_64.S
diff --git a/arch/i386/lib/usercopy.c b/arch/x86/lib/usercopy_32.c
index 9f38b12b4af1..9f38b12b4af1 100644
--- a/arch/i386/lib/usercopy.c
+++ b/arch/x86/lib/usercopy_32.c
diff --git a/arch/x86_64/lib/usercopy.c b/arch/x86/lib/usercopy_64.c
index 893d43f838cc..893d43f838cc 100644
--- a/arch/x86_64/lib/usercopy.c
+++ b/arch/x86/lib/usercopy_64.c
diff --git a/arch/i386/mach-default/Makefile b/arch/x86/mach-default/Makefile
index 012fe34459e6..012fe34459e6 100644
--- a/arch/i386/mach-default/Makefile
+++ b/arch/x86/mach-default/Makefile
diff --git a/arch/i386/mach-default/setup.c b/arch/x86/mach-default/setup.c
index 7f635c7a2381..7f635c7a2381 100644
--- a/arch/i386/mach-default/setup.c
+++ b/arch/x86/mach-default/setup.c
diff --git a/arch/i386/mach-es7000/Makefile b/arch/x86/mach-es7000/Makefile
index 69dd4da218dc..69dd4da218dc 100644
--- a/arch/i386/mach-es7000/Makefile
+++ b/arch/x86/mach-es7000/Makefile
diff --git a/arch/i386/mach-es7000/es7000.h b/arch/x86/mach-es7000/es7000.h
index c8d5aa132fa0..c8d5aa132fa0 100644
--- a/arch/i386/mach-es7000/es7000.h
+++ b/arch/x86/mach-es7000/es7000.h
diff --git a/arch/i386/mach-es7000/es7000plat.c b/arch/x86/mach-es7000/es7000plat.c
index ab99072d3f9a..ab99072d3f9a 100644
--- a/arch/i386/mach-es7000/es7000plat.c
+++ b/arch/x86/mach-es7000/es7000plat.c
diff --git a/arch/x86/mach-generic/Makefile b/arch/x86/mach-generic/Makefile
new file mode 100644
index 000000000000..19d6d407737b
--- /dev/null
+++ b/arch/x86/mach-generic/Makefile
@@ -0,0 +1,8 @@
1#
2# Makefile for the generic architecture
3#
4
5EXTRA_CFLAGS := -Iarch/x86/kernel
6
7obj-y := probe.o summit.o bigsmp.o es7000.o default.o
8obj-y += ../../x86/mach-es7000/
diff --git a/arch/i386/mach-generic/bigsmp.c b/arch/x86/mach-generic/bigsmp.c
index 292a225edabe..292a225edabe 100644
--- a/arch/i386/mach-generic/bigsmp.c
+++ b/arch/x86/mach-generic/bigsmp.c
diff --git a/arch/i386/mach-generic/default.c b/arch/x86/mach-generic/default.c
index 8685208d8512..8685208d8512 100644
--- a/arch/i386/mach-generic/default.c
+++ b/arch/x86/mach-generic/default.c
diff --git a/arch/i386/mach-generic/es7000.c b/arch/x86/mach-generic/es7000.c
index 4742626f08c4..4742626f08c4 100644
--- a/arch/i386/mach-generic/es7000.c
+++ b/arch/x86/mach-generic/es7000.c
diff --git a/arch/i386/mach-generic/probe.c b/arch/x86/mach-generic/probe.c
index 74f3da634423..74f3da634423 100644
--- a/arch/i386/mach-generic/probe.c
+++ b/arch/x86/mach-generic/probe.c
diff --git a/arch/i386/mach-generic/summit.c b/arch/x86/mach-generic/summit.c
index 74883ccb8f73..74883ccb8f73 100644
--- a/arch/i386/mach-generic/summit.c
+++ b/arch/x86/mach-generic/summit.c
diff --git a/arch/i386/mach-visws/Makefile b/arch/x86/mach-visws/Makefile
index 835fd96ad768..835fd96ad768 100644
--- a/arch/i386/mach-visws/Makefile
+++ b/arch/x86/mach-visws/Makefile
diff --git a/arch/i386/mach-visws/mpparse.c b/arch/x86/mach-visws/mpparse.c
index f3c74fab8b95..f3c74fab8b95 100644
--- a/arch/i386/mach-visws/mpparse.c
+++ b/arch/x86/mach-visws/mpparse.c
diff --git a/arch/i386/mach-visws/reboot.c b/arch/x86/mach-visws/reboot.c
index 99332abfad42..99332abfad42 100644
--- a/arch/i386/mach-visws/reboot.c
+++ b/arch/x86/mach-visws/reboot.c
diff --git a/arch/i386/mach-visws/setup.c b/arch/x86/mach-visws/setup.c
index 1f81f10e03a0..1f81f10e03a0 100644
--- a/arch/i386/mach-visws/setup.c
+++ b/arch/x86/mach-visws/setup.c
diff --git a/arch/i386/mach-visws/traps.c b/arch/x86/mach-visws/traps.c
index 843b67acf43b..843b67acf43b 100644
--- a/arch/i386/mach-visws/traps.c
+++ b/arch/x86/mach-visws/traps.c
diff --git a/arch/i386/mach-visws/visws_apic.c b/arch/x86/mach-visws/visws_apic.c
index 710faf71a650..710faf71a650 100644
--- a/arch/i386/mach-visws/visws_apic.c
+++ b/arch/x86/mach-visws/visws_apic.c
diff --git a/arch/x86/mach-voyager/Makefile b/arch/x86/mach-voyager/Makefile
new file mode 100644
index 000000000000..15c250b371d3
--- /dev/null
+++ b/arch/x86/mach-voyager/Makefile
@@ -0,0 +1,8 @@
1#
2# Makefile for the linux kernel.
3#
4
5EXTRA_CFLAGS := -Iarch/x86/kernel
6obj-y := setup.o voyager_basic.o voyager_thread.o
7
8obj-$(CONFIG_SMP) += voyager_smp.o voyager_cat.o
diff --git a/arch/i386/mach-voyager/setup.c b/arch/x86/mach-voyager/setup.c
index 2b55694e6400..2b55694e6400 100644
--- a/arch/i386/mach-voyager/setup.c
+++ b/arch/x86/mach-voyager/setup.c
diff --git a/arch/i386/mach-voyager/voyager_basic.c b/arch/x86/mach-voyager/voyager_basic.c
index 9b77b39b71a6..9b77b39b71a6 100644
--- a/arch/i386/mach-voyager/voyager_basic.c
+++ b/arch/x86/mach-voyager/voyager_basic.c
diff --git a/arch/i386/mach-voyager/voyager_cat.c b/arch/x86/mach-voyager/voyager_cat.c
index 26a2d4c54b68..26a2d4c54b68 100644
--- a/arch/i386/mach-voyager/voyager_cat.c
+++ b/arch/x86/mach-voyager/voyager_cat.c
diff --git a/arch/i386/mach-voyager/voyager_smp.c b/arch/x86/mach-voyager/voyager_smp.c
index b87f8548e75a..b87f8548e75a 100644
--- a/arch/i386/mach-voyager/voyager_smp.c
+++ b/arch/x86/mach-voyager/voyager_smp.c
diff --git a/arch/i386/mach-voyager/voyager_thread.c b/arch/x86/mach-voyager/voyager_thread.c
index f9d595338159..f9d595338159 100644
--- a/arch/i386/mach-voyager/voyager_thread.c
+++ b/arch/x86/mach-voyager/voyager_thread.c
diff --git a/arch/i386/math-emu/Makefile b/arch/x86/math-emu/Makefile
index 9c943fa6ce6b..9c943fa6ce6b 100644
--- a/arch/i386/math-emu/Makefile
+++ b/arch/x86/math-emu/Makefile
diff --git a/arch/i386/math-emu/README b/arch/x86/math-emu/README
index e6235491d6eb..e6235491d6eb 100644
--- a/arch/i386/math-emu/README
+++ b/arch/x86/math-emu/README
diff --git a/arch/i386/math-emu/control_w.h b/arch/x86/math-emu/control_w.h
index ae2274dbd305..ae2274dbd305 100644
--- a/arch/i386/math-emu/control_w.h
+++ b/arch/x86/math-emu/control_w.h
diff --git a/arch/i386/math-emu/div_Xsig.S b/arch/x86/math-emu/div_Xsig.S
index f77ba3058b31..f77ba3058b31 100644
--- a/arch/i386/math-emu/div_Xsig.S
+++ b/arch/x86/math-emu/div_Xsig.S
diff --git a/arch/i386/math-emu/div_small.S b/arch/x86/math-emu/div_small.S
index 47099628fa4c..47099628fa4c 100644
--- a/arch/i386/math-emu/div_small.S
+++ b/arch/x86/math-emu/div_small.S
diff --git a/arch/i386/math-emu/errors.c b/arch/x86/math-emu/errors.c
index a1b0d22f6978..a1b0d22f6978 100644
--- a/arch/i386/math-emu/errors.c
+++ b/arch/x86/math-emu/errors.c
diff --git a/arch/i386/math-emu/exception.h b/arch/x86/math-emu/exception.h
index b463f21a811e..b463f21a811e 100644
--- a/arch/i386/math-emu/exception.h
+++ b/arch/x86/math-emu/exception.h
diff --git a/arch/i386/math-emu/fpu_arith.c b/arch/x86/math-emu/fpu_arith.c
index 6972dec01af6..6972dec01af6 100644
--- a/arch/i386/math-emu/fpu_arith.c
+++ b/arch/x86/math-emu/fpu_arith.c
diff --git a/arch/i386/math-emu/fpu_asm.h b/arch/x86/math-emu/fpu_asm.h
index 9ba12416df12..9ba12416df12 100644
--- a/arch/i386/math-emu/fpu_asm.h
+++ b/arch/x86/math-emu/fpu_asm.h
diff --git a/arch/i386/math-emu/fpu_aux.c b/arch/x86/math-emu/fpu_aux.c
index 20886cfb9f76..20886cfb9f76 100644
--- a/arch/i386/math-emu/fpu_aux.c
+++ b/arch/x86/math-emu/fpu_aux.c
diff --git a/arch/i386/math-emu/fpu_emu.h b/arch/x86/math-emu/fpu_emu.h
index 65120f523853..65120f523853 100644
--- a/arch/i386/math-emu/fpu_emu.h
+++ b/arch/x86/math-emu/fpu_emu.h
diff --git a/arch/i386/math-emu/fpu_entry.c b/arch/x86/math-emu/fpu_entry.c
index 1853524c8b57..1853524c8b57 100644
--- a/arch/i386/math-emu/fpu_entry.c
+++ b/arch/x86/math-emu/fpu_entry.c
diff --git a/arch/i386/math-emu/fpu_etc.c b/arch/x86/math-emu/fpu_etc.c
index e3b5d465587f..e3b5d465587f 100644
--- a/arch/i386/math-emu/fpu_etc.c
+++ b/arch/x86/math-emu/fpu_etc.c
diff --git a/arch/i386/math-emu/fpu_proto.h b/arch/x86/math-emu/fpu_proto.h
index 37a8a7fe7e2b..37a8a7fe7e2b 100644
--- a/arch/i386/math-emu/fpu_proto.h
+++ b/arch/x86/math-emu/fpu_proto.h
diff --git a/arch/i386/math-emu/fpu_system.h b/arch/x86/math-emu/fpu_system.h
index a3ae28c49ddd..a3ae28c49ddd 100644
--- a/arch/i386/math-emu/fpu_system.h
+++ b/arch/x86/math-emu/fpu_system.h
diff --git a/arch/i386/math-emu/fpu_tags.c b/arch/x86/math-emu/fpu_tags.c
index cb436fe20e4c..cb436fe20e4c 100644
--- a/arch/i386/math-emu/fpu_tags.c
+++ b/arch/x86/math-emu/fpu_tags.c
diff --git a/arch/i386/math-emu/fpu_trig.c b/arch/x86/math-emu/fpu_trig.c
index 403cbde1d425..403cbde1d425 100644
--- a/arch/i386/math-emu/fpu_trig.c
+++ b/arch/x86/math-emu/fpu_trig.c
diff --git a/arch/i386/math-emu/get_address.c b/arch/x86/math-emu/get_address.c
index 2e2c51a8bd3a..2e2c51a8bd3a 100644
--- a/arch/i386/math-emu/get_address.c
+++ b/arch/x86/math-emu/get_address.c
diff --git a/arch/i386/math-emu/load_store.c b/arch/x86/math-emu/load_store.c
index eebd6fb1c8a8..eebd6fb1c8a8 100644
--- a/arch/i386/math-emu/load_store.c
+++ b/arch/x86/math-emu/load_store.c
diff --git a/arch/i386/math-emu/mul_Xsig.S b/arch/x86/math-emu/mul_Xsig.S
index 717785a53eb4..717785a53eb4 100644
--- a/arch/i386/math-emu/mul_Xsig.S
+++ b/arch/x86/math-emu/mul_Xsig.S
diff --git a/arch/i386/math-emu/poly.h b/arch/x86/math-emu/poly.h
index 4db798114923..4db798114923 100644
--- a/arch/i386/math-emu/poly.h
+++ b/arch/x86/math-emu/poly.h
diff --git a/arch/i386/math-emu/poly_2xm1.c b/arch/x86/math-emu/poly_2xm1.c
index 9766ad5e9743..9766ad5e9743 100644
--- a/arch/i386/math-emu/poly_2xm1.c
+++ b/arch/x86/math-emu/poly_2xm1.c
diff --git a/arch/i386/math-emu/poly_atan.c b/arch/x86/math-emu/poly_atan.c
index 82f702952f69..82f702952f69 100644
--- a/arch/i386/math-emu/poly_atan.c
+++ b/arch/x86/math-emu/poly_atan.c
diff --git a/arch/i386/math-emu/poly_l2.c b/arch/x86/math-emu/poly_l2.c
index dd00e1d5b074..dd00e1d5b074 100644
--- a/arch/i386/math-emu/poly_l2.c
+++ b/arch/x86/math-emu/poly_l2.c
diff --git a/arch/i386/math-emu/poly_sin.c b/arch/x86/math-emu/poly_sin.c
index a36313fb06f1..a36313fb06f1 100644
--- a/arch/i386/math-emu/poly_sin.c
+++ b/arch/x86/math-emu/poly_sin.c
diff --git a/arch/i386/math-emu/poly_tan.c b/arch/x86/math-emu/poly_tan.c
index 8df3e03b6e6f..8df3e03b6e6f 100644
--- a/arch/i386/math-emu/poly_tan.c
+++ b/arch/x86/math-emu/poly_tan.c
diff --git a/arch/i386/math-emu/polynom_Xsig.S b/arch/x86/math-emu/polynom_Xsig.S
index 17315c89ff3d..17315c89ff3d 100644
--- a/arch/i386/math-emu/polynom_Xsig.S
+++ b/arch/x86/math-emu/polynom_Xsig.S
diff --git a/arch/i386/math-emu/reg_add_sub.c b/arch/x86/math-emu/reg_add_sub.c
index 7cd3b37ac084..7cd3b37ac084 100644
--- a/arch/i386/math-emu/reg_add_sub.c
+++ b/arch/x86/math-emu/reg_add_sub.c
diff --git a/arch/i386/math-emu/reg_compare.c b/arch/x86/math-emu/reg_compare.c
index f37c5b5a35ad..f37c5b5a35ad 100644
--- a/arch/i386/math-emu/reg_compare.c
+++ b/arch/x86/math-emu/reg_compare.c
diff --git a/arch/i386/math-emu/reg_constant.c b/arch/x86/math-emu/reg_constant.c
index a85015801969..a85015801969 100644
--- a/arch/i386/math-emu/reg_constant.c
+++ b/arch/x86/math-emu/reg_constant.c
diff --git a/arch/i386/math-emu/reg_constant.h b/arch/x86/math-emu/reg_constant.h
index 1bffaec3a134..1bffaec3a134 100644
--- a/arch/i386/math-emu/reg_constant.h
+++ b/arch/x86/math-emu/reg_constant.h
diff --git a/arch/i386/math-emu/reg_convert.c b/arch/x86/math-emu/reg_convert.c
index 45a258752703..45a258752703 100644
--- a/arch/i386/math-emu/reg_convert.c
+++ b/arch/x86/math-emu/reg_convert.c
diff --git a/arch/i386/math-emu/reg_divide.c b/arch/x86/math-emu/reg_divide.c
index 5cee7ff920d9..5cee7ff920d9 100644
--- a/arch/i386/math-emu/reg_divide.c
+++ b/arch/x86/math-emu/reg_divide.c
diff --git a/arch/i386/math-emu/reg_ld_str.c b/arch/x86/math-emu/reg_ld_str.c
index e976caef6498..e976caef6498 100644
--- a/arch/i386/math-emu/reg_ld_str.c
+++ b/arch/x86/math-emu/reg_ld_str.c
diff --git a/arch/i386/math-emu/reg_mul.c b/arch/x86/math-emu/reg_mul.c
index 40f50b61bc67..40f50b61bc67 100644
--- a/arch/i386/math-emu/reg_mul.c
+++ b/arch/x86/math-emu/reg_mul.c
diff --git a/arch/i386/math-emu/reg_norm.S b/arch/x86/math-emu/reg_norm.S
index 8b6352efceef..8b6352efceef 100644
--- a/arch/i386/math-emu/reg_norm.S
+++ b/arch/x86/math-emu/reg_norm.S
diff --git a/arch/i386/math-emu/reg_round.S b/arch/x86/math-emu/reg_round.S
index d1d4e48b4f67..d1d4e48b4f67 100644
--- a/arch/i386/math-emu/reg_round.S
+++ b/arch/x86/math-emu/reg_round.S
diff --git a/arch/i386/math-emu/reg_u_add.S b/arch/x86/math-emu/reg_u_add.S
index 47c4c2434d85..47c4c2434d85 100644
--- a/arch/i386/math-emu/reg_u_add.S
+++ b/arch/x86/math-emu/reg_u_add.S
diff --git a/arch/i386/math-emu/reg_u_div.S b/arch/x86/math-emu/reg_u_div.S
index cc00654b6f9a..cc00654b6f9a 100644
--- a/arch/i386/math-emu/reg_u_div.S
+++ b/arch/x86/math-emu/reg_u_div.S
diff --git a/arch/i386/math-emu/reg_u_mul.S b/arch/x86/math-emu/reg_u_mul.S
index 973f12af97df..973f12af97df 100644
--- a/arch/i386/math-emu/reg_u_mul.S
+++ b/arch/x86/math-emu/reg_u_mul.S
diff --git a/arch/i386/math-emu/reg_u_sub.S b/arch/x86/math-emu/reg_u_sub.S
index 1b6c24801d22..1b6c24801d22 100644
--- a/arch/i386/math-emu/reg_u_sub.S
+++ b/arch/x86/math-emu/reg_u_sub.S
diff --git a/arch/i386/math-emu/round_Xsig.S b/arch/x86/math-emu/round_Xsig.S
index bbe0e87718e4..bbe0e87718e4 100644
--- a/arch/i386/math-emu/round_Xsig.S
+++ b/arch/x86/math-emu/round_Xsig.S
diff --git a/arch/i386/math-emu/shr_Xsig.S b/arch/x86/math-emu/shr_Xsig.S
index 31cdd118e918..31cdd118e918 100644
--- a/arch/i386/math-emu/shr_Xsig.S
+++ b/arch/x86/math-emu/shr_Xsig.S
diff --git a/arch/i386/math-emu/status_w.h b/arch/x86/math-emu/status_w.h
index 59e73302aa60..59e73302aa60 100644
--- a/arch/i386/math-emu/status_w.h
+++ b/arch/x86/math-emu/status_w.h
diff --git a/arch/i386/math-emu/version.h b/arch/x86/math-emu/version.h
index a0d73a1d2b67..a0d73a1d2b67 100644
--- a/arch/i386/math-emu/version.h
+++ b/arch/x86/math-emu/version.h
diff --git a/arch/i386/math-emu/wm_shrx.S b/arch/x86/math-emu/wm_shrx.S
index 518428317985..518428317985 100644
--- a/arch/i386/math-emu/wm_shrx.S
+++ b/arch/x86/math-emu/wm_shrx.S
diff --git a/arch/i386/math-emu/wm_sqrt.S b/arch/x86/math-emu/wm_sqrt.S
index d258f59564e1..d258f59564e1 100644
--- a/arch/i386/math-emu/wm_sqrt.S
+++ b/arch/x86/math-emu/wm_sqrt.S
diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
new file mode 100644
index 000000000000..983291096848
--- /dev/null
+++ b/arch/x86/mm/Makefile
@@ -0,0 +1,5 @@
1ifeq ($(CONFIG_X86_32),y)
2include ${srctree}/arch/x86/mm/Makefile_32
3else
4include ${srctree}/arch/x86/mm/Makefile_64
5endif
diff --git a/arch/x86/mm/Makefile_32 b/arch/x86/mm/Makefile_32
new file mode 100644
index 000000000000..362b4ad082de
--- /dev/null
+++ b/arch/x86/mm/Makefile_32
@@ -0,0 +1,10 @@
1#
2# Makefile for the linux i386-specific parts of the memory manager.
3#
4
5obj-y := init_32.o pgtable_32.o fault_32.o ioremap_32.o extable_32.o pageattr_32.o mmap_32.o
6
7obj-$(CONFIG_NUMA) += discontig_32.o
8obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o
9obj-$(CONFIG_HIGHMEM) += highmem_32.o
10obj-$(CONFIG_BOOT_IOREMAP) += boot_ioremap_32.o
diff --git a/arch/x86/mm/Makefile_64 b/arch/x86/mm/Makefile_64
new file mode 100644
index 000000000000..6bcb47945b87
--- /dev/null
+++ b/arch/x86/mm/Makefile_64
@@ -0,0 +1,10 @@
1#
2# Makefile for the linux x86_64-specific parts of the memory manager.
3#
4
5obj-y := init_64.o fault_64.o ioremap_64.o extable_64.o pageattr_64.o mmap_64.o
6obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o
7obj-$(CONFIG_NUMA) += numa_64.o
8obj-$(CONFIG_K8_NUMA) += k8topology_64.o
9obj-$(CONFIG_ACPI_NUMA) += srat_64.o
10
diff --git a/arch/i386/mm/boot_ioremap.c b/arch/x86/mm/boot_ioremap_32.c
index 4de95a17a7d4..4de95a17a7d4 100644
--- a/arch/i386/mm/boot_ioremap.c
+++ b/arch/x86/mm/boot_ioremap_32.c
diff --git a/arch/i386/mm/discontig.c b/arch/x86/mm/discontig_32.c
index 860e912a3fbb..860e912a3fbb 100644
--- a/arch/i386/mm/discontig.c
+++ b/arch/x86/mm/discontig_32.c
diff --git a/arch/i386/mm/extable.c b/arch/x86/mm/extable_32.c
index 0ce4f22a2635..0ce4f22a2635 100644
--- a/arch/i386/mm/extable.c
+++ b/arch/x86/mm/extable_32.c
diff --git a/arch/x86_64/mm/extable.c b/arch/x86/mm/extable_64.c
index 79ac6e7100af..79ac6e7100af 100644
--- a/arch/x86_64/mm/extable.c
+++ b/arch/x86/mm/extable_64.c
diff --git a/arch/i386/mm/fault.c b/arch/x86/mm/fault_32.c
index fcb38e7f3543..fcb38e7f3543 100644
--- a/arch/i386/mm/fault.c
+++ b/arch/x86/mm/fault_32.c
diff --git a/arch/x86_64/mm/fault.c b/arch/x86/mm/fault_64.c
index 54816adb8e93..54816adb8e93 100644
--- a/arch/x86_64/mm/fault.c
+++ b/arch/x86/mm/fault_64.c
diff --git a/arch/i386/mm/highmem.c b/arch/x86/mm/highmem_32.c
index 1c3bf95f7356..1c3bf95f7356 100644
--- a/arch/i386/mm/highmem.c
+++ b/arch/x86/mm/highmem_32.c
diff --git a/arch/i386/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
index 6c06d9c0488e..6c06d9c0488e 100644
--- a/arch/i386/mm/hugetlbpage.c
+++ b/arch/x86/mm/hugetlbpage.c
diff --git a/arch/i386/mm/init.c b/arch/x86/mm/init_32.c
index 730a5b177b1f..730a5b177b1f 100644
--- a/arch/i386/mm/init.c
+++ b/arch/x86/mm/init_32.c
diff --git a/arch/x86_64/mm/init.c b/arch/x86/mm/init_64.c
index 458893b376f8..458893b376f8 100644
--- a/arch/x86_64/mm/init.c
+++ b/arch/x86/mm/init_64.c
diff --git a/arch/i386/mm/ioremap.c b/arch/x86/mm/ioremap_32.c
index 0b278315d737..0b278315d737 100644
--- a/arch/i386/mm/ioremap.c
+++ b/arch/x86/mm/ioremap_32.c
diff --git a/arch/x86_64/mm/ioremap.c b/arch/x86/mm/ioremap_64.c
index 6cac90aa5032..6cac90aa5032 100644
--- a/arch/x86_64/mm/ioremap.c
+++ b/arch/x86/mm/ioremap_64.c
diff --git a/arch/x86_64/mm/k8topology.c b/arch/x86/mm/k8topology_64.c
index a96006f7ae0c..a96006f7ae0c 100644
--- a/arch/x86_64/mm/k8topology.c
+++ b/arch/x86/mm/k8topology_64.c
diff --git a/arch/i386/mm/mmap.c b/arch/x86/mm/mmap_32.c
index 552e08473755..552e08473755 100644
--- a/arch/i386/mm/mmap.c
+++ b/arch/x86/mm/mmap_32.c
diff --git a/arch/x86_64/mm/mmap.c b/arch/x86/mm/mmap_64.c
index 80bba0dc000e..80bba0dc000e 100644
--- a/arch/x86_64/mm/mmap.c
+++ b/arch/x86/mm/mmap_64.c
diff --git a/arch/x86_64/mm/numa.c b/arch/x86/mm/numa_64.c
index 6da235522269..6da235522269 100644
--- a/arch/x86_64/mm/numa.c
+++ b/arch/x86/mm/numa_64.c
diff --git a/arch/i386/mm/pageattr.c b/arch/x86/mm/pageattr_32.c
index 4241a74d16c8..4241a74d16c8 100644
--- a/arch/i386/mm/pageattr.c
+++ b/arch/x86/mm/pageattr_32.c
diff --git a/arch/x86_64/mm/pageattr.c b/arch/x86/mm/pageattr_64.c
index 10b9809ce821..10b9809ce821 100644
--- a/arch/x86_64/mm/pageattr.c
+++ b/arch/x86/mm/pageattr_64.c
diff --git a/arch/i386/mm/pgtable.c b/arch/x86/mm/pgtable_32.c
index 01437c46baae..01437c46baae 100644
--- a/arch/i386/mm/pgtable.c
+++ b/arch/x86/mm/pgtable_32.c
diff --git a/arch/x86_64/mm/srat.c b/arch/x86/mm/srat_64.c
index acdf03e19146..acdf03e19146 100644
--- a/arch/x86_64/mm/srat.c
+++ b/arch/x86/mm/srat_64.c
diff --git a/arch/i386/oprofile/Kconfig b/arch/x86/oprofile/Kconfig
index d8a84088471a..d8a84088471a 100644
--- a/arch/i386/oprofile/Kconfig
+++ b/arch/x86/oprofile/Kconfig
diff --git a/arch/i386/oprofile/Makefile b/arch/x86/oprofile/Makefile
index 30f3eb366667..30f3eb366667 100644
--- a/arch/i386/oprofile/Makefile
+++ b/arch/x86/oprofile/Makefile
diff --git a/arch/i386/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
index c049ce414f01..c049ce414f01 100644
--- a/arch/i386/oprofile/backtrace.c
+++ b/arch/x86/oprofile/backtrace.c
diff --git a/arch/i386/oprofile/init.c b/arch/x86/oprofile/init.c
index 5341d481d92f..5341d481d92f 100644
--- a/arch/i386/oprofile/init.c
+++ b/arch/x86/oprofile/init.c
diff --git a/arch/i386/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
index 11b7a51566a8..11b7a51566a8 100644
--- a/arch/i386/oprofile/nmi_int.c
+++ b/arch/x86/oprofile/nmi_int.c
diff --git a/arch/i386/oprofile/nmi_timer_int.c b/arch/x86/oprofile/nmi_timer_int.c
index 1418e36ae7ab..1418e36ae7ab 100644
--- a/arch/i386/oprofile/nmi_timer_int.c
+++ b/arch/x86/oprofile/nmi_timer_int.c
diff --git a/arch/i386/oprofile/op_counter.h b/arch/x86/oprofile/op_counter.h
index 2880b15c4675..2880b15c4675 100644
--- a/arch/i386/oprofile/op_counter.h
+++ b/arch/x86/oprofile/op_counter.h
diff --git a/arch/i386/oprofile/op_model_athlon.c b/arch/x86/oprofile/op_model_athlon.c
index 3057a19e4641..3057a19e4641 100644
--- a/arch/i386/oprofile/op_model_athlon.c
+++ b/arch/x86/oprofile/op_model_athlon.c
diff --git a/arch/i386/oprofile/op_model_p4.c b/arch/x86/oprofile/op_model_p4.c
index 47925927b12f..47925927b12f 100644
--- a/arch/i386/oprofile/op_model_p4.c
+++ b/arch/x86/oprofile/op_model_p4.c
diff --git a/arch/i386/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
index c554f52cb808..c554f52cb808 100644
--- a/arch/i386/oprofile/op_model_ppro.c
+++ b/arch/x86/oprofile/op_model_ppro.c
diff --git a/arch/i386/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
index abb1aa95b979..abb1aa95b979 100644
--- a/arch/i386/oprofile/op_x86_model.h
+++ b/arch/x86/oprofile/op_x86_model.h
diff --git a/arch/x86/pci/Makefile b/arch/x86/pci/Makefile
new file mode 100644
index 000000000000..c5c8e485fc44
--- /dev/null
+++ b/arch/x86/pci/Makefile
@@ -0,0 +1,5 @@
1ifeq ($(CONFIG_X86_32),y)
2include ${srctree}/arch/x86/pci/Makefile_32
3else
4include ${srctree}/arch/x86/pci/Makefile_64
5endif
diff --git a/arch/x86/pci/Makefile_32 b/arch/x86/pci/Makefile_32
new file mode 100644
index 000000000000..cdd6828b5abb
--- /dev/null
+++ b/arch/x86/pci/Makefile_32
@@ -0,0 +1,14 @@
1obj-y := i386.o init.o
2
3obj-$(CONFIG_PCI_BIOS) += pcbios.o
4obj-$(CONFIG_PCI_MMCONFIG) += mmconfig_32.o direct.o mmconfig-shared.o
5obj-$(CONFIG_PCI_DIRECT) += direct.o
6
7pci-y := fixup.o
8pci-$(CONFIG_ACPI) += acpi.o
9pci-y += legacy.o irq.o
10
11pci-$(CONFIG_X86_VISWS) := visws.o fixup.o
12pci-$(CONFIG_X86_NUMAQ) := numa.o irq.o
13
14obj-y += $(pci-y) common.o early.o
diff --git a/arch/x86/pci/Makefile_64 b/arch/x86/pci/Makefile_64
new file mode 100644
index 000000000000..7d8c467bf143
--- /dev/null
+++ b/arch/x86/pci/Makefile_64
@@ -0,0 +1,17 @@
1#
2# Makefile for X86_64 specific PCI routines
3#
4# Reuse the i386 PCI subsystem
5#
6EXTRA_CFLAGS += -Iarch/x86/pci
7
8obj-y := i386.o
9obj-$(CONFIG_PCI_DIRECT)+= direct.o
10obj-y += fixup.o init.o
11obj-$(CONFIG_ACPI) += acpi.o
12obj-y += legacy.o irq.o common.o early.o
13# mmconfig has a 64bit special
14obj-$(CONFIG_PCI_MMCONFIG) += mmconfig_64.o direct.o mmconfig-shared.o
15
16obj-$(CONFIG_NUMA) += k8-bus_64.o
17
diff --git a/arch/i386/pci/acpi.c b/arch/x86/pci/acpi.c
index bc8a44bddaa7..bc8a44bddaa7 100644
--- a/arch/i386/pci/acpi.c
+++ b/arch/x86/pci/acpi.c
diff --git a/arch/i386/pci/common.c b/arch/x86/pci/common.c
index 07d5223442bf..07d5223442bf 100644
--- a/arch/i386/pci/common.c
+++ b/arch/x86/pci/common.c
diff --git a/arch/i386/pci/direct.c b/arch/x86/pci/direct.c
index 431c9a51b157..431c9a51b157 100644
--- a/arch/i386/pci/direct.c
+++ b/arch/x86/pci/direct.c
diff --git a/arch/i386/pci/early.c b/arch/x86/pci/early.c
index 42df4b6606df..42df4b6606df 100644
--- a/arch/i386/pci/early.c
+++ b/arch/x86/pci/early.c
diff --git a/arch/i386/pci/fixup.c b/arch/x86/pci/fixup.c
index c82cbf4c7226..c82cbf4c7226 100644
--- a/arch/i386/pci/fixup.c
+++ b/arch/x86/pci/fixup.c
diff --git a/arch/i386/pci/i386.c b/arch/x86/pci/i386.c
index bcd2f94b732c..bcd2f94b732c 100644
--- a/arch/i386/pci/i386.c
+++ b/arch/x86/pci/i386.c
diff --git a/arch/i386/pci/init.c b/arch/x86/pci/init.c
index 3de9f9ba2da6..3de9f9ba2da6 100644
--- a/arch/i386/pci/init.c
+++ b/arch/x86/pci/init.c
diff --git a/arch/i386/pci/irq.c b/arch/x86/pci/irq.c
index d98c6b096f8e..d98c6b096f8e 100644
--- a/arch/i386/pci/irq.c
+++ b/arch/x86/pci/irq.c
diff --git a/arch/x86_64/pci/k8-bus.c b/arch/x86/pci/k8-bus_64.c
index 9cc813e29706..9cc813e29706 100644
--- a/arch/x86_64/pci/k8-bus.c
+++ b/arch/x86/pci/k8-bus_64.c
diff --git a/arch/i386/pci/legacy.c b/arch/x86/pci/legacy.c
index 5565d7016b75..5565d7016b75 100644
--- a/arch/i386/pci/legacy.c
+++ b/arch/x86/pci/legacy.c
diff --git a/arch/i386/pci/mmconfig-shared.c b/arch/x86/pci/mmconfig-shared.c
index 4df637e34f81..4df637e34f81 100644
--- a/arch/i386/pci/mmconfig-shared.c
+++ b/arch/x86/pci/mmconfig-shared.c
diff --git a/arch/i386/pci/mmconfig.c b/arch/x86/pci/mmconfig_32.c
index 1bf5816d34c8..1bf5816d34c8 100644
--- a/arch/i386/pci/mmconfig.c
+++ b/arch/x86/pci/mmconfig_32.c
diff --git a/arch/x86_64/pci/mmconfig.c b/arch/x86/pci/mmconfig_64.c
index 4095e4d66a1d..4095e4d66a1d 100644
--- a/arch/x86_64/pci/mmconfig.c
+++ b/arch/x86/pci/mmconfig_64.c
diff --git a/arch/i386/pci/numa.c b/arch/x86/pci/numa.c
index f5f165f69e0c..f5f165f69e0c 100644
--- a/arch/i386/pci/numa.c
+++ b/arch/x86/pci/numa.c
diff --git a/arch/i386/pci/pcbios.c b/arch/x86/pci/pcbios.c
index 10ac8c316c46..10ac8c316c46 100644
--- a/arch/i386/pci/pcbios.c
+++ b/arch/x86/pci/pcbios.c
diff --git a/arch/i386/pci/pci.h b/arch/x86/pci/pci.h
index 8c66f275756f..8c66f275756f 100644
--- a/arch/i386/pci/pci.h
+++ b/arch/x86/pci/pci.h
diff --git a/arch/i386/pci/visws.c b/arch/x86/pci/visws.c
index 8ecb1c722594..8ecb1c722594 100644
--- a/arch/i386/pci/visws.c
+++ b/arch/x86/pci/visws.c
diff --git a/arch/i386/power/Makefile b/arch/x86/power/Makefile
index d764ec950065..d764ec950065 100644
--- a/arch/i386/power/Makefile
+++ b/arch/x86/power/Makefile
diff --git a/arch/i386/power/cpu.c b/arch/x86/power/cpu.c
index 998fd3ec0d68..998fd3ec0d68 100644
--- a/arch/i386/power/cpu.c
+++ b/arch/x86/power/cpu.c
diff --git a/arch/i386/power/suspend.c b/arch/x86/power/suspend.c
index a0020b913f31..a0020b913f31 100644
--- a/arch/i386/power/suspend.c
+++ b/arch/x86/power/suspend.c
diff --git a/arch/i386/power/swsusp.S b/arch/x86/power/swsusp.S
index 53662e05b393..53662e05b393 100644
--- a/arch/i386/power/swsusp.S
+++ b/arch/x86/power/swsusp.S
diff --git a/arch/x86_64/vdso/.gitignore b/arch/x86/vdso/.gitignore
index f8b69d84238e..f8b69d84238e 100644
--- a/arch/x86_64/vdso/.gitignore
+++ b/arch/x86/vdso/.gitignore
diff --git a/arch/x86_64/vdso/Makefile b/arch/x86/vdso/Makefile
index 8d03de029d9b..8d03de029d9b 100644
--- a/arch/x86_64/vdso/Makefile
+++ b/arch/x86/vdso/Makefile
diff --git a/arch/x86_64/vdso/vclock_gettime.c b/arch/x86/vdso/vclock_gettime.c
index 5b54cdfb2b07..5b54cdfb2b07 100644
--- a/arch/x86_64/vdso/vclock_gettime.c
+++ b/arch/x86/vdso/vclock_gettime.c
diff --git a/arch/x86_64/vdso/vdso-note.S b/arch/x86/vdso/vdso-note.S
index 79a071e4357e..79a071e4357e 100644
--- a/arch/x86_64/vdso/vdso-note.S
+++ b/arch/x86/vdso/vdso-note.S
diff --git a/arch/x86_64/vdso/vdso-start.S b/arch/x86/vdso/vdso-start.S
index 2dc2cdb84d67..2dc2cdb84d67 100644
--- a/arch/x86_64/vdso/vdso-start.S
+++ b/arch/x86/vdso/vdso-start.S
diff --git a/arch/x86/vdso/vdso.S b/arch/x86/vdso/vdso.S
new file mode 100644
index 000000000000..4b1620a1529e
--- /dev/null
+++ b/arch/x86/vdso/vdso.S
@@ -0,0 +1,2 @@
1 .section ".vdso","a"
2 .incbin "arch/x86/vdso/vdso.so"
diff --git a/arch/x86_64/vdso/vdso.lds.S b/arch/x86/vdso/vdso.lds.S
index b9a60e665d08..b9a60e665d08 100644
--- a/arch/x86_64/vdso/vdso.lds.S
+++ b/arch/x86/vdso/vdso.lds.S
diff --git a/arch/x86_64/vdso/vextern.h b/arch/x86/vdso/vextern.h
index 1683ba2ae3e8..1683ba2ae3e8 100644
--- a/arch/x86_64/vdso/vextern.h
+++ b/arch/x86/vdso/vextern.h
diff --git a/arch/x86_64/vdso/vgetcpu.c b/arch/x86/vdso/vgetcpu.c
index 91f6e85d0fc2..91f6e85d0fc2 100644
--- a/arch/x86_64/vdso/vgetcpu.c
+++ b/arch/x86/vdso/vgetcpu.c
diff --git a/arch/x86_64/vdso/vma.c b/arch/x86/vdso/vma.c
index ff9333e5fb08..ff9333e5fb08 100644
--- a/arch/x86_64/vdso/vma.c
+++ b/arch/x86/vdso/vma.c
diff --git a/arch/x86_64/vdso/voffset.h b/arch/x86/vdso/voffset.h
index 4af67c79085f..4af67c79085f 100644
--- a/arch/x86_64/vdso/voffset.h
+++ b/arch/x86/vdso/voffset.h
diff --git a/arch/x86_64/vdso/vvar.c b/arch/x86/vdso/vvar.c
index 6fc22219a472..6fc22219a472 100644
--- a/arch/x86_64/vdso/vvar.c
+++ b/arch/x86/vdso/vvar.c
diff --git a/arch/i386/video/Makefile b/arch/x86/video/Makefile
index 2c447c94adcc..2c447c94adcc 100644
--- a/arch/i386/video/Makefile
+++ b/arch/x86/video/Makefile
diff --git a/arch/i386/video/fbdev.c b/arch/x86/video/fbdev.c
index 48fb38d7d2c0..48fb38d7d2c0 100644
--- a/arch/i386/video/fbdev.c
+++ b/arch/x86/video/fbdev.c
diff --git a/arch/i386/xen/Kconfig b/arch/x86/xen/Kconfig
index 9df99e1885a4..9df99e1885a4 100644
--- a/arch/i386/xen/Kconfig
+++ b/arch/x86/xen/Kconfig
diff --git a/arch/i386/xen/Makefile b/arch/x86/xen/Makefile
index 343df246bd3e..343df246bd3e 100644
--- a/arch/i386/xen/Makefile
+++ b/arch/x86/xen/Makefile
diff --git a/arch/i386/xen/enlighten.c b/arch/x86/xen/enlighten.c
index f01bfcd4bdee..f01bfcd4bdee 100644
--- a/arch/i386/xen/enlighten.c
+++ b/arch/x86/xen/enlighten.c
diff --git a/arch/i386/xen/events.c b/arch/x86/xen/events.c
index da1b173547a1..da1b173547a1 100644
--- a/arch/i386/xen/events.c
+++ b/arch/x86/xen/events.c
diff --git a/arch/i386/xen/features.c b/arch/x86/xen/features.c
index 0707714e40d6..0707714e40d6 100644
--- a/arch/i386/xen/features.c
+++ b/arch/x86/xen/features.c
diff --git a/arch/i386/xen/manage.c b/arch/x86/xen/manage.c
index aa7af9e6abc0..aa7af9e6abc0 100644
--- a/arch/i386/xen/manage.c
+++ b/arch/x86/xen/manage.c
diff --git a/arch/i386/xen/mmu.c b/arch/x86/xen/mmu.c
index 874db0cd1d2a..874db0cd1d2a 100644
--- a/arch/i386/xen/mmu.c
+++ b/arch/x86/xen/mmu.c
diff --git a/arch/i386/xen/mmu.h b/arch/x86/xen/mmu.h
index c9ff27f3ac3a..c9ff27f3ac3a 100644
--- a/arch/i386/xen/mmu.h
+++ b/arch/x86/xen/mmu.h
diff --git a/arch/i386/xen/multicalls.c b/arch/x86/xen/multicalls.c
index c837e8e463db..c837e8e463db 100644
--- a/arch/i386/xen/multicalls.c
+++ b/arch/x86/xen/multicalls.c
diff --git a/arch/i386/xen/multicalls.h b/arch/x86/xen/multicalls.h
index e6f7530b156c..e6f7530b156c 100644
--- a/arch/i386/xen/multicalls.h
+++ b/arch/x86/xen/multicalls.h
diff --git a/arch/i386/xen/setup.c b/arch/x86/xen/setup.c
index f84e77226646..f84e77226646 100644
--- a/arch/i386/xen/setup.c
+++ b/arch/x86/xen/setup.c
diff --git a/arch/i386/xen/smp.c b/arch/x86/xen/smp.c
index 557b8e24706a..557b8e24706a 100644
--- a/arch/i386/xen/smp.c
+++ b/arch/x86/xen/smp.c
diff --git a/arch/i386/xen/time.c b/arch/x86/xen/time.c
index dfd6db69ead5..dfd6db69ead5 100644
--- a/arch/i386/xen/time.c
+++ b/arch/x86/xen/time.c
diff --git a/arch/i386/xen/vdso.h b/arch/x86/xen/vdso.h
index 861fedfe5230..861fedfe5230 100644
--- a/arch/i386/xen/vdso.h
+++ b/arch/x86/xen/vdso.h
diff --git a/arch/i386/xen/xen-asm.S b/arch/x86/xen/xen-asm.S
index 1a43b60c0c62..1a43b60c0c62 100644
--- a/arch/i386/xen/xen-asm.S
+++ b/arch/x86/xen/xen-asm.S
diff --git a/arch/i386/xen/xen-head.S b/arch/x86/xen/xen-head.S
index f8d6937db2ec..f8d6937db2ec 100644
--- a/arch/i386/xen/xen-head.S
+++ b/arch/x86/xen/xen-head.S
diff --git a/arch/i386/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
index b9aaea45f07f..b9aaea45f07f 100644
--- a/arch/i386/xen/xen-ops.h
+++ b/arch/x86/xen/xen-ops.h
diff --git a/arch/x86_64/Kconfig b/arch/x86_64/Kconfig
index b4d9089a6a06..b1b98e614f7c 100644
--- a/arch/x86_64/Kconfig
+++ b/arch/x86_64/Kconfig
@@ -704,7 +704,7 @@ source kernel/power/Kconfig
704 704
705source "drivers/acpi/Kconfig" 705source "drivers/acpi/Kconfig"
706 706
707source "arch/x86_64/kernel/cpufreq/Kconfig" 707source "arch/x86/kernel/cpufreq/Kconfig"
708 708
709endmenu 709endmenu
710 710
@@ -778,7 +778,7 @@ source fs/Kconfig
778menu "Instrumentation Support" 778menu "Instrumentation Support"
779 depends on EXPERIMENTAL 779 depends on EXPERIMENTAL
780 780
781source "arch/x86_64/oprofile/Kconfig" 781source "arch/x86/oprofile/Kconfig"
782 782
783config KPROBES 783config KPROBES
784 bool "Kprobes" 784 bool "Kprobes"
diff --git a/arch/x86_64/Makefile b/arch/x86_64/Makefile
index b024e4a86895..8bffb94c71b5 100644
--- a/arch/x86_64/Makefile
+++ b/arch/x86_64/Makefile
@@ -21,6 +21,9 @@
21# 21#
22# $Id: Makefile,v 1.31 2002/03/22 15:56:07 ak Exp $ 22# $Id: Makefile,v 1.31 2002/03/22 15:56:07 ak Exp $
23 23
24# Fill in SRCARCH
25SRCARCH := x86
26
24LDFLAGS := -m elf_x86_64 27LDFLAGS := -m elf_x86_64
25OBJCOPYFLAGS := -O binary -R .note -R .comment -S 28OBJCOPYFLAGS := -O binary -R .note -R .comment -S
26LDFLAGS_vmlinux := 29LDFLAGS_vmlinux :=
@@ -71,18 +74,18 @@ CFLAGS += $(cflags-y)
71CFLAGS_KERNEL += $(cflags-kernel-y) 74CFLAGS_KERNEL += $(cflags-kernel-y)
72AFLAGS += -m64 75AFLAGS += -m64
73 76
74head-y := arch/x86_64/kernel/head.o arch/x86_64/kernel/head64.o arch/x86_64/kernel/init_task.o 77head-y := arch/x86/kernel/head_64.o arch/x86/kernel/head64.o arch/x86/kernel/init_task_64.o
75 78
76libs-y += arch/x86_64/lib/ 79libs-y += arch/x86/lib/
77core-y += arch/x86_64/kernel/ \ 80core-y += arch/x86/kernel/ \
78 arch/x86_64/mm/ \ 81 arch/x86/mm/ \
79 arch/x86_64/crypto/ \ 82 arch/x86/crypto/ \
80 arch/x86_64/vdso/ 83 arch/x86/vdso/
81core-$(CONFIG_IA32_EMULATION) += arch/x86_64/ia32/ 84core-$(CONFIG_IA32_EMULATION) += arch/x86/ia32/
82drivers-$(CONFIG_PCI) += arch/x86_64/pci/ 85drivers-$(CONFIG_PCI) += arch/x86/pci/
83drivers-$(CONFIG_OPROFILE) += arch/x86_64/oprofile/ 86drivers-$(CONFIG_OPROFILE) += arch/x86/oprofile/
84 87
85boot := arch/x86_64/boot 88boot := arch/x86/boot
86 89
87PHONY += bzImage bzlilo install archmrproper \ 90PHONY += bzImage bzlilo install archmrproper \
88 fdimage fdimage144 fdimage288 isoimage archclean 91 fdimage fdimage144 fdimage288 isoimage archclean
@@ -90,10 +93,12 @@ PHONY += bzImage bzlilo install archmrproper \
90#Default target when executing "make" 93#Default target when executing "make"
91all: bzImage 94all: bzImage
92 95
93BOOTIMAGE := arch/x86_64/boot/bzImage 96BOOTIMAGE := arch/x86/boot/bzImage
94KBUILD_IMAGE := $(BOOTIMAGE) 97KBUILD_IMAGE := $(BOOTIMAGE)
95 98
96bzImage: vmlinux 99bzImage: vmlinux
100 $(Q)mkdir -p $(objtree)/arch/x86_64/boot
101 $(Q)ln -fsn $(objtree)/arch/x86/boot/bzImage $(objtree)/arch/x86_64/boot/bzImage
97 $(Q)$(MAKE) $(build)=$(boot) $(BOOTIMAGE) 102 $(Q)$(MAKE) $(build)=$(boot) $(BOOTIMAGE)
98 103
99bzlilo: vmlinux 104bzlilo: vmlinux
@@ -109,6 +114,7 @@ install:
109 $(Q)$(MAKE) $(build)=$(boot) BOOTIMAGE=$(BOOTIMAGE) $@ 114 $(Q)$(MAKE) $(build)=$(boot) BOOTIMAGE=$(BOOTIMAGE) $@
110 115
111archclean: 116archclean:
117 $(Q)rm -rf $(objtree)/arch/x86_64/boot
112 $(Q)$(MAKE) $(clean)=$(boot) 118 $(Q)$(MAKE) $(clean)=$(boot)
113 119
114define archhelp 120define archhelp
diff --git a/arch/x86_64/boot/.gitignore b/arch/x86_64/boot/.gitignore
deleted file mode 100644
index 18465143cfa2..000000000000
--- a/arch/x86_64/boot/.gitignore
+++ /dev/null
@@ -1,5 +0,0 @@
1bootsect
2bzImage
3setup
4setup.bin
5setup.elf
diff --git a/arch/x86_64/boot/Makefile b/arch/x86_64/boot/Makefile
deleted file mode 100644
index 67096389de1f..000000000000
--- a/arch/x86_64/boot/Makefile
+++ /dev/null
@@ -1,9 +0,0 @@
1#
2# arch/x86_64/boot/Makefile
3#
4# The actual boot code is shared with i386 including the Makefile.
5# So tell kbuild that we fetch the code from i386 and include the
6# Makefile from i386 too.
7
8src := arch/i386/boot
9include $(src)/Makefile
diff --git a/arch/x86_64/boot/compressed/Makefile b/arch/x86_64/boot/compressed/Makefile
deleted file mode 100644
index 877c0bdbbc67..000000000000
--- a/arch/x86_64/boot/compressed/Makefile
+++ /dev/null
@@ -1,30 +0,0 @@
1#
2# linux/arch/x86_64/boot/compressed/Makefile
3#
4# create a compressed vmlinux image from the original vmlinux
5#
6
7targets := vmlinux vmlinux.bin vmlinux.bin.gz head.o misc.o piggy.o
8
9CFLAGS := -m64 -D__KERNEL__ $(LINUXINCLUDE) -O2 \
10 -fno-strict-aliasing -fPIC -mcmodel=small \
11 $(call cc-option, -ffreestanding) \
12 $(call cc-option, -fno-stack-protector)
13AFLAGS := $(CFLAGS) -D__ASSEMBLY__
14LDFLAGS := -m elf_x86_64
15
16LDFLAGS_vmlinux := -T
17$(obj)/vmlinux: $(src)/vmlinux.lds $(obj)/head.o $(obj)/misc.o $(obj)/piggy.o FORCE
18 $(call if_changed,ld)
19 @:
20
21$(obj)/vmlinux.bin: vmlinux FORCE
22 $(call if_changed,objcopy)
23
24$(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bin FORCE
25 $(call if_changed,gzip)
26
27LDFLAGS_piggy.o := -r --format binary --oformat elf64-x86-64 -T
28
29$(obj)/piggy.o: $(obj)/vmlinux.scr $(obj)/vmlinux.bin.gz FORCE
30 $(call if_changed,ld)
diff --git a/arch/x86_64/boot/compressed/head.S b/arch/x86_64/boot/compressed/head.S
deleted file mode 100644
index 9fd8030cc54f..000000000000
--- a/arch/x86_64/boot/compressed/head.S
+++ /dev/null
@@ -1,311 +0,0 @@
1/*
2 * linux/boot/head.S
3 *
4 * Copyright (C) 1991, 1992, 1993 Linus Torvalds
5 */
6
7/*
8 * head.S contains the 32-bit startup code.
9 *
10 * NOTE!!! Startup happens at absolute address 0x00001000, which is also where
11 * the page directory will exist. The startup code will be overwritten by
12 * the page directory. [According to comments etc elsewhere on a compressed
13 * kernel it will end up at 0x1000 + 1Mb I hope so as I assume this. - AC]
14 *
15 * Page 0 is deliberately kept safe, since System Management Mode code in
16 * laptops may need to access the BIOS data stored there. This is also
17 * useful for future device drivers that either access the BIOS via VM86
18 * mode.
19 */
20
21/*
22 * High loaded stuff by Hans Lermen & Werner Almesberger, Feb. 1996
23 */
24.code32
25.text
26
27#include <linux/linkage.h>
28#include <asm/segment.h>
29#include <asm/pgtable.h>
30#include <asm/page.h>
31#include <asm/msr.h>
32
33.section ".text.head"
34 .code32
35 .globl startup_32
36
37startup_32:
38 cld
39 cli
40 movl $(__KERNEL_DS), %eax
41 movl %eax, %ds
42 movl %eax, %es
43 movl %eax, %ss
44
45/* Calculate the delta between where we were compiled to run
46 * at and where we were actually loaded at. This can only be done
47 * with a short local call on x86. Nothing else will tell us what
48 * address we are running at. The reserved chunk of the real-mode
49 * data at 0x1e4 (defined as a scratch field) are used as the stack
50 * for this calculation. Only 4 bytes are needed.
51 */
52 leal (0x1e4+4)(%esi), %esp
53 call 1f
541: popl %ebp
55 subl $1b, %ebp
56
57/* setup a stack and make sure cpu supports long mode. */
58 movl $user_stack_end, %eax
59 addl %ebp, %eax
60 movl %eax, %esp
61
62 call verify_cpu
63 testl %eax, %eax
64 jnz no_longmode
65
66/* Compute the delta between where we were compiled to run at
67 * and where the code will actually run at.
68 */
69/* %ebp contains the address we are loaded at by the boot loader and %ebx
70 * contains the address where we should move the kernel image temporarily
71 * for safe in-place decompression.
72 */
73
74#ifdef CONFIG_RELOCATABLE
75 movl %ebp, %ebx
76 addl $(LARGE_PAGE_SIZE -1), %ebx
77 andl $LARGE_PAGE_MASK, %ebx
78#else
79 movl $CONFIG_PHYSICAL_START, %ebx
80#endif
81
82 /* Replace the compressed data size with the uncompressed size */
83 subl input_len(%ebp), %ebx
84 movl output_len(%ebp), %eax
85 addl %eax, %ebx
86 /* Add 8 bytes for every 32K input block */
87 shrl $12, %eax
88 addl %eax, %ebx
89 /* Add 32K + 18 bytes of extra slack and align on a 4K boundary */
90 addl $(32768 + 18 + 4095), %ebx
91 andl $~4095, %ebx
92
93/*
94 * Prepare for entering 64 bit mode
95 */
96
97 /* Load new GDT with the 64bit segments using 32bit descriptor */
98 leal gdt(%ebp), %eax
99 movl %eax, gdt+2(%ebp)
100 lgdt gdt(%ebp)
101
102 /* Enable PAE mode */
103 xorl %eax, %eax
104 orl $(1 << 5), %eax
105 movl %eax, %cr4
106
107 /*
108 * Build early 4G boot pagetable
109 */
110 /* Initialize Page tables to 0*/
111 leal pgtable(%ebx), %edi
112 xorl %eax, %eax
113 movl $((4096*6)/4), %ecx
114 rep stosl
115
116 /* Build Level 4 */
117 leal pgtable + 0(%ebx), %edi
118 leal 0x1007 (%edi), %eax
119 movl %eax, 0(%edi)
120
121 /* Build Level 3 */
122 leal pgtable + 0x1000(%ebx), %edi
123 leal 0x1007(%edi), %eax
124 movl $4, %ecx
1251: movl %eax, 0x00(%edi)
126 addl $0x00001000, %eax
127 addl $8, %edi
128 decl %ecx
129 jnz 1b
130
131 /* Build Level 2 */
132 leal pgtable + 0x2000(%ebx), %edi
133 movl $0x00000183, %eax
134 movl $2048, %ecx
1351: movl %eax, 0(%edi)
136 addl $0x00200000, %eax
137 addl $8, %edi
138 decl %ecx
139 jnz 1b
140
141 /* Enable the boot page tables */
142 leal pgtable(%ebx), %eax
143 movl %eax, %cr3
144
145 /* Enable Long mode in EFER (Extended Feature Enable Register) */
146 movl $MSR_EFER, %ecx
147 rdmsr
148 btsl $_EFER_LME, %eax
149 wrmsr
150
151 /* Setup for the jump to 64bit mode
152 *
153 * When the jump is performend we will be in long mode but
154 * in 32bit compatibility mode with EFER.LME = 1, CS.L = 0, CS.D = 1
155 * (and in turn EFER.LMA = 1). To jump into 64bit mode we use
156 * the new gdt/idt that has __KERNEL_CS with CS.L = 1.
157 * We place all of the values on our mini stack so lret can
158 * used to perform that far jump.
159 */
160 pushl $__KERNEL_CS
161 leal startup_64(%ebp), %eax
162 pushl %eax
163
164 /* Enter paged protected Mode, activating Long Mode */
165 movl $0x80000001, %eax /* Enable Paging and Protected mode */
166 movl %eax, %cr0
167
168 /* Jump from 32bit compatibility mode into 64bit mode. */
169 lret
170
171no_longmode:
172 /* This isn't an x86-64 CPU so hang */
1731:
174 hlt
175 jmp 1b
176
177#include "../../kernel/verify_cpu.S"
178
179 /* Be careful here startup_64 needs to be at a predictable
180 * address so I can export it in an ELF header. Bootloaders
181 * should look at the ELF header to find this address, as
182 * it may change in the future.
183 */
184 .code64
185 .org 0x200
186ENTRY(startup_64)
187 /* We come here either from startup_32 or directly from a
188 * 64bit bootloader. If we come here from a bootloader we depend on
189 * an identity mapped page table being provied that maps our
190 * entire text+data+bss and hopefully all of memory.
191 */
192
193 /* Setup data segments. */
194 xorl %eax, %eax
195 movl %eax, %ds
196 movl %eax, %es
197 movl %eax, %ss
198 movl %eax, %fs
199 movl %eax, %gs
200 lldt %ax
201 movl $0x20, %eax
202 ltr %ax
203
204 /* Compute the decompressed kernel start address. It is where
205 * we were loaded at aligned to a 2M boundary. %rbp contains the
206 * decompressed kernel start address.
207 *
208 * If it is a relocatable kernel then decompress and run the kernel
209 * from load address aligned to 2MB addr, otherwise decompress and
210 * run the kernel from CONFIG_PHYSICAL_START
211 */
212
213 /* Start with the delta to where the kernel will run at. */
214#ifdef CONFIG_RELOCATABLE
215 leaq startup_32(%rip) /* - $startup_32 */, %rbp
216 addq $(LARGE_PAGE_SIZE - 1), %rbp
217 andq $LARGE_PAGE_MASK, %rbp
218 movq %rbp, %rbx
219#else
220 movq $CONFIG_PHYSICAL_START, %rbp
221 movq %rbp, %rbx
222#endif
223
224 /* Replace the compressed data size with the uncompressed size */
225 movl input_len(%rip), %eax
226 subq %rax, %rbx
227 movl output_len(%rip), %eax
228 addq %rax, %rbx
229 /* Add 8 bytes for every 32K input block */
230 shrq $12, %rax
231 addq %rax, %rbx
232 /* Add 32K + 18 bytes of extra slack and align on a 4K boundary */
233 addq $(32768 + 18 + 4095), %rbx
234 andq $~4095, %rbx
235
236/* Copy the compressed kernel to the end of our buffer
237 * where decompression in place becomes safe.
238 */
239 leaq _end(%rip), %r8
240 leaq _end(%rbx), %r9
241 movq $_end /* - $startup_32 */, %rcx
2421: subq $8, %r8
243 subq $8, %r9
244 movq 0(%r8), %rax
245 movq %rax, 0(%r9)
246 subq $8, %rcx
247 jnz 1b
248
249/*
250 * Jump to the relocated address.
251 */
252 leaq relocated(%rbx), %rax
253 jmp *%rax
254
255.section ".text"
256relocated:
257
258/*
259 * Clear BSS
260 */
261 xorq %rax, %rax
262 leaq _edata(%rbx), %rdi
263 leaq _end(%rbx), %rcx
264 subq %rdi, %rcx
265 cld
266 rep
267 stosb
268
269 /* Setup the stack */
270 leaq user_stack_end(%rip), %rsp
271
272 /* zero EFLAGS after setting rsp */
273 pushq $0
274 popfq
275
276/*
277 * Do the decompression, and jump to the new kernel..
278 */
279 pushq %rsi # Save the real mode argument
280 movq %rsi, %rdi # real mode address
281 leaq _heap(%rip), %rsi # _heap
282 leaq input_data(%rip), %rdx # input_data
283 movl input_len(%rip), %eax
284 movq %rax, %rcx # input_len
285 movq %rbp, %r8 # output
286 call decompress_kernel
287 popq %rsi
288
289
290/*
291 * Jump to the decompressed kernel.
292 */
293 jmp *%rbp
294
295 .data
296gdt:
297 .word gdt_end - gdt
298 .long gdt
299 .word 0
300 .quad 0x0000000000000000 /* NULL descriptor */
301 .quad 0x00af9a000000ffff /* __KERNEL_CS */
302 .quad 0x00cf92000000ffff /* __KERNEL_DS */
303 .quad 0x0080890000000000 /* TS descriptor */
304 .quad 0x0000000000000000 /* TS continued */
305gdt_end:
306 .bss
307/* Stack for uncompression */
308 .balign 4
309user_stack:
310 .fill 4096,4,0
311user_stack_end:
diff --git a/arch/x86_64/boot/tools/.gitignore b/arch/x86_64/boot/tools/.gitignore
deleted file mode 100644
index 378eac25d311..000000000000
--- a/arch/x86_64/boot/tools/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
1build
diff --git a/arch/x86_64/crypto/Makefile b/arch/x86_64/crypto/Makefile
deleted file mode 100644
index 15b538a8b7f7..000000000000
--- a/arch/x86_64/crypto/Makefile
+++ /dev/null
@@ -1,12 +0,0 @@
1#
2# x86_64/crypto/Makefile
3#
4# Arch-specific CryptoAPI modules.
5#
6
7obj-$(CONFIG_CRYPTO_AES_X86_64) += aes-x86_64.o
8obj-$(CONFIG_CRYPTO_TWOFISH_X86_64) += twofish-x86_64.o
9
10aes-x86_64-y := aes-x86_64-asm.o aes.o
11twofish-x86_64-y := twofish-x86_64-asm.o twofish.o
12
diff --git a/arch/x86_64/ia32/audit.c b/arch/x86_64/ia32/audit.c
deleted file mode 100644
index 8850fe40ea34..000000000000
--- a/arch/x86_64/ia32/audit.c
+++ /dev/null
@@ -1,42 +0,0 @@
1#include <asm-i386/unistd.h>
2
3unsigned ia32_dir_class[] = {
4#include <asm-generic/audit_dir_write.h>
5~0U
6};
7
8unsigned ia32_chattr_class[] = {
9#include <asm-generic/audit_change_attr.h>
10~0U
11};
12
13unsigned ia32_write_class[] = {
14#include <asm-generic/audit_write.h>
15~0U
16};
17
18unsigned ia32_read_class[] = {
19#include <asm-generic/audit_read.h>
20~0U
21};
22
23unsigned ia32_signal_class[] = {
24#include <asm-generic/audit_signal.h>
25~0U
26};
27
28int ia32_classify_syscall(unsigned syscall)
29{
30 switch(syscall) {
31 case __NR_open:
32 return 2;
33 case __NR_openat:
34 return 3;
35 case __NR_socketcall:
36 return 4;
37 case __NR_execve:
38 return 5;
39 default:
40 return 1;
41 }
42}
diff --git a/arch/x86_64/ia32/ipc32.c b/arch/x86_64/ia32/ipc32.c
deleted file mode 100644
index 369151dc3213..000000000000
--- a/arch/x86_64/ia32/ipc32.c
+++ /dev/null
@@ -1,57 +0,0 @@
1#include <linux/kernel.h>
2#include <linux/spinlock.h>
3#include <linux/list.h>
4#include <linux/syscalls.h>
5#include <linux/time.h>
6#include <linux/sem.h>
7#include <linux/msg.h>
8#include <linux/shm.h>
9#include <linux/ipc.h>
10#include <linux/compat.h>
11
12#include <asm-i386/ipc.h>
13
14asmlinkage long
15sys32_ipc(u32 call, int first, int second, int third,
16 compat_uptr_t ptr, u32 fifth)
17{
18 int version;
19
20 version = call >> 16; /* hack for backward compatibility */
21 call &= 0xffff;
22
23 switch (call) {
24 case SEMOP:
25 /* struct sembuf is the same on 32 and 64bit :)) */
26 return sys_semtimedop(first, compat_ptr(ptr), second, NULL);
27 case SEMTIMEDOP:
28 return compat_sys_semtimedop(first, compat_ptr(ptr), second,
29 compat_ptr(fifth));
30 case SEMGET:
31 return sys_semget(first, second, third);
32 case SEMCTL:
33 return compat_sys_semctl(first, second, third, compat_ptr(ptr));
34
35 case MSGSND:
36 return compat_sys_msgsnd(first, second, third, compat_ptr(ptr));
37 case MSGRCV:
38 return compat_sys_msgrcv(first, second, fifth, third,
39 version, compat_ptr(ptr));
40 case MSGGET:
41 return sys_msgget((key_t) first, second);
42 case MSGCTL:
43 return compat_sys_msgctl(first, second, compat_ptr(ptr));
44
45 case SHMAT:
46 return compat_sys_shmat(first, second, third, version,
47 compat_ptr(ptr));
48 break;
49 case SHMDT:
50 return sys_shmdt(compat_ptr(ptr));
51 case SHMGET:
52 return sys_shmget(first, (unsigned)second, third);
53 case SHMCTL:
54 return compat_sys_shmctl(first, second, compat_ptr(ptr));
55 }
56 return -ENOSYS;
57}
diff --git a/arch/x86_64/ia32/syscall32_syscall.S b/arch/x86_64/ia32/syscall32_syscall.S
deleted file mode 100644
index 8f8271bdf135..000000000000
--- a/arch/x86_64/ia32/syscall32_syscall.S
+++ /dev/null
@@ -1,17 +0,0 @@
1/* 32bit VDSOs mapped into user space. */
2
3 .section ".init.data","aw"
4
5 .globl syscall32_syscall
6 .globl syscall32_syscall_end
7
8syscall32_syscall:
9 .incbin "arch/x86_64/ia32/vsyscall-syscall.so"
10syscall32_syscall_end:
11
12 .globl syscall32_sysenter
13 .globl syscall32_sysenter_end
14
15syscall32_sysenter:
16 .incbin "arch/x86_64/ia32/vsyscall-sysenter.so"
17syscall32_sysenter_end:
diff --git a/arch/x86_64/ia32/vsyscall-sigreturn.S b/arch/x86_64/ia32/vsyscall-sigreturn.S
deleted file mode 100644
index 1384367cdbe1..000000000000
--- a/arch/x86_64/ia32/vsyscall-sigreturn.S
+++ /dev/null
@@ -1,143 +0,0 @@
1/*
2 * Common code for the sigreturn entry points on the vsyscall page.
3 * This code uses SYSCALL_ENTER_KERNEL (either syscall or int $0x80)
4 * to enter the kernel.
5 * This file is #include'd by vsyscall-*.S to define them after the
6 * vsyscall entry point. The addresses we get for these entry points
7 * by doing ".balign 32" must match in both versions of the page.
8 */
9
10 .code32
11 .section .text.sigreturn,"ax"
12 .balign 32
13 .globl __kernel_sigreturn
14 .type __kernel_sigreturn,@function
15__kernel_sigreturn:
16.LSTART_sigreturn:
17 popl %eax
18 movl $__NR_ia32_sigreturn, %eax
19 SYSCALL_ENTER_KERNEL
20.LEND_sigreturn:
21 .size __kernel_sigreturn,.-.LSTART_sigreturn
22
23 .section .text.rtsigreturn,"ax"
24 .balign 32
25 .globl __kernel_rt_sigreturn
26 .type __kernel_rt_sigreturn,@function
27__kernel_rt_sigreturn:
28.LSTART_rt_sigreturn:
29 movl $__NR_ia32_rt_sigreturn, %eax
30 SYSCALL_ENTER_KERNEL
31.LEND_rt_sigreturn:
32 .size __kernel_rt_sigreturn,.-.LSTART_rt_sigreturn
33
34 .section .eh_frame,"a",@progbits
35.LSTARTFRAMES:
36 .long .LENDCIES-.LSTARTCIES
37.LSTARTCIES:
38 .long 0 /* CIE ID */
39 .byte 1 /* Version number */
40 .string "zRS" /* NUL-terminated augmentation string */
41 .uleb128 1 /* Code alignment factor */
42 .sleb128 -4 /* Data alignment factor */
43 .byte 8 /* Return address register column */
44 .uleb128 1 /* Augmentation value length */
45 .byte 0x1b /* DW_EH_PE_pcrel|DW_EH_PE_sdata4. */
46 .byte 0x0c /* DW_CFA_def_cfa */
47 .uleb128 4
48 .uleb128 4
49 .byte 0x88 /* DW_CFA_offset, column 0x8 */
50 .uleb128 1
51 .align 4
52.LENDCIES:
53
54 .long .LENDFDE2-.LSTARTFDE2 /* Length FDE */
55.LSTARTFDE2:
56 .long .LSTARTFDE2-.LSTARTFRAMES /* CIE pointer */
57 /* HACK: The dwarf2 unwind routines will subtract 1 from the
58 return address to get an address in the middle of the
59 presumed call instruction. Since we didn't get here via
60 a call, we need to include the nop before the real start
61 to make up for it. */
62 .long .LSTART_sigreturn-1-. /* PC-relative start address */
63 .long .LEND_sigreturn-.LSTART_sigreturn+1
64 .uleb128 0 /* Augmentation length */
65 /* What follows are the instructions for the table generation.
66 We record the locations of each register saved. This is
67 complicated by the fact that the "CFA" is always assumed to
68 be the value of the stack pointer in the caller. This means
69 that we must define the CFA of this body of code to be the
70 saved value of the stack pointer in the sigcontext. Which
71 also means that there is no fixed relation to the other
72 saved registers, which means that we must use DW_CFA_expression
73 to compute their addresses. It also means that when we
74 adjust the stack with the popl, we have to do it all over again. */
75
76#define do_cfa_expr(offset) \
77 .byte 0x0f; /* DW_CFA_def_cfa_expression */ \
78 .uleb128 1f-0f; /* length */ \
790: .byte 0x74; /* DW_OP_breg4 */ \
80 .sleb128 offset; /* offset */ \
81 .byte 0x06; /* DW_OP_deref */ \
821:
83
84#define do_expr(regno, offset) \
85 .byte 0x10; /* DW_CFA_expression */ \
86 .uleb128 regno; /* regno */ \
87 .uleb128 1f-0f; /* length */ \
880: .byte 0x74; /* DW_OP_breg4 */ \
89 .sleb128 offset; /* offset */ \
901:
91
92 do_cfa_expr(IA32_SIGCONTEXT_esp+4)
93 do_expr(0, IA32_SIGCONTEXT_eax+4)
94 do_expr(1, IA32_SIGCONTEXT_ecx+4)
95 do_expr(2, IA32_SIGCONTEXT_edx+4)
96 do_expr(3, IA32_SIGCONTEXT_ebx+4)
97 do_expr(5, IA32_SIGCONTEXT_ebp+4)
98 do_expr(6, IA32_SIGCONTEXT_esi+4)
99 do_expr(7, IA32_SIGCONTEXT_edi+4)
100 do_expr(8, IA32_SIGCONTEXT_eip+4)
101
102 .byte 0x42 /* DW_CFA_advance_loc 2 -- nop; popl eax. */
103
104 do_cfa_expr(IA32_SIGCONTEXT_esp)
105 do_expr(0, IA32_SIGCONTEXT_eax)
106 do_expr(1, IA32_SIGCONTEXT_ecx)
107 do_expr(2, IA32_SIGCONTEXT_edx)
108 do_expr(3, IA32_SIGCONTEXT_ebx)
109 do_expr(5, IA32_SIGCONTEXT_ebp)
110 do_expr(6, IA32_SIGCONTEXT_esi)
111 do_expr(7, IA32_SIGCONTEXT_edi)
112 do_expr(8, IA32_SIGCONTEXT_eip)
113
114 .align 4
115.LENDFDE2:
116
117 .long .LENDFDE3-.LSTARTFDE3 /* Length FDE */
118.LSTARTFDE3:
119 .long .LSTARTFDE3-.LSTARTFRAMES /* CIE pointer */
120 /* HACK: See above wrt unwind library assumptions. */
121 .long .LSTART_rt_sigreturn-1-. /* PC-relative start address */
122 .long .LEND_rt_sigreturn-.LSTART_rt_sigreturn+1
123 .uleb128 0 /* Augmentation */
124 /* What follows are the instructions for the table generation.
125 We record the locations of each register saved. This is
126 slightly less complicated than the above, since we don't
127 modify the stack pointer in the process. */
128
129 do_cfa_expr(IA32_RT_SIGFRAME_sigcontext-4 + IA32_SIGCONTEXT_esp)
130 do_expr(0, IA32_RT_SIGFRAME_sigcontext-4 + IA32_SIGCONTEXT_eax)
131 do_expr(1, IA32_RT_SIGFRAME_sigcontext-4 + IA32_SIGCONTEXT_ecx)
132 do_expr(2, IA32_RT_SIGFRAME_sigcontext-4 + IA32_SIGCONTEXT_edx)
133 do_expr(3, IA32_RT_SIGFRAME_sigcontext-4 + IA32_SIGCONTEXT_ebx)
134 do_expr(5, IA32_RT_SIGFRAME_sigcontext-4 + IA32_SIGCONTEXT_ebp)
135 do_expr(6, IA32_RT_SIGFRAME_sigcontext-4 + IA32_SIGCONTEXT_esi)
136 do_expr(7, IA32_RT_SIGFRAME_sigcontext-4 + IA32_SIGCONTEXT_edi)
137 do_expr(8, IA32_RT_SIGFRAME_sigcontext-4 + IA32_SIGCONTEXT_eip)
138
139 .align 4
140.LENDFDE3:
141
142#include "../../i386/kernel/vsyscall-note.S"
143
diff --git a/arch/x86_64/kernel/Makefile b/arch/x86_64/kernel/Makefile
deleted file mode 100644
index ff5d8c9b96d9..000000000000
--- a/arch/x86_64/kernel/Makefile
+++ /dev/null
@@ -1,63 +0,0 @@
1#
2# Makefile for the linux kernel.
3#
4
5extra-y := head.o head64.o init_task.o vmlinux.lds
6EXTRA_AFLAGS := -traditional
7obj-y := process.o signal.o entry.o traps.o irq.o \
8 ptrace.o time.o ioport.o ldt.o setup.o i8259.o sys_x86_64.o \
9 x8664_ksyms.o i387.o syscall.o vsyscall.o \
10 setup64.o bootflag.o e820.o reboot.o quirks.o i8237.o \
11 pci-dma.o pci-nommu.o alternative.o hpet.o tsc.o bugs.o \
12 perfctr-watchdog.o
13
14obj-$(CONFIG_STACKTRACE) += stacktrace.o
15obj-$(CONFIG_X86_MCE) += mce.o therm_throt.o
16obj-$(CONFIG_X86_MCE_INTEL) += mce_intel.o
17obj-$(CONFIG_X86_MCE_AMD) += mce_amd.o
18obj-$(CONFIG_MTRR) += ../../i386/kernel/cpu/mtrr/
19obj-$(CONFIG_ACPI) += acpi/
20obj-$(CONFIG_X86_MSR) += msr.o
21obj-$(CONFIG_MICROCODE) += microcode.o
22obj-$(CONFIG_X86_CPUID) += cpuid.o
23obj-$(CONFIG_SMP) += smp.o smpboot.o trampoline.o tsc_sync.o
24obj-y += apic.o nmi.o
25obj-y += io_apic.o mpparse.o genapic.o genapic_flat.o
26obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o crash.o
27obj-$(CONFIG_CRASH_DUMP) += crash_dump.o
28obj-$(CONFIG_PM) += suspend.o
29obj-$(CONFIG_HIBERNATION) += suspend_asm.o
30obj-$(CONFIG_CPU_FREQ) += cpufreq/
31obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
32obj-$(CONFIG_IOMMU) += pci-gart.o aperture.o
33obj-$(CONFIG_CALGARY_IOMMU) += pci-calgary.o tce.o
34obj-$(CONFIG_SWIOTLB) += pci-swiotlb.o
35obj-$(CONFIG_KPROBES) += kprobes.o
36obj-$(CONFIG_X86_PM_TIMER) += pmtimer.o
37obj-$(CONFIG_X86_VSMP) += vsmp.o
38obj-$(CONFIG_K8_NB) += k8.o
39obj-$(CONFIG_AUDIT) += audit.o
40
41obj-$(CONFIG_MODULES) += module.o
42obj-$(CONFIG_PCI) += early-quirks.o
43
44obj-y += topology.o
45obj-y += intel_cacheinfo.o
46obj-y += addon_cpuid_features.o
47obj-y += pcspeaker.o
48
49CFLAGS_vsyscall.o := $(PROFILING) -g0
50
51therm_throt-y += ../../i386/kernel/cpu/mcheck/therm_throt.o
52bootflag-y += ../../i386/kernel/bootflag.o
53cpuid-$(subst m,y,$(CONFIG_X86_CPUID)) += ../../i386/kernel/cpuid.o
54topology-y += ../../i386/kernel/topology.o
55microcode-$(subst m,y,$(CONFIG_MICROCODE)) += ../../i386/kernel/microcode.o
56intel_cacheinfo-y += ../../i386/kernel/cpu/intel_cacheinfo.o
57addon_cpuid_features-y += ../../i386/kernel/cpu/addon_cpuid_features.o
58quirks-y += ../../i386/kernel/quirks.o
59i8237-y += ../../i386/kernel/i8237.o
60msr-$(subst m,y,$(CONFIG_X86_MSR)) += ../../i386/kernel/msr.o
61alternative-y += ../../i386/kernel/alternative.o
62pcspeaker-y += ../../i386/kernel/pcspeaker.o
63perfctr-watchdog-y += ../../i386/kernel/cpu/perfctr-watchdog.o
diff --git a/arch/x86_64/kernel/acpi/Makefile b/arch/x86_64/kernel/acpi/Makefile
deleted file mode 100644
index 080b9963f1bc..000000000000
--- a/arch/x86_64/kernel/acpi/Makefile
+++ /dev/null
@@ -1,9 +0,0 @@
1obj-y := boot.o
2boot-y := ../../../i386/kernel/acpi/boot.o
3obj-$(CONFIG_ACPI_SLEEP) += sleep.o wakeup.o
4
5ifneq ($(CONFIG_ACPI_PROCESSOR),)
6obj-y += processor.o
7processor-y := ../../../i386/kernel/acpi/processor.o ../../../i386/kernel/acpi/cstate.o
8endif
9
diff --git a/arch/x86_64/kernel/acpi/wakeup.S b/arch/x86_64/kernel/acpi/wakeup.S
deleted file mode 100644
index a06f2bcabef9..000000000000
--- a/arch/x86_64/kernel/acpi/wakeup.S
+++ /dev/null
@@ -1,456 +0,0 @@
1.text
2#include <linux/linkage.h>
3#include <asm/segment.h>
4#include <asm/pgtable.h>
5#include <asm/page.h>
6#include <asm/msr.h>
7
8# Copyright 2003 Pavel Machek <pavel@suse.cz>, distribute under GPLv2
9#
10# wakeup_code runs in real mode, and at unknown address (determined at run-time).
11# Therefore it must only use relative jumps/calls.
12#
13# Do we need to deal with A20? It is okay: ACPI specs says A20 must be enabled
14#
15# If physical address of wakeup_code is 0x12345, BIOS should call us with
16# cs = 0x1234, eip = 0x05
17#
18
19#define BEEP \
20 inb $97, %al; \
21 outb %al, $0x80; \
22 movb $3, %al; \
23 outb %al, $97; \
24 outb %al, $0x80; \
25 movb $-74, %al; \
26 outb %al, $67; \
27 outb %al, $0x80; \
28 movb $-119, %al; \
29 outb %al, $66; \
30 outb %al, $0x80; \
31 movb $15, %al; \
32 outb %al, $66;
33
34
35ALIGN
36 .align 16
37ENTRY(wakeup_start)
38wakeup_code:
39 wakeup_code_start = .
40 .code16
41
42# Running in *copy* of this code, somewhere in low 1MB.
43
44 movb $0xa1, %al ; outb %al, $0x80
45 cli
46 cld
47 # setup data segment
48 movw %cs, %ax
49 movw %ax, %ds # Make ds:0 point to wakeup_start
50 movw %ax, %ss
51
52 # Data segment must be set up before we can see whether to beep.
53 testl $4, realmode_flags - wakeup_code
54 jz 1f
55 BEEP
561:
57
58 # Private stack is needed for ASUS board
59 mov $(wakeup_stack - wakeup_code), %sp
60
61 pushl $0 # Kill any dangerous flags
62 popfl
63
64 movl real_magic - wakeup_code, %eax
65 cmpl $0x12345678, %eax
66 jne bogus_real_magic
67
68 call verify_cpu # Verify the cpu supports long
69 # mode
70 testl %eax, %eax
71 jnz no_longmode
72
73 testl $1, realmode_flags - wakeup_code
74 jz 1f
75 lcall $0xc000,$3
76 movw %cs, %ax
77 movw %ax, %ds # Bios might have played with that
78 movw %ax, %ss
791:
80
81 testl $2, realmode_flags - wakeup_code
82 jz 1f
83 mov video_mode - wakeup_code, %ax
84 call mode_set
851:
86
87 movw $0xb800, %ax
88 movw %ax,%fs
89 movw $0x0e00 + 'L', %fs:(0x10)
90
91 movb $0xa2, %al ; outb %al, $0x80
92
93 mov %ds, %ax # Find 32bit wakeup_code addr
94 movzx %ax, %esi # (Convert %ds:gdt to a liner ptr)
95 shll $4, %esi
96 # Fix up the vectors
97 addl %esi, wakeup_32_vector - wakeup_code
98 addl %esi, wakeup_long64_vector - wakeup_code
99 addl %esi, gdt_48a + 2 - wakeup_code # Fixup the gdt pointer
100
101 lidtl %ds:idt_48a - wakeup_code
102 lgdtl %ds:gdt_48a - wakeup_code # load gdt with whatever is
103 # appropriate
104
105 movl $1, %eax # protected mode (PE) bit
106 lmsw %ax # This is it!
107 jmp 1f
1081:
109
110 ljmpl *(wakeup_32_vector - wakeup_code)
111
112 .balign 4
113wakeup_32_vector:
114 .long wakeup_32 - wakeup_code
115 .word __KERNEL32_CS, 0
116
117 .code32
118wakeup_32:
119# Running in this code, but at low address; paging is not yet turned on.
120 movb $0xa5, %al ; outb %al, $0x80
121
122 movl $__KERNEL_DS, %eax
123 movl %eax, %ds
124
125 movw $0x0e00 + 'i', %ds:(0xb8012)
126 movb $0xa8, %al ; outb %al, $0x80;
127
128 /*
129 * Prepare for entering 64bits mode
130 */
131
132 /* Enable PAE */
133 xorl %eax, %eax
134 btsl $5, %eax
135 movl %eax, %cr4
136
137 /* Setup early boot stage 4 level pagetables */
138 leal (wakeup_level4_pgt - wakeup_code)(%esi), %eax
139 movl %eax, %cr3
140
141 /* Check if nx is implemented */
142 movl $0x80000001, %eax
143 cpuid
144 movl %edx,%edi
145
146 /* Enable Long Mode */
147 xorl %eax, %eax
148 btsl $_EFER_LME, %eax
149
150 /* No Execute supported? */
151 btl $20,%edi
152 jnc 1f
153 btsl $_EFER_NX, %eax
154
155 /* Make changes effective */
1561: movl $MSR_EFER, %ecx
157 xorl %edx, %edx
158 wrmsr
159
160 xorl %eax, %eax
161 btsl $31, %eax /* Enable paging and in turn activate Long Mode */
162 btsl $0, %eax /* Enable protected mode */
163
164 /* Make changes effective */
165 movl %eax, %cr0
166
167 /* At this point:
168 CR4.PAE must be 1
169 CS.L must be 0
170 CR3 must point to PML4
171 Next instruction must be a branch
172 This must be on identity-mapped page
173 */
174 /*
175 * At this point we're in long mode but in 32bit compatibility mode
176 * with EFER.LME = 1, CS.L = 0, CS.D = 1 (and in turn
177 * EFER.LMA = 1). Now we want to jump in 64bit mode, to do that we load
178 * the new gdt/idt that has __KERNEL_CS with CS.L = 1.
179 */
180
181 /* Finally jump in 64bit mode */
182 ljmp *(wakeup_long64_vector - wakeup_code)(%esi)
183
184 .balign 4
185wakeup_long64_vector:
186 .long wakeup_long64 - wakeup_code
187 .word __KERNEL_CS, 0
188
189.code64
190
191 /* Hooray, we are in Long 64-bit mode (but still running in
192 * low memory)
193 */
194wakeup_long64:
195 /*
196 * We must switch to a new descriptor in kernel space for the GDT
197 * because soon the kernel won't have access anymore to the userspace
198 * addresses where we're currently running on. We have to do that here
199 * because in 32bit we couldn't load a 64bit linear address.
200 */
201 lgdt cpu_gdt_descr
202
203 movw $0x0e00 + 'n', %ds:(0xb8014)
204 movb $0xa9, %al ; outb %al, $0x80
205
206 movq saved_magic, %rax
207 movq $0x123456789abcdef0, %rdx
208 cmpq %rdx, %rax
209 jne bogus_64_magic
210
211 movw $0x0e00 + 'u', %ds:(0xb8016)
212
213 nop
214 nop
215 movw $__KERNEL_DS, %ax
216 movw %ax, %ss
217 movw %ax, %ds
218 movw %ax, %es
219 movw %ax, %fs
220 movw %ax, %gs
221 movq saved_rsp, %rsp
222
223 movw $0x0e00 + 'x', %ds:(0xb8018)
224 movq saved_rbx, %rbx
225 movq saved_rdi, %rdi
226 movq saved_rsi, %rsi
227 movq saved_rbp, %rbp
228
229 movw $0x0e00 + '!', %ds:(0xb801a)
230 movq saved_rip, %rax
231 jmp *%rax
232
233.code32
234
235 .align 64
236gdta:
237 /* Its good to keep gdt in sync with one in trampoline.S */
238 .word 0, 0, 0, 0 # dummy
239 /* ??? Why I need the accessed bit set in order for this to work? */
240 .quad 0x00cf9b000000ffff # __KERNEL32_CS
241 .quad 0x00af9b000000ffff # __KERNEL_CS
242 .quad 0x00cf93000000ffff # __KERNEL_DS
243
244idt_48a:
245 .word 0 # idt limit = 0
246 .word 0, 0 # idt base = 0L
247
248gdt_48a:
249 .word 0x800 # gdt limit=2048,
250 # 256 GDT entries
251 .long gdta - wakeup_code # gdt base (relocated in later)
252
253real_magic: .quad 0
254video_mode: .quad 0
255realmode_flags: .quad 0
256
257.code16
258bogus_real_magic:
259 movb $0xba,%al ; outb %al,$0x80
260 jmp bogus_real_magic
261
262.code64
263bogus_64_magic:
264 movb $0xb3,%al ; outb %al,$0x80
265 jmp bogus_64_magic
266
267.code16
268no_longmode:
269 movb $0xbc,%al ; outb %al,$0x80
270 jmp no_longmode
271
272#include "../verify_cpu.S"
273
274/* This code uses an extended set of video mode numbers. These include:
275 * Aliases for standard modes
276 * NORMAL_VGA (-1)
277 * EXTENDED_VGA (-2)
278 * ASK_VGA (-3)
279 * Video modes numbered by menu position -- NOT RECOMMENDED because of lack
280 * of compatibility when extending the table. These are between 0x00 and 0xff.
281 */
282#define VIDEO_FIRST_MENU 0x0000
283
284/* Standard BIOS video modes (BIOS number + 0x0100) */
285#define VIDEO_FIRST_BIOS 0x0100
286
287/* VESA BIOS video modes (VESA number + 0x0200) */
288#define VIDEO_FIRST_VESA 0x0200
289
290/* Video7 special modes (BIOS number + 0x0900) */
291#define VIDEO_FIRST_V7 0x0900
292
293# Setting of user mode (AX=mode ID) => CF=success
294
295# For now, we only handle VESA modes (0x0200..0x03ff). To handle other
296# modes, we should probably compile in the video code from the boot
297# directory.
298.code16
299mode_set:
300 movw %ax, %bx
301 subb $VIDEO_FIRST_VESA>>8, %bh
302 cmpb $2, %bh
303 jb check_vesa
304
305setbad:
306 clc
307 ret
308
309check_vesa:
310 orw $0x4000, %bx # Use linear frame buffer
311 movw $0x4f02, %ax # VESA BIOS mode set call
312 int $0x10
313 cmpw $0x004f, %ax # AL=4f if implemented
314 jnz setbad # AH=0 if OK
315
316 stc
317 ret
318
319wakeup_stack_begin: # Stack grows down
320
321.org 0xff0
322wakeup_stack: # Just below end of page
323
324.org 0x1000
325ENTRY(wakeup_level4_pgt)
326 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
327 .fill 510,8,0
328 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
329 .quad level3_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
330
331ENTRY(wakeup_end)
332
333##
334# acpi_copy_wakeup_routine
335#
336# Copy the above routine to low memory.
337#
338# Parameters:
339# %rdi: place to copy wakeup routine to
340#
341# Returned address is location of code in low memory (past data and stack)
342#
343 .code64
344ENTRY(acpi_copy_wakeup_routine)
345 pushq %rax
346 pushq %rdx
347
348 movl saved_video_mode, %edx
349 movl %edx, video_mode - wakeup_start (,%rdi)
350 movl acpi_realmode_flags, %edx
351 movl %edx, realmode_flags - wakeup_start (,%rdi)
352 movq $0x12345678, real_magic - wakeup_start (,%rdi)
353 movq $0x123456789abcdef0, %rdx
354 movq %rdx, saved_magic
355
356 movq saved_magic, %rax
357 movq $0x123456789abcdef0, %rdx
358 cmpq %rdx, %rax
359 jne bogus_64_magic
360
361 # restore the regs we used
362 popq %rdx
363 popq %rax
364ENTRY(do_suspend_lowlevel_s4bios)
365 ret
366
367 .align 2
368 .p2align 4,,15
369.globl do_suspend_lowlevel
370 .type do_suspend_lowlevel,@function
371do_suspend_lowlevel:
372.LFB5:
373 subq $8, %rsp
374 xorl %eax, %eax
375 call save_processor_state
376
377 movq %rsp, saved_context_esp(%rip)
378 movq %rax, saved_context_eax(%rip)
379 movq %rbx, saved_context_ebx(%rip)
380 movq %rcx, saved_context_ecx(%rip)
381 movq %rdx, saved_context_edx(%rip)
382 movq %rbp, saved_context_ebp(%rip)
383 movq %rsi, saved_context_esi(%rip)
384 movq %rdi, saved_context_edi(%rip)
385 movq %r8, saved_context_r08(%rip)
386 movq %r9, saved_context_r09(%rip)
387 movq %r10, saved_context_r10(%rip)
388 movq %r11, saved_context_r11(%rip)
389 movq %r12, saved_context_r12(%rip)
390 movq %r13, saved_context_r13(%rip)
391 movq %r14, saved_context_r14(%rip)
392 movq %r15, saved_context_r15(%rip)
393 pushfq ; popq saved_context_eflags(%rip)
394
395 movq $.L97, saved_rip(%rip)
396
397 movq %rsp,saved_rsp
398 movq %rbp,saved_rbp
399 movq %rbx,saved_rbx
400 movq %rdi,saved_rdi
401 movq %rsi,saved_rsi
402
403 addq $8, %rsp
404 movl $3, %edi
405 xorl %eax, %eax
406 jmp acpi_enter_sleep_state
407.L97:
408 .p2align 4,,7
409.L99:
410 .align 4
411 movl $24, %eax
412 movw %ax, %ds
413 movq saved_context+58(%rip), %rax
414 movq %rax, %cr4
415 movq saved_context+50(%rip), %rax
416 movq %rax, %cr3
417 movq saved_context+42(%rip), %rax
418 movq %rax, %cr2
419 movq saved_context+34(%rip), %rax
420 movq %rax, %cr0
421 pushq saved_context_eflags(%rip) ; popfq
422 movq saved_context_esp(%rip), %rsp
423 movq saved_context_ebp(%rip), %rbp
424 movq saved_context_eax(%rip), %rax
425 movq saved_context_ebx(%rip), %rbx
426 movq saved_context_ecx(%rip), %rcx
427 movq saved_context_edx(%rip), %rdx
428 movq saved_context_esi(%rip), %rsi
429 movq saved_context_edi(%rip), %rdi
430 movq saved_context_r08(%rip), %r8
431 movq saved_context_r09(%rip), %r9
432 movq saved_context_r10(%rip), %r10
433 movq saved_context_r11(%rip), %r11
434 movq saved_context_r12(%rip), %r12
435 movq saved_context_r13(%rip), %r13
436 movq saved_context_r14(%rip), %r14
437 movq saved_context_r15(%rip), %r15
438
439 xorl %eax, %eax
440 addq $8, %rsp
441 jmp restore_processor_state
442.LFE5:
443.Lfe5:
444 .size do_suspend_lowlevel,.Lfe5-do_suspend_lowlevel
445
446.data
447ALIGN
448ENTRY(saved_rbp) .quad 0
449ENTRY(saved_rsi) .quad 0
450ENTRY(saved_rdi) .quad 0
451ENTRY(saved_rbx) .quad 0
452
453ENTRY(saved_rip) .quad 0
454ENTRY(saved_rsp) .quad 0
455
456ENTRY(saved_magic) .quad 0
diff --git a/arch/x86_64/kernel/cpufreq/Makefile b/arch/x86_64/kernel/cpufreq/Makefile
deleted file mode 100644
index 753ce1dd418e..000000000000
--- a/arch/x86_64/kernel/cpufreq/Makefile
+++ /dev/null
@@ -1,17 +0,0 @@
1#
2# Reuse the i386 cpufreq drivers
3#
4
5SRCDIR := ../../../i386/kernel/cpu/cpufreq
6
7obj-$(CONFIG_X86_POWERNOW_K8) += powernow-k8.o
8obj-$(CONFIG_X86_ACPI_CPUFREQ) += acpi-cpufreq.o
9obj-$(CONFIG_X86_SPEEDSTEP_CENTRINO) += speedstep-centrino.o
10obj-$(CONFIG_X86_P4_CLOCKMOD) += p4-clockmod.o
11obj-$(CONFIG_X86_SPEEDSTEP_LIB) += speedstep-lib.o
12
13powernow-k8-objs := ${SRCDIR}/powernow-k8.o
14speedstep-centrino-objs := ${SRCDIR}/speedstep-centrino.o
15acpi-cpufreq-objs := ${SRCDIR}/acpi-cpufreq.o
16p4-clockmod-objs := ${SRCDIR}/p4-clockmod.o
17speedstep-lib-objs := ${SRCDIR}/speedstep-lib.o
diff --git a/arch/x86_64/kernel/syscall.c b/arch/x86_64/kernel/syscall.c
deleted file mode 100644
index 63d592c276cc..000000000000
--- a/arch/x86_64/kernel/syscall.c
+++ /dev/null
@@ -1,26 +0,0 @@
1/* System call table for x86-64. */
2
3#include <linux/linkage.h>
4#include <linux/sys.h>
5#include <linux/cache.h>
6#include <asm/asm-offsets.h>
7
8#define __NO_STUBS
9
10#define __SYSCALL(nr, sym) extern asmlinkage void sym(void) ;
11#undef _ASM_X86_64_UNISTD_H_
12#include <asm-x86_64/unistd.h>
13
14#undef __SYSCALL
15#define __SYSCALL(nr, sym) [ nr ] = sym,
16#undef _ASM_X86_64_UNISTD_H_
17
18typedef void (*sys_call_ptr_t)(void);
19
20extern void sys_ni_syscall(void);
21
22const sys_call_ptr_t sys_call_table[__NR_syscall_max+1] = {
23 /* Smells like a like a compiler bug -- it doesn't work when the & below is removed. */
24 [0 ... __NR_syscall_max] = &sys_ni_syscall,
25#include <asm-x86_64/unistd.h>
26};
diff --git a/arch/x86_64/kernel/trampoline.S b/arch/x86_64/kernel/trampoline.S
deleted file mode 100644
index e7e2764c461b..000000000000
--- a/arch/x86_64/kernel/trampoline.S
+++ /dev/null
@@ -1,166 +0,0 @@
1/*
2 *
3 * Trampoline.S Derived from Setup.S by Linus Torvalds
4 *
5 * 4 Jan 1997 Michael Chastain: changed to gnu as.
6 * 15 Sept 2005 Eric Biederman: 64bit PIC support
7 *
8 * Entry: CS:IP point to the start of our code, we are
9 * in real mode with no stack, but the rest of the
10 * trampoline page to make our stack and everything else
11 * is a mystery.
12 *
13 * In fact we don't actually need a stack so we don't
14 * set one up.
15 *
16 * On entry to trampoline_data, the processor is in real mode
17 * with 16-bit addressing and 16-bit data. CS has some value
18 * and IP is zero. Thus, data addresses need to be absolute
19 * (no relocation) and are taken with regard to r_base.
20 *
21 * With the addition of trampoline_level4_pgt this code can
22 * now enter a 64bit kernel that lives at arbitrary 64bit
23 * physical addresses.
24 *
25 * If you work on this file, check the object module with objdump
26 * --full-contents --reloc to make sure there are no relocation
27 * entries.
28 */
29
30#include <linux/linkage.h>
31#include <asm/pgtable.h>
32#include <asm/page.h>
33#include <asm/msr.h>
34#include <asm/segment.h>
35
36.data
37
38.code16
39
40ENTRY(trampoline_data)
41r_base = .
42 cli # We should be safe anyway
43 wbinvd
44 mov %cs, %ax # Code and data in the same place
45 mov %ax, %ds
46 mov %ax, %es
47 mov %ax, %ss
48
49
50 movl $0xA5A5A5A5, trampoline_data - r_base
51 # write marker for master knows we're running
52
53 # Setup stack
54 movw $(trampoline_stack_end - r_base), %sp
55
56 call verify_cpu # Verify the cpu supports long mode
57 testl %eax, %eax # Check for return code
58 jnz no_longmode
59
60 mov %cs, %ax
61 movzx %ax, %esi # Find the 32bit trampoline location
62 shll $4, %esi
63
64 # Fixup the vectors
65 addl %esi, startup_32_vector - r_base
66 addl %esi, startup_64_vector - r_base
67 addl %esi, tgdt + 2 - r_base # Fixup the gdt pointer
68
69 /*
70 * GDT tables in non default location kernel can be beyond 16MB and
71 * lgdt will not be able to load the address as in real mode default
72 * operand size is 16bit. Use lgdtl instead to force operand size
73 * to 32 bit.
74 */
75
76 lidtl tidt - r_base # load idt with 0, 0
77 lgdtl tgdt - r_base # load gdt with whatever is appropriate
78
79 xor %ax, %ax
80 inc %ax # protected mode (PE) bit
81 lmsw %ax # into protected mode
82
83 # flush prefetch and jump to startup_32
84 ljmpl *(startup_32_vector - r_base)
85
86 .code32
87 .balign 4
88startup_32:
89 movl $__KERNEL_DS, %eax # Initialize the %ds segment register
90 movl %eax, %ds
91
92 xorl %eax, %eax
93 btsl $5, %eax # Enable PAE mode
94 movl %eax, %cr4
95
96 # Setup trampoline 4 level pagetables
97 leal (trampoline_level4_pgt - r_base)(%esi), %eax
98 movl %eax, %cr3
99
100 movl $MSR_EFER, %ecx
101 movl $(1 << _EFER_LME), %eax # Enable Long Mode
102 xorl %edx, %edx
103 wrmsr
104
105 xorl %eax, %eax
106 btsl $31, %eax # Enable paging and in turn activate Long Mode
107 btsl $0, %eax # Enable protected mode
108 movl %eax, %cr0
109
110 /*
111 * At this point we're in long mode but in 32bit compatibility mode
112 * with EFER.LME = 1, CS.L = 0, CS.D = 1 (and in turn
113 * EFER.LMA = 1). Now we want to jump in 64bit mode, to do that we use
114 * the new gdt/idt that has __KERNEL_CS with CS.L = 1.
115 */
116 ljmp *(startup_64_vector - r_base)(%esi)
117
118 .code64
119 .balign 4
120startup_64:
121 # Now jump into the kernel using virtual addresses
122 movq $secondary_startup_64, %rax
123 jmp *%rax
124
125 .code16
126no_longmode:
127 hlt
128 jmp no_longmode
129#include "verify_cpu.S"
130
131 # Careful these need to be in the same 64K segment as the above;
132tidt:
133 .word 0 # idt limit = 0
134 .word 0, 0 # idt base = 0L
135
136 # Duplicate the global descriptor table
137 # so the kernel can live anywhere
138 .balign 4
139tgdt:
140 .short tgdt_end - tgdt # gdt limit
141 .long tgdt - r_base
142 .short 0
143 .quad 0x00cf9b000000ffff # __KERNEL32_CS
144 .quad 0x00af9b000000ffff # __KERNEL_CS
145 .quad 0x00cf93000000ffff # __KERNEL_DS
146tgdt_end:
147
148 .balign 4
149startup_32_vector:
150 .long startup_32 - r_base
151 .word __KERNEL32_CS, 0
152
153 .balign 4
154startup_64_vector:
155 .long startup_64 - r_base
156 .word __KERNEL_CS, 0
157
158trampoline_stack:
159 .org 0x1000
160trampoline_stack_end:
161ENTRY(trampoline_level4_pgt)
162 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
163 .fill 510,8,0
164 .quad level3_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
165
166ENTRY(trampoline_end)
diff --git a/arch/x86_64/lib/Makefile b/arch/x86_64/lib/Makefile
deleted file mode 100644
index c94327178398..000000000000
--- a/arch/x86_64/lib/Makefile
+++ /dev/null
@@ -1,13 +0,0 @@
1#
2# Makefile for x86_64-specific library files.
3#
4
5CFLAGS_csum-partial.o := -funroll-loops
6
7obj-y := io.o iomap_copy.o
8obj-$(CONFIG_SMP) += msr-on-cpu.o
9
10lib-y := csum-partial.o csum-copy.o csum-wrappers.o delay.o \
11 usercopy.o getuser.o putuser.o \
12 thunk.o clear_page.o copy_page.o bitstr.o bitops.o
13lib-y += memcpy.o memmove.o memset.o copy_user.o rwlock.o copy_user_nocache.o
diff --git a/arch/x86_64/lib/msr-on-cpu.c b/arch/x86_64/lib/msr-on-cpu.c
deleted file mode 100644
index 47e0ec47c376..000000000000
--- a/arch/x86_64/lib/msr-on-cpu.c
+++ /dev/null
@@ -1 +0,0 @@
1#include "../../i386/lib/msr-on-cpu.c"
diff --git a/arch/x86_64/mm/Makefile b/arch/x86_64/mm/Makefile
deleted file mode 100644
index d25ac86fe27a..000000000000
--- a/arch/x86_64/mm/Makefile
+++ /dev/null
@@ -1,11 +0,0 @@
1#
2# Makefile for the linux x86_64-specific parts of the memory manager.
3#
4
5obj-y := init.o fault.o ioremap.o extable.o pageattr.o mmap.o
6obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o
7obj-$(CONFIG_NUMA) += numa.o
8obj-$(CONFIG_K8_NUMA) += k8topology.o
9obj-$(CONFIG_ACPI_NUMA) += srat.o
10
11hugetlbpage-y = ../../i386/mm/hugetlbpage.o
diff --git a/arch/x86_64/oprofile/Kconfig b/arch/x86_64/oprofile/Kconfig
deleted file mode 100644
index d8a84088471a..000000000000
--- a/arch/x86_64/oprofile/Kconfig
+++ /dev/null
@@ -1,17 +0,0 @@
1config PROFILING
2 bool "Profiling support (EXPERIMENTAL)"
3 help
4 Say Y here to enable the extended profiling support mechanisms used
5 by profilers such as OProfile.
6
7
8config OPROFILE
9 tristate "OProfile system profiling (EXPERIMENTAL)"
10 depends on PROFILING
11 help
12 OProfile is a profiling system capable of profiling the
13 whole system, include the kernel, kernel modules, libraries,
14 and applications.
15
16 If unsure, say N.
17
diff --git a/arch/x86_64/oprofile/Makefile b/arch/x86_64/oprofile/Makefile
deleted file mode 100644
index 6be32683e1bc..000000000000
--- a/arch/x86_64/oprofile/Makefile
+++ /dev/null
@@ -1,19 +0,0 @@
1#
2# oprofile for x86-64.
3# Just reuse the one from i386.
4#
5
6obj-$(CONFIG_OPROFILE) += oprofile.o
7
8DRIVER_OBJS = $(addprefix ../../../drivers/oprofile/, \
9 oprof.o cpu_buffer.o buffer_sync.o \
10 event_buffer.o oprofile_files.o \
11 oprofilefs.o oprofile_stats.o \
12 timer_int.o )
13
14OPROFILE-y := init.o backtrace.o
15OPROFILE-$(CONFIG_X86_LOCAL_APIC) += nmi_int.o op_model_athlon.o op_model_p4.o \
16 op_model_ppro.o
17OPROFILE-$(CONFIG_X86_IO_APIC) += nmi_timer_int.o
18
19oprofile-y = $(DRIVER_OBJS) $(addprefix ../../i386/oprofile/, $(OPROFILE-y))
diff --git a/arch/x86_64/pci/Makefile b/arch/x86_64/pci/Makefile
deleted file mode 100644
index c9eddc8859c0..000000000000
--- a/arch/x86_64/pci/Makefile
+++ /dev/null
@@ -1,27 +0,0 @@
1#
2# Makefile for X86_64 specific PCI routines
3#
4# Reuse the i386 PCI subsystem
5#
6EXTRA_CFLAGS += -Iarch/i386/pci
7
8obj-y := i386.o
9obj-$(CONFIG_PCI_DIRECT)+= direct.o
10obj-y += fixup.o init.o
11obj-$(CONFIG_ACPI) += acpi.o
12obj-y += legacy.o irq.o common.o early.o
13# mmconfig has a 64bit special
14obj-$(CONFIG_PCI_MMCONFIG) += mmconfig.o direct.o mmconfig-shared.o
15
16obj-$(CONFIG_NUMA) += k8-bus.o
17
18direct-y += ../../i386/pci/direct.o
19acpi-y += ../../i386/pci/acpi.o
20legacy-y += ../../i386/pci/legacy.o
21irq-y += ../../i386/pci/irq.o
22common-y += ../../i386/pci/common.o
23fixup-y += ../../i386/pci/fixup.o
24i386-y += ../../i386/pci/i386.o
25init-y += ../../i386/pci/init.o
26early-y += ../../i386/pci/early.o
27mmconfig-shared-y += ../../i386/pci/mmconfig-shared.o
diff --git a/arch/x86_64/vdso/vdso.S b/arch/x86_64/vdso/vdso.S
deleted file mode 100644
index 92e80c1972a7..000000000000
--- a/arch/x86_64/vdso/vdso.S
+++ /dev/null
@@ -1,2 +0,0 @@
1 .section ".vdso","a"
2 .incbin "arch/x86_64/vdso/vdso.so"
diff --git a/block/Makefile b/block/Makefile
index 959feeb253be..3cfe7cebaa6a 100644
--- a/block/Makefile
+++ b/block/Makefile
@@ -11,3 +11,4 @@ obj-$(CONFIG_IOSCHED_DEADLINE) += deadline-iosched.o
11obj-$(CONFIG_IOSCHED_CFQ) += cfq-iosched.o 11obj-$(CONFIG_IOSCHED_CFQ) += cfq-iosched.o
12 12
13obj-$(CONFIG_BLK_DEV_IO_TRACE) += blktrace.o 13obj-$(CONFIG_BLK_DEV_IO_TRACE) += blktrace.o
14obj-$(CONFIG_COMPAT) += compat_ioctl.o
diff --git a/block/blktrace.c b/block/blktrace.c
index 20fa034ea4a2..775471ef84a5 100644
--- a/block/blktrace.c
+++ b/block/blktrace.c
@@ -312,33 +312,26 @@ static struct rchan_callbacks blk_relay_callbacks = {
312/* 312/*
313 * Setup everything required to start tracing 313 * Setup everything required to start tracing
314 */ 314 */
315static int blk_trace_setup(struct request_queue *q, struct block_device *bdev, 315int do_blk_trace_setup(struct request_queue *q, struct block_device *bdev,
316 char __user *arg) 316 struct blk_user_trace_setup *buts)
317{ 317{
318 struct blk_user_trace_setup buts;
319 struct blk_trace *old_bt, *bt = NULL; 318 struct blk_trace *old_bt, *bt = NULL;
320 struct dentry *dir = NULL; 319 struct dentry *dir = NULL;
321 char b[BDEVNAME_SIZE]; 320 char b[BDEVNAME_SIZE];
322 int ret, i; 321 int ret, i;
323 322
324 if (copy_from_user(&buts, arg, sizeof(buts))) 323 if (!buts->buf_size || !buts->buf_nr)
325 return -EFAULT;
326
327 if (!buts.buf_size || !buts.buf_nr)
328 return -EINVAL; 324 return -EINVAL;
329 325
330 strcpy(buts.name, bdevname(bdev, b)); 326 strcpy(buts->name, bdevname(bdev, b));
331 327
332 /* 328 /*
333 * some device names have larger paths - convert the slashes 329 * some device names have larger paths - convert the slashes
334 * to underscores for this to work as expected 330 * to underscores for this to work as expected
335 */ 331 */
336 for (i = 0; i < strlen(buts.name); i++) 332 for (i = 0; i < strlen(buts->name); i++)
337 if (buts.name[i] == '/') 333 if (buts->name[i] == '/')
338 buts.name[i] = '_'; 334 buts->name[i] = '_';
339
340 if (copy_to_user(arg, &buts, sizeof(buts)))
341 return -EFAULT;
342 335
343 ret = -ENOMEM; 336 ret = -ENOMEM;
344 bt = kzalloc(sizeof(*bt), GFP_KERNEL); 337 bt = kzalloc(sizeof(*bt), GFP_KERNEL);
@@ -350,7 +343,7 @@ static int blk_trace_setup(struct request_queue *q, struct block_device *bdev,
350 goto err; 343 goto err;
351 344
352 ret = -ENOENT; 345 ret = -ENOENT;
353 dir = blk_create_tree(buts.name); 346 dir = blk_create_tree(buts->name);
354 if (!dir) 347 if (!dir)
355 goto err; 348 goto err;
356 349
@@ -363,20 +356,21 @@ static int blk_trace_setup(struct request_queue *q, struct block_device *bdev,
363 if (!bt->dropped_file) 356 if (!bt->dropped_file)
364 goto err; 357 goto err;
365 358
366 bt->rchan = relay_open("trace", dir, buts.buf_size, buts.buf_nr, &blk_relay_callbacks, bt); 359 bt->rchan = relay_open("trace", dir, buts->buf_size,
360 buts->buf_nr, &blk_relay_callbacks, bt);
367 if (!bt->rchan) 361 if (!bt->rchan)
368 goto err; 362 goto err;
369 363
370 bt->act_mask = buts.act_mask; 364 bt->act_mask = buts->act_mask;
371 if (!bt->act_mask) 365 if (!bt->act_mask)
372 bt->act_mask = (u16) -1; 366 bt->act_mask = (u16) -1;
373 367
374 bt->start_lba = buts.start_lba; 368 bt->start_lba = buts->start_lba;
375 bt->end_lba = buts.end_lba; 369 bt->end_lba = buts->end_lba;
376 if (!bt->end_lba) 370 if (!bt->end_lba)
377 bt->end_lba = -1ULL; 371 bt->end_lba = -1ULL;
378 372
379 bt->pid = buts.pid; 373 bt->pid = buts->pid;
380 bt->trace_state = Blktrace_setup; 374 bt->trace_state = Blktrace_setup;
381 375
382 ret = -EBUSY; 376 ret = -EBUSY;
@@ -401,6 +395,26 @@ err:
401 return ret; 395 return ret;
402} 396}
403 397
398static int blk_trace_setup(struct request_queue *q, struct block_device *bdev,
399 char __user *arg)
400{
401 struct blk_user_trace_setup buts;
402 int ret;
403
404 ret = copy_from_user(&buts, arg, sizeof(buts));
405 if (ret)
406 return -EFAULT;
407
408 ret = do_blk_trace_setup(q, bdev, &buts);
409 if (ret)
410 return ret;
411
412 if (copy_to_user(arg, &buts, sizeof(buts)))
413 return -EFAULT;
414
415 return 0;
416}
417
404static int blk_trace_startstop(struct request_queue *q, int start) 418static int blk_trace_startstop(struct request_queue *q, int start)
405{ 419{
406 struct blk_trace *bt; 420 struct blk_trace *bt;
diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
new file mode 100644
index 000000000000..f84093b97f70
--- /dev/null
+++ b/block/compat_ioctl.c
@@ -0,0 +1,814 @@
1#include <linux/blkdev.h>
2#include <linux/blkpg.h>
3#include <linux/blktrace_api.h>
4#include <linux/cdrom.h>
5#include <linux/compat.h>
6#include <linux/elevator.h>
7#include <linux/fd.h>
8#include <linux/hdreg.h>
9#include <linux/syscalls.h>
10#include <linux/smp_lock.h>
11#include <linux/types.h>
12#include <linux/uaccess.h>
13
14static int compat_put_ushort(unsigned long arg, unsigned short val)
15{
16 return put_user(val, (unsigned short __user *)compat_ptr(arg));
17}
18
19static int compat_put_int(unsigned long arg, int val)
20{
21 return put_user(val, (compat_int_t __user *)compat_ptr(arg));
22}
23
24static int compat_put_long(unsigned long arg, long val)
25{
26 return put_user(val, (compat_long_t __user *)compat_ptr(arg));
27}
28
29static int compat_put_ulong(unsigned long arg, compat_ulong_t val)
30{
31 return put_user(val, (compat_ulong_t __user *)compat_ptr(arg));
32}
33
34static int compat_put_u64(unsigned long arg, u64 val)
35{
36 return put_user(val, (compat_u64 __user *)compat_ptr(arg));
37}
38
39struct compat_hd_geometry {
40 unsigned char heads;
41 unsigned char sectors;
42 unsigned short cylinders;
43 u32 start;
44};
45
46static int compat_hdio_getgeo(struct gendisk *disk, struct block_device *bdev,
47 struct compat_hd_geometry __user *ugeo)
48{
49 struct hd_geometry geo;
50 int ret;
51
52 if (!ugeo)
53 return -EINVAL;
54 if (!disk->fops->getgeo)
55 return -ENOTTY;
56
57 /*
58 * We need to set the startsect first, the driver may
59 * want to override it.
60 */
61 geo.start = get_start_sect(bdev);
62 ret = disk->fops->getgeo(bdev, &geo);
63 if (ret)
64 return ret;
65
66 ret = copy_to_user(ugeo, &geo, 4);
67 ret |= __put_user(geo.start, &ugeo->start);
68 if (ret)
69 ret = -EFAULT;
70
71 return ret;
72}
73
74static int compat_hdio_ioctl(struct inode *inode, struct file *file,
75 struct gendisk *disk, unsigned int cmd, unsigned long arg)
76{
77 mm_segment_t old_fs = get_fs();
78 unsigned long kval;
79 unsigned int __user *uvp;
80 int error;
81
82 set_fs(KERNEL_DS);
83 error = blkdev_driver_ioctl(inode, file, disk,
84 cmd, (unsigned long)(&kval));
85 set_fs(old_fs);
86
87 if (error == 0) {
88 uvp = compat_ptr(arg);
89 if (put_user(kval, uvp))
90 error = -EFAULT;
91 }
92 return error;
93}
94
95struct compat_cdrom_read_audio {
96 union cdrom_addr addr;
97 u8 addr_format;
98 compat_int_t nframes;
99 compat_caddr_t buf;
100};
101
102struct compat_cdrom_generic_command {
103 unsigned char cmd[CDROM_PACKET_SIZE];
104 compat_caddr_t buffer;
105 compat_uint_t buflen;
106 compat_int_t stat;
107 compat_caddr_t sense;
108 unsigned char data_direction;
109 compat_int_t quiet;
110 compat_int_t timeout;
111 compat_caddr_t reserved[1];
112};
113
114static int compat_cdrom_read_audio(struct inode *inode, struct file *file,
115 struct gendisk *disk, unsigned int cmd, unsigned long arg)
116{
117 struct cdrom_read_audio __user *cdread_audio;
118 struct compat_cdrom_read_audio __user *cdread_audio32;
119 __u32 data;
120 void __user *datap;
121
122 cdread_audio = compat_alloc_user_space(sizeof(*cdread_audio));
123 cdread_audio32 = compat_ptr(arg);
124
125 if (copy_in_user(&cdread_audio->addr,
126 &cdread_audio32->addr,
127 (sizeof(*cdread_audio32) -
128 sizeof(compat_caddr_t))))
129 return -EFAULT;
130
131 if (get_user(data, &cdread_audio32->buf))
132 return -EFAULT;
133 datap = compat_ptr(data);
134 if (put_user(datap, &cdread_audio->buf))
135 return -EFAULT;
136
137 return blkdev_driver_ioctl(inode, file, disk, cmd,
138 (unsigned long)cdread_audio);
139}
140
141static int compat_cdrom_generic_command(struct inode *inode, struct file *file,
142 struct gendisk *disk, unsigned int cmd, unsigned long arg)
143{
144 struct cdrom_generic_command __user *cgc;
145 struct compat_cdrom_generic_command __user *cgc32;
146 u32 data;
147 unsigned char dir;
148 int itmp;
149
150 cgc = compat_alloc_user_space(sizeof(*cgc));
151 cgc32 = compat_ptr(arg);
152
153 if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
154 get_user(data, &cgc32->buffer) ||
155 put_user(compat_ptr(data), &cgc->buffer) ||
156 copy_in_user(&cgc->buflen, &cgc32->buflen,
157 (sizeof(unsigned int) + sizeof(int))) ||
158 get_user(data, &cgc32->sense) ||
159 put_user(compat_ptr(data), &cgc->sense) ||
160 get_user(dir, &cgc32->data_direction) ||
161 put_user(dir, &cgc->data_direction) ||
162 get_user(itmp, &cgc32->quiet) ||
163 put_user(itmp, &cgc->quiet) ||
164 get_user(itmp, &cgc32->timeout) ||
165 put_user(itmp, &cgc->timeout) ||
166 get_user(data, &cgc32->reserved[0]) ||
167 put_user(compat_ptr(data), &cgc->reserved[0]))
168 return -EFAULT;
169
170 return blkdev_driver_ioctl(inode, file, disk, cmd, (unsigned long)cgc);
171}
172
173struct compat_blkpg_ioctl_arg {
174 compat_int_t op;
175 compat_int_t flags;
176 compat_int_t datalen;
177 compat_caddr_t data;
178};
179
180static int compat_blkpg_ioctl(struct inode *inode, struct file *file,
181 unsigned int cmd, struct compat_blkpg_ioctl_arg __user *ua32)
182{
183 struct blkpg_ioctl_arg __user *a = compat_alloc_user_space(sizeof(*a));
184 compat_caddr_t udata;
185 compat_int_t n;
186 int err;
187
188 err = get_user(n, &ua32->op);
189 err |= put_user(n, &a->op);
190 err |= get_user(n, &ua32->flags);
191 err |= put_user(n, &a->flags);
192 err |= get_user(n, &ua32->datalen);
193 err |= put_user(n, &a->datalen);
194 err |= get_user(udata, &ua32->data);
195 err |= put_user(compat_ptr(udata), &a->data);
196 if (err)
197 return err;
198
199 return blkdev_ioctl(inode, file, cmd, (unsigned long)a);
200}
201
202#define BLKBSZGET_32 _IOR(0x12, 112, int)
203#define BLKBSZSET_32 _IOW(0x12, 113, int)
204#define BLKGETSIZE64_32 _IOR(0x12, 114, int)
205
206struct compat_floppy_struct {
207 compat_uint_t size;
208 compat_uint_t sect;
209 compat_uint_t head;
210 compat_uint_t track;
211 compat_uint_t stretch;
212 unsigned char gap;
213 unsigned char rate;
214 unsigned char spec1;
215 unsigned char fmt_gap;
216 const compat_caddr_t name;
217};
218
219struct compat_floppy_drive_params {
220 char cmos;
221 compat_ulong_t max_dtr;
222 compat_ulong_t hlt;
223 compat_ulong_t hut;
224 compat_ulong_t srt;
225 compat_ulong_t spinup;
226 compat_ulong_t spindown;
227 unsigned char spindown_offset;
228 unsigned char select_delay;
229 unsigned char rps;
230 unsigned char tracks;
231 compat_ulong_t timeout;
232 unsigned char interleave_sect;
233 struct floppy_max_errors max_errors;
234 char flags;
235 char read_track;
236 short autodetect[8];
237 compat_int_t checkfreq;
238 compat_int_t native_format;
239};
240
241struct compat_floppy_drive_struct {
242 signed char flags;
243 compat_ulong_t spinup_date;
244 compat_ulong_t select_date;
245 compat_ulong_t first_read_date;
246 short probed_format;
247 short track;
248 short maxblock;
249 short maxtrack;
250 compat_int_t generation;
251 compat_int_t keep_data;
252 compat_int_t fd_ref;
253 compat_int_t fd_device;
254 compat_int_t last_checked;
255 compat_caddr_t dmabuf;
256 compat_int_t bufblocks;
257};
258
259struct compat_floppy_fdc_state {
260 compat_int_t spec1;
261 compat_int_t spec2;
262 compat_int_t dtr;
263 unsigned char version;
264 unsigned char dor;
265 compat_ulong_t address;
266 unsigned int rawcmd:2;
267 unsigned int reset:1;
268 unsigned int need_configure:1;
269 unsigned int perp_mode:2;
270 unsigned int has_fifo:1;
271 unsigned int driver_version;
272 unsigned char track[4];
273};
274
275struct compat_floppy_write_errors {
276 unsigned int write_errors;
277 compat_ulong_t first_error_sector;
278 compat_int_t first_error_generation;
279 compat_ulong_t last_error_sector;
280 compat_int_t last_error_generation;
281 compat_uint_t badness;
282};
283
284#define FDSETPRM32 _IOW(2, 0x42, struct compat_floppy_struct)
285#define FDDEFPRM32 _IOW(2, 0x43, struct compat_floppy_struct)
286#define FDGETPRM32 _IOR(2, 0x04, struct compat_floppy_struct)
287#define FDSETDRVPRM32 _IOW(2, 0x90, struct compat_floppy_drive_params)
288#define FDGETDRVPRM32 _IOR(2, 0x11, struct compat_floppy_drive_params)
289#define FDGETDRVSTAT32 _IOR(2, 0x12, struct compat_floppy_drive_struct)
290#define FDPOLLDRVSTAT32 _IOR(2, 0x13, struct compat_floppy_drive_struct)
291#define FDGETFDCSTAT32 _IOR(2, 0x15, struct compat_floppy_fdc_state)
292#define FDWERRORGET32 _IOR(2, 0x17, struct compat_floppy_write_errors)
293
294static struct {
295 unsigned int cmd32;
296 unsigned int cmd;
297} fd_ioctl_trans_table[] = {
298 { FDSETPRM32, FDSETPRM },
299 { FDDEFPRM32, FDDEFPRM },
300 { FDGETPRM32, FDGETPRM },
301 { FDSETDRVPRM32, FDSETDRVPRM },
302 { FDGETDRVPRM32, FDGETDRVPRM },
303 { FDGETDRVSTAT32, FDGETDRVSTAT },
304 { FDPOLLDRVSTAT32, FDPOLLDRVSTAT },
305 { FDGETFDCSTAT32, FDGETFDCSTAT },
306 { FDWERRORGET32, FDWERRORGET }
307};
308
309#define NR_FD_IOCTL_TRANS ARRAY_SIZE(fd_ioctl_trans_table)
310
311static int compat_fd_ioctl(struct inode *inode, struct file *file,
312 struct gendisk *disk, unsigned int cmd, unsigned long arg)
313{
314 mm_segment_t old_fs = get_fs();
315 void *karg = NULL;
316 unsigned int kcmd = 0;
317 int i, err;
318
319 for (i = 0; i < NR_FD_IOCTL_TRANS; i++)
320 if (cmd == fd_ioctl_trans_table[i].cmd32) {
321 kcmd = fd_ioctl_trans_table[i].cmd;
322 break;
323 }
324 if (!kcmd)
325 return -EINVAL;
326
327 switch (cmd) {
328 case FDSETPRM32:
329 case FDDEFPRM32:
330 case FDGETPRM32:
331 {
332 compat_uptr_t name;
333 struct compat_floppy_struct __user *uf;
334 struct floppy_struct *f;
335
336 uf = compat_ptr(arg);
337 f = karg = kmalloc(sizeof(struct floppy_struct), GFP_KERNEL);
338 if (!karg)
339 return -ENOMEM;
340 if (cmd == FDGETPRM32)
341 break;
342 err = __get_user(f->size, &uf->size);
343 err |= __get_user(f->sect, &uf->sect);
344 err |= __get_user(f->head, &uf->head);
345 err |= __get_user(f->track, &uf->track);
346 err |= __get_user(f->stretch, &uf->stretch);
347 err |= __get_user(f->gap, &uf->gap);
348 err |= __get_user(f->rate, &uf->rate);
349 err |= __get_user(f->spec1, &uf->spec1);
350 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
351 err |= __get_user(name, &uf->name);
352 f->name = compat_ptr(name);
353 if (err) {
354 err = -EFAULT;
355 goto out;
356 }
357 break;
358 }
359 case FDSETDRVPRM32:
360 case FDGETDRVPRM32:
361 {
362 struct compat_floppy_drive_params __user *uf;
363 struct floppy_drive_params *f;
364
365 uf = compat_ptr(arg);
366 f = karg = kmalloc(sizeof(struct floppy_drive_params), GFP_KERNEL);
367 if (!karg)
368 return -ENOMEM;
369 if (cmd == FDGETDRVPRM32)
370 break;
371 err = __get_user(f->cmos, &uf->cmos);
372 err |= __get_user(f->max_dtr, &uf->max_dtr);
373 err |= __get_user(f->hlt, &uf->hlt);
374 err |= __get_user(f->hut, &uf->hut);
375 err |= __get_user(f->srt, &uf->srt);
376 err |= __get_user(f->spinup, &uf->spinup);
377 err |= __get_user(f->spindown, &uf->spindown);
378 err |= __get_user(f->spindown_offset, &uf->spindown_offset);
379 err |= __get_user(f->select_delay, &uf->select_delay);
380 err |= __get_user(f->rps, &uf->rps);
381 err |= __get_user(f->tracks, &uf->tracks);
382 err |= __get_user(f->timeout, &uf->timeout);
383 err |= __get_user(f->interleave_sect, &uf->interleave_sect);
384 err |= __copy_from_user(&f->max_errors, &uf->max_errors, sizeof(f->max_errors));
385 err |= __get_user(f->flags, &uf->flags);
386 err |= __get_user(f->read_track, &uf->read_track);
387 err |= __copy_from_user(f->autodetect, uf->autodetect, sizeof(f->autodetect));
388 err |= __get_user(f->checkfreq, &uf->checkfreq);
389 err |= __get_user(f->native_format, &uf->native_format);
390 if (err) {
391 err = -EFAULT;
392 goto out;
393 }
394 break;
395 }
396 case FDGETDRVSTAT32:
397 case FDPOLLDRVSTAT32:
398 karg = kmalloc(sizeof(struct floppy_drive_struct), GFP_KERNEL);
399 if (!karg)
400 return -ENOMEM;
401 break;
402 case FDGETFDCSTAT32:
403 karg = kmalloc(sizeof(struct floppy_fdc_state), GFP_KERNEL);
404 if (!karg)
405 return -ENOMEM;
406 break;
407 case FDWERRORGET32:
408 karg = kmalloc(sizeof(struct floppy_write_errors), GFP_KERNEL);
409 if (!karg)
410 return -ENOMEM;
411 break;
412 default:
413 return -EINVAL;
414 }
415 set_fs(KERNEL_DS);
416 err = blkdev_driver_ioctl(inode, file, disk, kcmd, (unsigned long)karg);
417 set_fs(old_fs);
418 if (err)
419 goto out;
420 switch (cmd) {
421 case FDGETPRM32:
422 {
423 struct floppy_struct *f = karg;
424 struct compat_floppy_struct __user *uf = compat_ptr(arg);
425
426 err = __put_user(f->size, &uf->size);
427 err |= __put_user(f->sect, &uf->sect);
428 err |= __put_user(f->head, &uf->head);
429 err |= __put_user(f->track, &uf->track);
430 err |= __put_user(f->stretch, &uf->stretch);
431 err |= __put_user(f->gap, &uf->gap);
432 err |= __put_user(f->rate, &uf->rate);
433 err |= __put_user(f->spec1, &uf->spec1);
434 err |= __put_user(f->fmt_gap, &uf->fmt_gap);
435 err |= __put_user((u64)f->name, (compat_caddr_t __user *)&uf->name);
436 break;
437 }
438 case FDGETDRVPRM32:
439 {
440 struct compat_floppy_drive_params __user *uf;
441 struct floppy_drive_params *f = karg;
442
443 uf = compat_ptr(arg);
444 err = __put_user(f->cmos, &uf->cmos);
445 err |= __put_user(f->max_dtr, &uf->max_dtr);
446 err |= __put_user(f->hlt, &uf->hlt);
447 err |= __put_user(f->hut, &uf->hut);
448 err |= __put_user(f->srt, &uf->srt);
449 err |= __put_user(f->spinup, &uf->spinup);
450 err |= __put_user(f->spindown, &uf->spindown);
451 err |= __put_user(f->spindown_offset, &uf->spindown_offset);
452 err |= __put_user(f->select_delay, &uf->select_delay);
453 err |= __put_user(f->rps, &uf->rps);
454 err |= __put_user(f->tracks, &uf->tracks);
455 err |= __put_user(f->timeout, &uf->timeout);
456 err |= __put_user(f->interleave_sect, &uf->interleave_sect);
457 err |= __copy_to_user(&uf->max_errors, &f->max_errors, sizeof(f->max_errors));
458 err |= __put_user(f->flags, &uf->flags);
459 err |= __put_user(f->read_track, &uf->read_track);
460 err |= __copy_to_user(uf->autodetect, f->autodetect, sizeof(f->autodetect));
461 err |= __put_user(f->checkfreq, &uf->checkfreq);
462 err |= __put_user(f->native_format, &uf->native_format);
463 break;
464 }
465 case FDGETDRVSTAT32:
466 case FDPOLLDRVSTAT32:
467 {
468 struct compat_floppy_drive_struct __user *uf;
469 struct floppy_drive_struct *f = karg;
470
471 uf = compat_ptr(arg);
472 err = __put_user(f->flags, &uf->flags);
473 err |= __put_user(f->spinup_date, &uf->spinup_date);
474 err |= __put_user(f->select_date, &uf->select_date);
475 err |= __put_user(f->first_read_date, &uf->first_read_date);
476 err |= __put_user(f->probed_format, &uf->probed_format);
477 err |= __put_user(f->track, &uf->track);
478 err |= __put_user(f->maxblock, &uf->maxblock);
479 err |= __put_user(f->maxtrack, &uf->maxtrack);
480 err |= __put_user(f->generation, &uf->generation);
481 err |= __put_user(f->keep_data, &uf->keep_data);
482 err |= __put_user(f->fd_ref, &uf->fd_ref);
483 err |= __put_user(f->fd_device, &uf->fd_device);
484 err |= __put_user(f->last_checked, &uf->last_checked);
485 err |= __put_user((u64)f->dmabuf, &uf->dmabuf);
486 err |= __put_user((u64)f->bufblocks, &uf->bufblocks);
487 break;
488 }
489 case FDGETFDCSTAT32:
490 {
491 struct compat_floppy_fdc_state __user *uf;
492 struct floppy_fdc_state *f = karg;
493
494 uf = compat_ptr(arg);
495 err = __put_user(f->spec1, &uf->spec1);
496 err |= __put_user(f->spec2, &uf->spec2);
497 err |= __put_user(f->dtr, &uf->dtr);
498 err |= __put_user(f->version, &uf->version);
499 err |= __put_user(f->dor, &uf->dor);
500 err |= __put_user(f->address, &uf->address);
501 err |= __copy_to_user((char __user *)&uf->address + sizeof(uf->address),
502 (char *)&f->address + sizeof(f->address), sizeof(int));
503 err |= __put_user(f->driver_version, &uf->driver_version);
504 err |= __copy_to_user(uf->track, f->track, sizeof(f->track));
505 break;
506 }
507 case FDWERRORGET32:
508 {
509 struct compat_floppy_write_errors __user *uf;
510 struct floppy_write_errors *f = karg;
511
512 uf = compat_ptr(arg);
513 err = __put_user(f->write_errors, &uf->write_errors);
514 err |= __put_user(f->first_error_sector, &uf->first_error_sector);
515 err |= __put_user(f->first_error_generation, &uf->first_error_generation);
516 err |= __put_user(f->last_error_sector, &uf->last_error_sector);
517 err |= __put_user(f->last_error_generation, &uf->last_error_generation);
518 err |= __put_user(f->badness, &uf->badness);
519 break;
520 }
521 default:
522 break;
523 }
524 if (err)
525 err = -EFAULT;
526
527out:
528 kfree(karg);
529 return err;
530}
531
532struct compat_blk_user_trace_setup {
533 char name[32];
534 u16 act_mask;
535 u32 buf_size;
536 u32 buf_nr;
537 compat_u64 start_lba;
538 compat_u64 end_lba;
539 u32 pid;
540};
541#define BLKTRACESETUP32 _IOWR(0x12, 115, struct compat_blk_user_trace_setup)
542
543static int compat_blk_trace_setup(struct block_device *bdev, char __user *arg)
544{
545 struct blk_user_trace_setup buts;
546 struct compat_blk_user_trace_setup cbuts;
547 struct request_queue *q;
548 int ret;
549
550 q = bdev_get_queue(bdev);
551 if (!q)
552 return -ENXIO;
553
554 if (copy_from_user(&cbuts, arg, sizeof(cbuts)))
555 return -EFAULT;
556
557 buts = (struct blk_user_trace_setup) {
558 .act_mask = cbuts.act_mask,
559 .buf_size = cbuts.buf_size,
560 .buf_nr = cbuts.buf_nr,
561 .start_lba = cbuts.start_lba,
562 .end_lba = cbuts.end_lba,
563 .pid = cbuts.pid,
564 };
565 memcpy(&buts.name, &cbuts.name, 32);
566
567 mutex_lock(&bdev->bd_mutex);
568 ret = do_blk_trace_setup(q, bdev, &buts);
569 mutex_unlock(&bdev->bd_mutex);
570 if (ret)
571 return ret;
572
573 if (copy_to_user(arg, &buts.name, 32))
574 return -EFAULT;
575
576 return 0;
577}
578
579static int compat_blkdev_driver_ioctl(struct inode *inode, struct file *file,
580 struct gendisk *disk, unsigned cmd, unsigned long arg)
581{
582 int ret;
583
584 switch (arg) {
585 case HDIO_GET_UNMASKINTR:
586 case HDIO_GET_MULTCOUNT:
587 case HDIO_GET_KEEPSETTINGS:
588 case HDIO_GET_32BIT:
589 case HDIO_GET_NOWERR:
590 case HDIO_GET_DMA:
591 case HDIO_GET_NICE:
592 case HDIO_GET_WCACHE:
593 case HDIO_GET_ACOUSTIC:
594 case HDIO_GET_ADDRESS:
595 case HDIO_GET_BUSSTATE:
596 return compat_hdio_ioctl(inode, file, disk, cmd, arg);
597 case FDSETPRM32:
598 case FDDEFPRM32:
599 case FDGETPRM32:
600 case FDSETDRVPRM32:
601 case FDGETDRVPRM32:
602 case FDGETDRVSTAT32:
603 case FDPOLLDRVSTAT32:
604 case FDGETFDCSTAT32:
605 case FDWERRORGET32:
606 return compat_fd_ioctl(inode, file, disk, cmd, arg);
607 case CDROMREADAUDIO:
608 return compat_cdrom_read_audio(inode, file, disk, cmd, arg);
609 case CDROM_SEND_PACKET:
610 return compat_cdrom_generic_command(inode, file, disk, cmd, arg);
611
612 /*
613 * No handler required for the ones below, we just need to
614 * convert arg to a 64 bit pointer.
615 */
616 case BLKSECTSET:
617 /*
618 * 0x03 -- HD/IDE ioctl's used by hdparm and friends.
619 * Some need translations, these do not.
620 */
621 case HDIO_GET_IDENTITY:
622 case HDIO_DRIVE_TASK:
623 case HDIO_DRIVE_CMD:
624 case HDIO_SCAN_HWIF:
625 /* 0x330 is reserved -- it used to be HDIO_GETGEO_BIG */
626 case 0x330:
627 /* 0x02 -- Floppy ioctls */
628 case FDMSGON:
629 case FDMSGOFF:
630 case FDSETEMSGTRESH:
631 case FDFLUSH:
632 case FDWERRORCLR:
633 case FDSETMAXERRS:
634 case FDGETMAXERRS:
635 case FDGETDRVTYP:
636 case FDEJECT:
637 case FDCLRPRM:
638 case FDFMTBEG:
639 case FDFMTEND:
640 case FDRESET:
641 case FDTWADDLE:
642 case FDFMTTRK:
643 case FDRAWCMD:
644 /* CDROM stuff */
645 case CDROMPAUSE:
646 case CDROMRESUME:
647 case CDROMPLAYMSF:
648 case CDROMPLAYTRKIND:
649 case CDROMREADTOCHDR:
650 case CDROMREADTOCENTRY:
651 case CDROMSTOP:
652 case CDROMSTART:
653 case CDROMEJECT:
654 case CDROMVOLCTRL:
655 case CDROMSUBCHNL:
656 case CDROMMULTISESSION:
657 case CDROM_GET_MCN:
658 case CDROMRESET:
659 case CDROMVOLREAD:
660 case CDROMSEEK:
661 case CDROMPLAYBLK:
662 case CDROMCLOSETRAY:
663 case CDROM_DISC_STATUS:
664 case CDROM_CHANGER_NSLOTS:
665 case CDROM_GET_CAPABILITY:
666 /* Ignore cdrom.h about these next 5 ioctls, they absolutely do
667 * not take a struct cdrom_read, instead they take a struct cdrom_msf
668 * which is compatible.
669 */
670 case CDROMREADMODE2:
671 case CDROMREADMODE1:
672 case CDROMREADRAW:
673 case CDROMREADCOOKED:
674 case CDROMREADALL:
675 /* DVD ioctls */
676 case DVD_READ_STRUCT:
677 case DVD_WRITE_STRUCT:
678 case DVD_AUTH:
679 arg = (unsigned long)compat_ptr(arg);
680 /* These intepret arg as an unsigned long, not as a pointer,
681 * so we must not do compat_ptr() conversion. */
682 case HDIO_SET_MULTCOUNT:
683 case HDIO_SET_UNMASKINTR:
684 case HDIO_SET_KEEPSETTINGS:
685 case HDIO_SET_32BIT:
686 case HDIO_SET_NOWERR:
687 case HDIO_SET_DMA:
688 case HDIO_SET_PIO_MODE:
689 case HDIO_SET_NICE:
690 case HDIO_SET_WCACHE:
691 case HDIO_SET_ACOUSTIC:
692 case HDIO_SET_BUSSTATE:
693 case HDIO_SET_ADDRESS:
694 case CDROMEJECT_SW:
695 case CDROM_SET_OPTIONS:
696 case CDROM_CLEAR_OPTIONS:
697 case CDROM_SELECT_SPEED:
698 case CDROM_SELECT_DISC:
699 case CDROM_MEDIA_CHANGED:
700 case CDROM_DRIVE_STATUS:
701 case CDROM_LOCKDOOR:
702 case CDROM_DEBUG:
703 break;
704 default:
705 /* unknown ioctl number */
706 return -ENOIOCTLCMD;
707 }
708
709 if (disk->fops->unlocked_ioctl)
710 return disk->fops->unlocked_ioctl(file, cmd, arg);
711
712 if (disk->fops->ioctl) {
713 lock_kernel();
714 ret = disk->fops->ioctl(inode, file, cmd, arg);
715 unlock_kernel();
716 return ret;
717 }
718
719 return -ENOTTY;
720}
721
722static int compat_blkdev_locked_ioctl(struct inode *inode, struct file *file,
723 struct block_device *bdev,
724 unsigned cmd, unsigned long arg)
725{
726 struct backing_dev_info *bdi;
727
728 switch (cmd) {
729 case BLKRAGET:
730 case BLKFRAGET:
731 if (!arg)
732 return -EINVAL;
733 bdi = blk_get_backing_dev_info(bdev);
734 if (bdi == NULL)
735 return -ENOTTY;
736 return compat_put_long(arg,
737 (bdi->ra_pages * PAGE_CACHE_SIZE) / 512);
738 case BLKROGET: /* compatible */
739 return compat_put_int(arg, bdev_read_only(bdev) != 0);
740 case BLKBSZGET_32: /* get the logical block size (cf. BLKSSZGET) */
741 return compat_put_int(arg, block_size(bdev));
742 case BLKSSZGET: /* get block device hardware sector size */
743 return compat_put_int(arg, bdev_hardsect_size(bdev));
744 case BLKSECTGET:
745 return compat_put_ushort(arg,
746 bdev_get_queue(bdev)->max_sectors);
747 case BLKRASET: /* compatible, but no compat_ptr (!) */
748 case BLKFRASET:
749 if (!capable(CAP_SYS_ADMIN))
750 return -EACCES;
751 bdi = blk_get_backing_dev_info(bdev);
752 if (bdi == NULL)
753 return -ENOTTY;
754 bdi->ra_pages = (arg * 512) / PAGE_CACHE_SIZE;
755 return 0;
756 case BLKGETSIZE:
757 if ((bdev->bd_inode->i_size >> 9) > ~0UL)
758 return -EFBIG;
759 return compat_put_ulong(arg, bdev->bd_inode->i_size >> 9);
760
761 case BLKGETSIZE64_32:
762 return compat_put_u64(arg, bdev->bd_inode->i_size);
763
764 case BLKTRACESETUP32:
765 return compat_blk_trace_setup(bdev, compat_ptr(arg));
766 case BLKTRACESTART: /* compatible */
767 case BLKTRACESTOP: /* compatible */
768 case BLKTRACETEARDOWN: /* compatible */
769 return blk_trace_ioctl(bdev, cmd, compat_ptr(arg));
770 }
771 return -ENOIOCTLCMD;
772}
773
774/* Most of the generic ioctls are handled in the normal fallback path.
775 This assumes the blkdev's low level compat_ioctl always returns
776 ENOIOCTLCMD for unknown ioctls. */
777long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
778{
779 int ret = -ENOIOCTLCMD;
780 struct inode *inode = file->f_mapping->host;
781 struct block_device *bdev = inode->i_bdev;
782 struct gendisk *disk = bdev->bd_disk;
783
784 switch (cmd) {
785 case HDIO_GETGEO:
786 return compat_hdio_getgeo(disk, bdev, compat_ptr(arg));
787 case BLKFLSBUF:
788 case BLKROSET:
789 /*
790 * the ones below are implemented in blkdev_locked_ioctl,
791 * but we call blkdev_ioctl, which gets the lock for us
792 */
793 case BLKRRPART:
794 return blkdev_ioctl(inode, file, cmd,
795 (unsigned long)compat_ptr(arg));
796 case BLKBSZSET_32:
797 return blkdev_ioctl(inode, file, BLKBSZSET,
798 (unsigned long)compat_ptr(arg));
799 case BLKPG:
800 return compat_blkpg_ioctl(inode, file, cmd, compat_ptr(arg));
801 }
802
803 lock_kernel();
804 ret = compat_blkdev_locked_ioctl(inode, file, bdev, cmd, arg);
805 /* FIXME: why do we assume -> compat_ioctl needs the BKL? */
806 if (ret == -ENOIOCTLCMD && disk->fops->compat_ioctl)
807 ret = disk->fops->compat_ioctl(file, cmd, arg);
808 unlock_kernel();
809
810 if (ret != -ENOIOCTLCMD)
811 return ret;
812
813 return compat_blkdev_driver_ioctl(inode, file, disk, cmd, arg);
814}
diff --git a/block/ioctl.c b/block/ioctl.c
index f7e3e8abf887..52d6385216ad 100644
--- a/block/ioctl.c
+++ b/block/ioctl.c
@@ -217,6 +217,10 @@ int blkdev_driver_ioctl(struct inode *inode, struct file *file,
217} 217}
218EXPORT_SYMBOL_GPL(blkdev_driver_ioctl); 218EXPORT_SYMBOL_GPL(blkdev_driver_ioctl);
219 219
220/*
221 * always keep this in sync with compat_blkdev_ioctl() and
222 * compat_blkdev_locked_ioctl()
223 */
220int blkdev_ioctl(struct inode *inode, struct file *file, unsigned cmd, 224int blkdev_ioctl(struct inode *inode, struct file *file, unsigned cmd,
221 unsigned long arg) 225 unsigned long arg)
222{ 226{
@@ -284,21 +288,4 @@ int blkdev_ioctl(struct inode *inode, struct file *file, unsigned cmd,
284 288
285 return blkdev_driver_ioctl(inode, file, disk, cmd, arg); 289 return blkdev_driver_ioctl(inode, file, disk, cmd, arg);
286} 290}
287
288/* Most of the generic ioctls are handled in the normal fallback path.
289 This assumes the blkdev's low level compat_ioctl always returns
290 ENOIOCTLCMD for unknown ioctls. */
291long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
292{
293 struct block_device *bdev = file->f_path.dentry->d_inode->i_bdev;
294 struct gendisk *disk = bdev->bd_disk;
295 int ret = -ENOIOCTLCMD;
296 if (disk->fops->compat_ioctl) {
297 lock_kernel();
298 ret = disk->fops->compat_ioctl(file, cmd, arg);
299 unlock_kernel();
300 }
301 return ret;
302}
303
304EXPORT_SYMBOL_GPL(blkdev_ioctl); 291EXPORT_SYMBOL_GPL(blkdev_ioctl);
diff --git a/block/ll_rw_blk.c b/block/ll_rw_blk.c
index ed39313c4085..cd9d2c5d91ae 100644
--- a/block/ll_rw_blk.c
+++ b/block/ll_rw_blk.c
@@ -42,6 +42,9 @@ static void drive_stat_acct(struct request *rq, int nr_sectors, int new_io);
42static void init_request_from_bio(struct request *req, struct bio *bio); 42static void init_request_from_bio(struct request *req, struct bio *bio);
43static int __make_request(struct request_queue *q, struct bio *bio); 43static int __make_request(struct request_queue *q, struct bio *bio);
44static struct io_context *current_io_context(gfp_t gfp_flags, int node); 44static struct io_context *current_io_context(gfp_t gfp_flags, int node);
45static void blk_recalc_rq_segments(struct request *rq);
46static void blk_rq_bio_prep(struct request_queue *q, struct request *rq,
47 struct bio *bio);
45 48
46/* 49/*
47 * For the allocated request tables 50 * For the allocated request tables
@@ -428,7 +431,6 @@ static void queue_flush(struct request_queue *q, unsigned which)
428static inline struct request *start_ordered(struct request_queue *q, 431static inline struct request *start_ordered(struct request_queue *q,
429 struct request *rq) 432 struct request *rq)
430{ 433{
431 q->bi_size = 0;
432 q->orderr = 0; 434 q->orderr = 0;
433 q->ordered = q->next_ordered; 435 q->ordered = q->next_ordered;
434 q->ordseq |= QUEUE_ORDSEQ_STARTED; 436 q->ordseq |= QUEUE_ORDSEQ_STARTED;
@@ -525,56 +527,36 @@ int blk_do_ordered(struct request_queue *q, struct request **rqp)
525 return 1; 527 return 1;
526} 528}
527 529
528static int flush_dry_bio_endio(struct bio *bio, unsigned int bytes, int error) 530static void req_bio_endio(struct request *rq, struct bio *bio,
529{ 531 unsigned int nbytes, int error)
530 struct request_queue *q = bio->bi_private;
531
532 /*
533 * This is dry run, restore bio_sector and size. We'll finish
534 * this request again with the original bi_end_io after an
535 * error occurs or post flush is complete.
536 */
537 q->bi_size += bytes;
538
539 if (bio->bi_size)
540 return 1;
541
542 /* Reset bio */
543 set_bit(BIO_UPTODATE, &bio->bi_flags);
544 bio->bi_size = q->bi_size;
545 bio->bi_sector -= (q->bi_size >> 9);
546 q->bi_size = 0;
547
548 return 0;
549}
550
551static int ordered_bio_endio(struct request *rq, struct bio *bio,
552 unsigned int nbytes, int error)
553{ 532{
554 struct request_queue *q = rq->q; 533 struct request_queue *q = rq->q;
555 bio_end_io_t *endio;
556 void *private;
557 534
558 if (&q->bar_rq != rq) 535 if (&q->bar_rq != rq) {
559 return 0; 536 if (error)
560 537 clear_bit(BIO_UPTODATE, &bio->bi_flags);
561 /* 538 else if (!test_bit(BIO_UPTODATE, &bio->bi_flags))
562 * Okay, this is the barrier request in progress, dry finish it. 539 error = -EIO;
563 */
564 if (error && !q->orderr)
565 q->orderr = error;
566 540
567 endio = bio->bi_end_io; 541 if (unlikely(nbytes > bio->bi_size)) {
568 private = bio->bi_private; 542 printk("%s: want %u bytes done, only %u left\n",
569 bio->bi_end_io = flush_dry_bio_endio; 543 __FUNCTION__, nbytes, bio->bi_size);
570 bio->bi_private = q; 544 nbytes = bio->bi_size;
571 545 }
572 bio_endio(bio, nbytes, error);
573 546
574 bio->bi_end_io = endio; 547 bio->bi_size -= nbytes;
575 bio->bi_private = private; 548 bio->bi_sector += (nbytes >> 9);
549 if (bio->bi_size == 0)
550 bio_endio(bio, error);
551 } else {
576 552
577 return 1; 553 /*
554 * Okay, this is the barrier request in progress, just
555 * record the error;
556 */
557 if (error && !q->orderr)
558 q->orderr = error;
559 }
578} 560}
579 561
580/** 562/**
@@ -1220,16 +1202,40 @@ EXPORT_SYMBOL(blk_dump_rq_flags);
1220 1202
1221void blk_recount_segments(struct request_queue *q, struct bio *bio) 1203void blk_recount_segments(struct request_queue *q, struct bio *bio)
1222{ 1204{
1205 struct request rq;
1206 struct bio *nxt = bio->bi_next;
1207 rq.q = q;
1208 rq.bio = rq.biotail = bio;
1209 bio->bi_next = NULL;
1210 blk_recalc_rq_segments(&rq);
1211 bio->bi_next = nxt;
1212 bio->bi_phys_segments = rq.nr_phys_segments;
1213 bio->bi_hw_segments = rq.nr_hw_segments;
1214 bio->bi_flags |= (1 << BIO_SEG_VALID);
1215}
1216EXPORT_SYMBOL(blk_recount_segments);
1217
1218static void blk_recalc_rq_segments(struct request *rq)
1219{
1220 int nr_phys_segs;
1221 int nr_hw_segs;
1222 unsigned int phys_size;
1223 unsigned int hw_size;
1223 struct bio_vec *bv, *bvprv = NULL; 1224 struct bio_vec *bv, *bvprv = NULL;
1224 int i, nr_phys_segs, nr_hw_segs, seg_size, hw_seg_size, cluster; 1225 int seg_size;
1226 int hw_seg_size;
1227 int cluster;
1228 struct req_iterator iter;
1225 int high, highprv = 1; 1229 int high, highprv = 1;
1230 struct request_queue *q = rq->q;
1226 1231
1227 if (unlikely(!bio->bi_io_vec)) 1232 if (!rq->bio)
1228 return; 1233 return;
1229 1234
1230 cluster = q->queue_flags & (1 << QUEUE_FLAG_CLUSTER); 1235 cluster = q->queue_flags & (1 << QUEUE_FLAG_CLUSTER);
1231 hw_seg_size = seg_size = nr_phys_segs = nr_hw_segs = 0; 1236 hw_seg_size = seg_size = 0;
1232 bio_for_each_segment(bv, bio, i) { 1237 phys_size = hw_size = nr_phys_segs = nr_hw_segs = 0;
1238 rq_for_each_segment(bv, rq, iter) {
1233 /* 1239 /*
1234 * the trick here is making sure that a high page is never 1240 * the trick here is making sure that a high page is never
1235 * considered part of another segment, since that might 1241 * considered part of another segment, since that might
@@ -1255,12 +1261,13 @@ void blk_recount_segments(struct request_queue *q, struct bio *bio)
1255 } 1261 }
1256new_segment: 1262new_segment:
1257 if (BIOVEC_VIRT_MERGEABLE(bvprv, bv) && 1263 if (BIOVEC_VIRT_MERGEABLE(bvprv, bv) &&
1258 !BIOVEC_VIRT_OVERSIZE(hw_seg_size + bv->bv_len)) { 1264 !BIOVEC_VIRT_OVERSIZE(hw_seg_size + bv->bv_len))
1259 hw_seg_size += bv->bv_len; 1265 hw_seg_size += bv->bv_len;
1260 } else { 1266 else {
1261new_hw_segment: 1267new_hw_segment:
1262 if (hw_seg_size > bio->bi_hw_front_size) 1268 if (nr_hw_segs == 1 &&
1263 bio->bi_hw_front_size = hw_seg_size; 1269 hw_seg_size > rq->bio->bi_hw_front_size)
1270 rq->bio->bi_hw_front_size = hw_seg_size;
1264 hw_seg_size = BIOVEC_VIRT_START_SIZE(bv) + bv->bv_len; 1271 hw_seg_size = BIOVEC_VIRT_START_SIZE(bv) + bv->bv_len;
1265 nr_hw_segs++; 1272 nr_hw_segs++;
1266 } 1273 }
@@ -1270,15 +1277,15 @@ new_hw_segment:
1270 seg_size = bv->bv_len; 1277 seg_size = bv->bv_len;
1271 highprv = high; 1278 highprv = high;
1272 } 1279 }
1273 if (hw_seg_size > bio->bi_hw_back_size) 1280
1274 bio->bi_hw_back_size = hw_seg_size; 1281 if (nr_hw_segs == 1 &&
1275 if (nr_hw_segs == 1 && hw_seg_size > bio->bi_hw_front_size) 1282 hw_seg_size > rq->bio->bi_hw_front_size)
1276 bio->bi_hw_front_size = hw_seg_size; 1283 rq->bio->bi_hw_front_size = hw_seg_size;
1277 bio->bi_phys_segments = nr_phys_segs; 1284 if (hw_seg_size > rq->biotail->bi_hw_back_size)
1278 bio->bi_hw_segments = nr_hw_segs; 1285 rq->biotail->bi_hw_back_size = hw_seg_size;
1279 bio->bi_flags |= (1 << BIO_SEG_VALID); 1286 rq->nr_phys_segments = nr_phys_segs;
1287 rq->nr_hw_segments = nr_hw_segs;
1280} 1288}
1281EXPORT_SYMBOL(blk_recount_segments);
1282 1289
1283static int blk_phys_contig_segment(struct request_queue *q, struct bio *bio, 1290static int blk_phys_contig_segment(struct request_queue *q, struct bio *bio,
1284 struct bio *nxt) 1291 struct bio *nxt)
@@ -1325,8 +1332,8 @@ int blk_rq_map_sg(struct request_queue *q, struct request *rq,
1325 struct scatterlist *sg) 1332 struct scatterlist *sg)
1326{ 1333{
1327 struct bio_vec *bvec, *bvprv; 1334 struct bio_vec *bvec, *bvprv;
1328 struct bio *bio; 1335 struct req_iterator iter;
1329 int nsegs, i, cluster; 1336 int nsegs, cluster;
1330 1337
1331 nsegs = 0; 1338 nsegs = 0;
1332 cluster = q->queue_flags & (1 << QUEUE_FLAG_CLUSTER); 1339 cluster = q->queue_flags & (1 << QUEUE_FLAG_CLUSTER);
@@ -1335,35 +1342,30 @@ int blk_rq_map_sg(struct request_queue *q, struct request *rq,
1335 * for each bio in rq 1342 * for each bio in rq
1336 */ 1343 */
1337 bvprv = NULL; 1344 bvprv = NULL;
1338 rq_for_each_bio(bio, rq) { 1345 rq_for_each_segment(bvec, rq, iter) {
1339 /* 1346 int nbytes = bvec->bv_len;
1340 * for each segment in bio
1341 */
1342 bio_for_each_segment(bvec, bio, i) {
1343 int nbytes = bvec->bv_len;
1344 1347
1345 if (bvprv && cluster) { 1348 if (bvprv && cluster) {
1346 if (sg[nsegs - 1].length + nbytes > q->max_segment_size) 1349 if (sg[nsegs - 1].length + nbytes > q->max_segment_size)
1347 goto new_segment; 1350 goto new_segment;
1348 1351
1349 if (!BIOVEC_PHYS_MERGEABLE(bvprv, bvec)) 1352 if (!BIOVEC_PHYS_MERGEABLE(bvprv, bvec))
1350 goto new_segment; 1353 goto new_segment;
1351 if (!BIOVEC_SEG_BOUNDARY(q, bvprv, bvec)) 1354 if (!BIOVEC_SEG_BOUNDARY(q, bvprv, bvec))
1352 goto new_segment; 1355 goto new_segment;
1353 1356
1354 sg[nsegs - 1].length += nbytes; 1357 sg[nsegs - 1].length += nbytes;
1355 } else { 1358 } else {
1356new_segment: 1359new_segment:
1357 memset(&sg[nsegs],0,sizeof(struct scatterlist)); 1360 memset(&sg[nsegs],0,sizeof(struct scatterlist));
1358 sg[nsegs].page = bvec->bv_page; 1361 sg[nsegs].page = bvec->bv_page;
1359 sg[nsegs].length = nbytes; 1362 sg[nsegs].length = nbytes;
1360 sg[nsegs].offset = bvec->bv_offset; 1363 sg[nsegs].offset = bvec->bv_offset;
1361 1364
1362 nsegs++; 1365 nsegs++;
1363 } 1366 }
1364 bvprv = bvec; 1367 bvprv = bvec;
1365 } /* segments in bio */ 1368 } /* segments in rq */
1366 } /* bios in rq */
1367 1369
1368 return nsegs; 1370 return nsegs;
1369} 1371}
@@ -1420,7 +1422,8 @@ static inline int ll_new_hw_segment(struct request_queue *q,
1420 return 1; 1422 return 1;
1421} 1423}
1422 1424
1423int ll_back_merge_fn(struct request_queue *q, struct request *req, struct bio *bio) 1425static int ll_back_merge_fn(struct request_queue *q, struct request *req,
1426 struct bio *bio)
1424{ 1427{
1425 unsigned short max_sectors; 1428 unsigned short max_sectors;
1426 int len; 1429 int len;
@@ -1456,7 +1459,6 @@ int ll_back_merge_fn(struct request_queue *q, struct request *req, struct bio *b
1456 1459
1457 return ll_new_hw_segment(q, req, bio); 1460 return ll_new_hw_segment(q, req, bio);
1458} 1461}
1459EXPORT_SYMBOL(ll_back_merge_fn);
1460 1462
1461static int ll_front_merge_fn(struct request_queue *q, struct request *req, 1463static int ll_front_merge_fn(struct request_queue *q, struct request *req,
1462 struct bio *bio) 1464 struct bio *bio)
@@ -2346,6 +2348,23 @@ static int __blk_rq_unmap_user(struct bio *bio)
2346 return ret; 2348 return ret;
2347} 2349}
2348 2350
2351int blk_rq_append_bio(struct request_queue *q, struct request *rq,
2352 struct bio *bio)
2353{
2354 if (!rq->bio)
2355 blk_rq_bio_prep(q, rq, bio);
2356 else if (!ll_back_merge_fn(q, rq, bio))
2357 return -EINVAL;
2358 else {
2359 rq->biotail->bi_next = bio;
2360 rq->biotail = bio;
2361
2362 rq->data_len += bio->bi_size;
2363 }
2364 return 0;
2365}
2366EXPORT_SYMBOL(blk_rq_append_bio);
2367
2349static int __blk_rq_map_user(struct request_queue *q, struct request *rq, 2368static int __blk_rq_map_user(struct request_queue *q, struct request *rq,
2350 void __user *ubuf, unsigned int len) 2369 void __user *ubuf, unsigned int len)
2351{ 2370{
@@ -2377,23 +2396,12 @@ static int __blk_rq_map_user(struct request_queue *q, struct request *rq,
2377 */ 2396 */
2378 bio_get(bio); 2397 bio_get(bio);
2379 2398
2380 if (!rq->bio) 2399 ret = blk_rq_append_bio(q, rq, bio);
2381 blk_rq_bio_prep(q, rq, bio); 2400 if (!ret)
2382 else if (!ll_back_merge_fn(q, rq, bio)) { 2401 return bio->bi_size;
2383 ret = -EINVAL;
2384 goto unmap_bio;
2385 } else {
2386 rq->biotail->bi_next = bio;
2387 rq->biotail = bio;
2388
2389 rq->data_len += bio->bi_size;
2390 }
2391
2392 return bio->bi_size;
2393 2402
2394unmap_bio:
2395 /* if it was boucned we must call the end io function */ 2403 /* if it was boucned we must call the end io function */
2396 bio_endio(bio, bio->bi_size, 0); 2404 bio_endio(bio, 0);
2397 __blk_rq_unmap_user(orig_bio); 2405 __blk_rq_unmap_user(orig_bio);
2398 bio_put(bio); 2406 bio_put(bio);
2399 return ret; 2407 return ret;
@@ -2502,7 +2510,7 @@ int blk_rq_map_user_iov(struct request_queue *q, struct request *rq,
2502 return PTR_ERR(bio); 2510 return PTR_ERR(bio);
2503 2511
2504 if (bio->bi_size != len) { 2512 if (bio->bi_size != len) {
2505 bio_endio(bio, bio->bi_size, 0); 2513 bio_endio(bio, 0);
2506 bio_unmap_user(bio); 2514 bio_unmap_user(bio);
2507 return -EINVAL; 2515 return -EINVAL;
2508 } 2516 }
@@ -2912,15 +2920,9 @@ static void init_request_from_bio(struct request *req, struct bio *bio)
2912 2920
2913 req->errors = 0; 2921 req->errors = 0;
2914 req->hard_sector = req->sector = bio->bi_sector; 2922 req->hard_sector = req->sector = bio->bi_sector;
2915 req->hard_nr_sectors = req->nr_sectors = bio_sectors(bio);
2916 req->current_nr_sectors = req->hard_cur_sectors = bio_cur_sectors(bio);
2917 req->nr_phys_segments = bio_phys_segments(req->q, bio);
2918 req->nr_hw_segments = bio_hw_segments(req->q, bio);
2919 req->buffer = bio_data(bio); /* see ->buffer comment above */
2920 req->bio = req->biotail = bio;
2921 req->ioprio = bio_prio(bio); 2923 req->ioprio = bio_prio(bio);
2922 req->rq_disk = bio->bi_bdev->bd_disk;
2923 req->start_time = jiffies; 2924 req->start_time = jiffies;
2925 blk_rq_bio_prep(req->q, req, bio);
2924} 2926}
2925 2927
2926static int __make_request(struct request_queue *q, struct bio *bio) 2928static int __make_request(struct request_queue *q, struct bio *bio)
@@ -3038,7 +3040,7 @@ out:
3038 return 0; 3040 return 0;
3039 3041
3040end_io: 3042end_io:
3041 bio_endio(bio, nr_sectors << 9, err); 3043 bio_endio(bio, err);
3042 return 0; 3044 return 0;
3043} 3045}
3044 3046
@@ -3185,7 +3187,7 @@ static inline void __generic_make_request(struct bio *bio)
3185 bdevname(bio->bi_bdev, b), 3187 bdevname(bio->bi_bdev, b),
3186 (long long) bio->bi_sector); 3188 (long long) bio->bi_sector);
3187end_io: 3189end_io:
3188 bio_endio(bio, bio->bi_size, -EIO); 3190 bio_endio(bio, -EIO);
3189 break; 3191 break;
3190 } 3192 }
3191 3193
@@ -3329,48 +3331,6 @@ void submit_bio(int rw, struct bio *bio)
3329 3331
3330EXPORT_SYMBOL(submit_bio); 3332EXPORT_SYMBOL(submit_bio);
3331 3333
3332static void blk_recalc_rq_segments(struct request *rq)
3333{
3334 struct bio *bio, *prevbio = NULL;
3335 int nr_phys_segs, nr_hw_segs;
3336 unsigned int phys_size, hw_size;
3337 struct request_queue *q = rq->q;
3338
3339 if (!rq->bio)
3340 return;
3341
3342 phys_size = hw_size = nr_phys_segs = nr_hw_segs = 0;
3343 rq_for_each_bio(bio, rq) {
3344 /* Force bio hw/phys segs to be recalculated. */
3345 bio->bi_flags &= ~(1 << BIO_SEG_VALID);
3346
3347 nr_phys_segs += bio_phys_segments(q, bio);
3348 nr_hw_segs += bio_hw_segments(q, bio);
3349 if (prevbio) {
3350 int pseg = phys_size + prevbio->bi_size + bio->bi_size;
3351 int hseg = hw_size + prevbio->bi_size + bio->bi_size;
3352
3353 if (blk_phys_contig_segment(q, prevbio, bio) &&
3354 pseg <= q->max_segment_size) {
3355 nr_phys_segs--;
3356 phys_size += prevbio->bi_size + bio->bi_size;
3357 } else
3358 phys_size = 0;
3359
3360 if (blk_hw_contig_segment(q, prevbio, bio) &&
3361 hseg <= q->max_segment_size) {
3362 nr_hw_segs--;
3363 hw_size += prevbio->bi_size + bio->bi_size;
3364 } else
3365 hw_size = 0;
3366 }
3367 prevbio = bio;
3368 }
3369
3370 rq->nr_phys_segments = nr_phys_segs;
3371 rq->nr_hw_segments = nr_hw_segs;
3372}
3373
3374static void blk_recalc_rq_sectors(struct request *rq, int nsect) 3334static void blk_recalc_rq_sectors(struct request *rq, int nsect)
3375{ 3335{
3376 if (blk_fs_request(rq)) { 3336 if (blk_fs_request(rq)) {
@@ -3442,8 +3402,7 @@ static int __end_that_request_first(struct request *req, int uptodate,
3442 if (nr_bytes >= bio->bi_size) { 3402 if (nr_bytes >= bio->bi_size) {
3443 req->bio = bio->bi_next; 3403 req->bio = bio->bi_next;
3444 nbytes = bio->bi_size; 3404 nbytes = bio->bi_size;
3445 if (!ordered_bio_endio(req, bio, nbytes, error)) 3405 req_bio_endio(req, bio, nbytes, error);
3446 bio_endio(bio, nbytes, error);
3447 next_idx = 0; 3406 next_idx = 0;
3448 bio_nbytes = 0; 3407 bio_nbytes = 0;
3449 } else { 3408 } else {
@@ -3498,8 +3457,7 @@ static int __end_that_request_first(struct request *req, int uptodate,
3498 * if the request wasn't completed, update state 3457 * if the request wasn't completed, update state
3499 */ 3458 */
3500 if (bio_nbytes) { 3459 if (bio_nbytes) {
3501 if (!ordered_bio_endio(req, bio, bio_nbytes, error)) 3460 req_bio_endio(req, bio, bio_nbytes, error);
3502 bio_endio(bio, bio_nbytes, error);
3503 bio->bi_idx += next_idx; 3461 bio->bi_idx += next_idx;
3504 bio_iovec(bio)->bv_offset += nr_bytes; 3462 bio_iovec(bio)->bv_offset += nr_bytes;
3505 bio_iovec(bio)->bv_len -= nr_bytes; 3463 bio_iovec(bio)->bv_len -= nr_bytes;
@@ -3574,7 +3532,7 @@ static void blk_done_softirq(struct softirq_action *h)
3574 } 3532 }
3575} 3533}
3576 3534
3577static int blk_cpu_notify(struct notifier_block *self, unsigned long action, 3535static int __cpuinit blk_cpu_notify(struct notifier_block *self, unsigned long action,
3578 void *hcpu) 3536 void *hcpu)
3579{ 3537{
3580 /* 3538 /*
@@ -3595,7 +3553,7 @@ static int blk_cpu_notify(struct notifier_block *self, unsigned long action,
3595} 3553}
3596 3554
3597 3555
3598static struct notifier_block __devinitdata blk_cpu_notifier = { 3556static struct notifier_block blk_cpu_notifier __cpuinitdata = {
3599 .notifier_call = blk_cpu_notify, 3557 .notifier_call = blk_cpu_notify,
3600}; 3558};
3601 3559
@@ -3680,8 +3638,8 @@ void end_request(struct request *req, int uptodate)
3680 3638
3681EXPORT_SYMBOL(end_request); 3639EXPORT_SYMBOL(end_request);
3682 3640
3683void blk_rq_bio_prep(struct request_queue *q, struct request *rq, 3641static void blk_rq_bio_prep(struct request_queue *q, struct request *rq,
3684 struct bio *bio) 3642 struct bio *bio)
3685{ 3643{
3686 /* first two bits are identical in rq->cmd_flags and bio->bi_rw */ 3644 /* first two bits are identical in rq->cmd_flags and bio->bi_rw */
3687 rq->cmd_flags |= (bio->bi_rw & 3); 3645 rq->cmd_flags |= (bio->bi_rw & 3);
@@ -3695,9 +3653,10 @@ void blk_rq_bio_prep(struct request_queue *q, struct request *rq,
3695 rq->data_len = bio->bi_size; 3653 rq->data_len = bio->bi_size;
3696 3654
3697 rq->bio = rq->biotail = bio; 3655 rq->bio = rq->biotail = bio;
3698}
3699 3656
3700EXPORT_SYMBOL(blk_rq_bio_prep); 3657 if (bio->bi_bdev)
3658 rq->rq_disk = bio->bi_bdev->bd_disk;
3659}
3701 3660
3702int kblockd_schedule_work(struct work_struct *work) 3661int kblockd_schedule_work(struct work_struct *work)
3703{ 3662{
diff --git a/drivers/block/aoe/aoeblk.c b/drivers/block/aoe/aoeblk.c
index 007faaf008e7..b1d00ef6659c 100644
--- a/drivers/block/aoe/aoeblk.c
+++ b/drivers/block/aoe/aoeblk.c
@@ -138,7 +138,7 @@ aoeblk_make_request(struct request_queue *q, struct bio *bio)
138 buf = mempool_alloc(d->bufpool, GFP_NOIO); 138 buf = mempool_alloc(d->bufpool, GFP_NOIO);
139 if (buf == NULL) { 139 if (buf == NULL) {
140 printk(KERN_INFO "aoe: buf allocation failure\n"); 140 printk(KERN_INFO "aoe: buf allocation failure\n");
141 bio_endio(bio, bio->bi_size, -ENOMEM); 141 bio_endio(bio, -ENOMEM);
142 return 0; 142 return 0;
143 } 143 }
144 memset(buf, 0, sizeof(*buf)); 144 memset(buf, 0, sizeof(*buf));
@@ -159,7 +159,7 @@ aoeblk_make_request(struct request_queue *q, struct bio *bio)
159 d->aoemajor, d->aoeminor); 159 d->aoemajor, d->aoeminor);
160 spin_unlock_irqrestore(&d->lock, flags); 160 spin_unlock_irqrestore(&d->lock, flags);
161 mempool_free(buf, d->bufpool); 161 mempool_free(buf, d->bufpool);
162 bio_endio(bio, bio->bi_size, -ENXIO); 162 bio_endio(bio, -ENXIO);
163 return 0; 163 return 0;
164 } 164 }
165 165
diff --git a/drivers/block/aoe/aoecmd.c b/drivers/block/aoe/aoecmd.c
index 01fbdd38e3be..5abae34ad65b 100644
--- a/drivers/block/aoe/aoecmd.c
+++ b/drivers/block/aoe/aoecmd.c
@@ -652,7 +652,7 @@ aoecmd_ata_rsp(struct sk_buff *skb)
652 disk_stat_add(disk, sectors[rw], n_sect); 652 disk_stat_add(disk, sectors[rw], n_sect);
653 disk_stat_add(disk, io_ticks, duration); 653 disk_stat_add(disk, io_ticks, duration);
654 n = (buf->flags & BUFFL_FAIL) ? -EIO : 0; 654 n = (buf->flags & BUFFL_FAIL) ? -EIO : 0;
655 bio_endio(buf->bio, buf->bio->bi_size, n); 655 bio_endio(buf->bio, n);
656 mempool_free(buf, d->bufpool); 656 mempool_free(buf, d->bufpool);
657 } 657 }
658 } 658 }
diff --git a/drivers/block/aoe/aoedev.c b/drivers/block/aoe/aoedev.c
index 05a97197c918..51f50710e5fc 100644
--- a/drivers/block/aoe/aoedev.c
+++ b/drivers/block/aoe/aoedev.c
@@ -119,7 +119,7 @@ aoedev_downdev(struct aoedev *d)
119 bio = buf->bio; 119 bio = buf->bio;
120 if (--buf->nframesout == 0) { 120 if (--buf->nframesout == 0) {
121 mempool_free(buf, d->bufpool); 121 mempool_free(buf, d->bufpool);
122 bio_endio(bio, bio->bi_size, -EIO); 122 bio_endio(bio, -EIO);
123 } 123 }
124 skb_shinfo(f->skb)->nr_frags = f->skb->data_len = 0; 124 skb_shinfo(f->skb)->nr_frags = f->skb->data_len = 0;
125 } 125 }
@@ -130,7 +130,7 @@ aoedev_downdev(struct aoedev *d)
130 list_del(d->bufq.next); 130 list_del(d->bufq.next);
131 bio = buf->bio; 131 bio = buf->bio;
132 mempool_free(buf, d->bufpool); 132 mempool_free(buf, d->bufpool);
133 bio_endio(bio, bio->bi_size, -EIO); 133 bio_endio(bio, -EIO);
134 } 134 }
135 135
136 if (d->gd) 136 if (d->gd)
diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
index 084358a828e9..28d145756f6c 100644
--- a/drivers/block/cciss.c
+++ b/drivers/block/cciss.c
@@ -1194,7 +1194,7 @@ static inline void complete_buffers(struct bio *bio, int status)
1194 int nr_sectors = bio_sectors(bio); 1194 int nr_sectors = bio_sectors(bio);
1195 1195
1196 bio->bi_next = NULL; 1196 bio->bi_next = NULL;
1197 bio_endio(bio, nr_sectors << 9, status ? 0 : -EIO); 1197 bio_endio(bio, status ? 0 : -EIO);
1198 bio = xbh; 1198 bio = xbh;
1199 } 1199 }
1200} 1200}
diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
index eb9799acf65b..3853c9a38d6a 100644
--- a/drivers/block/cpqarray.c
+++ b/drivers/block/cpqarray.c
@@ -987,7 +987,7 @@ static inline void complete_buffers(struct bio *bio, int ok)
987 xbh = bio->bi_next; 987 xbh = bio->bi_next;
988 bio->bi_next = NULL; 988 bio->bi_next = NULL;
989 989
990 bio_endio(bio, nr_sectors << 9, ok ? 0 : -EIO); 990 bio_endio(bio, ok ? 0 : -EIO);
991 991
992 bio = xbh; 992 bio = xbh;
993 } 993 }
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index 085b7794fb3e..80483aac4cc9 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -2437,22 +2437,19 @@ static void rw_interrupt(void)
2437/* Compute maximal contiguous buffer size. */ 2437/* Compute maximal contiguous buffer size. */
2438static int buffer_chain_size(void) 2438static int buffer_chain_size(void)
2439{ 2439{
2440 struct bio *bio;
2441 struct bio_vec *bv; 2440 struct bio_vec *bv;
2442 int size, i; 2441 int size;
2442 struct req_iterator iter;
2443 char *base; 2443 char *base;
2444 2444
2445 base = bio_data(current_req->bio); 2445 base = bio_data(current_req->bio);
2446 size = 0; 2446 size = 0;
2447 2447
2448 rq_for_each_bio(bio, current_req) { 2448 rq_for_each_segment(bv, current_req, iter) {
2449 bio_for_each_segment(bv, bio, i) { 2449 if (page_address(bv->bv_page) + bv->bv_offset != base + size)
2450 if (page_address(bv->bv_page) + bv->bv_offset != 2450 break;
2451 base + size)
2452 break;
2453 2451
2454 size += bv->bv_len; 2452 size += bv->bv_len;
2455 }
2456 } 2453 }
2457 2454
2458 return size >> 9; 2455 return size >> 9;
@@ -2479,9 +2476,9 @@ static void copy_buffer(int ssize, int max_sector, int max_sector_2)
2479{ 2476{
2480 int remaining; /* number of transferred 512-byte sectors */ 2477 int remaining; /* number of transferred 512-byte sectors */
2481 struct bio_vec *bv; 2478 struct bio_vec *bv;
2482 struct bio *bio;
2483 char *buffer, *dma_buffer; 2479 char *buffer, *dma_buffer;
2484 int size, i; 2480 int size;
2481 struct req_iterator iter;
2485 2482
2486 max_sector = transfer_size(ssize, 2483 max_sector = transfer_size(ssize,
2487 min(max_sector, max_sector_2), 2484 min(max_sector, max_sector_2),
@@ -2514,43 +2511,41 @@ static void copy_buffer(int ssize, int max_sector, int max_sector_2)
2514 2511
2515 size = current_req->current_nr_sectors << 9; 2512 size = current_req->current_nr_sectors << 9;
2516 2513
2517 rq_for_each_bio(bio, current_req) { 2514 rq_for_each_segment(bv, current_req, iter) {
2518 bio_for_each_segment(bv, bio, i) { 2515 if (!remaining)
2519 if (!remaining) 2516 break;
2520 break;
2521 2517
2522 size = bv->bv_len; 2518 size = bv->bv_len;
2523 SUPBOUND(size, remaining); 2519 SUPBOUND(size, remaining);
2524 2520
2525 buffer = page_address(bv->bv_page) + bv->bv_offset; 2521 buffer = page_address(bv->bv_page) + bv->bv_offset;
2526#ifdef FLOPPY_SANITY_CHECK 2522#ifdef FLOPPY_SANITY_CHECK
2527 if (dma_buffer + size > 2523 if (dma_buffer + size >
2528 floppy_track_buffer + (max_buffer_sectors << 10) || 2524 floppy_track_buffer + (max_buffer_sectors << 10) ||
2529 dma_buffer < floppy_track_buffer) { 2525 dma_buffer < floppy_track_buffer) {
2530 DPRINT("buffer overrun in copy buffer %d\n", 2526 DPRINT("buffer overrun in copy buffer %d\n",
2531 (int)((floppy_track_buffer - 2527 (int)((floppy_track_buffer -
2532 dma_buffer) >> 9)); 2528 dma_buffer) >> 9));
2533 printk("fsector_t=%d buffer_min=%d\n", 2529 printk("fsector_t=%d buffer_min=%d\n",
2534 fsector_t, buffer_min); 2530 fsector_t, buffer_min);
2535 printk("current_count_sectors=%ld\n", 2531 printk("current_count_sectors=%ld\n",
2536 current_count_sectors); 2532 current_count_sectors);
2537 if (CT(COMMAND) == FD_READ)
2538 printk("read\n");
2539 if (CT(COMMAND) == FD_WRITE)
2540 printk("write\n");
2541 break;
2542 }
2543 if (((unsigned long)buffer) % 512)
2544 DPRINT("%p buffer not aligned\n", buffer);
2545#endif
2546 if (CT(COMMAND) == FD_READ) 2533 if (CT(COMMAND) == FD_READ)
2547 memcpy(buffer, dma_buffer, size); 2534 printk("read\n");
2548 else 2535 if (CT(COMMAND) == FD_WRITE)
2549 memcpy(dma_buffer, buffer, size); 2536 printk("write\n");
2550 2537 break;
2551 remaining -= size;
2552 dma_buffer += size;
2553 } 2538 }
2539 if (((unsigned long)buffer) % 512)
2540 DPRINT("%p buffer not aligned\n", buffer);
2541#endif
2542 if (CT(COMMAND) == FD_READ)
2543 memcpy(buffer, dma_buffer, size);
2544 else
2545 memcpy(dma_buffer, buffer, size);
2546
2547 remaining -= size;
2548 dma_buffer += size;
2554 } 2549 }
2555#ifdef FLOPPY_SANITY_CHECK 2550#ifdef FLOPPY_SANITY_CHECK
2556 if (remaining) { 2551 if (remaining) {
@@ -3815,14 +3810,10 @@ static int check_floppy_change(struct gendisk *disk)
3815 * a disk in the drive, and whether that disk is writable. 3810 * a disk in the drive, and whether that disk is writable.
3816 */ 3811 */
3817 3812
3818static int floppy_rb0_complete(struct bio *bio, unsigned int bytes_done, 3813static void floppy_rb0_complete(struct bio *bio,
3819 int err) 3814 int err)
3820{ 3815{
3821 if (bio->bi_size)
3822 return 1;
3823
3824 complete((struct completion *)bio->bi_private); 3816 complete((struct completion *)bio->bi_private);
3825 return 0;
3826} 3817}
3827 3818
3828static int __floppy_read_block_0(struct block_device *bdev) 3819static int __floppy_read_block_0(struct block_device *bdev)
diff --git a/drivers/block/lguest_blk.c b/drivers/block/lguest_blk.c
index 160cf14431ac..fa8e42341b87 100644
--- a/drivers/block/lguest_blk.c
+++ b/drivers/block/lguest_blk.c
@@ -142,25 +142,23 @@ static irqreturn_t lgb_irq(int irq, void *_bd)
142 * return the total length. */ 142 * return the total length. */
143static unsigned int req_to_dma(struct request *req, struct lguest_dma *dma) 143static unsigned int req_to_dma(struct request *req, struct lguest_dma *dma)
144{ 144{
145 unsigned int i = 0, idx, len = 0; 145 unsigned int i = 0, len = 0;
146 struct bio *bio; 146 struct req_iterator iter;
147 147 struct bio_vec *bvec;
148 rq_for_each_bio(bio, req) { 148
149 struct bio_vec *bvec; 149 rq_for_each_segment(bvec, req, iter) {
150 bio_for_each_segment(bvec, bio, idx) { 150 /* We told the block layer not to give us too many. */
151 /* We told the block layer not to give us too many. */ 151 BUG_ON(i == LGUEST_MAX_DMA_SECTIONS);
152 BUG_ON(i == LGUEST_MAX_DMA_SECTIONS); 152 /* If we had a zero-length segment, it would look like
153 /* If we had a zero-length segment, it would look like 153 * the end of the data referred to by the "struct
154 * the end of the data referred to by the "struct 154 * lguest_dma", so make sure that doesn't happen. */
155 * lguest_dma", so make sure that doesn't happen. */ 155 BUG_ON(!bvec->bv_len);
156 BUG_ON(!bvec->bv_len); 156 /* Convert page & offset to a physical address */
157 /* Convert page & offset to a physical address */ 157 dma->addr[i] = page_to_phys(bvec->bv_page)
158 dma->addr[i] = page_to_phys(bvec->bv_page) 158 + bvec->bv_offset;
159 + bvec->bv_offset; 159 dma->len[i] = bvec->bv_len;
160 dma->len[i] = bvec->bv_len; 160 len += bvec->bv_len;
161 len += bvec->bv_len; 161 i++;
162 i++;
163 }
164 } 162 }
165 /* If the array isn't full, we mark the end with a 0 length */ 163 /* If the array isn't full, we mark the end with a 0 length */
166 if (i < LGUEST_MAX_DMA_SECTIONS) 164 if (i < LGUEST_MAX_DMA_SECTIONS)
diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 9f015fce4135..b9233a06934c 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -551,7 +551,7 @@ static int loop_make_request(struct request_queue *q, struct bio *old_bio)
551 551
552out: 552out:
553 spin_unlock_irq(&lo->lo_lock); 553 spin_unlock_irq(&lo->lo_lock);
554 bio_io_error(old_bio, old_bio->bi_size); 554 bio_io_error(old_bio);
555 return 0; 555 return 0;
556} 556}
557 557
@@ -580,7 +580,7 @@ static inline void loop_handle_bio(struct loop_device *lo, struct bio *bio)
580 bio_put(bio); 580 bio_put(bio);
581 } else { 581 } else {
582 int ret = do_bio_filebacked(lo, bio); 582 int ret = do_bio_filebacked(lo, bio);
583 bio_endio(bio, bio->bi_size, ret); 583 bio_endio(bio, ret);
584 } 584 }
585} 585}
586 586
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index be92c658f06e..be5ec3a9b1fc 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -180,7 +180,7 @@ static inline int sock_send_bvec(struct socket *sock, struct bio_vec *bvec,
180 180
181static int nbd_send_req(struct nbd_device *lo, struct request *req) 181static int nbd_send_req(struct nbd_device *lo, struct request *req)
182{ 182{
183 int result, i, flags; 183 int result, flags;
184 struct nbd_request request; 184 struct nbd_request request;
185 unsigned long size = req->nr_sectors << 9; 185 unsigned long size = req->nr_sectors << 9;
186 struct socket *sock = lo->sock; 186 struct socket *sock = lo->sock;
@@ -205,27 +205,23 @@ static int nbd_send_req(struct nbd_device *lo, struct request *req)
205 } 205 }
206 206
207 if (nbd_cmd(req) == NBD_CMD_WRITE) { 207 if (nbd_cmd(req) == NBD_CMD_WRITE) {
208 struct bio *bio; 208 struct req_iterator iter;
209 struct bio_vec *bvec;
209 /* 210 /*
210 * we are really probing at internals to determine 211 * we are really probing at internals to determine
211 * whether to set MSG_MORE or not... 212 * whether to set MSG_MORE or not...
212 */ 213 */
213 rq_for_each_bio(bio, req) { 214 rq_for_each_segment(bvec, req, iter) {
214 struct bio_vec *bvec; 215 flags = 0;
215 bio_for_each_segment(bvec, bio, i) { 216 if (!rq_iter_last(req, iter))
216 flags = 0; 217 flags = MSG_MORE;
217 if ((i < (bio->bi_vcnt - 1)) || bio->bi_next) 218 dprintk(DBG_TX, "%s: request %p: sending %d bytes data\n",
218 flags = MSG_MORE; 219 lo->disk->disk_name, req, bvec->bv_len);
219 dprintk(DBG_TX, "%s: request %p: sending %d bytes data\n", 220 result = sock_send_bvec(sock, bvec, flags);
220 lo->disk->disk_name, req, 221 if (result <= 0) {
221 bvec->bv_len); 222 printk(KERN_ERR "%s: Send data failed (result %d)\n",
222 result = sock_send_bvec(sock, bvec, flags); 223 lo->disk->disk_name, result);
223 if (result <= 0) { 224 goto error_out;
224 printk(KERN_ERR "%s: Send data failed (result %d)\n",
225 lo->disk->disk_name,
226 result);
227 goto error_out;
228 }
229 } 225 }
230 } 226 }
231 } 227 }
@@ -321,22 +317,19 @@ static struct request *nbd_read_stat(struct nbd_device *lo)
321 dprintk(DBG_RX, "%s: request %p: got reply\n", 317 dprintk(DBG_RX, "%s: request %p: got reply\n",
322 lo->disk->disk_name, req); 318 lo->disk->disk_name, req);
323 if (nbd_cmd(req) == NBD_CMD_READ) { 319 if (nbd_cmd(req) == NBD_CMD_READ) {
324 int i; 320 struct req_iterator iter;
325 struct bio *bio; 321 struct bio_vec *bvec;
326 rq_for_each_bio(bio, req) { 322
327 struct bio_vec *bvec; 323 rq_for_each_segment(bvec, req, iter) {
328 bio_for_each_segment(bvec, bio, i) { 324 result = sock_recv_bvec(sock, bvec);
329 result = sock_recv_bvec(sock, bvec); 325 if (result <= 0) {
330 if (result <= 0) { 326 printk(KERN_ERR "%s: Receive data failed (result %d)\n",
331 printk(KERN_ERR "%s: Receive data failed (result %d)\n", 327 lo->disk->disk_name, result);
332 lo->disk->disk_name, 328 req->errors++;
333 result); 329 return req;
334 req->errors++;
335 return req;
336 }
337 dprintk(DBG_RX, "%s: request %p: got %d bytes data\n",
338 lo->disk->disk_name, req, bvec->bv_len);
339 } 330 }
331 dprintk(DBG_RX, "%s: request %p: got %d bytes data\n",
332 lo->disk->disk_name, req, bvec->bv_len);
340 } 333 }
341 } 334 }
342 return req; 335 return req;
diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index fadbfd880bab..540bf3676985 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -1058,15 +1058,12 @@ static void pkt_make_local_copy(struct packet_data *pkt, struct bio_vec *bvec)
1058 } 1058 }
1059} 1059}
1060 1060
1061static int pkt_end_io_read(struct bio *bio, unsigned int bytes_done, int err) 1061static void pkt_end_io_read(struct bio *bio, int err)
1062{ 1062{
1063 struct packet_data *pkt = bio->bi_private; 1063 struct packet_data *pkt = bio->bi_private;
1064 struct pktcdvd_device *pd = pkt->pd; 1064 struct pktcdvd_device *pd = pkt->pd;
1065 BUG_ON(!pd); 1065 BUG_ON(!pd);
1066 1066
1067 if (bio->bi_size)
1068 return 1;
1069
1070 VPRINTK("pkt_end_io_read: bio=%p sec0=%llx sec=%llx err=%d\n", bio, 1067 VPRINTK("pkt_end_io_read: bio=%p sec0=%llx sec=%llx err=%d\n", bio,
1071 (unsigned long long)pkt->sector, (unsigned long long)bio->bi_sector, err); 1068 (unsigned long long)pkt->sector, (unsigned long long)bio->bi_sector, err);
1072 1069
@@ -1077,19 +1074,14 @@ static int pkt_end_io_read(struct bio *bio, unsigned int bytes_done, int err)
1077 wake_up(&pd->wqueue); 1074 wake_up(&pd->wqueue);
1078 } 1075 }
1079 pkt_bio_finished(pd); 1076 pkt_bio_finished(pd);
1080
1081 return 0;
1082} 1077}
1083 1078
1084static int pkt_end_io_packet_write(struct bio *bio, unsigned int bytes_done, int err) 1079static void pkt_end_io_packet_write(struct bio *bio, int err)
1085{ 1080{
1086 struct packet_data *pkt = bio->bi_private; 1081 struct packet_data *pkt = bio->bi_private;
1087 struct pktcdvd_device *pd = pkt->pd; 1082 struct pktcdvd_device *pd = pkt->pd;
1088 BUG_ON(!pd); 1083 BUG_ON(!pd);
1089 1084
1090 if (bio->bi_size)
1091 return 1;
1092
1093 VPRINTK("pkt_end_io_packet_write: id=%d, err=%d\n", pkt->id, err); 1085 VPRINTK("pkt_end_io_packet_write: id=%d, err=%d\n", pkt->id, err);
1094 1086
1095 pd->stats.pkt_ended++; 1087 pd->stats.pkt_ended++;
@@ -1098,7 +1090,6 @@ static int pkt_end_io_packet_write(struct bio *bio, unsigned int bytes_done, int
1098 atomic_dec(&pkt->io_wait); 1090 atomic_dec(&pkt->io_wait);
1099 atomic_inc(&pkt->run_sm); 1091 atomic_inc(&pkt->run_sm);
1100 wake_up(&pd->wqueue); 1092 wake_up(&pd->wqueue);
1101 return 0;
1102} 1093}
1103 1094
1104/* 1095/*
@@ -1470,7 +1461,7 @@ static void pkt_finish_packet(struct packet_data *pkt, int uptodate)
1470 while (bio) { 1461 while (bio) {
1471 next = bio->bi_next; 1462 next = bio->bi_next;
1472 bio->bi_next = NULL; 1463 bio->bi_next = NULL;
1473 bio_endio(bio, bio->bi_size, uptodate ? 0 : -EIO); 1464 bio_endio(bio, uptodate ? 0 : -EIO);
1474 bio = next; 1465 bio = next;
1475 } 1466 }
1476 pkt->orig_bios = pkt->orig_bios_tail = NULL; 1467 pkt->orig_bios = pkt->orig_bios_tail = NULL;
@@ -2462,19 +2453,15 @@ static int pkt_close(struct inode *inode, struct file *file)
2462} 2453}
2463 2454
2464 2455
2465static int pkt_end_io_read_cloned(struct bio *bio, unsigned int bytes_done, int err) 2456static void pkt_end_io_read_cloned(struct bio *bio, int err)
2466{ 2457{
2467 struct packet_stacked_data *psd = bio->bi_private; 2458 struct packet_stacked_data *psd = bio->bi_private;
2468 struct pktcdvd_device *pd = psd->pd; 2459 struct pktcdvd_device *pd = psd->pd;
2469 2460
2470 if (bio->bi_size)
2471 return 1;
2472
2473 bio_put(bio); 2461 bio_put(bio);
2474 bio_endio(psd->bio, psd->bio->bi_size, err); 2462 bio_endio(psd->bio, err);
2475 mempool_free(psd, psd_pool); 2463 mempool_free(psd, psd_pool);
2476 pkt_bio_finished(pd); 2464 pkt_bio_finished(pd);
2477 return 0;
2478} 2465}
2479 2466
2480static int pkt_make_request(struct request_queue *q, struct bio *bio) 2467static int pkt_make_request(struct request_queue *q, struct bio *bio)
@@ -2620,7 +2607,7 @@ static int pkt_make_request(struct request_queue *q, struct bio *bio)
2620 } 2607 }
2621 return 0; 2608 return 0;
2622end_io: 2609end_io:
2623 bio_io_error(bio, bio->bi_size); 2610 bio_io_error(bio);
2624 return 0; 2611 return 0;
2625} 2612}
2626 2613
diff --git a/drivers/block/ps3disk.c b/drivers/block/ps3disk.c
index aa8b890c80d7..06d0552cf49c 100644
--- a/drivers/block/ps3disk.c
+++ b/drivers/block/ps3disk.c
@@ -91,30 +91,29 @@ static void ps3disk_scatter_gather(struct ps3_storage_device *dev,
91 struct request *req, int gather) 91 struct request *req, int gather)
92{ 92{
93 unsigned int offset = 0; 93 unsigned int offset = 0;
94 struct bio *bio; 94 struct req_iterator iter;
95 sector_t sector;
96 struct bio_vec *bvec; 95 struct bio_vec *bvec;
97 unsigned int i = 0, j; 96 unsigned int i = 0;
98 size_t size; 97 size_t size;
99 void *buf; 98 void *buf;
100 99
101 rq_for_each_bio(bio, req) { 100 rq_for_each_segment(bvec, req, iter) {
102 sector = bio->bi_sector; 101 unsigned long flags;
103 dev_dbg(&dev->sbd.core, 102 dev_dbg(&dev->sbd.core,
104 "%s:%u: bio %u: %u segs %u sectors from %lu\n", 103 "%s:%u: bio %u: %u segs %u sectors from %lu\n",
105 __func__, __LINE__, i, bio_segments(bio), 104 __func__, __LINE__, i, bio_segments(iter.bio),
106 bio_sectors(bio), sector); 105 bio_sectors(iter.bio),
107 bio_for_each_segment(bvec, bio, j) { 106 (unsigned long)iter.bio->bi_sector);
108 size = bvec->bv_len; 107
109 buf = __bio_kmap_atomic(bio, j, KM_IRQ0); 108 size = bvec->bv_len;
110 if (gather) 109 buf = bvec_kmap_irq(bvec, &flags);
111 memcpy(dev->bounce_buf+offset, buf, size); 110 if (gather)
112 else 111 memcpy(dev->bounce_buf+offset, buf, size);
113 memcpy(buf, dev->bounce_buf+offset, size); 112 else
114 offset += size; 113 memcpy(buf, dev->bounce_buf+offset, size);
115 flush_kernel_dcache_page(bio_iovec_idx(bio, j)->bv_page); 114 offset += size;
116 __bio_kunmap_atomic(bio, KM_IRQ0); 115 flush_kernel_dcache_page(bvec->bv_page);
117 } 116 bvec_kunmap_irq(bvec, &flags);
118 i++; 117 i++;
119 } 118 }
120} 119}
@@ -130,12 +129,13 @@ static int ps3disk_submit_request_sg(struct ps3_storage_device *dev,
130 129
131#ifdef DEBUG 130#ifdef DEBUG
132 unsigned int n = 0; 131 unsigned int n = 0;
133 struct bio *bio; 132 struct bio_vec *bv;
133 struct req_iterator iter;
134 134
135 rq_for_each_bio(bio, req) 135 rq_for_each_segment(bv, req, iter)
136 n++; 136 n++;
137 dev_dbg(&dev->sbd.core, 137 dev_dbg(&dev->sbd.core,
138 "%s:%u: %s req has %u bios for %lu sectors %lu hard sectors\n", 138 "%s:%u: %s req has %u bvecs for %lu sectors %lu hard sectors\n",
139 __func__, __LINE__, op, n, req->nr_sectors, 139 __func__, __LINE__, op, n, req->nr_sectors,
140 req->hard_nr_sectors); 140 req->hard_nr_sectors);
141#endif 141#endif
diff --git a/drivers/block/rd.c b/drivers/block/rd.c
index 65150b548f3a..701ea77f62e9 100644
--- a/drivers/block/rd.c
+++ b/drivers/block/rd.c
@@ -287,10 +287,10 @@ static int rd_make_request(struct request_queue *q, struct bio *bio)
287 if (ret) 287 if (ret)
288 goto fail; 288 goto fail;
289 289
290 bio_endio(bio, bio->bi_size, 0); 290 bio_endio(bio, 0);
291 return 0; 291 return 0;
292fail: 292fail:
293 bio_io_error(bio, bio->bi_size); 293 bio_io_error(bio);
294 return 0; 294 return 0;
295} 295}
296 296
diff --git a/drivers/block/umem.c b/drivers/block/umem.c
index 6b7c02d6360d..99806f9ee4ce 100644
--- a/drivers/block/umem.c
+++ b/drivers/block/umem.c
@@ -52,7 +52,7 @@
52#include <linux/fcntl.h> /* O_ACCMODE */ 52#include <linux/fcntl.h> /* O_ACCMODE */
53#include <linux/hdreg.h> /* HDIO_GETGEO */ 53#include <linux/hdreg.h> /* HDIO_GETGEO */
54 54
55#include <linux/umem.h> 55#include "umem.h"
56 56
57#include <asm/uaccess.h> 57#include <asm/uaccess.h>
58#include <asm/io.h> 58#include <asm/io.h>
@@ -67,9 +67,10 @@
67 * Version Information 67 * Version Information
68 */ 68 */
69 69
70#define DRIVER_VERSION "v2.3" 70#define DRIVER_NAME "umem"
71#define DRIVER_AUTHOR "San Mehat, Johannes Erdfelt, NeilBrown" 71#define DRIVER_VERSION "v2.3"
72#define DRIVER_DESC "Micro Memory(tm) PCI memory board block driver" 72#define DRIVER_AUTHOR "San Mehat, Johannes Erdfelt, NeilBrown"
73#define DRIVER_DESC "Micro Memory(tm) PCI memory board block driver"
73 74
74static int debug; 75static int debug;
75/* #define HW_TRACE(x) writeb(x,cards[0].csr_remap + MEMCTRLSTATUS_MAGIC) */ 76/* #define HW_TRACE(x) writeb(x,cards[0].csr_remap + MEMCTRLSTATUS_MAGIC) */
@@ -97,15 +98,9 @@ static int major_nr;
97#include <linux/blkpg.h> 98#include <linux/blkpg.h>
98 99
99struct cardinfo { 100struct cardinfo {
100 int card_number;
101 struct pci_dev *dev; 101 struct pci_dev *dev;
102 102
103 int irq;
104
105 unsigned long csr_base;
106 unsigned char __iomem *csr_remap; 103 unsigned char __iomem *csr_remap;
107 unsigned long csr_len;
108 unsigned int win_size; /* PCI window size */
109 unsigned int mm_size; /* size in kbytes */ 104 unsigned int mm_size; /* size in kbytes */
110 105
111 unsigned int init_size; /* initial segment, in sectors, 106 unsigned int init_size; /* initial segment, in sectors,
@@ -113,6 +108,8 @@ struct cardinfo {
113 * have been written 108 * have been written
114 */ 109 */
115 struct bio *bio, *currentbio, **biotail; 110 struct bio *bio, *currentbio, **biotail;
111 int current_idx;
112 sector_t current_sector;
116 113
117 struct request_queue *queue; 114 struct request_queue *queue;
118 115
@@ -121,6 +118,7 @@ struct cardinfo {
121 struct mm_dma_desc *desc; 118 struct mm_dma_desc *desc;
122 int cnt, headcnt; 119 int cnt, headcnt;
123 struct bio *bio, **biotail; 120 struct bio *bio, **biotail;
121 int idx;
124 } mm_pages[2]; 122 } mm_pages[2];
125#define DESC_PER_PAGE ((PAGE_SIZE*2)/sizeof(struct mm_dma_desc)) 123#define DESC_PER_PAGE ((PAGE_SIZE*2)/sizeof(struct mm_dma_desc))
126 124
@@ -233,7 +231,7 @@ static void dump_regs(struct cardinfo *card)
233*/ 231*/
234static void dump_dmastat(struct cardinfo *card, unsigned int dmastat) 232static void dump_dmastat(struct cardinfo *card, unsigned int dmastat)
235{ 233{
236 printk(KERN_DEBUG "MM%d*: DMAstat - ", card->card_number); 234 dev_printk(KERN_DEBUG, &card->dev->dev, "DMAstat - ");
237 if (dmastat & DMASCR_ANY_ERR) 235 if (dmastat & DMASCR_ANY_ERR)
238 printk("ANY_ERR "); 236 printk("ANY_ERR ");
239 if (dmastat & DMASCR_MBE_ERR) 237 if (dmastat & DMASCR_MBE_ERR)
@@ -295,7 +293,7 @@ static void mm_start_io(struct cardinfo *card)
295 desc->control_bits &= ~cpu_to_le32(DMASCR_CHAIN_EN); 293 desc->control_bits &= ~cpu_to_le32(DMASCR_CHAIN_EN);
296 desc->sem_control_bits = desc->control_bits; 294 desc->sem_control_bits = desc->control_bits;
297 295
298 296
299 if (debug & DEBUG_LED_ON_TRANSFER) 297 if (debug & DEBUG_LED_ON_TRANSFER)
300 set_led(card, LED_REMOVE, LED_ON); 298 set_led(card, LED_REMOVE, LED_ON);
301 299
@@ -329,7 +327,7 @@ static int add_bio(struct cardinfo *card);
329 327
330static void activate(struct cardinfo *card) 328static void activate(struct cardinfo *card)
331{ 329{
332 /* if No page is Active, and Ready is 330 /* if No page is Active, and Ready is
333 * not empty, then switch Ready page 331 * not empty, then switch Ready page
334 * to active and start IO. 332 * to active and start IO.
335 * Then add any bh's that are available to Ready 333 * Then add any bh's that are available to Ready
@@ -368,7 +366,7 @@ static void mm_unplug_device(struct request_queue *q)
368 spin_unlock_irqrestore(&card->lock, flags); 366 spin_unlock_irqrestore(&card->lock, flags);
369} 367}
370 368
371/* 369/*
372 * If there is room on Ready page, take 370 * If there is room on Ready page, take
373 * one bh off list and add it. 371 * one bh off list and add it.
374 * return 1 if there was room, else 0. 372 * return 1 if there was room, else 0.
@@ -380,12 +378,16 @@ static int add_bio(struct cardinfo *card)
380 dma_addr_t dma_handle; 378 dma_addr_t dma_handle;
381 int offset; 379 int offset;
382 struct bio *bio; 380 struct bio *bio;
381 struct bio_vec *vec;
382 int idx;
383 int rw; 383 int rw;
384 int len; 384 int len;
385 385
386 bio = card->currentbio; 386 bio = card->currentbio;
387 if (!bio && card->bio) { 387 if (!bio && card->bio) {
388 card->currentbio = card->bio; 388 card->currentbio = card->bio;
389 card->current_idx = card->bio->bi_idx;
390 card->current_sector = card->bio->bi_sector;
389 card->bio = card->bio->bi_next; 391 card->bio = card->bio->bi_next;
390 if (card->bio == NULL) 392 if (card->bio == NULL)
391 card->biotail = &card->bio; 393 card->biotail = &card->bio;
@@ -394,15 +396,17 @@ static int add_bio(struct cardinfo *card)
394 } 396 }
395 if (!bio) 397 if (!bio)
396 return 0; 398 return 0;
399 idx = card->current_idx;
397 400
398 rw = bio_rw(bio); 401 rw = bio_rw(bio);
399 if (card->mm_pages[card->Ready].cnt >= DESC_PER_PAGE) 402 if (card->mm_pages[card->Ready].cnt >= DESC_PER_PAGE)
400 return 0; 403 return 0;
401 404
402 len = bio_iovec(bio)->bv_len; 405 vec = bio_iovec_idx(bio, idx);
403 dma_handle = pci_map_page(card->dev, 406 len = vec->bv_len;
404 bio_page(bio), 407 dma_handle = pci_map_page(card->dev,
405 bio_offset(bio), 408 vec->bv_page,
409 vec->bv_offset,
406 len, 410 len,
407 (rw==READ) ? 411 (rw==READ) ?
408 PCI_DMA_FROMDEVICE : PCI_DMA_TODEVICE); 412 PCI_DMA_FROMDEVICE : PCI_DMA_TODEVICE);
@@ -410,6 +414,8 @@ static int add_bio(struct cardinfo *card)
410 p = &card->mm_pages[card->Ready]; 414 p = &card->mm_pages[card->Ready];
411 desc = &p->desc[p->cnt]; 415 desc = &p->desc[p->cnt];
412 p->cnt++; 416 p->cnt++;
417 if (p->bio == NULL)
418 p->idx = idx;
413 if ((p->biotail) != &bio->bi_next) { 419 if ((p->biotail) != &bio->bi_next) {
414 *(p->biotail) = bio; 420 *(p->biotail) = bio;
415 p->biotail = &(bio->bi_next); 421 p->biotail = &(bio->bi_next);
@@ -419,7 +425,7 @@ static int add_bio(struct cardinfo *card)
419 desc->data_dma_handle = dma_handle; 425 desc->data_dma_handle = dma_handle;
420 426
421 desc->pci_addr = cpu_to_le64((u64)desc->data_dma_handle); 427 desc->pci_addr = cpu_to_le64((u64)desc->data_dma_handle);
422 desc->local_addr= cpu_to_le64(bio->bi_sector << 9); 428 desc->local_addr = cpu_to_le64(card->current_sector << 9);
423 desc->transfer_size = cpu_to_le32(len); 429 desc->transfer_size = cpu_to_le32(len);
424 offset = ( ((char*)&desc->sem_control_bits) - ((char*)p->desc)); 430 offset = ( ((char*)&desc->sem_control_bits) - ((char*)p->desc));
425 desc->sem_addr = cpu_to_le64((u64)(p->page_dma+offset)); 431 desc->sem_addr = cpu_to_le64((u64)(p->page_dma+offset));
@@ -435,10 +441,10 @@ static int add_bio(struct cardinfo *card)
435 desc->control_bits |= cpu_to_le32(DMASCR_TRANSFER_READ); 441 desc->control_bits |= cpu_to_le32(DMASCR_TRANSFER_READ);
436 desc->sem_control_bits = desc->control_bits; 442 desc->sem_control_bits = desc->control_bits;
437 443
438 bio->bi_sector += (len>>9); 444 card->current_sector += (len >> 9);
439 bio->bi_size -= len; 445 idx++;
440 bio->bi_idx++; 446 card->current_idx = idx;
441 if (bio->bi_idx >= bio->bi_vcnt) 447 if (idx >= bio->bi_vcnt)
442 card->currentbio = NULL; 448 card->currentbio = NULL;
443 449
444 return 1; 450 return 1;
@@ -461,7 +467,7 @@ static void process_page(unsigned long data)
461 if (card->Active < 0) 467 if (card->Active < 0)
462 goto out_unlock; 468 goto out_unlock;
463 page = &card->mm_pages[card->Active]; 469 page = &card->mm_pages[card->Active];
464 470
465 while (page->headcnt < page->cnt) { 471 while (page->headcnt < page->cnt) {
466 struct bio *bio = page->bio; 472 struct bio *bio = page->bio;
467 struct mm_dma_desc *desc = &page->desc[page->headcnt]; 473 struct mm_dma_desc *desc = &page->desc[page->headcnt];
@@ -471,32 +477,34 @@ static void process_page(unsigned long data)
471 477
472 if (!(control & DMASCR_DMA_COMPLETE)) { 478 if (!(control & DMASCR_DMA_COMPLETE)) {
473 control = dma_status; 479 control = dma_status;
474 last=1; 480 last=1;
475 } 481 }
476 page->headcnt++; 482 page->headcnt++;
477 idx = bio->bi_phys_segments; 483 idx = page->idx;
478 bio->bi_phys_segments++; 484 page->idx++;
479 if (bio->bi_phys_segments >= bio->bi_vcnt) 485 if (page->idx >= bio->bi_vcnt) {
480 page->bio = bio->bi_next; 486 page->bio = bio->bi_next;
487 page->idx = page->bio->bi_idx;
488 }
481 489
482 pci_unmap_page(card->dev, desc->data_dma_handle, 490 pci_unmap_page(card->dev, desc->data_dma_handle,
483 bio_iovec_idx(bio,idx)->bv_len, 491 bio_iovec_idx(bio,idx)->bv_len,
484 (control& DMASCR_TRANSFER_READ) ? 492 (control& DMASCR_TRANSFER_READ) ?
485 PCI_DMA_TODEVICE : PCI_DMA_FROMDEVICE); 493 PCI_DMA_TODEVICE : PCI_DMA_FROMDEVICE);
486 if (control & DMASCR_HARD_ERROR) { 494 if (control & DMASCR_HARD_ERROR) {
487 /* error */ 495 /* error */
488 clear_bit(BIO_UPTODATE, &bio->bi_flags); 496 clear_bit(BIO_UPTODATE, &bio->bi_flags);
489 printk(KERN_WARNING "MM%d: I/O error on sector %d/%d\n", 497 dev_printk(KERN_WARNING, &card->dev->dev,
490 card->card_number, 498 "I/O error on sector %d/%d\n",
491 le32_to_cpu(desc->local_addr)>>9, 499 le32_to_cpu(desc->local_addr)>>9,
492 le32_to_cpu(desc->transfer_size)); 500 le32_to_cpu(desc->transfer_size));
493 dump_dmastat(card, control); 501 dump_dmastat(card, control);
494 } else if (test_bit(BIO_RW, &bio->bi_rw) && 502 } else if (test_bit(BIO_RW, &bio->bi_rw) &&
495 le32_to_cpu(desc->local_addr)>>9 == card->init_size) { 503 le32_to_cpu(desc->local_addr)>>9 == card->init_size) {
496 card->init_size += le32_to_cpu(desc->transfer_size)>>9; 504 card->init_size += le32_to_cpu(desc->transfer_size)>>9;
497 if (card->init_size>>1 >= card->mm_size) { 505 if (card->init_size>>1 >= card->mm_size) {
498 printk(KERN_INFO "MM%d: memory now initialised\n", 506 dev_printk(KERN_INFO, &card->dev->dev,
499 card->card_number); 507 "memory now initialised\n");
500 set_userbit(card, MEMORY_INITIALIZED, 1); 508 set_userbit(card, MEMORY_INITIALIZED, 1);
501 } 509 }
502 } 510 }
@@ -532,7 +540,7 @@ static void process_page(unsigned long data)
532 540
533 return_bio = bio->bi_next; 541 return_bio = bio->bi_next;
534 bio->bi_next = NULL; 542 bio->bi_next = NULL;
535 bio_endio(bio, bio->bi_size, 0); 543 bio_endio(bio, 0);
536 } 544 }
537} 545}
538 546
@@ -547,7 +555,6 @@ static int mm_make_request(struct request_queue *q, struct bio *bio)
547 pr_debug("mm_make_request %llu %u\n", 555 pr_debug("mm_make_request %llu %u\n",
548 (unsigned long long)bio->bi_sector, bio->bi_size); 556 (unsigned long long)bio->bi_sector, bio->bi_size);
549 557
550 bio->bi_phys_segments = bio->bi_idx; /* count of completed segments*/
551 spin_lock_irq(&card->lock); 558 spin_lock_irq(&card->lock);
552 *card->biotail = bio; 559 *card->biotail = bio;
553 bio->bi_next = NULL; 560 bio->bi_next = NULL;
@@ -585,7 +592,7 @@ HW_TRACE(0x30);
585 else 592 else
586 writeb((DMASCR_DMA_COMPLETE|DMASCR_CHAIN_COMPLETE) >> 16, 593 writeb((DMASCR_DMA_COMPLETE|DMASCR_CHAIN_COMPLETE) >> 16,
587 card->csr_remap+ DMA_STATUS_CTRL + 2); 594 card->csr_remap+ DMA_STATUS_CTRL + 2);
588 595
589 /* log errors and clear interrupt status */ 596 /* log errors and clear interrupt status */
590 if (dma_status & DMASCR_ANY_ERR) { 597 if (dma_status & DMASCR_ANY_ERR) {
591 unsigned int data_log1, data_log2; 598 unsigned int data_log1, data_log2;
@@ -606,46 +613,51 @@ HW_TRACE(0x30);
606 dump_dmastat(card, dma_status); 613 dump_dmastat(card, dma_status);
607 614
608 if (stat & 0x01) 615 if (stat & 0x01)
609 printk(KERN_ERR "MM%d*: Memory access error detected (err count %d)\n", 616 dev_printk(KERN_ERR, &card->dev->dev,
610 card->card_number, count); 617 "Memory access error detected (err count %d)\n",
618 count);
611 if (stat & 0x02) 619 if (stat & 0x02)
612 printk(KERN_ERR "MM%d*: Multi-bit EDC error\n", 620 dev_printk(KERN_ERR, &card->dev->dev,
613 card->card_number); 621 "Multi-bit EDC error\n");
614 622
615 printk(KERN_ERR "MM%d*: Fault Address 0x%02x%08x, Fault Data 0x%08x%08x\n", 623 dev_printk(KERN_ERR, &card->dev->dev,
616 card->card_number, addr_log2, addr_log1, data_log2, data_log1); 624 "Fault Address 0x%02x%08x, Fault Data 0x%08x%08x\n",
617 printk(KERN_ERR "MM%d*: Fault Check 0x%02x, Fault Syndrome 0x%02x\n", 625 addr_log2, addr_log1, data_log2, data_log1);
618 card->card_number, check, syndrome); 626 dev_printk(KERN_ERR, &card->dev->dev,
627 "Fault Check 0x%02x, Fault Syndrome 0x%02x\n",
628 check, syndrome);
619 629
620 writeb(0, card->csr_remap + ERROR_COUNT); 630 writeb(0, card->csr_remap + ERROR_COUNT);
621 } 631 }
622 632
623 if (dma_status & DMASCR_PARITY_ERR_REP) { 633 if (dma_status & DMASCR_PARITY_ERR_REP) {
624 printk(KERN_ERR "MM%d*: PARITY ERROR REPORTED\n", card->card_number); 634 dev_printk(KERN_ERR, &card->dev->dev,
635 "PARITY ERROR REPORTED\n");
625 pci_read_config_word(card->dev, PCI_STATUS, &cfg_status); 636 pci_read_config_word(card->dev, PCI_STATUS, &cfg_status);
626 pci_write_config_word(card->dev, PCI_STATUS, cfg_status); 637 pci_write_config_word(card->dev, PCI_STATUS, cfg_status);
627 } 638 }
628 639
629 if (dma_status & DMASCR_PARITY_ERR_DET) { 640 if (dma_status & DMASCR_PARITY_ERR_DET) {
630 printk(KERN_ERR "MM%d*: PARITY ERROR DETECTED\n", card->card_number); 641 dev_printk(KERN_ERR, &card->dev->dev,
642 "PARITY ERROR DETECTED\n");
631 pci_read_config_word(card->dev, PCI_STATUS, &cfg_status); 643 pci_read_config_word(card->dev, PCI_STATUS, &cfg_status);
632 pci_write_config_word(card->dev, PCI_STATUS, cfg_status); 644 pci_write_config_word(card->dev, PCI_STATUS, cfg_status);
633 } 645 }
634 646
635 if (dma_status & DMASCR_SYSTEM_ERR_SIG) { 647 if (dma_status & DMASCR_SYSTEM_ERR_SIG) {
636 printk(KERN_ERR "MM%d*: SYSTEM ERROR\n", card->card_number); 648 dev_printk(KERN_ERR, &card->dev->dev, "SYSTEM ERROR\n");
637 pci_read_config_word(card->dev, PCI_STATUS, &cfg_status); 649 pci_read_config_word(card->dev, PCI_STATUS, &cfg_status);
638 pci_write_config_word(card->dev, PCI_STATUS, cfg_status); 650 pci_write_config_word(card->dev, PCI_STATUS, cfg_status);
639 } 651 }
640 652
641 if (dma_status & DMASCR_TARGET_ABT) { 653 if (dma_status & DMASCR_TARGET_ABT) {
642 printk(KERN_ERR "MM%d*: TARGET ABORT\n", card->card_number); 654 dev_printk(KERN_ERR, &card->dev->dev, "TARGET ABORT\n");
643 pci_read_config_word(card->dev, PCI_STATUS, &cfg_status); 655 pci_read_config_word(card->dev, PCI_STATUS, &cfg_status);
644 pci_write_config_word(card->dev, PCI_STATUS, cfg_status); 656 pci_write_config_word(card->dev, PCI_STATUS, cfg_status);
645 } 657 }
646 658
647 if (dma_status & DMASCR_MASTER_ABT) { 659 if (dma_status & DMASCR_MASTER_ABT) {
648 printk(KERN_ERR "MM%d*: MASTER ABORT\n", card->card_number); 660 dev_printk(KERN_ERR, &card->dev->dev, "MASTER ABORT\n");
649 pci_read_config_word(card->dev, PCI_STATUS, &cfg_status); 661 pci_read_config_word(card->dev, PCI_STATUS, &cfg_status);
650 pci_write_config_word(card->dev, PCI_STATUS, cfg_status); 662 pci_write_config_word(card->dev, PCI_STATUS, cfg_status);
651 } 663 }
@@ -656,7 +668,7 @@ HW_TRACE(0x30);
656 668
657HW_TRACE(0x36); 669HW_TRACE(0x36);
658 670
659 return IRQ_HANDLED; 671 return IRQ_HANDLED;
660} 672}
661/* 673/*
662----------------------------------------------------------------------------------- 674-----------------------------------------------------------------------------------
@@ -696,20 +708,20 @@ static int check_battery(struct cardinfo *card, int battery, int status)
696 card->battery[battery].last_change = jiffies; 708 card->battery[battery].last_change = jiffies;
697 709
698 if (card->battery[battery].good) { 710 if (card->battery[battery].good) {
699 printk(KERN_ERR "MM%d: Battery %d now good\n", 711 dev_printk(KERN_ERR, &card->dev->dev,
700 card->card_number, battery + 1); 712 "Battery %d now good\n", battery + 1);
701 card->battery[battery].warned = 0; 713 card->battery[battery].warned = 0;
702 } else 714 } else
703 printk(KERN_ERR "MM%d: Battery %d now FAILED\n", 715 dev_printk(KERN_ERR, &card->dev->dev,
704 card->card_number, battery + 1); 716 "Battery %d now FAILED\n", battery + 1);
705 717
706 return 1; 718 return 1;
707 } else if (!card->battery[battery].good && 719 } else if (!card->battery[battery].good &&
708 !card->battery[battery].warned && 720 !card->battery[battery].warned &&
709 time_after_eq(jiffies, card->battery[battery].last_change + 721 time_after_eq(jiffies, card->battery[battery].last_change +
710 (HZ * 60 * 60 * 5))) { 722 (HZ * 60 * 60 * 5))) {
711 printk(KERN_ERR "MM%d: Battery %d still FAILED after 5 hours\n", 723 dev_printk(KERN_ERR, &card->dev->dev,
712 card->card_number, battery + 1); 724 "Battery %d still FAILED after 5 hours\n", battery + 1);
713 card->battery[battery].warned = 1; 725 card->battery[battery].warned = 1;
714 726
715 return 1; 727 return 1;
@@ -733,8 +745,8 @@ static void check_batteries(struct cardinfo *card)
733 745
734 status = readb(card->csr_remap + MEMCTRLSTATUS_BATTERY); 746 status = readb(card->csr_remap + MEMCTRLSTATUS_BATTERY);
735 if (debug & DEBUG_BATTERY_POLLING) 747 if (debug & DEBUG_BATTERY_POLLING)
736 printk(KERN_DEBUG "MM%d: checking battery status, 1 = %s, 2 = %s\n", 748 dev_printk(KERN_DEBUG, &card->dev->dev,
737 card->card_number, 749 "checking battery status, 1 = %s, 2 = %s\n",
738 (status & BATTERY_1_FAILURE) ? "FAILURE" : "OK", 750 (status & BATTERY_1_FAILURE) ? "FAILURE" : "OK",
739 (status & BATTERY_2_FAILURE) ? "FAILURE" : "OK"); 751 (status & BATTERY_2_FAILURE) ? "FAILURE" : "OK");
740 752
@@ -749,7 +761,7 @@ static void check_all_batteries(unsigned long ptr)
749{ 761{
750 int i; 762 int i;
751 763
752 for (i = 0; i < num_cards; i++) 764 for (i = 0; i < num_cards; i++)
753 if (!(cards[i].flags & UM_FLAG_NO_BATT)) { 765 if (!(cards[i].flags & UM_FLAG_NO_BATT)) {
754 struct cardinfo *card = &cards[i]; 766 struct cardinfo *card = &cards[i];
755 spin_lock_bh(&card->lock); 767 spin_lock_bh(&card->lock);
@@ -853,45 +865,56 @@ static int __devinit mm_pci_probe(struct pci_dev *dev, const struct pci_device_i
853 unsigned char mem_present; 865 unsigned char mem_present;
854 unsigned char batt_status; 866 unsigned char batt_status;
855 unsigned int saved_bar, data; 867 unsigned int saved_bar, data;
868 unsigned long csr_base;
869 unsigned long csr_len;
856 int magic_number; 870 int magic_number;
871 static int printed_version;
857 872
858 if (pci_enable_device(dev) < 0) 873 if (!printed_version++)
859 return -ENODEV; 874 printk(KERN_INFO DRIVER_VERSION " : " DRIVER_DESC "\n");
875
876 ret = pci_enable_device(dev);
877 if (ret)
878 return ret;
860 879
861 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0xF8); 880 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0xF8);
862 pci_set_master(dev); 881 pci_set_master(dev);
863 882
864 card->dev = dev; 883 card->dev = dev;
865 card->card_number = num_cards;
866 884
867 card->csr_base = pci_resource_start(dev, 0); 885 csr_base = pci_resource_start(dev, 0);
868 card->csr_len = pci_resource_len(dev, 0); 886 csr_len = pci_resource_len(dev, 0);
887 if (!csr_base || !csr_len)
888 return -ENODEV;
869 889
870 printk(KERN_INFO "Micro Memory(tm) controller #%d found at %02x:%02x (PCI Mem Module (Battery Backup))\n", 890 dev_printk(KERN_INFO, &dev->dev,
871 card->card_number, dev->bus->number, dev->devfn); 891 "Micro Memory(tm) controller found (PCI Mem Module (Battery Backup))\n");
872 892
873 if (pci_set_dma_mask(dev, DMA_64BIT_MASK) && 893 if (pci_set_dma_mask(dev, DMA_64BIT_MASK) &&
874 pci_set_dma_mask(dev, DMA_32BIT_MASK)) { 894 pci_set_dma_mask(dev, DMA_32BIT_MASK)) {
875 printk(KERN_WARNING "MM%d: NO suitable DMA found\n",num_cards); 895 dev_printk(KERN_WARNING, &dev->dev, "NO suitable DMA found\n");
876 return -ENOMEM; 896 return -ENOMEM;
877 } 897 }
878 if (!request_mem_region(card->csr_base, card->csr_len, "Micro Memory")) {
879 printk(KERN_ERR "MM%d: Unable to request memory region\n", card->card_number);
880 ret = -ENOMEM;
881 898
899 ret = pci_request_regions(dev, DRIVER_NAME);
900 if (ret) {
901 dev_printk(KERN_ERR, &card->dev->dev,
902 "Unable to request memory region\n");
882 goto failed_req_csr; 903 goto failed_req_csr;
883 } 904 }
884 905
885 card->csr_remap = ioremap_nocache(card->csr_base, card->csr_len); 906 card->csr_remap = ioremap_nocache(csr_base, csr_len);
886 if (!card->csr_remap) { 907 if (!card->csr_remap) {
887 printk(KERN_ERR "MM%d: Unable to remap memory region\n", card->card_number); 908 dev_printk(KERN_ERR, &card->dev->dev,
909 "Unable to remap memory region\n");
888 ret = -ENOMEM; 910 ret = -ENOMEM;
889 911
890 goto failed_remap_csr; 912 goto failed_remap_csr;
891 } 913 }
892 914
893 printk(KERN_INFO "MM%d: CSR 0x%08lx -> 0x%p (0x%lx)\n", card->card_number, 915 dev_printk(KERN_INFO, &card->dev->dev,
894 card->csr_base, card->csr_remap, card->csr_len); 916 "CSR 0x%08lx -> 0x%p (0x%lx)\n",
917 csr_base, card->csr_remap, csr_len);
895 918
896 switch(card->dev->device) { 919 switch(card->dev->device) {
897 case 0x5415: 920 case 0x5415:
@@ -915,7 +938,7 @@ static int __devinit mm_pci_probe(struct pci_dev *dev, const struct pci_device_i
915 } 938 }
916 939
917 if (readb(card->csr_remap + MEMCTRLSTATUS_MAGIC) != magic_number) { 940 if (readb(card->csr_remap + MEMCTRLSTATUS_MAGIC) != magic_number) {
918 printk(KERN_ERR "MM%d: Magic number invalid\n", card->card_number); 941 dev_printk(KERN_ERR, &card->dev->dev, "Magic number invalid\n");
919 ret = -ENOMEM; 942 ret = -ENOMEM;
920 goto failed_magic; 943 goto failed_magic;
921 } 944 }
@@ -928,7 +951,7 @@ static int __devinit mm_pci_probe(struct pci_dev *dev, const struct pci_device_i
928 &card->mm_pages[1].page_dma); 951 &card->mm_pages[1].page_dma);
929 if (card->mm_pages[0].desc == NULL || 952 if (card->mm_pages[0].desc == NULL ||
930 card->mm_pages[1].desc == NULL) { 953 card->mm_pages[1].desc == NULL) {
931 printk(KERN_ERR "MM%d: alloc failed\n", card->card_number); 954 dev_printk(KERN_ERR, &card->dev->dev, "alloc failed\n");
932 goto failed_alloc; 955 goto failed_alloc;
933 } 956 }
934 reset_page(&card->mm_pages[0]); 957 reset_page(&card->mm_pages[0]);
@@ -949,7 +972,7 @@ static int __devinit mm_pci_probe(struct pci_dev *dev, const struct pci_device_i
949 tasklet_init(&card->tasklet, process_page, (unsigned long)card); 972 tasklet_init(&card->tasklet, process_page, (unsigned long)card);
950 973
951 card->check_batteries = 0; 974 card->check_batteries = 0;
952 975
953 mem_present = readb(card->csr_remap + MEMCTRLSTATUS_MEMORY); 976 mem_present = readb(card->csr_remap + MEMCTRLSTATUS_MEMORY);
954 switch (mem_present) { 977 switch (mem_present) {
955 case MEM_128_MB: 978 case MEM_128_MB:
@@ -982,12 +1005,13 @@ static int __devinit mm_pci_probe(struct pci_dev *dev, const struct pci_device_i
982 card->battery[1].good = !(batt_status & BATTERY_2_FAILURE); 1005 card->battery[1].good = !(batt_status & BATTERY_2_FAILURE);
983 card->battery[0].last_change = card->battery[1].last_change = jiffies; 1006 card->battery[0].last_change = card->battery[1].last_change = jiffies;
984 1007
985 if (card->flags & UM_FLAG_NO_BATT) 1008 if (card->flags & UM_FLAG_NO_BATT)
986 printk(KERN_INFO "MM%d: Size %d KB\n", 1009 dev_printk(KERN_INFO, &card->dev->dev,
987 card->card_number, card->mm_size); 1010 "Size %d KB\n", card->mm_size);
988 else { 1011 else {
989 printk(KERN_INFO "MM%d: Size %d KB, Battery 1 %s (%s), Battery 2 %s (%s)\n", 1012 dev_printk(KERN_INFO, &card->dev->dev,
990 card->card_number, card->mm_size, 1013 "Size %d KB, Battery 1 %s (%s), Battery 2 %s (%s)\n",
1014 card->mm_size,
991 (batt_status & BATTERY_1_DISABLED ? "Disabled" : "Enabled"), 1015 (batt_status & BATTERY_1_DISABLED ? "Disabled" : "Enabled"),
992 card->battery[0].good ? "OK" : "FAILURE", 1016 card->battery[0].good ? "OK" : "FAILURE",
993 (batt_status & BATTERY_2_DISABLED ? "Disabled" : "Enabled"), 1017 (batt_status & BATTERY_2_DISABLED ? "Disabled" : "Enabled"),
@@ -1005,19 +1029,16 @@ static int __devinit mm_pci_probe(struct pci_dev *dev, const struct pci_device_i
1005 data = ~data; 1029 data = ~data;
1006 data += 1; 1030 data += 1;
1007 1031
1008 card->win_size = data; 1032 if (request_irq(dev->irq, mm_interrupt, IRQF_SHARED, DRIVER_NAME, card)) {
1009 1033 dev_printk(KERN_ERR, &card->dev->dev,
1010 1034 "Unable to allocate IRQ\n");
1011 if (request_irq(dev->irq, mm_interrupt, IRQF_SHARED, "pci-umem", card)) {
1012 printk(KERN_ERR "MM%d: Unable to allocate IRQ\n", card->card_number);
1013 ret = -ENODEV; 1035 ret = -ENODEV;
1014 1036
1015 goto failed_req_irq; 1037 goto failed_req_irq;
1016 } 1038 }
1017 1039
1018 card->irq = dev->irq; 1040 dev_printk(KERN_INFO, &card->dev->dev,
1019 printk(KERN_INFO "MM%d: Window size %d bytes, IRQ %d\n", card->card_number, 1041 "Window size %d bytes, IRQ %d\n", data, dev->irq);
1020 card->win_size, card->irq);
1021 1042
1022 spin_lock_init(&card->lock); 1043 spin_lock_init(&card->lock);
1023 1044
@@ -1037,10 +1058,12 @@ static int __devinit mm_pci_probe(struct pci_dev *dev, const struct pci_device_i
1037 num_cards++; 1058 num_cards++;
1038 1059
1039 if (!get_userbit(card, MEMORY_INITIALIZED)) { 1060 if (!get_userbit(card, MEMORY_INITIALIZED)) {
1040 printk(KERN_INFO "MM%d: memory NOT initialized. Consider over-writing whole device.\n", card->card_number); 1061 dev_printk(KERN_INFO, &card->dev->dev,
1062 "memory NOT initialized. Consider over-writing whole device.\n");
1041 card->init_size = 0; 1063 card->init_size = 0;
1042 } else { 1064 } else {
1043 printk(KERN_INFO "MM%d: memory already initialized\n", card->card_number); 1065 dev_printk(KERN_INFO, &card->dev->dev,
1066 "memory already initialized\n");
1044 card->init_size = card->mm_size; 1067 card->init_size = card->mm_size;
1045 } 1068 }
1046 1069
@@ -1062,7 +1085,7 @@ static int __devinit mm_pci_probe(struct pci_dev *dev, const struct pci_device_i
1062 failed_magic: 1085 failed_magic:
1063 iounmap(card->csr_remap); 1086 iounmap(card->csr_remap);
1064 failed_remap_csr: 1087 failed_remap_csr:
1065 release_mem_region(card->csr_base, card->csr_len); 1088 pci_release_regions(dev);
1066 failed_req_csr: 1089 failed_req_csr:
1067 1090
1068 return ret; 1091 return ret;
@@ -1077,9 +1100,8 @@ static void mm_pci_remove(struct pci_dev *dev)
1077 struct cardinfo *card = pci_get_drvdata(dev); 1100 struct cardinfo *card = pci_get_drvdata(dev);
1078 1101
1079 tasklet_kill(&card->tasklet); 1102 tasklet_kill(&card->tasklet);
1103 free_irq(dev->irq, card);
1080 iounmap(card->csr_remap); 1104 iounmap(card->csr_remap);
1081 release_mem_region(card->csr_base, card->csr_len);
1082 free_irq(card->irq, card);
1083 1105
1084 if (card->mm_pages[0].desc) 1106 if (card->mm_pages[0].desc)
1085 pci_free_consistent(card->dev, PAGE_SIZE*2, 1107 pci_free_consistent(card->dev, PAGE_SIZE*2,
@@ -1090,6 +1112,9 @@ static void mm_pci_remove(struct pci_dev *dev)
1090 card->mm_pages[1].desc, 1112 card->mm_pages[1].desc,
1091 card->mm_pages[1].page_dma); 1113 card->mm_pages[1].page_dma);
1092 blk_cleanup_queue(card->queue); 1114 blk_cleanup_queue(card->queue);
1115
1116 pci_release_regions(dev);
1117 pci_disable_device(dev);
1093} 1118}
1094 1119
1095static const struct pci_device_id mm_pci_ids[] = { 1120static const struct pci_device_id mm_pci_ids[] = {
@@ -1109,11 +1134,12 @@ static const struct pci_device_id mm_pci_ids[] = {
1109MODULE_DEVICE_TABLE(pci, mm_pci_ids); 1134MODULE_DEVICE_TABLE(pci, mm_pci_ids);
1110 1135
1111static struct pci_driver mm_pci_driver = { 1136static struct pci_driver mm_pci_driver = {
1112 .name = "umem", 1137 .name = DRIVER_NAME,
1113 .id_table = mm_pci_ids, 1138 .id_table = mm_pci_ids,
1114 .probe = mm_pci_probe, 1139 .probe = mm_pci_probe,
1115 .remove = mm_pci_remove, 1140 .remove = mm_pci_remove,
1116}; 1141};
1142
1117/* 1143/*
1118----------------------------------------------------------------------------------- 1144-----------------------------------------------------------------------------------
1119-- mm_init 1145-- mm_init
@@ -1125,13 +1151,11 @@ static int __init mm_init(void)
1125 int retval, i; 1151 int retval, i;
1126 int err; 1152 int err;
1127 1153
1128 printk(KERN_INFO DRIVER_VERSION " : " DRIVER_DESC "\n");
1129
1130 retval = pci_register_driver(&mm_pci_driver); 1154 retval = pci_register_driver(&mm_pci_driver);
1131 if (retval) 1155 if (retval)
1132 return -ENOMEM; 1156 return -ENOMEM;
1133 1157
1134 err = major_nr = register_blkdev(0, "umem"); 1158 err = major_nr = register_blkdev(0, DRIVER_NAME);
1135 if (err < 0) { 1159 if (err < 0) {
1136 pci_unregister_driver(&mm_pci_driver); 1160 pci_unregister_driver(&mm_pci_driver);
1137 return -EIO; 1161 return -EIO;
@@ -1157,13 +1181,13 @@ static int __init mm_init(void)
1157 } 1181 }
1158 1182
1159 init_battery_timer(); 1183 init_battery_timer();
1160 printk("MM: desc_per_page = %ld\n", DESC_PER_PAGE); 1184 printk(KERN_INFO "MM: desc_per_page = %ld\n", DESC_PER_PAGE);
1161/* printk("mm_init: Done. 10-19-01 9:00\n"); */ 1185/* printk("mm_init: Done. 10-19-01 9:00\n"); */
1162 return 0; 1186 return 0;
1163 1187
1164out: 1188out:
1165 pci_unregister_driver(&mm_pci_driver); 1189 pci_unregister_driver(&mm_pci_driver);
1166 unregister_blkdev(major_nr, "umem"); 1190 unregister_blkdev(major_nr, DRIVER_NAME);
1167 while (i--) 1191 while (i--)
1168 put_disk(mm_gendisk[i]); 1192 put_disk(mm_gendisk[i]);
1169 return -ENOMEM; 1193 return -ENOMEM;
@@ -1186,7 +1210,7 @@ static void __exit mm_cleanup(void)
1186 1210
1187 pci_unregister_driver(&mm_pci_driver); 1211 pci_unregister_driver(&mm_pci_driver);
1188 1212
1189 unregister_blkdev(major_nr, "umem"); 1213 unregister_blkdev(major_nr, DRIVER_NAME);
1190} 1214}
1191 1215
1192module_init(mm_init); 1216module_init(mm_init);
diff --git a/drivers/block/umem.h b/drivers/block/umem.h
new file mode 100644
index 000000000000..375c68974c9a
--- /dev/null
+++ b/drivers/block/umem.h
@@ -0,0 +1,133 @@
1
2/*
3 * This file contains defines for the
4 * Micro Memory MM5415
5 * family PCI Memory Module with Battery Backup.
6 *
7 * Copyright Micro Memory INC 2001. All rights reserved.
8 * Release under the terms of the GNU GENERAL PUBLIC LICENSE version 2.
9 * See the file COPYING.
10 */
11
12#ifndef _DRIVERS_BLOCK_MM_H
13#define _DRIVERS_BLOCK_MM_H
14
15
16#define IRQ_TIMEOUT (1 * HZ)
17
18/* CSR register definition */
19#define MEMCTRLSTATUS_MAGIC 0x00
20#define MM_MAGIC_VALUE (unsigned char)0x59
21
22#define MEMCTRLSTATUS_BATTERY 0x04
23#define BATTERY_1_DISABLED 0x01
24#define BATTERY_1_FAILURE 0x02
25#define BATTERY_2_DISABLED 0x04
26#define BATTERY_2_FAILURE 0x08
27
28#define MEMCTRLSTATUS_MEMORY 0x07
29#define MEM_128_MB 0xfe
30#define MEM_256_MB 0xfc
31#define MEM_512_MB 0xf8
32#define MEM_1_GB 0xf0
33#define MEM_2_GB 0xe0
34
35#define MEMCTRLCMD_LEDCTRL 0x08
36#define LED_REMOVE 2
37#define LED_FAULT 4
38#define LED_POWER 6
39#define LED_FLIP 255
40#define LED_OFF 0x00
41#define LED_ON 0x01
42#define LED_FLASH_3_5 0x02
43#define LED_FLASH_7_0 0x03
44#define LED_POWER_ON 0x00
45#define LED_POWER_OFF 0x01
46#define USER_BIT1 0x01
47#define USER_BIT2 0x02
48
49#define MEMORY_INITIALIZED USER_BIT1
50
51#define MEMCTRLCMD_ERRCTRL 0x0C
52#define EDC_NONE_DEFAULT 0x00
53#define EDC_NONE 0x01
54#define EDC_STORE_READ 0x02
55#define EDC_STORE_CORRECT 0x03
56
57#define MEMCTRLCMD_ERRCNT 0x0D
58#define MEMCTRLCMD_ERRSTATUS 0x0E
59
60#define ERROR_DATA_LOG 0x20
61#define ERROR_ADDR_LOG 0x28
62#define ERROR_COUNT 0x3D
63#define ERROR_SYNDROME 0x3E
64#define ERROR_CHECK 0x3F
65
66#define DMA_PCI_ADDR 0x40
67#define DMA_LOCAL_ADDR 0x48
68#define DMA_TRANSFER_SIZE 0x50
69#define DMA_DESCRIPTOR_ADDR 0x58
70#define DMA_SEMAPHORE_ADDR 0x60
71#define DMA_STATUS_CTRL 0x68
72#define DMASCR_GO 0x00001
73#define DMASCR_TRANSFER_READ 0x00002
74#define DMASCR_CHAIN_EN 0x00004
75#define DMASCR_SEM_EN 0x00010
76#define DMASCR_DMA_COMP_EN 0x00020
77#define DMASCR_CHAIN_COMP_EN 0x00040
78#define DMASCR_ERR_INT_EN 0x00080
79#define DMASCR_PARITY_INT_EN 0x00100
80#define DMASCR_ANY_ERR 0x00800
81#define DMASCR_MBE_ERR 0x01000
82#define DMASCR_PARITY_ERR_REP 0x02000
83#define DMASCR_PARITY_ERR_DET 0x04000
84#define DMASCR_SYSTEM_ERR_SIG 0x08000
85#define DMASCR_TARGET_ABT 0x10000
86#define DMASCR_MASTER_ABT 0x20000
87#define DMASCR_DMA_COMPLETE 0x40000
88#define DMASCR_CHAIN_COMPLETE 0x80000
89
90/*
913.SOME PCs HAVE HOST BRIDGES WHICH APPARENTLY DO NOT CORRECTLY HANDLE
92READ-LINE (0xE) OR READ-MULTIPLE (0xC) PCI COMMAND CODES DURING DMA
93TRANSFERS. IN OTHER SYSTEMS THESE COMMAND CODES WILL CAUSE THE HOST BRIDGE
94TO ALLOW LONGER BURSTS DURING DMA READ OPERATIONS. THE UPPER FOUR BITS
95(31..28) OF THE DMA CSR HAVE BEEN MADE PROGRAMMABLE, SO THAT EITHER A 0x6,
96AN 0xE OR A 0xC CAN BE WRITTEN TO THEM TO SET THE COMMAND CODE USED DURING
97DMA READ OPERATIONS.
98*/
99#define DMASCR_READ 0x60000000
100#define DMASCR_READLINE 0xE0000000
101#define DMASCR_READMULTI 0xC0000000
102
103
104#define DMASCR_ERROR_MASK (DMASCR_MASTER_ABT | DMASCR_TARGET_ABT | DMASCR_SYSTEM_ERR_SIG | DMASCR_PARITY_ERR_DET | DMASCR_MBE_ERR | DMASCR_ANY_ERR)
105#define DMASCR_HARD_ERROR (DMASCR_MASTER_ABT | DMASCR_TARGET_ABT | DMASCR_SYSTEM_ERR_SIG | DMASCR_PARITY_ERR_DET | DMASCR_MBE_ERR)
106
107#define WINDOWMAP_WINNUM 0x7B
108
109#define DMA_READ_FROM_HOST 0
110#define DMA_WRITE_TO_HOST 1
111
112struct mm_dma_desc {
113 __le64 pci_addr;
114 __le64 local_addr;
115 __le32 transfer_size;
116 u32 zero1;
117 __le64 next_desc_addr;
118 __le64 sem_addr;
119 __le32 control_bits;
120 u32 zero2;
121
122 dma_addr_t data_dma_handle;
123
124 /* Copy of the bits */
125 __le64 sem_control_bits;
126} __attribute__((aligned(8)));
127
128/* bits for card->flags */
129#define UM_FLAG_DMA_IN_REGS 1
130#define UM_FLAG_NO_BYTE_STATUS 2
131#define UM_FLAG_NO_BATTREG 4
132#define UM_FLAG_NO_BATT 8
133#endif
diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
index 964e51634f2d..2bdebcb3ff16 100644
--- a/drivers/block/xen-blkfront.c
+++ b/drivers/block/xen-blkfront.c
@@ -150,9 +150,8 @@ static int blkif_queue_request(struct request *req)
150 struct blkfront_info *info = req->rq_disk->private_data; 150 struct blkfront_info *info = req->rq_disk->private_data;
151 unsigned long buffer_mfn; 151 unsigned long buffer_mfn;
152 struct blkif_request *ring_req; 152 struct blkif_request *ring_req;
153 struct bio *bio; 153 struct req_iterator iter;
154 struct bio_vec *bvec; 154 struct bio_vec *bvec;
155 int idx;
156 unsigned long id; 155 unsigned long id;
157 unsigned int fsect, lsect; 156 unsigned int fsect, lsect;
158 int ref; 157 int ref;
@@ -186,34 +185,31 @@ static int blkif_queue_request(struct request *req)
186 ring_req->operation = BLKIF_OP_WRITE_BARRIER; 185 ring_req->operation = BLKIF_OP_WRITE_BARRIER;
187 186
188 ring_req->nr_segments = 0; 187 ring_req->nr_segments = 0;
189 rq_for_each_bio (bio, req) { 188 rq_for_each_segment(bvec, req, iter) {
190 bio_for_each_segment (bvec, bio, idx) { 189 BUG_ON(ring_req->nr_segments == BLKIF_MAX_SEGMENTS_PER_REQUEST);
191 BUG_ON(ring_req->nr_segments 190 buffer_mfn = pfn_to_mfn(page_to_pfn(bvec->bv_page));
192 == BLKIF_MAX_SEGMENTS_PER_REQUEST); 191 fsect = bvec->bv_offset >> 9;
193 buffer_mfn = pfn_to_mfn(page_to_pfn(bvec->bv_page)); 192 lsect = fsect + (bvec->bv_len >> 9) - 1;
194 fsect = bvec->bv_offset >> 9; 193 /* install a grant reference. */
195 lsect = fsect + (bvec->bv_len >> 9) - 1; 194 ref = gnttab_claim_grant_reference(&gref_head);
196 /* install a grant reference. */ 195 BUG_ON(ref == -ENOSPC);
197 ref = gnttab_claim_grant_reference(&gref_head); 196
198 BUG_ON(ref == -ENOSPC); 197 gnttab_grant_foreign_access_ref(
199
200 gnttab_grant_foreign_access_ref(
201 ref, 198 ref,
202 info->xbdev->otherend_id, 199 info->xbdev->otherend_id,
203 buffer_mfn, 200 buffer_mfn,
204 rq_data_dir(req) ); 201 rq_data_dir(req) );
205 202
206 info->shadow[id].frame[ring_req->nr_segments] = 203 info->shadow[id].frame[ring_req->nr_segments] =
207 mfn_to_pfn(buffer_mfn); 204 mfn_to_pfn(buffer_mfn);
208 205
209 ring_req->seg[ring_req->nr_segments] = 206 ring_req->seg[ring_req->nr_segments] =
210 (struct blkif_request_segment) { 207 (struct blkif_request_segment) {
211 .gref = ref, 208 .gref = ref,
212 .first_sect = fsect, 209 .first_sect = fsect,
213 .last_sect = lsect }; 210 .last_sect = lsect };
214 211
215 ring_req->nr_segments++; 212 ring_req->nr_segments++;
216 }
217 } 213 }
218 214
219 info->ring.req_prod_pvt++; 215 info->ring.req_prod_pvt++;
diff --git a/drivers/block/xsysace.c b/drivers/block/xsysace.c
index 3ede0b63da13..9e7652dcde6c 100644
--- a/drivers/block/xsysace.c
+++ b/drivers/block/xsysace.c
@@ -91,6 +91,10 @@
91#include <linux/blkdev.h> 91#include <linux/blkdev.h>
92#include <linux/hdreg.h> 92#include <linux/hdreg.h>
93#include <linux/platform_device.h> 93#include <linux/platform_device.h>
94#if defined(CONFIG_OF)
95#include <linux/of_device.h>
96#include <linux/of_platform.h>
97#endif
94 98
95MODULE_AUTHOR("Grant Likely <grant.likely@secretlab.ca>"); 99MODULE_AUTHOR("Grant Likely <grant.likely@secretlab.ca>");
96MODULE_DESCRIPTION("Xilinx SystemACE device driver"); 100MODULE_DESCRIPTION("Xilinx SystemACE device driver");
@@ -158,6 +162,9 @@ MODULE_LICENSE("GPL");
158#define ACE_FIFO_SIZE (32) 162#define ACE_FIFO_SIZE (32)
159#define ACE_BUF_PER_SECTOR (ACE_SECTOR_SIZE / ACE_FIFO_SIZE) 163#define ACE_BUF_PER_SECTOR (ACE_SECTOR_SIZE / ACE_FIFO_SIZE)
160 164
165#define ACE_BUS_WIDTH_8 0
166#define ACE_BUS_WIDTH_16 1
167
161struct ace_reg_ops; 168struct ace_reg_ops;
162 169
163struct ace_device { 170struct ace_device {
@@ -188,7 +195,7 @@ struct ace_device {
188 195
189 /* Details of hardware device */ 196 /* Details of hardware device */
190 unsigned long physaddr; 197 unsigned long physaddr;
191 void *baseaddr; 198 void __iomem *baseaddr;
192 int irq; 199 int irq;
193 int bus_width; /* 0 := 8 bit; 1 := 16 bit */ 200 int bus_width; /* 0 := 8 bit; 1 := 16 bit */
194 struct ace_reg_ops *reg_ops; 201 struct ace_reg_ops *reg_ops;
@@ -220,20 +227,20 @@ struct ace_reg_ops {
220/* 8 Bit bus width */ 227/* 8 Bit bus width */
221static u16 ace_in_8(struct ace_device *ace, int reg) 228static u16 ace_in_8(struct ace_device *ace, int reg)
222{ 229{
223 void *r = ace->baseaddr + reg; 230 void __iomem *r = ace->baseaddr + reg;
224 return in_8(r) | (in_8(r + 1) << 8); 231 return in_8(r) | (in_8(r + 1) << 8);
225} 232}
226 233
227static void ace_out_8(struct ace_device *ace, int reg, u16 val) 234static void ace_out_8(struct ace_device *ace, int reg, u16 val)
228{ 235{
229 void *r = ace->baseaddr + reg; 236 void __iomem *r = ace->baseaddr + reg;
230 out_8(r, val); 237 out_8(r, val);
231 out_8(r + 1, val >> 8); 238 out_8(r + 1, val >> 8);
232} 239}
233 240
234static void ace_datain_8(struct ace_device *ace) 241static void ace_datain_8(struct ace_device *ace)
235{ 242{
236 void *r = ace->baseaddr + 0x40; 243 void __iomem *r = ace->baseaddr + 0x40;
237 u8 *dst = ace->data_ptr; 244 u8 *dst = ace->data_ptr;
238 int i = ACE_FIFO_SIZE; 245 int i = ACE_FIFO_SIZE;
239 while (i--) 246 while (i--)
@@ -243,7 +250,7 @@ static void ace_datain_8(struct ace_device *ace)
243 250
244static void ace_dataout_8(struct ace_device *ace) 251static void ace_dataout_8(struct ace_device *ace)
245{ 252{
246 void *r = ace->baseaddr + 0x40; 253 void __iomem *r = ace->baseaddr + 0x40;
247 u8 *src = ace->data_ptr; 254 u8 *src = ace->data_ptr;
248 int i = ACE_FIFO_SIZE; 255 int i = ACE_FIFO_SIZE;
249 while (i--) 256 while (i--)
@@ -931,9 +938,11 @@ static int __devinit ace_setup(struct ace_device *ace)
931{ 938{
932 u16 version; 939 u16 version;
933 u16 val; 940 u16 val;
934
935 int rc; 941 int rc;
936 942
943 dev_dbg(ace->dev, "ace_setup(ace=0x%p)\n", ace);
944 dev_dbg(ace->dev, "physaddr=0x%lx irq=%i\n", ace->physaddr, ace->irq);
945
937 spin_lock_init(&ace->lock); 946 spin_lock_init(&ace->lock);
938 init_completion(&ace->id_completion); 947 init_completion(&ace->id_completion);
939 948
@@ -944,15 +953,6 @@ static int __devinit ace_setup(struct ace_device *ace)
944 if (!ace->baseaddr) 953 if (!ace->baseaddr)
945 goto err_ioremap; 954 goto err_ioremap;
946 955
947 if (ace->irq != NO_IRQ) {
948 rc = request_irq(ace->irq, ace_interrupt, 0, "systemace", ace);
949 if (rc) {
950 /* Failure - fall back to polled mode */
951 dev_err(ace->dev, "request_irq failed\n");
952 ace->irq = NO_IRQ;
953 }
954 }
955
956 /* 956 /*
957 * Initialize the state machine tasklet and stall timer 957 * Initialize the state machine tasklet and stall timer
958 */ 958 */
@@ -982,7 +982,7 @@ static int __devinit ace_setup(struct ace_device *ace)
982 snprintf(ace->gd->disk_name, 32, "xs%c", ace->id + 'a'); 982 snprintf(ace->gd->disk_name, 32, "xs%c", ace->id + 'a');
983 983
984 /* set bus width */ 984 /* set bus width */
985 if (ace->bus_width == 1) { 985 if (ace->bus_width == ACE_BUS_WIDTH_16) {
986 /* 0x0101 should work regardless of endianess */ 986 /* 0x0101 should work regardless of endianess */
987 ace_out_le16(ace, ACE_BUSMODE, 0x0101); 987 ace_out_le16(ace, ACE_BUSMODE, 0x0101);
988 988
@@ -1005,6 +1005,16 @@ static int __devinit ace_setup(struct ace_device *ace)
1005 ace_out(ace, ACE_CTRL, ACE_CTRL_FORCECFGMODE | 1005 ace_out(ace, ACE_CTRL, ACE_CTRL_FORCECFGMODE |
1006 ACE_CTRL_DATABUFRDYIRQ | ACE_CTRL_ERRORIRQ); 1006 ACE_CTRL_DATABUFRDYIRQ | ACE_CTRL_ERRORIRQ);
1007 1007
1008 /* Now we can hook up the irq handler */
1009 if (ace->irq != NO_IRQ) {
1010 rc = request_irq(ace->irq, ace_interrupt, 0, "systemace", ace);
1011 if (rc) {
1012 /* Failure - fall back to polled mode */
1013 dev_err(ace->dev, "request_irq failed\n");
1014 ace->irq = NO_IRQ;
1015 }
1016 }
1017
1008 /* Enable interrupts */ 1018 /* Enable interrupts */
1009 val = ace_in(ace, ACE_CTRL); 1019 val = ace_in(ace, ACE_CTRL);
1010 val |= ACE_CTRL_DATABUFRDYIRQ | ACE_CTRL_ERRORIRQ; 1020 val |= ACE_CTRL_DATABUFRDYIRQ | ACE_CTRL_ERRORIRQ;
@@ -1024,16 +1034,14 @@ static int __devinit ace_setup(struct ace_device *ace)
1024 1034
1025 return 0; 1035 return 0;
1026 1036
1027 err_read: 1037err_read:
1028 put_disk(ace->gd); 1038 put_disk(ace->gd);
1029 err_alloc_disk: 1039err_alloc_disk:
1030 blk_cleanup_queue(ace->queue); 1040 blk_cleanup_queue(ace->queue);
1031 err_blk_initq: 1041err_blk_initq:
1032 iounmap(ace->baseaddr); 1042 iounmap(ace->baseaddr);
1033 if (ace->irq != NO_IRQ) 1043err_ioremap:
1034 free_irq(ace->irq, ace); 1044 dev_info(ace->dev, "xsysace: error initializing device at 0x%lx\n",
1035 err_ioremap:
1036 printk(KERN_INFO "xsysace: error initializing device at 0x%lx\n",
1037 ace->physaddr); 1045 ace->physaddr);
1038 return -ENOMEM; 1046 return -ENOMEM;
1039} 1047}
@@ -1056,98 +1064,222 @@ static void __devexit ace_teardown(struct ace_device *ace)
1056 iounmap(ace->baseaddr); 1064 iounmap(ace->baseaddr);
1057} 1065}
1058 1066
1059/* --------------------------------------------------------------------- 1067static int __devinit
1060 * Platform Bus Support 1068ace_alloc(struct device *dev, int id, unsigned long physaddr,
1061 */ 1069 int irq, int bus_width)
1062
1063static int __devinit ace_probe(struct device *device)
1064{ 1070{
1065 struct platform_device *dev = to_platform_device(device);
1066 struct ace_device *ace; 1071 struct ace_device *ace;
1067 int i; 1072 int rc;
1073 dev_dbg(dev, "ace_alloc(%p)\n", dev);
1068 1074
1069 dev_dbg(device, "ace_probe(%p)\n", device); 1075 if (!physaddr) {
1076 rc = -ENODEV;
1077 goto err_noreg;
1078 }
1070 1079
1071 /* 1080 /* Allocate and initialize the ace device structure */
1072 * Allocate the ace device structure
1073 */
1074 ace = kzalloc(sizeof(struct ace_device), GFP_KERNEL); 1081 ace = kzalloc(sizeof(struct ace_device), GFP_KERNEL);
1075 if (!ace) 1082 if (!ace) {
1083 rc = -ENOMEM;
1076 goto err_alloc; 1084 goto err_alloc;
1077
1078 ace->dev = device;
1079 ace->id = dev->id;
1080 ace->irq = NO_IRQ;
1081
1082 for (i = 0; i < dev->num_resources; i++) {
1083 if (dev->resource[i].flags & IORESOURCE_MEM)
1084 ace->physaddr = dev->resource[i].start;
1085 if (dev->resource[i].flags & IORESOURCE_IRQ)
1086 ace->irq = dev->resource[i].start;
1087 } 1085 }
1088 1086
1089 /* FIXME: Should get bus_width from the platform_device struct */ 1087 ace->dev = dev;
1090 ace->bus_width = 1; 1088 ace->id = id;
1091 1089 ace->physaddr = physaddr;
1092 dev_set_drvdata(&dev->dev, ace); 1090 ace->irq = irq;
1091 ace->bus_width = bus_width;
1093 1092
1094 /* Call the bus-independant setup code */ 1093 /* Call the setup code */
1095 if (ace_setup(ace) != 0) 1094 rc = ace_setup(ace);
1095 if (rc)
1096 goto err_setup; 1096 goto err_setup;
1097 1097
1098 dev_set_drvdata(dev, ace);
1098 return 0; 1099 return 0;
1099 1100
1100 err_setup: 1101err_setup:
1101 dev_set_drvdata(&dev->dev, NULL); 1102 dev_set_drvdata(dev, NULL);
1102 kfree(ace); 1103 kfree(ace);
1103 err_alloc: 1104err_alloc:
1104 printk(KERN_ERR "xsysace: could not initialize device\n"); 1105err_noreg:
1105 return -ENOMEM; 1106 dev_err(dev, "could not initialize device, err=%i\n", rc);
1107 return rc;
1106} 1108}
1107 1109
1108/* 1110static void __devexit ace_free(struct device *dev)
1109 * Platform bus remove() method
1110 */
1111static int __devexit ace_remove(struct device *device)
1112{ 1111{
1113 struct ace_device *ace = dev_get_drvdata(device); 1112 struct ace_device *ace = dev_get_drvdata(dev);
1114 1113 dev_dbg(dev, "ace_free(%p)\n", dev);
1115 dev_dbg(device, "ace_remove(%p)\n", device);
1116 1114
1117 if (ace) { 1115 if (ace) {
1118 ace_teardown(ace); 1116 ace_teardown(ace);
1117 dev_set_drvdata(dev, NULL);
1119 kfree(ace); 1118 kfree(ace);
1120 } 1119 }
1120}
1121
1122/* ---------------------------------------------------------------------
1123 * Platform Bus Support
1124 */
1125
1126static int __devinit ace_probe(struct platform_device *dev)
1127{
1128 unsigned long physaddr = 0;
1129 int bus_width = ACE_BUS_WIDTH_16; /* FIXME: should not be hard coded */
1130 int id = dev->id;
1131 int irq = NO_IRQ;
1132 int i;
1121 1133
1134 dev_dbg(&dev->dev, "ace_probe(%p)\n", dev);
1135
1136 for (i = 0; i < dev->num_resources; i++) {
1137 if (dev->resource[i].flags & IORESOURCE_MEM)
1138 physaddr = dev->resource[i].start;
1139 if (dev->resource[i].flags & IORESOURCE_IRQ)
1140 irq = dev->resource[i].start;
1141 }
1142
1143 /* Call the bus-independant setup code */
1144 return ace_alloc(&dev->dev, id, physaddr, irq, bus_width);
1145}
1146
1147/*
1148 * Platform bus remove() method
1149 */
1150static int __devexit ace_remove(struct platform_device *dev)
1151{
1152 ace_free(&dev->dev);
1122 return 0; 1153 return 0;
1123} 1154}
1124 1155
1125static struct device_driver ace_driver = { 1156static struct platform_driver ace_platform_driver = {
1126 .name = "xsysace",
1127 .bus = &platform_bus_type,
1128 .probe = ace_probe, 1157 .probe = ace_probe,
1129 .remove = __devexit_p(ace_remove), 1158 .remove = __devexit_p(ace_remove),
1159 .driver = {
1160 .owner = THIS_MODULE,
1161 .name = "xsysace",
1162 },
1163};
1164
1165/* ---------------------------------------------------------------------
1166 * OF_Platform Bus Support
1167 */
1168
1169#if defined(CONFIG_OF)
1170static int __devinit
1171ace_of_probe(struct of_device *op, const struct of_device_id *match)
1172{
1173 struct resource res;
1174 unsigned long physaddr;
1175 const u32 *id;
1176 int irq, bus_width, rc;
1177
1178 dev_dbg(&op->dev, "ace_of_probe(%p, %p)\n", op, match);
1179
1180 /* device id */
1181 id = of_get_property(op->node, "port-number", NULL);
1182
1183 /* physaddr */
1184 rc = of_address_to_resource(op->node, 0, &res);
1185 if (rc) {
1186 dev_err(&op->dev, "invalid address\n");
1187 return rc;
1188 }
1189 physaddr = res.start;
1190
1191 /* irq */
1192 irq = irq_of_parse_and_map(op->node, 0);
1193
1194 /* bus width */
1195 bus_width = ACE_BUS_WIDTH_16;
1196 if (of_find_property(op->node, "8-bit", NULL))
1197 bus_width = ACE_BUS_WIDTH_8;
1198
1199 /* Call the bus-independant setup code */
1200 return ace_alloc(&op->dev, id ? *id : 0, physaddr, irq, bus_width);
1201}
1202
1203static int __devexit ace_of_remove(struct of_device *op)
1204{
1205 ace_free(&op->dev);
1206 return 0;
1207}
1208
1209/* Match table for of_platform binding */
1210static struct of_device_id __devinit ace_of_match[] = {
1211 { .compatible = "xilinx,xsysace", },
1212 {},
1213};
1214MODULE_DEVICE_TABLE(of, ace_of_match);
1215
1216static struct of_platform_driver ace_of_driver = {
1217 .owner = THIS_MODULE,
1218 .name = "xsysace",
1219 .match_table = ace_of_match,
1220 .probe = ace_of_probe,
1221 .remove = __devexit_p(ace_of_remove),
1222 .driver = {
1223 .name = "xsysace",
1224 },
1130}; 1225};
1131 1226
1227/* Registration helpers to keep the number of #ifdefs to a minimum */
1228static inline int __init ace_of_register(void)
1229{
1230 pr_debug("xsysace: registering OF binding\n");
1231 return of_register_platform_driver(&ace_of_driver);
1232}
1233
1234static inline void __exit ace_of_unregister(void)
1235{
1236 of_unregister_platform_driver(&ace_of_driver);
1237}
1238#else /* CONFIG_OF */
1239/* CONFIG_OF not enabled; do nothing helpers */
1240static inline int __init ace_of_register(void) { return 0; }
1241static inline void __exit ace_of_unregister(void) { }
1242#endif /* CONFIG_OF */
1243
1132/* --------------------------------------------------------------------- 1244/* ---------------------------------------------------------------------
1133 * Module init/exit routines 1245 * Module init/exit routines
1134 */ 1246 */
1135static int __init ace_init(void) 1247static int __init ace_init(void)
1136{ 1248{
1249 int rc;
1250
1137 ace_major = register_blkdev(ace_major, "xsysace"); 1251 ace_major = register_blkdev(ace_major, "xsysace");
1138 if (ace_major <= 0) { 1252 if (ace_major <= 0) {
1139 printk(KERN_WARNING "xsysace: register_blkdev() failed\n"); 1253 rc = -ENOMEM;
1140 return ace_major; 1254 goto err_blk;
1141 } 1255 }
1142 1256
1143 pr_debug("Registering Xilinx SystemACE driver, major=%i\n", ace_major); 1257 rc = ace_of_register();
1144 return driver_register(&ace_driver); 1258 if (rc)
1259 goto err_of;
1260
1261 pr_debug("xsysace: registering platform binding\n");
1262 rc = platform_driver_register(&ace_platform_driver);
1263 if (rc)
1264 goto err_plat;
1265
1266 pr_info("Xilinx SystemACE device driver, major=%i\n", ace_major);
1267 return 0;
1268
1269err_plat:
1270 ace_of_unregister();
1271err_of:
1272 unregister_blkdev(ace_major, "xsysace");
1273err_blk:
1274 printk(KERN_ERR "xsysace: registration failed; err=%i\n", rc);
1275 return rc;
1145} 1276}
1146 1277
1147static void __exit ace_exit(void) 1278static void __exit ace_exit(void)
1148{ 1279{
1149 pr_debug("Unregistering Xilinx SystemACE driver\n"); 1280 pr_debug("Unregistering Xilinx SystemACE driver\n");
1150 driver_unregister(&ace_driver); 1281 platform_driver_unregister(&ace_platform_driver);
1282 ace_of_unregister();
1151 unregister_blkdev(ace_major, "xsysace"); 1283 unregister_blkdev(ace_major, "xsysace");
1152} 1284}
1153 1285
diff --git a/drivers/ide/ide-floppy.c b/drivers/ide/ide-floppy.c
index ae8e1a64b8ad..04a357808f2e 100644
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -606,26 +606,24 @@ static void idefloppy_input_buffers (ide_drive_t *drive, idefloppy_pc_t *pc, uns
606{ 606{
607 struct request *rq = pc->rq; 607 struct request *rq = pc->rq;
608 struct bio_vec *bvec; 608 struct bio_vec *bvec;
609 struct bio *bio; 609 struct req_iterator iter;
610 unsigned long flags; 610 unsigned long flags;
611 char *data; 611 char *data;
612 int count, i, done = 0; 612 int count, done = 0;
613 613
614 rq_for_each_bio(bio, rq) { 614 rq_for_each_segment(bvec, rq, iter) {
615 bio_for_each_segment(bvec, bio, i) { 615 if (!bcount)
616 if (!bcount) 616 break;
617 break;
618 617
619 count = min(bvec->bv_len, bcount); 618 count = min(bvec->bv_len, bcount);
620 619
621 data = bvec_kmap_irq(bvec, &flags); 620 data = bvec_kmap_irq(bvec, &flags);
622 drive->hwif->atapi_input_bytes(drive, data, count); 621 drive->hwif->atapi_input_bytes(drive, data, count);
623 bvec_kunmap_irq(data, &flags); 622 bvec_kunmap_irq(data, &flags);
624 623
625 bcount -= count; 624 bcount -= count;
626 pc->b_count += count; 625 pc->b_count += count;
627 done += count; 626 done += count;
628 }
629 } 627 }
630 628
631 idefloppy_do_end_request(drive, 1, done >> 9); 629 idefloppy_do_end_request(drive, 1, done >> 9);
@@ -639,27 +637,25 @@ static void idefloppy_input_buffers (ide_drive_t *drive, idefloppy_pc_t *pc, uns
639static void idefloppy_output_buffers (ide_drive_t *drive, idefloppy_pc_t *pc, unsigned int bcount) 637static void idefloppy_output_buffers (ide_drive_t *drive, idefloppy_pc_t *pc, unsigned int bcount)
640{ 638{
641 struct request *rq = pc->rq; 639 struct request *rq = pc->rq;
642 struct bio *bio; 640 struct req_iterator iter;
643 struct bio_vec *bvec; 641 struct bio_vec *bvec;
644 unsigned long flags; 642 unsigned long flags;
645 int count, i, done = 0; 643 int count, done = 0;
646 char *data; 644 char *data;
647 645
648 rq_for_each_bio(bio, rq) { 646 rq_for_each_segment(bvec, rq, iter) {
649 bio_for_each_segment(bvec, bio, i) { 647 if (!bcount)
650 if (!bcount) 648 break;
651 break;
652 649
653 count = min(bvec->bv_len, bcount); 650 count = min(bvec->bv_len, bcount);
654 651
655 data = bvec_kmap_irq(bvec, &flags); 652 data = bvec_kmap_irq(bvec, &flags);
656 drive->hwif->atapi_output_bytes(drive, data, count); 653 drive->hwif->atapi_output_bytes(drive, data, count);
657 bvec_kunmap_irq(data, &flags); 654 bvec_kunmap_irq(data, &flags);
658 655
659 bcount -= count; 656 bcount -= count;
660 pc->b_count += count; 657 pc->b_count += count;
661 done += count; 658 done += count;
662 }
663 } 659 }
664 660
665 idefloppy_do_end_request(drive, 1, done >> 9); 661 idefloppy_do_end_request(drive, 1, done >> 9);
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index bdc52d6922b7..8216a6f75be5 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -489,7 +489,7 @@ static void dec_pending(struct dm_crypt_io *io, int error)
489 if (!atomic_dec_and_test(&io->pending)) 489 if (!atomic_dec_and_test(&io->pending))
490 return; 490 return;
491 491
492 bio_endio(io->base_bio, io->base_bio->bi_size, io->error); 492 bio_endio(io->base_bio, io->error);
493 493
494 mempool_free(io, cc->io_pool); 494 mempool_free(io, cc->io_pool);
495} 495}
@@ -509,25 +509,19 @@ static void kcryptd_queue_io(struct dm_crypt_io *io)
509 queue_work(_kcryptd_workqueue, &io->work); 509 queue_work(_kcryptd_workqueue, &io->work);
510} 510}
511 511
512static int crypt_endio(struct bio *clone, unsigned int done, int error) 512static void crypt_endio(struct bio *clone, int error)
513{ 513{
514 struct dm_crypt_io *io = clone->bi_private; 514 struct dm_crypt_io *io = clone->bi_private;
515 struct crypt_config *cc = io->target->private; 515 struct crypt_config *cc = io->target->private;
516 unsigned read_io = bio_data_dir(clone) == READ; 516 unsigned read_io = bio_data_dir(clone) == READ;
517 517
518 /* 518 /*
519 * free the processed pages, even if 519 * free the processed pages
520 * it's only a partially completed write
521 */ 520 */
522 if (!read_io) 521 if (!read_io) {
523 crypt_free_buffer_pages(cc, clone, done); 522 crypt_free_buffer_pages(cc, clone, clone->bi_size);
524
525 /* keep going - not finished yet */
526 if (unlikely(clone->bi_size))
527 return 1;
528
529 if (!read_io)
530 goto out; 523 goto out;
524 }
531 525
532 if (unlikely(!bio_flagged(clone, BIO_UPTODATE))) { 526 if (unlikely(!bio_flagged(clone, BIO_UPTODATE))) {
533 error = -EIO; 527 error = -EIO;
@@ -537,12 +531,11 @@ static int crypt_endio(struct bio *clone, unsigned int done, int error)
537 bio_put(clone); 531 bio_put(clone);
538 io->post_process = 1; 532 io->post_process = 1;
539 kcryptd_queue_io(io); 533 kcryptd_queue_io(io);
540 return 0; 534 return;
541 535
542out: 536out:
543 bio_put(clone); 537 bio_put(clone);
544 dec_pending(io, error); 538 dec_pending(io, error);
545 return error;
546} 539}
547 540
548static void clone_init(struct dm_crypt_io *io, struct bio *clone) 541static void clone_init(struct dm_crypt_io *io, struct bio *clone)
diff --git a/drivers/md/dm-emc.c b/drivers/md/dm-emc.c
index 265c467854da..a2191a4fcf77 100644
--- a/drivers/md/dm-emc.c
+++ b/drivers/md/dm-emc.c
@@ -38,13 +38,10 @@ static inline void free_bio(struct bio *bio)
38 bio_put(bio); 38 bio_put(bio);
39} 39}
40 40
41static int emc_endio(struct bio *bio, unsigned int bytes_done, int error) 41static void emc_endio(struct bio *bio, int error)
42{ 42{
43 struct dm_path *path = bio->bi_private; 43 struct dm_path *path = bio->bi_private;
44 44
45 if (bio->bi_size)
46 return 1;
47
48 /* We also need to look at the sense keys here whether or not to 45 /* We also need to look at the sense keys here whether or not to
49 * switch to the next PG etc. 46 * switch to the next PG etc.
50 * 47 *
@@ -109,15 +106,7 @@ static struct request *get_failover_req(struct emc_handler *h,
109 return NULL; 106 return NULL;
110 } 107 }
111 108
112 rq->bio = rq->biotail = bio; 109 blk_rq_append_bio(q, rq, bio);
113 blk_rq_bio_prep(q, rq, bio);
114
115 rq->rq_disk = bdev->bd_contains->bd_disk;
116
117 /* bio backed don't set data */
118 rq->buffer = rq->data = NULL;
119 /* rq data_len used for pc cmd's request_bufflen */
120 rq->data_len = bio->bi_size;
121 110
122 rq->sense = h->sense; 111 rq->sense = h->sense;
123 memset(rq->sense, 0, SCSI_SENSE_BUFFERSIZE); 112 memset(rq->sense, 0, SCSI_SENSE_BUFFERSIZE);
diff --git a/drivers/md/dm-io.c b/drivers/md/dm-io.c
index f3a772486437..b8e342fe7586 100644
--- a/drivers/md/dm-io.c
+++ b/drivers/md/dm-io.c
@@ -124,15 +124,11 @@ static void dec_count(struct io *io, unsigned int region, int error)
124 } 124 }
125} 125}
126 126
127static int endio(struct bio *bio, unsigned int done, int error) 127static void endio(struct bio *bio, int error)
128{ 128{
129 struct io *io; 129 struct io *io;
130 unsigned region; 130 unsigned region;
131 131
132 /* keep going until we've finished */
133 if (bio->bi_size)
134 return 1;
135
136 if (error && bio_data_dir(bio) == READ) 132 if (error && bio_data_dir(bio) == READ)
137 zero_fill_bio(bio); 133 zero_fill_bio(bio);
138 134
@@ -146,8 +142,6 @@ static int endio(struct bio *bio, unsigned int done, int error)
146 bio_put(bio); 142 bio_put(bio);
147 143
148 dec_count(io, region, error); 144 dec_count(io, region, error);
149
150 return 0;
151} 145}
152 146
153/*----------------------------------------------------------------- 147/*-----------------------------------------------------------------
diff --git a/drivers/md/dm-mpath.c b/drivers/md/dm-mpath.c
index d6ca9d0a6fd1..31056abca89d 100644
--- a/drivers/md/dm-mpath.c
+++ b/drivers/md/dm-mpath.c
@@ -390,11 +390,11 @@ static void dispatch_queued_ios(struct multipath *m)
390 390
391 r = map_io(m, bio, mpio, 1); 391 r = map_io(m, bio, mpio, 1);
392 if (r < 0) 392 if (r < 0)
393 bio_endio(bio, bio->bi_size, r); 393 bio_endio(bio, r);
394 else if (r == DM_MAPIO_REMAPPED) 394 else if (r == DM_MAPIO_REMAPPED)
395 generic_make_request(bio); 395 generic_make_request(bio);
396 else if (r == DM_MAPIO_REQUEUE) 396 else if (r == DM_MAPIO_REQUEUE)
397 bio_endio(bio, bio->bi_size, -EIO); 397 bio_endio(bio, -EIO);
398 398
399 bio = next; 399 bio = next;
400 } 400 }
diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
index 144071e70a93..d09ff15490a5 100644
--- a/drivers/md/dm-raid1.c
+++ b/drivers/md/dm-raid1.c
@@ -820,7 +820,7 @@ static void write_callback(unsigned long error, void *context)
820 break; 820 break;
821 } 821 }
822 } 822 }
823 bio_endio(bio, bio->bi_size, 0); 823 bio_endio(bio, 0);
824} 824}
825 825
826static void do_write(struct mirror_set *ms, struct bio *bio) 826static void do_write(struct mirror_set *ms, struct bio *bio)
@@ -900,7 +900,7 @@ static void do_writes(struct mirror_set *ms, struct bio_list *writes)
900 */ 900 */
901 if (unlikely(ms->log_failure)) 901 if (unlikely(ms->log_failure))
902 while ((bio = bio_list_pop(&sync))) 902 while ((bio = bio_list_pop(&sync)))
903 bio_endio(bio, bio->bi_size, -EIO); 903 bio_endio(bio, -EIO);
904 else while ((bio = bio_list_pop(&sync))) 904 else while ((bio = bio_list_pop(&sync)))
905 do_write(ms, bio); 905 do_write(ms, bio);
906 906
diff --git a/drivers/md/dm-snap.c b/drivers/md/dm-snap.c
index 83ddbfe6b8a4..98a633f3d6b0 100644
--- a/drivers/md/dm-snap.c
+++ b/drivers/md/dm-snap.c
@@ -636,7 +636,7 @@ static void error_bios(struct bio *bio)
636 while (bio) { 636 while (bio) {
637 n = bio->bi_next; 637 n = bio->bi_next;
638 bio->bi_next = NULL; 638 bio->bi_next = NULL;
639 bio_io_error(bio, bio->bi_size); 639 bio_io_error(bio);
640 bio = n; 640 bio = n;
641 } 641 }
642} 642}
diff --git a/drivers/md/dm-zero.c b/drivers/md/dm-zero.c
index f314d7dc9c26..bdec206c404b 100644
--- a/drivers/md/dm-zero.c
+++ b/drivers/md/dm-zero.c
@@ -43,7 +43,7 @@ static int zero_map(struct dm_target *ti, struct bio *bio,
43 break; 43 break;
44 } 44 }
45 45
46 bio_endio(bio, bio->bi_size, 0); 46 bio_endio(bio, 0);
47 47
48 /* accepted bio, don't make new request */ 48 /* accepted bio, don't make new request */
49 return DM_MAPIO_SUBMITTED; 49 return DM_MAPIO_SUBMITTED;
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index 2120155929a6..167765c47747 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -484,23 +484,20 @@ static void dec_pending(struct dm_io *io, int error)
484 blk_add_trace_bio(io->md->queue, io->bio, 484 blk_add_trace_bio(io->md->queue, io->bio,
485 BLK_TA_COMPLETE); 485 BLK_TA_COMPLETE);
486 486
487 bio_endio(io->bio, io->bio->bi_size, io->error); 487 bio_endio(io->bio, io->error);
488 } 488 }
489 489
490 free_io(io->md, io); 490 free_io(io->md, io);
491 } 491 }
492} 492}
493 493
494static int clone_endio(struct bio *bio, unsigned int done, int error) 494static void clone_endio(struct bio *bio, int error)
495{ 495{
496 int r = 0; 496 int r = 0;
497 struct dm_target_io *tio = bio->bi_private; 497 struct dm_target_io *tio = bio->bi_private;
498 struct mapped_device *md = tio->io->md; 498 struct mapped_device *md = tio->io->md;
499 dm_endio_fn endio = tio->ti->type->end_io; 499 dm_endio_fn endio = tio->ti->type->end_io;
500 500
501 if (bio->bi_size)
502 return 1;
503
504 if (!bio_flagged(bio, BIO_UPTODATE) && !error) 501 if (!bio_flagged(bio, BIO_UPTODATE) && !error)
505 error = -EIO; 502 error = -EIO;
506 503
@@ -514,7 +511,7 @@ static int clone_endio(struct bio *bio, unsigned int done, int error)
514 error = r; 511 error = r;
515 else if (r == DM_ENDIO_INCOMPLETE) 512 else if (r == DM_ENDIO_INCOMPLETE)
516 /* The target will handle the io */ 513 /* The target will handle the io */
517 return 1; 514 return;
518 else if (r) { 515 else if (r) {
519 DMWARN("unimplemented target endio return value: %d", r); 516 DMWARN("unimplemented target endio return value: %d", r);
520 BUG(); 517 BUG();
@@ -530,7 +527,6 @@ static int clone_endio(struct bio *bio, unsigned int done, int error)
530 527
531 bio_put(bio); 528 bio_put(bio);
532 free_tio(md, tio); 529 free_tio(md, tio);
533 return r;
534} 530}
535 531
536static sector_t max_io_len(struct mapped_device *md, 532static sector_t max_io_len(struct mapped_device *md,
@@ -761,7 +757,7 @@ static void __split_bio(struct mapped_device *md, struct bio *bio)
761 757
762 ci.map = dm_get_table(md); 758 ci.map = dm_get_table(md);
763 if (!ci.map) { 759 if (!ci.map) {
764 bio_io_error(bio, bio->bi_size); 760 bio_io_error(bio);
765 return; 761 return;
766 } 762 }
767 763
@@ -803,7 +799,7 @@ static int dm_request(struct request_queue *q, struct bio *bio)
803 * guarantee it is (or can be) handled by the targets correctly. 799 * guarantee it is (or can be) handled by the targets correctly.
804 */ 800 */
805 if (unlikely(bio_barrier(bio))) { 801 if (unlikely(bio_barrier(bio))) {
806 bio_endio(bio, bio->bi_size, -EOPNOTSUPP); 802 bio_endio(bio, -EOPNOTSUPP);
807 return 0; 803 return 0;
808 } 804 }
809 805
@@ -820,13 +816,13 @@ static int dm_request(struct request_queue *q, struct bio *bio)
820 up_read(&md->io_lock); 816 up_read(&md->io_lock);
821 817
822 if (bio_rw(bio) == READA) { 818 if (bio_rw(bio) == READA) {
823 bio_io_error(bio, bio->bi_size); 819 bio_io_error(bio);
824 return 0; 820 return 0;
825 } 821 }
826 822
827 r = queue_io(md, bio); 823 r = queue_io(md, bio);
828 if (r < 0) { 824 if (r < 0) {
829 bio_io_error(bio, bio->bi_size); 825 bio_io_error(bio);
830 return 0; 826 return 0;
831 827
832 } else if (r == 0) 828 } else if (r == 0)
diff --git a/drivers/md/faulty.c b/drivers/md/faulty.c
index cb059cf14c2e..cf2ddce34118 100644
--- a/drivers/md/faulty.c
+++ b/drivers/md/faulty.c
@@ -65,18 +65,16 @@
65#include <linux/raid/md.h> 65#include <linux/raid/md.h>
66 66
67 67
68static int faulty_fail(struct bio *bio, unsigned int bytes_done, int error) 68static void faulty_fail(struct bio *bio, int error)
69{ 69{
70 struct bio *b = bio->bi_private; 70 struct bio *b = bio->bi_private;
71 71
72 b->bi_size = bio->bi_size; 72 b->bi_size = bio->bi_size;
73 b->bi_sector = bio->bi_sector; 73 b->bi_sector = bio->bi_sector;
74 74
75 if (bio->bi_size == 0) 75 bio_put(bio);
76 bio_put(bio);
77 76
78 clear_bit(BIO_UPTODATE, &b->bi_flags); 77 bio_io_error(b);
79 return (b->bi_end_io)(b, bytes_done, -EIO);
80} 78}
81 79
82typedef struct faulty_conf { 80typedef struct faulty_conf {
@@ -179,7 +177,7 @@ static int make_request(struct request_queue *q, struct bio *bio)
179 /* special case - don't decrement, don't generic_make_request, 177 /* special case - don't decrement, don't generic_make_request,
180 * just fail immediately 178 * just fail immediately
181 */ 179 */
182 bio_endio(bio, bio->bi_size, -EIO); 180 bio_endio(bio, -EIO);
183 return 0; 181 return 0;
184 } 182 }
185 183
diff --git a/drivers/md/linear.c b/drivers/md/linear.c
index 17f795c3e0ab..550148770bb2 100644
--- a/drivers/md/linear.c
+++ b/drivers/md/linear.c
@@ -338,7 +338,7 @@ static int linear_make_request (struct request_queue *q, struct bio *bio)
338 sector_t block; 338 sector_t block;
339 339
340 if (unlikely(bio_barrier(bio))) { 340 if (unlikely(bio_barrier(bio))) {
341 bio_endio(bio, bio->bi_size, -EOPNOTSUPP); 341 bio_endio(bio, -EOPNOTSUPP);
342 return 0; 342 return 0;
343 } 343 }
344 344
@@ -358,7 +358,7 @@ static int linear_make_request (struct request_queue *q, struct bio *bio)
358 bdevname(tmp_dev->rdev->bdev, b), 358 bdevname(tmp_dev->rdev->bdev, b),
359 (unsigned long long)tmp_dev->size, 359 (unsigned long long)tmp_dev->size,
360 (unsigned long long)tmp_dev->offset); 360 (unsigned long long)tmp_dev->offset);
361 bio_io_error(bio, bio->bi_size); 361 bio_io_error(bio);
362 return 0; 362 return 0;
363 } 363 }
364 if (unlikely(bio->bi_sector + (bio->bi_size >> 9) > 364 if (unlikely(bio->bi_sector + (bio->bi_size >> 9) >
diff --git a/drivers/md/md.c b/drivers/md/md.c
index f883b7e37f3d..e8f102ea9b03 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -213,7 +213,7 @@ static DEFINE_SPINLOCK(all_mddevs_lock);
213 213
214static int md_fail_request (struct request_queue *q, struct bio *bio) 214static int md_fail_request (struct request_queue *q, struct bio *bio)
215{ 215{
216 bio_io_error(bio, bio->bi_size); 216 bio_io_error(bio);
217 return 0; 217 return 0;
218} 218}
219 219
@@ -384,12 +384,10 @@ static void free_disk_sb(mdk_rdev_t * rdev)
384} 384}
385 385
386 386
387static int super_written(struct bio *bio, unsigned int bytes_done, int error) 387static void super_written(struct bio *bio, int error)
388{ 388{
389 mdk_rdev_t *rdev = bio->bi_private; 389 mdk_rdev_t *rdev = bio->bi_private;
390 mddev_t *mddev = rdev->mddev; 390 mddev_t *mddev = rdev->mddev;
391 if (bio->bi_size)
392 return 1;
393 391
394 if (error || !test_bit(BIO_UPTODATE, &bio->bi_flags)) { 392 if (error || !test_bit(BIO_UPTODATE, &bio->bi_flags)) {
395 printk("md: super_written gets error=%d, uptodate=%d\n", 393 printk("md: super_written gets error=%d, uptodate=%d\n",
@@ -401,16 +399,13 @@ static int super_written(struct bio *bio, unsigned int bytes_done, int error)
401 if (atomic_dec_and_test(&mddev->pending_writes)) 399 if (atomic_dec_and_test(&mddev->pending_writes))
402 wake_up(&mddev->sb_wait); 400 wake_up(&mddev->sb_wait);
403 bio_put(bio); 401 bio_put(bio);
404 return 0;
405} 402}
406 403
407static int super_written_barrier(struct bio *bio, unsigned int bytes_done, int error) 404static void super_written_barrier(struct bio *bio, int error)
408{ 405{
409 struct bio *bio2 = bio->bi_private; 406 struct bio *bio2 = bio->bi_private;
410 mdk_rdev_t *rdev = bio2->bi_private; 407 mdk_rdev_t *rdev = bio2->bi_private;
411 mddev_t *mddev = rdev->mddev; 408 mddev_t *mddev = rdev->mddev;
412 if (bio->bi_size)
413 return 1;
414 409
415 if (!test_bit(BIO_UPTODATE, &bio->bi_flags) && 410 if (!test_bit(BIO_UPTODATE, &bio->bi_flags) &&
416 error == -EOPNOTSUPP) { 411 error == -EOPNOTSUPP) {
@@ -424,11 +419,11 @@ static int super_written_barrier(struct bio *bio, unsigned int bytes_done, int e
424 spin_unlock_irqrestore(&mddev->write_lock, flags); 419 spin_unlock_irqrestore(&mddev->write_lock, flags);
425 wake_up(&mddev->sb_wait); 420 wake_up(&mddev->sb_wait);
426 bio_put(bio); 421 bio_put(bio);
427 return 0; 422 } else {
423 bio_put(bio2);
424 bio->bi_private = rdev;
425 super_written(bio, error);
428 } 426 }
429 bio_put(bio2);
430 bio->bi_private = rdev;
431 return super_written(bio, bytes_done, error);
432} 427}
433 428
434void md_super_write(mddev_t *mddev, mdk_rdev_t *rdev, 429void md_super_write(mddev_t *mddev, mdk_rdev_t *rdev,
@@ -489,13 +484,9 @@ void md_super_wait(mddev_t *mddev)
489 finish_wait(&mddev->sb_wait, &wq); 484 finish_wait(&mddev->sb_wait, &wq);
490} 485}
491 486
492static int bi_complete(struct bio *bio, unsigned int bytes_done, int error) 487static void bi_complete(struct bio *bio, int error)
493{ 488{
494 if (bio->bi_size)
495 return 1;
496
497 complete((struct completion*)bio->bi_private); 489 complete((struct completion*)bio->bi_private);
498 return 0;
499} 490}
500 491
501int sync_page_io(struct block_device *bdev, sector_t sector, int size, 492int sync_page_io(struct block_device *bdev, sector_t sector, int size,
diff --git a/drivers/md/multipath.c b/drivers/md/multipath.c
index 1e2af43a73b9..f2a63f394ad9 100644
--- a/drivers/md/multipath.c
+++ b/drivers/md/multipath.c
@@ -82,21 +82,17 @@ static void multipath_end_bh_io (struct multipath_bh *mp_bh, int err)
82 struct bio *bio = mp_bh->master_bio; 82 struct bio *bio = mp_bh->master_bio;
83 multipath_conf_t *conf = mddev_to_conf(mp_bh->mddev); 83 multipath_conf_t *conf = mddev_to_conf(mp_bh->mddev);
84 84
85 bio_endio(bio, bio->bi_size, err); 85 bio_endio(bio, err);
86 mempool_free(mp_bh, conf->pool); 86 mempool_free(mp_bh, conf->pool);
87} 87}
88 88
89static int multipath_end_request(struct bio *bio, unsigned int bytes_done, 89static void multipath_end_request(struct bio *bio, int error)
90 int error)
91{ 90{
92 int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); 91 int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags);
93 struct multipath_bh * mp_bh = (struct multipath_bh *)(bio->bi_private); 92 struct multipath_bh * mp_bh = (struct multipath_bh *)(bio->bi_private);
94 multipath_conf_t *conf = mddev_to_conf(mp_bh->mddev); 93 multipath_conf_t *conf = mddev_to_conf(mp_bh->mddev);
95 mdk_rdev_t *rdev = conf->multipaths[mp_bh->path].rdev; 94 mdk_rdev_t *rdev = conf->multipaths[mp_bh->path].rdev;
96 95
97 if (bio->bi_size)
98 return 1;
99
100 if (uptodate) 96 if (uptodate)
101 multipath_end_bh_io(mp_bh, 0); 97 multipath_end_bh_io(mp_bh, 0);
102 else if (!bio_rw_ahead(bio)) { 98 else if (!bio_rw_ahead(bio)) {
@@ -112,7 +108,6 @@ static int multipath_end_request(struct bio *bio, unsigned int bytes_done,
112 } else 108 } else
113 multipath_end_bh_io(mp_bh, error); 109 multipath_end_bh_io(mp_bh, error);
114 rdev_dec_pending(rdev, conf->mddev); 110 rdev_dec_pending(rdev, conf->mddev);
115 return 0;
116} 111}
117 112
118static void unplug_slaves(mddev_t *mddev) 113static void unplug_slaves(mddev_t *mddev)
@@ -155,7 +150,7 @@ static int multipath_make_request (struct request_queue *q, struct bio * bio)
155 const int rw = bio_data_dir(bio); 150 const int rw = bio_data_dir(bio);
156 151
157 if (unlikely(bio_barrier(bio))) { 152 if (unlikely(bio_barrier(bio))) {
158 bio_endio(bio, bio->bi_size, -EOPNOTSUPP); 153 bio_endio(bio, -EOPNOTSUPP);
159 return 0; 154 return 0;
160 } 155 }
161 156
@@ -169,7 +164,7 @@ static int multipath_make_request (struct request_queue *q, struct bio * bio)
169 164
170 mp_bh->path = multipath_map(conf); 165 mp_bh->path = multipath_map(conf);
171 if (mp_bh->path < 0) { 166 if (mp_bh->path < 0) {
172 bio_endio(bio, bio->bi_size, -EIO); 167 bio_endio(bio, -EIO);
173 mempool_free(mp_bh, conf->pool); 168 mempool_free(mp_bh, conf->pool);
174 return 0; 169 return 0;
175 } 170 }
diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index b8216bc6db45..ef0da2d84959 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -420,7 +420,7 @@ static int raid0_make_request (struct request_queue *q, struct bio *bio)
420 const int rw = bio_data_dir(bio); 420 const int rw = bio_data_dir(bio);
421 421
422 if (unlikely(bio_barrier(bio))) { 422 if (unlikely(bio_barrier(bio))) {
423 bio_endio(bio, bio->bi_size, -EOPNOTSUPP); 423 bio_endio(bio, -EOPNOTSUPP);
424 return 0; 424 return 0;
425 } 425 }
426 426
@@ -490,7 +490,7 @@ bad_map:
490 " or bigger than %dk %llu %d\n", chunk_size, 490 " or bigger than %dk %llu %d\n", chunk_size,
491 (unsigned long long)bio->bi_sector, bio->bi_size >> 10); 491 (unsigned long long)bio->bi_sector, bio->bi_size >> 10);
492 492
493 bio_io_error(bio, bio->bi_size); 493 bio_io_error(bio);
494 return 0; 494 return 0;
495} 495}
496 496
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index f33a729960ca..6d03bea6fa58 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -238,7 +238,7 @@ static void raid_end_bio_io(r1bio_t *r1_bio)
238 (unsigned long long) bio->bi_sector + 238 (unsigned long long) bio->bi_sector +
239 (bio->bi_size >> 9) - 1); 239 (bio->bi_size >> 9) - 1);
240 240
241 bio_endio(bio, bio->bi_size, 241 bio_endio(bio,
242 test_bit(R1BIO_Uptodate, &r1_bio->state) ? 0 : -EIO); 242 test_bit(R1BIO_Uptodate, &r1_bio->state) ? 0 : -EIO);
243 } 243 }
244 free_r1bio(r1_bio); 244 free_r1bio(r1_bio);
@@ -255,16 +255,13 @@ static inline void update_head_pos(int disk, r1bio_t *r1_bio)
255 r1_bio->sector + (r1_bio->sectors); 255 r1_bio->sector + (r1_bio->sectors);
256} 256}
257 257
258static int raid1_end_read_request(struct bio *bio, unsigned int bytes_done, int error) 258static void raid1_end_read_request(struct bio *bio, int error)
259{ 259{
260 int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); 260 int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags);
261 r1bio_t * r1_bio = (r1bio_t *)(bio->bi_private); 261 r1bio_t * r1_bio = (r1bio_t *)(bio->bi_private);
262 int mirror; 262 int mirror;
263 conf_t *conf = mddev_to_conf(r1_bio->mddev); 263 conf_t *conf = mddev_to_conf(r1_bio->mddev);
264 264
265 if (bio->bi_size)
266 return 1;
267
268 mirror = r1_bio->read_disk; 265 mirror = r1_bio->read_disk;
269 /* 266 /*
270 * this branch is our 'one mirror IO has finished' event handler: 267 * this branch is our 'one mirror IO has finished' event handler:
@@ -301,10 +298,9 @@ static int raid1_end_read_request(struct bio *bio, unsigned int bytes_done, int
301 } 298 }
302 299
303 rdev_dec_pending(conf->mirrors[mirror].rdev, conf->mddev); 300 rdev_dec_pending(conf->mirrors[mirror].rdev, conf->mddev);
304 return 0;
305} 301}
306 302
307static int raid1_end_write_request(struct bio *bio, unsigned int bytes_done, int error) 303static void raid1_end_write_request(struct bio *bio, int error)
308{ 304{
309 int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); 305 int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags);
310 r1bio_t * r1_bio = (r1bio_t *)(bio->bi_private); 306 r1bio_t * r1_bio = (r1bio_t *)(bio->bi_private);
@@ -312,8 +308,6 @@ static int raid1_end_write_request(struct bio *bio, unsigned int bytes_done, int
312 conf_t *conf = mddev_to_conf(r1_bio->mddev); 308 conf_t *conf = mddev_to_conf(r1_bio->mddev);
313 struct bio *to_put = NULL; 309 struct bio *to_put = NULL;
314 310
315 if (bio->bi_size)
316 return 1;
317 311
318 for (mirror = 0; mirror < conf->raid_disks; mirror++) 312 for (mirror = 0; mirror < conf->raid_disks; mirror++)
319 if (r1_bio->bios[mirror] == bio) 313 if (r1_bio->bios[mirror] == bio)
@@ -366,7 +360,7 @@ static int raid1_end_write_request(struct bio *bio, unsigned int bytes_done, int
366 (unsigned long long) mbio->bi_sector, 360 (unsigned long long) mbio->bi_sector,
367 (unsigned long long) mbio->bi_sector + 361 (unsigned long long) mbio->bi_sector +
368 (mbio->bi_size >> 9) - 1); 362 (mbio->bi_size >> 9) - 1);
369 bio_endio(mbio, mbio->bi_size, 0); 363 bio_endio(mbio, 0);
370 } 364 }
371 } 365 }
372 } 366 }
@@ -400,8 +394,6 @@ static int raid1_end_write_request(struct bio *bio, unsigned int bytes_done, int
400 394
401 if (to_put) 395 if (to_put)
402 bio_put(to_put); 396 bio_put(to_put);
403
404 return 0;
405} 397}
406 398
407 399
@@ -796,7 +788,7 @@ static int make_request(struct request_queue *q, struct bio * bio)
796 if (unlikely(!mddev->barriers_work && bio_barrier(bio))) { 788 if (unlikely(!mddev->barriers_work && bio_barrier(bio))) {
797 if (rw == WRITE) 789 if (rw == WRITE)
798 md_write_end(mddev); 790 md_write_end(mddev);
799 bio_endio(bio, bio->bi_size, -EOPNOTSUPP); 791 bio_endio(bio, -EOPNOTSUPP);
800 return 0; 792 return 0;
801 } 793 }
802 794
@@ -1137,14 +1129,11 @@ abort:
1137} 1129}
1138 1130
1139 1131
1140static int end_sync_read(struct bio *bio, unsigned int bytes_done, int error) 1132static void end_sync_read(struct bio *bio, int error)
1141{ 1133{
1142 r1bio_t * r1_bio = (r1bio_t *)(bio->bi_private); 1134 r1bio_t * r1_bio = (r1bio_t *)(bio->bi_private);
1143 int i; 1135 int i;
1144 1136
1145 if (bio->bi_size)
1146 return 1;
1147
1148 for (i=r1_bio->mddev->raid_disks; i--; ) 1137 for (i=r1_bio->mddev->raid_disks; i--; )
1149 if (r1_bio->bios[i] == bio) 1138 if (r1_bio->bios[i] == bio)
1150 break; 1139 break;
@@ -1160,10 +1149,9 @@ static int end_sync_read(struct bio *bio, unsigned int bytes_done, int error)
1160 1149
1161 if (atomic_dec_and_test(&r1_bio->remaining)) 1150 if (atomic_dec_and_test(&r1_bio->remaining))
1162 reschedule_retry(r1_bio); 1151 reschedule_retry(r1_bio);
1163 return 0;
1164} 1152}
1165 1153
1166static int end_sync_write(struct bio *bio, unsigned int bytes_done, int error) 1154static void end_sync_write(struct bio *bio, int error)
1167{ 1155{
1168 int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); 1156 int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags);
1169 r1bio_t * r1_bio = (r1bio_t *)(bio->bi_private); 1157 r1bio_t * r1_bio = (r1bio_t *)(bio->bi_private);
@@ -1172,9 +1160,6 @@ static int end_sync_write(struct bio *bio, unsigned int bytes_done, int error)
1172 int i; 1160 int i;
1173 int mirror=0; 1161 int mirror=0;
1174 1162
1175 if (bio->bi_size)
1176 return 1;
1177
1178 for (i = 0; i < conf->raid_disks; i++) 1163 for (i = 0; i < conf->raid_disks; i++)
1179 if (r1_bio->bios[i] == bio) { 1164 if (r1_bio->bios[i] == bio) {
1180 mirror = i; 1165 mirror = i;
@@ -1200,7 +1185,6 @@ static int end_sync_write(struct bio *bio, unsigned int bytes_done, int error)
1200 md_done_sync(mddev, r1_bio->sectors, uptodate); 1185 md_done_sync(mddev, r1_bio->sectors, uptodate);
1201 put_buf(r1_bio); 1186 put_buf(r1_bio);
1202 } 1187 }
1203 return 0;
1204} 1188}
1205 1189
1206static void sync_request_write(mddev_t *mddev, r1bio_t *r1_bio) 1190static void sync_request_write(mddev_t *mddev, r1bio_t *r1_bio)
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 4e53792aa520..25a96c42bdb0 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -227,7 +227,7 @@ static void raid_end_bio_io(r10bio_t *r10_bio)
227{ 227{
228 struct bio *bio = r10_bio->master_bio; 228 struct bio *bio = r10_bio->master_bio;
229 229
230 bio_endio(bio, bio->bi_size, 230 bio_endio(bio,
231 test_bit(R10BIO_Uptodate, &r10_bio->state) ? 0 : -EIO); 231 test_bit(R10BIO_Uptodate, &r10_bio->state) ? 0 : -EIO);
232 free_r10bio(r10_bio); 232 free_r10bio(r10_bio);
233} 233}
@@ -243,15 +243,13 @@ static inline void update_head_pos(int slot, r10bio_t *r10_bio)
243 r10_bio->devs[slot].addr + (r10_bio->sectors); 243 r10_bio->devs[slot].addr + (r10_bio->sectors);
244} 244}
245 245
246static int raid10_end_read_request(struct bio *bio, unsigned int bytes_done, int error) 246static void raid10_end_read_request(struct bio *bio, int error)
247{ 247{
248 int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); 248 int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags);
249 r10bio_t * r10_bio = (r10bio_t *)(bio->bi_private); 249 r10bio_t * r10_bio = (r10bio_t *)(bio->bi_private);
250 int slot, dev; 250 int slot, dev;
251 conf_t *conf = mddev_to_conf(r10_bio->mddev); 251 conf_t *conf = mddev_to_conf(r10_bio->mddev);
252 252
253 if (bio->bi_size)
254 return 1;
255 253
256 slot = r10_bio->read_slot; 254 slot = r10_bio->read_slot;
257 dev = r10_bio->devs[slot].devnum; 255 dev = r10_bio->devs[slot].devnum;
@@ -284,19 +282,15 @@ static int raid10_end_read_request(struct bio *bio, unsigned int bytes_done, int
284 } 282 }
285 283
286 rdev_dec_pending(conf->mirrors[dev].rdev, conf->mddev); 284 rdev_dec_pending(conf->mirrors[dev].rdev, conf->mddev);
287 return 0;
288} 285}
289 286
290static int raid10_end_write_request(struct bio *bio, unsigned int bytes_done, int error) 287static void raid10_end_write_request(struct bio *bio, int error)
291{ 288{
292 int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); 289 int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags);
293 r10bio_t * r10_bio = (r10bio_t *)(bio->bi_private); 290 r10bio_t * r10_bio = (r10bio_t *)(bio->bi_private);
294 int slot, dev; 291 int slot, dev;
295 conf_t *conf = mddev_to_conf(r10_bio->mddev); 292 conf_t *conf = mddev_to_conf(r10_bio->mddev);
296 293
297 if (bio->bi_size)
298 return 1;
299
300 for (slot = 0; slot < conf->copies; slot++) 294 for (slot = 0; slot < conf->copies; slot++)
301 if (r10_bio->devs[slot].bio == bio) 295 if (r10_bio->devs[slot].bio == bio)
302 break; 296 break;
@@ -339,7 +333,6 @@ static int raid10_end_write_request(struct bio *bio, unsigned int bytes_done, in
339 } 333 }
340 334
341 rdev_dec_pending(conf->mirrors[dev].rdev, conf->mddev); 335 rdev_dec_pending(conf->mirrors[dev].rdev, conf->mddev);
342 return 0;
343} 336}
344 337
345 338
@@ -787,7 +780,7 @@ static int make_request(struct request_queue *q, struct bio * bio)
787 unsigned long flags; 780 unsigned long flags;
788 781
789 if (unlikely(bio_barrier(bio))) { 782 if (unlikely(bio_barrier(bio))) {
790 bio_endio(bio, bio->bi_size, -EOPNOTSUPP); 783 bio_endio(bio, -EOPNOTSUPP);
791 return 0; 784 return 0;
792 } 785 }
793 786
@@ -819,7 +812,7 @@ static int make_request(struct request_queue *q, struct bio * bio)
819 " or bigger than %dk %llu %d\n", chunk_sects/2, 812 " or bigger than %dk %llu %d\n", chunk_sects/2,
820 (unsigned long long)bio->bi_sector, bio->bi_size >> 10); 813 (unsigned long long)bio->bi_sector, bio->bi_size >> 10);
821 814
822 bio_io_error(bio, bio->bi_size); 815 bio_io_error(bio);
823 return 0; 816 return 0;
824 } 817 }
825 818
@@ -1155,15 +1148,12 @@ abort:
1155} 1148}
1156 1149
1157 1150
1158static int end_sync_read(struct bio *bio, unsigned int bytes_done, int error) 1151static void end_sync_read(struct bio *bio, int error)
1159{ 1152{
1160 r10bio_t * r10_bio = (r10bio_t *)(bio->bi_private); 1153 r10bio_t * r10_bio = (r10bio_t *)(bio->bi_private);
1161 conf_t *conf = mddev_to_conf(r10_bio->mddev); 1154 conf_t *conf = mddev_to_conf(r10_bio->mddev);
1162 int i,d; 1155 int i,d;
1163 1156
1164 if (bio->bi_size)
1165 return 1;
1166
1167 for (i=0; i<conf->copies; i++) 1157 for (i=0; i<conf->copies; i++)
1168 if (r10_bio->devs[i].bio == bio) 1158 if (r10_bio->devs[i].bio == bio)
1169 break; 1159 break;
@@ -1192,10 +1182,9 @@ static int end_sync_read(struct bio *bio, unsigned int bytes_done, int error)
1192 reschedule_retry(r10_bio); 1182 reschedule_retry(r10_bio);
1193 } 1183 }
1194 rdev_dec_pending(conf->mirrors[d].rdev, conf->mddev); 1184 rdev_dec_pending(conf->mirrors[d].rdev, conf->mddev);
1195 return 0;
1196} 1185}
1197 1186
1198static int end_sync_write(struct bio *bio, unsigned int bytes_done, int error) 1187static void end_sync_write(struct bio *bio, int error)
1199{ 1188{
1200 int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); 1189 int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags);
1201 r10bio_t * r10_bio = (r10bio_t *)(bio->bi_private); 1190 r10bio_t * r10_bio = (r10bio_t *)(bio->bi_private);
@@ -1203,9 +1192,6 @@ static int end_sync_write(struct bio *bio, unsigned int bytes_done, int error)
1203 conf_t *conf = mddev_to_conf(mddev); 1192 conf_t *conf = mddev_to_conf(mddev);
1204 int i,d; 1193 int i,d;
1205 1194
1206 if (bio->bi_size)
1207 return 1;
1208
1209 for (i = 0; i < conf->copies; i++) 1195 for (i = 0; i < conf->copies; i++)
1210 if (r10_bio->devs[i].bio == bio) 1196 if (r10_bio->devs[i].bio == bio)
1211 break; 1197 break;
@@ -1228,7 +1214,6 @@ static int end_sync_write(struct bio *bio, unsigned int bytes_done, int error)
1228 } 1214 }
1229 } 1215 }
1230 rdev_dec_pending(conf->mirrors[d].rdev, mddev); 1216 rdev_dec_pending(conf->mirrors[d].rdev, mddev);
1231 return 0;
1232} 1217}
1233 1218
1234/* 1219/*
@@ -1374,7 +1359,7 @@ static void recovery_request_write(mddev_t *mddev, r10bio_t *r10_bio)
1374 if (test_bit(R10BIO_Uptodate, &r10_bio->state)) 1359 if (test_bit(R10BIO_Uptodate, &r10_bio->state))
1375 generic_make_request(wbio); 1360 generic_make_request(wbio);
1376 else 1361 else
1377 bio_endio(wbio, wbio->bi_size, -EIO); 1362 bio_endio(wbio, -EIO);
1378} 1363}
1379 1364
1380 1365
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index f96dea975fa5..caaca9e178bc 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -108,12 +108,11 @@ static void return_io(struct bio *return_bi)
108{ 108{
109 struct bio *bi = return_bi; 109 struct bio *bi = return_bi;
110 while (bi) { 110 while (bi) {
111 int bytes = bi->bi_size;
112 111
113 return_bi = bi->bi_next; 112 return_bi = bi->bi_next;
114 bi->bi_next = NULL; 113 bi->bi_next = NULL;
115 bi->bi_size = 0; 114 bi->bi_size = 0;
116 bi->bi_end_io(bi, bytes, 115 bi->bi_end_io(bi,
117 test_bit(BIO_UPTODATE, &bi->bi_flags) 116 test_bit(BIO_UPTODATE, &bi->bi_flags)
118 ? 0 : -EIO); 117 ? 0 : -EIO);
119 bi = return_bi; 118 bi = return_bi;
@@ -382,10 +381,10 @@ static unsigned long get_stripe_work(struct stripe_head *sh)
382 return pending; 381 return pending;
383} 382}
384 383
385static int 384static void
386raid5_end_read_request(struct bio *bi, unsigned int bytes_done, int error); 385raid5_end_read_request(struct bio *bi, int error);
387static int 386static void
388raid5_end_write_request (struct bio *bi, unsigned int bytes_done, int error); 387raid5_end_write_request(struct bio *bi, int error);
389 388
390static void ops_run_io(struct stripe_head *sh) 389static void ops_run_io(struct stripe_head *sh)
391{ 390{
@@ -1110,8 +1109,7 @@ static void shrink_stripes(raid5_conf_t *conf)
1110 conf->slab_cache = NULL; 1109 conf->slab_cache = NULL;
1111} 1110}
1112 1111
1113static int raid5_end_read_request(struct bio * bi, unsigned int bytes_done, 1112static void raid5_end_read_request(struct bio * bi, int error)
1114 int error)
1115{ 1113{
1116 struct stripe_head *sh = bi->bi_private; 1114 struct stripe_head *sh = bi->bi_private;
1117 raid5_conf_t *conf = sh->raid_conf; 1115 raid5_conf_t *conf = sh->raid_conf;
@@ -1120,8 +1118,6 @@ static int raid5_end_read_request(struct bio * bi, unsigned int bytes_done,
1120 char b[BDEVNAME_SIZE]; 1118 char b[BDEVNAME_SIZE];
1121 mdk_rdev_t *rdev; 1119 mdk_rdev_t *rdev;
1122 1120
1123 if (bi->bi_size)
1124 return 1;
1125 1121
1126 for (i=0 ; i<disks; i++) 1122 for (i=0 ; i<disks; i++)
1127 if (bi == &sh->dev[i].req) 1123 if (bi == &sh->dev[i].req)
@@ -1132,7 +1128,7 @@ static int raid5_end_read_request(struct bio * bi, unsigned int bytes_done,
1132 uptodate); 1128 uptodate);
1133 if (i == disks) { 1129 if (i == disks) {
1134 BUG(); 1130 BUG();
1135 return 0; 1131 return;
1136 } 1132 }
1137 1133
1138 if (uptodate) { 1134 if (uptodate) {
@@ -1185,20 +1181,15 @@ static int raid5_end_read_request(struct bio * bi, unsigned int bytes_done,
1185 clear_bit(R5_LOCKED, &sh->dev[i].flags); 1181 clear_bit(R5_LOCKED, &sh->dev[i].flags);
1186 set_bit(STRIPE_HANDLE, &sh->state); 1182 set_bit(STRIPE_HANDLE, &sh->state);
1187 release_stripe(sh); 1183 release_stripe(sh);
1188 return 0;
1189} 1184}
1190 1185
1191static int raid5_end_write_request (struct bio *bi, unsigned int bytes_done, 1186static void raid5_end_write_request (struct bio *bi, int error)
1192 int error)
1193{ 1187{
1194 struct stripe_head *sh = bi->bi_private; 1188 struct stripe_head *sh = bi->bi_private;
1195 raid5_conf_t *conf = sh->raid_conf; 1189 raid5_conf_t *conf = sh->raid_conf;
1196 int disks = sh->disks, i; 1190 int disks = sh->disks, i;
1197 int uptodate = test_bit(BIO_UPTODATE, &bi->bi_flags); 1191 int uptodate = test_bit(BIO_UPTODATE, &bi->bi_flags);
1198 1192
1199 if (bi->bi_size)
1200 return 1;
1201
1202 for (i=0 ; i<disks; i++) 1193 for (i=0 ; i<disks; i++)
1203 if (bi == &sh->dev[i].req) 1194 if (bi == &sh->dev[i].req)
1204 break; 1195 break;
@@ -1208,7 +1199,7 @@ static int raid5_end_write_request (struct bio *bi, unsigned int bytes_done,
1208 uptodate); 1199 uptodate);
1209 if (i == disks) { 1200 if (i == disks) {
1210 BUG(); 1201 BUG();
1211 return 0; 1202 return;
1212 } 1203 }
1213 1204
1214 if (!uptodate) 1205 if (!uptodate)
@@ -1219,7 +1210,6 @@ static int raid5_end_write_request (struct bio *bi, unsigned int bytes_done,
1219 clear_bit(R5_LOCKED, &sh->dev[i].flags); 1210 clear_bit(R5_LOCKED, &sh->dev[i].flags);
1220 set_bit(STRIPE_HANDLE, &sh->state); 1211 set_bit(STRIPE_HANDLE, &sh->state);
1221 release_stripe(sh); 1212 release_stripe(sh);
1222 return 0;
1223} 1213}
1224 1214
1225 1215
@@ -3340,7 +3330,7 @@ static struct bio *remove_bio_from_retry(raid5_conf_t *conf)
3340 * first). 3330 * first).
3341 * If the read failed.. 3331 * If the read failed..
3342 */ 3332 */
3343static int raid5_align_endio(struct bio *bi, unsigned int bytes, int error) 3333static void raid5_align_endio(struct bio *bi, int error)
3344{ 3334{
3345 struct bio* raid_bi = bi->bi_private; 3335 struct bio* raid_bi = bi->bi_private;
3346 mddev_t *mddev; 3336 mddev_t *mddev;
@@ -3348,8 +3338,6 @@ static int raid5_align_endio(struct bio *bi, unsigned int bytes, int error)
3348 int uptodate = test_bit(BIO_UPTODATE, &bi->bi_flags); 3338 int uptodate = test_bit(BIO_UPTODATE, &bi->bi_flags);
3349 mdk_rdev_t *rdev; 3339 mdk_rdev_t *rdev;
3350 3340
3351 if (bi->bi_size)
3352 return 1;
3353 bio_put(bi); 3341 bio_put(bi);
3354 3342
3355 mddev = raid_bi->bi_bdev->bd_disk->queue->queuedata; 3343 mddev = raid_bi->bi_bdev->bd_disk->queue->queuedata;
@@ -3360,17 +3348,16 @@ static int raid5_align_endio(struct bio *bi, unsigned int bytes, int error)
3360 rdev_dec_pending(rdev, conf->mddev); 3348 rdev_dec_pending(rdev, conf->mddev);
3361 3349
3362 if (!error && uptodate) { 3350 if (!error && uptodate) {
3363 bio_endio(raid_bi, bytes, 0); 3351 bio_endio(raid_bi, 0);
3364 if (atomic_dec_and_test(&conf->active_aligned_reads)) 3352 if (atomic_dec_and_test(&conf->active_aligned_reads))
3365 wake_up(&conf->wait_for_stripe); 3353 wake_up(&conf->wait_for_stripe);
3366 return 0; 3354 return;
3367 } 3355 }
3368 3356
3369 3357
3370 pr_debug("raid5_align_endio : io error...handing IO for a retry\n"); 3358 pr_debug("raid5_align_endio : io error...handing IO for a retry\n");
3371 3359
3372 add_bio_to_retry(raid_bi, conf); 3360 add_bio_to_retry(raid_bi, conf);
3373 return 0;
3374} 3361}
3375 3362
3376static int bio_fits_rdev(struct bio *bi) 3363static int bio_fits_rdev(struct bio *bi)
@@ -3476,7 +3463,7 @@ static int make_request(struct request_queue *q, struct bio * bi)
3476 int remaining; 3463 int remaining;
3477 3464
3478 if (unlikely(bio_barrier(bi))) { 3465 if (unlikely(bio_barrier(bi))) {
3479 bio_endio(bi, bi->bi_size, -EOPNOTSUPP); 3466 bio_endio(bi, -EOPNOTSUPP);
3480 return 0; 3467 return 0;
3481 } 3468 }
3482 3469
@@ -3592,12 +3579,11 @@ static int make_request(struct request_queue *q, struct bio * bi)
3592 remaining = --bi->bi_phys_segments; 3579 remaining = --bi->bi_phys_segments;
3593 spin_unlock_irq(&conf->device_lock); 3580 spin_unlock_irq(&conf->device_lock);
3594 if (remaining == 0) { 3581 if (remaining == 0) {
3595 int bytes = bi->bi_size;
3596 3582
3597 if ( rw == WRITE ) 3583 if ( rw == WRITE )
3598 md_write_end(mddev); 3584 md_write_end(mddev);
3599 bi->bi_size = 0; 3585
3600 bi->bi_end_io(bi, bytes, 3586 bi->bi_end_io(bi,
3601 test_bit(BIO_UPTODATE, &bi->bi_flags) 3587 test_bit(BIO_UPTODATE, &bi->bi_flags)
3602 ? 0 : -EIO); 3588 ? 0 : -EIO);
3603 } 3589 }
@@ -3875,10 +3861,8 @@ static int retry_aligned_read(raid5_conf_t *conf, struct bio *raid_bio)
3875 remaining = --raid_bio->bi_phys_segments; 3861 remaining = --raid_bio->bi_phys_segments;
3876 spin_unlock_irq(&conf->device_lock); 3862 spin_unlock_irq(&conf->device_lock);
3877 if (remaining == 0) { 3863 if (remaining == 0) {
3878 int bytes = raid_bio->bi_size;
3879 3864
3880 raid_bio->bi_size = 0; 3865 raid_bio->bi_end_io(raid_bio,
3881 raid_bio->bi_end_io(raid_bio, bytes,
3882 test_bit(BIO_UPTODATE, &raid_bio->bi_flags) 3866 test_bit(BIO_UPTODATE, &raid_bio->bi_flags)
3883 ? 0 : -EIO); 3867 ? 0 : -EIO);
3884 } 3868 }
diff --git a/drivers/media/Kconfig b/drivers/media/Kconfig
index d9d033e07e19..dd9bd4310c84 100644
--- a/drivers/media/Kconfig
+++ b/drivers/media/Kconfig
@@ -69,13 +69,79 @@ source "drivers/media/common/Kconfig"
69config VIDEO_TUNER 69config VIDEO_TUNER
70 tristate 70 tristate
71 depends on I2C 71 depends on I2C
72 select TUNER_MT20XX if !VIDEO_TUNER_CUSTOMIZE
73 select TUNER_TDA8290 if !VIDEO_TUNER_CUSTOMIZE
74 select TUNER_TEA5761 if !VIDEO_TUNER_CUSTOMIZE
75 select TUNER_TEA5767 if !VIDEO_TUNER_CUSTOMIZE
76 select TUNER_SIMPLE if !VIDEO_TUNER_CUSTOMIZE
77
78menuconfig VIDEO_TUNER_CUSTOMIZE
79 bool "Customize analog tuner modules to build"
80 depends on VIDEO_TUNER
81 help
82 This allows the user to deselect tuner drivers unnecessary
83 for their hardware from the build. Use this option with care
84 as deselecting tuner drivers which are in fact necessary will
85 result in V4L devices which cannot be tuned due to lack of
86 driver support
87
88 If unsure say N.
89
90if VIDEO_TUNER_CUSTOMIZE
91
92config TUNER_MT20XX
93 tristate "Microtune 2032 / 2050 tuners"
94 depends on I2C
95 default m if VIDEO_TUNER_CUSTOMIZE
96 help
97 Say Y here to include support for the MT2032 / MT2050 tuner.
98
99config TUNER_TDA8290
100 tristate "TDA 8290+8275(a) tuner combo"
101 depends on I2C
102 default m if VIDEO_TUNER_CUSTOMIZE
103 help
104 Say Y here to include support for Philips TDA8290+8275(a) tuner.
105
106config TUNER_TEA5761
107 tristate "TEA 5761 radio tuner (EXPERIMENTAL)"
108 depends on I2C && EXPERIMENTAL
109 default m if VIDEO_TUNER_CUSTOMIZE
110 help
111 Say Y here to include support for the Philips TEA5761 radio tuner.
112
113config TUNER_TEA5767
114 tristate "TEA 5767 radio tuner"
115 depends on I2C
116 default m if VIDEO_TUNER_CUSTOMIZE
117 help
118 Say Y here to include support for the Philips TEA5767 radio tuner.
119
120config TUNER_SIMPLE
121 tristate "Simple tuner support"
122 depends on I2C
123 default m if VIDEO_TUNER_CUSTOMIZE
124 help
125 Say Y here to include support for various simple tuners.
72 126
73config VIDEO_BUF 127endif # VIDEO_TUNER_CUSTOMIZE
128
129config VIDEOBUF_GEN
130 tristate
131
132config VIDEOBUF_DMA_SG
74 depends on PCI 133 depends on PCI
134 select VIDEOBUF_GEN
135 tristate
136
137config VIDEOBUF_VMALLOC
138 select VIDEOBUF_GEN
75 tristate 139 tristate
76 140
77config VIDEO_BUF_DVB 141config VIDEOBUF_DVB
78 tristate 142 tristate
143 select VIDEOBUF_GEN
144 select VIDEOBUF_DMA_SG
79 145
80config VIDEO_BTCX 146config VIDEO_BTCX
81 tristate 147 tristate
diff --git a/drivers/media/common/Kconfig b/drivers/media/common/Kconfig
index 5c63c8e24ee7..c5092ef1082f 100644
--- a/drivers/media/common/Kconfig
+++ b/drivers/media/common/Kconfig
@@ -5,5 +5,5 @@ config VIDEO_SAA7146
5config VIDEO_SAA7146_VV 5config VIDEO_SAA7146_VV
6 tristate 6 tristate
7 depends on VIDEO_DEV 7 depends on VIDEO_DEV
8 select VIDEO_BUF 8 select VIDEOBUF_DMA_SG
9 select VIDEO_SAA7146 9 select VIDEO_SAA7146
diff --git a/drivers/media/common/ir-functions.c b/drivers/media/common/ir-functions.c
index a3292e955aaa..e7c3ab951a44 100644
--- a/drivers/media/common/ir-functions.c
+++ b/drivers/media/common/ir-functions.c
@@ -21,7 +21,6 @@
21 */ 21 */
22 22
23#include <linux/module.h> 23#include <linux/module.h>
24#include <linux/moduleparam.h>
25#include <linux/string.h> 24#include <linux/string.h>
26#include <linux/jiffies.h> 25#include <linux/jiffies.h>
27#include <media/ir-common.h> 26#include <media/ir-common.h>
diff --git a/drivers/media/common/ir-keymaps.c b/drivers/media/common/ir-keymaps.c
index cbd1184b5219..aefcf28da1ca 100644
--- a/drivers/media/common/ir-keymaps.c
+++ b/drivers/media/common/ir-keymaps.c
@@ -20,7 +20,6 @@
20 20
21 */ 21 */
22#include <linux/module.h> 22#include <linux/module.h>
23#include <linux/moduleparam.h>
24 23
25#include <linux/input.h> 24#include <linux/input.h>
26#include <media/ir-common.h> 25#include <media/ir-common.h>
@@ -1783,3 +1782,64 @@ IR_KEYTAB_TYPE ir_codes_tt_1500[IR_KEYTAB_SIZE] = {
1783}; 1782};
1784 1783
1785EXPORT_SYMBOL_GPL(ir_codes_tt_1500); 1784EXPORT_SYMBOL_GPL(ir_codes_tt_1500);
1785
1786/* DViCO FUSION HDTV MCE remote */
1787IR_KEYTAB_TYPE ir_codes_fusionhdtv_mce[IR_KEYTAB_SIZE] = {
1788
1789 [ 0x0b ] = KEY_1,
1790 [ 0x17 ] = KEY_2,
1791 [ 0x1b ] = KEY_3,
1792 [ 0x07 ] = KEY_4,
1793 [ 0x50 ] = KEY_5,
1794 [ 0x54 ] = KEY_6,
1795 [ 0x48 ] = KEY_7,
1796 [ 0x4c ] = KEY_8,
1797 [ 0x58 ] = KEY_9,
1798 [ 0x03 ] = KEY_0,
1799
1800 [ 0x5e ] = KEY_OK,
1801 [ 0x51 ] = KEY_UP,
1802 [ 0x53 ] = KEY_DOWN,
1803 [ 0x5b ] = KEY_LEFT,
1804 [ 0x5f ] = KEY_RIGHT,
1805
1806 [ 0x02 ] = KEY_TV, /* Labeled DTV on remote */
1807 [ 0x0e ] = KEY_MP3,
1808 [ 0x1a ] = KEY_DVD,
1809 [ 0x1e ] = KEY_FAVORITES, /* Labeled CPF on remote */
1810 [ 0x16 ] = KEY_SETUP,
1811 [ 0x46 ] = KEY_POWER2, /* TV On/Off button on remote */
1812 [ 0x0a ] = KEY_EPG, /* Labeled Guide on remote */
1813
1814 [ 0x49 ] = KEY_BACK,
1815 [ 0x59 ] = KEY_INFO, /* Labeled MORE on remote */
1816 [ 0x4d ] = KEY_MENU, /* Labeled DVDMENU on remote */
1817 [ 0x55 ] = KEY_CYCLEWINDOWS, /* Labeled ALT-TAB on remote */
1818
1819 [ 0x0f ] = KEY_PREVIOUSSONG, /* Labeled |<< REPLAY on remote */
1820 [ 0x12 ] = KEY_NEXTSONG, /* Labeled >>| SKIP on remote */
1821 [ 0x42 ] = KEY_ENTER, /* Labeled START with a green
1822 * MS windows logo on remote */
1823
1824 [ 0x15 ] = KEY_VOLUMEUP,
1825 [ 0x05 ] = KEY_VOLUMEDOWN,
1826 [ 0x11 ] = KEY_CHANNELUP,
1827 [ 0x09 ] = KEY_CHANNELDOWN,
1828
1829 [ 0x52 ] = KEY_CAMERA,
1830 [ 0x5a ] = KEY_TUNER,
1831 [ 0x19 ] = KEY_OPEN,
1832
1833 [ 0x13 ] = KEY_MODE, /* 4:3 16:9 select */
1834 [ 0x1f ] = KEY_ZOOM,
1835
1836 [ 0x43 ] = KEY_REWIND,
1837 [ 0x47 ] = KEY_PLAYPAUSE,
1838 [ 0x4f ] = KEY_FASTFORWARD,
1839 [ 0x57 ] = KEY_MUTE,
1840 [ 0x0d ] = KEY_STOP,
1841 [ 0x01 ] = KEY_RECORD,
1842 [ 0x4e ] = KEY_POWER,
1843};
1844
1845EXPORT_SYMBOL_GPL(ir_codes_fusionhdtv_mce);
diff --git a/drivers/media/common/saa7146_core.c b/drivers/media/common/saa7146_core.c
index ba6701e97671..365a22118a09 100644
--- a/drivers/media/common/saa7146_core.c
+++ b/drivers/media/common/saa7146_core.c
@@ -100,7 +100,7 @@ int saa7146_wait_for_debi_done(struct saa7146_dev *dev, int nobusyloop)
100 * general helper functions 100 * general helper functions
101 ****************************************************************************/ 101 ****************************************************************************/
102 102
103/* this is videobuf_vmalloc_to_sg() from video-buf.c 103/* this is videobuf_vmalloc_to_sg() from videobuf-dma-sg.c
104 make sure virt has been allocated with vmalloc_32(), otherwise the BUG() 104 make sure virt has been allocated with vmalloc_32(), otherwise the BUG()
105 may be triggered on highmem machines */ 105 may be triggered on highmem machines */
106static struct scatterlist* vmalloc_to_sg(unsigned char *virt, int nr_pages) 106static struct scatterlist* vmalloc_to_sg(unsigned char *virt, int nr_pages)
@@ -248,10 +248,11 @@ int saa7146_pgtable_build_single(struct pci_dev *pci, struct saa7146_pgtable *pt
248static irqreturn_t interrupt_hw(int irq, void *dev_id) 248static irqreturn_t interrupt_hw(int irq, void *dev_id)
249{ 249{
250 struct saa7146_dev *dev = dev_id; 250 struct saa7146_dev *dev = dev_id;
251 u32 isr = 0; 251 u32 isr;
252 u32 ack_isr;
252 253
253 /* read out the interrupt status register */ 254 /* read out the interrupt status register */
254 isr = saa7146_read(dev, ISR); 255 ack_isr = isr = saa7146_read(dev, ISR);
255 256
256 /* is this our interrupt? */ 257 /* is this our interrupt? */
257 if ( 0 == isr ) { 258 if ( 0 == isr ) {
@@ -259,8 +260,6 @@ static irqreturn_t interrupt_hw(int irq, void *dev_id)
259 return IRQ_NONE; 260 return IRQ_NONE;
260 } 261 }
261 262
262 saa7146_write(dev, ISR, isr);
263
264 if( 0 != (dev->ext)) { 263 if( 0 != (dev->ext)) {
265 if( 0 != (dev->ext->irq_mask & isr )) { 264 if( 0 != (dev->ext->irq_mask & isr )) {
266 if( 0 != dev->ext->irq_func ) { 265 if( 0 != dev->ext->irq_func ) {
@@ -283,21 +282,16 @@ static irqreturn_t interrupt_hw(int irq, void *dev_id)
283 isr &= ~MASK_28; 282 isr &= ~MASK_28;
284 } 283 }
285 if (0 != (isr & (MASK_16|MASK_17))) { 284 if (0 != (isr & (MASK_16|MASK_17))) {
286 u32 status = saa7146_read(dev, I2C_STATUS); 285 SAA7146_IER_DISABLE(dev, MASK_16|MASK_17);
287 if( (0x3 == (status & 0x3)) || (0 == (status & 0x1)) ) { 286 /* only wake up if we expect something */
288 SAA7146_IER_DISABLE(dev, MASK_16|MASK_17); 287 if (0 != dev->i2c_op) {
289 /* only wake up if we expect something */ 288 dev->i2c_op = 0;
290 if( 0 != dev->i2c_op ) { 289 wake_up(&dev->i2c_wq);
291 u32 psr = (saa7146_read(dev, PSR) >> 16) & 0x2;
292 u32 ssr = (saa7146_read(dev, SSR) >> 17) & 0x1f;
293 DEB_I2C(("irq: i2c, status: 0x%08x, psr:0x%02x, ssr:0x%02x).\n",status,psr,ssr));
294 dev->i2c_op = 0;
295 wake_up(&dev->i2c_wq);
296 } else {
297 DEB_I2C(("unexpected irq: i2c, status: 0x%08x, isr %#x\n",status, isr));
298 }
299 } else { 290 } else {
300 DEB_I2C(("unhandled irq: i2c, status: 0x%08x, isr %#x\n",status, isr)); 291 u32 psr = saa7146_read(dev, PSR);
292 u32 ssr = saa7146_read(dev, SSR);
293 printk(KERN_WARNING "%s: unexpected i2c irq: isr %08x psr %08x ssr %08x\n",
294 dev->name, isr, psr, ssr);
301 } 295 }
302 isr &= ~(MASK_16|MASK_17); 296 isr &= ~(MASK_16|MASK_17);
303 } 297 }
@@ -306,6 +300,7 @@ static irqreturn_t interrupt_hw(int irq, void *dev_id)
306 ERR(("disabling interrupt source(s)!\n")); 300 ERR(("disabling interrupt source(s)!\n"));
307 SAA7146_IER_DISABLE(dev,isr); 301 SAA7146_IER_DISABLE(dev,isr);
308 } 302 }
303 saa7146_write(dev, ISR, ack_isr);
309 return IRQ_HANDLED; 304 return IRQ_HANDLED;
310} 305}
311 306
@@ -548,7 +543,6 @@ EXPORT_SYMBOL_GPL(saa7146_wait_for_debi_done);
548 543
549EXPORT_SYMBOL_GPL(saa7146_setgpio); 544EXPORT_SYMBOL_GPL(saa7146_setgpio);
550 545
551EXPORT_SYMBOL_GPL(saa7146_i2c_transfer);
552EXPORT_SYMBOL_GPL(saa7146_i2c_adapter_prepare); 546EXPORT_SYMBOL_GPL(saa7146_i2c_adapter_prepare);
553 547
554EXPORT_SYMBOL_GPL(saa7146_debug); 548EXPORT_SYMBOL_GPL(saa7146_debug);
diff --git a/drivers/media/common/saa7146_fops.c b/drivers/media/common/saa7146_fops.c
index b4770aecc01d..67d1b1b1b254 100644
--- a/drivers/media/common/saa7146_fops.c
+++ b/drivers/media/common/saa7146_fops.c
@@ -53,13 +53,14 @@ void saa7146_res_free(struct saa7146_fh *fh, unsigned int bits)
53void saa7146_dma_free(struct saa7146_dev *dev,struct videobuf_queue *q, 53void saa7146_dma_free(struct saa7146_dev *dev,struct videobuf_queue *q,
54 struct saa7146_buf *buf) 54 struct saa7146_buf *buf)
55{ 55{
56 struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb);
56 DEB_EE(("dev:%p, buf:%p\n",dev,buf)); 57 DEB_EE(("dev:%p, buf:%p\n",dev,buf));
57 58
58 BUG_ON(in_interrupt()); 59 BUG_ON(in_interrupt());
59 60
60 videobuf_waiton(&buf->vb,0,0); 61 videobuf_waiton(&buf->vb,0,0);
61 videobuf_dma_unmap(q, &buf->vb.dma); 62 videobuf_dma_unmap(q, dma);
62 videobuf_dma_free(&buf->vb.dma); 63 videobuf_dma_free(dma);
63 buf->vb.state = STATE_NEEDS_INIT; 64 buf->vb.state = STATE_NEEDS_INIT;
64} 65}
65 66
diff --git a/drivers/media/common/saa7146_i2c.c b/drivers/media/common/saa7146_i2c.c
index 8c85efc26527..7e7689afae62 100644
--- a/drivers/media/common/saa7146_i2c.c
+++ b/drivers/media/common/saa7146_i2c.c
@@ -202,7 +202,8 @@ static int saa7146_i2c_writeout(struct saa7146_dev *dev, u32* dword, int short_d
202 /* a signal arrived */ 202 /* a signal arrived */
203 return -ERESTARTSYS; 203 return -ERESTARTSYS;
204 204
205 printk(KERN_WARNING "saa7146_i2c_writeout: 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 return -EIO; 207 return -EIO;
207 } 208 }
208 status = saa7146_read(dev, I2C_STATUS); 209 status = saa7146_read(dev, I2C_STATUS);
@@ -219,7 +220,8 @@ static int saa7146_i2c_writeout(struct saa7146_dev *dev, u32* dword, int short_d
219 break; 220 break;
220 } 221 }
221 if (time_after(jiffies,timeout)) { 222 if (time_after(jiffies,timeout)) {
222 printk(KERN_WARNING "saa7146_i2c_writeout: timed out waiting for MC2\n"); 223 printk(KERN_WARNING "%s %s: timed out waiting for MC2\n",
224 dev->name, __FUNCTION__);
223 return -EIO; 225 return -EIO;
224 } 226 }
225 } 227 }
@@ -235,7 +237,8 @@ static int saa7146_i2c_writeout(struct saa7146_dev *dev, u32* dword, int short_d
235 /* this is normal when probing the bus 237 /* this is normal when probing the bus
236 * (no answer from nonexisistant device...) 238 * (no answer from nonexisistant device...)
237 */ 239 */
238 DEB_I2C(("saa7146_i2c_writeout: 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__);
239 return -EIO; 242 return -EIO;
240 } 243 }
241 if (++trial < 50 && short_delay) 244 if (++trial < 50 && short_delay)
@@ -246,8 +249,16 @@ static int saa7146_i2c_writeout(struct saa7146_dev *dev, u32* dword, int short_d
246 } 249 }
247 250
248 /* give a detailed status report */ 251 /* give a detailed status report */
249 if ( 0 != (status & SAA7146_I2C_ERR)) { 252 if ( 0 != (status & (SAA7146_I2C_SPERR | SAA7146_I2C_APERR |
250 253 SAA7146_I2C_DTERR | SAA7146_I2C_DRERR |
254 SAA7146_I2C_AL | SAA7146_I2C_ERR |
255 SAA7146_I2C_BUSY)) ) {
256
257 if ( 0 == (status & SAA7146_I2C_ERR) ||
258 0 == (status & SAA7146_I2C_BUSY) ) {
259 /* it may take some time until ERR goes high - ignore */
260 DEB_I2C(("unexpected i2c status %04x\n", status));
261 }
251 if( 0 != (status & SAA7146_I2C_SPERR) ) { 262 if( 0 != (status & SAA7146_I2C_SPERR) ) {
252 DEB_I2C(("error due to invalid start/stop condition.\n")); 263 DEB_I2C(("error due to invalid start/stop condition.\n"));
253 } 264 }
@@ -277,7 +288,7 @@ static int saa7146_i2c_writeout(struct saa7146_dev *dev, u32* dword, int short_d
277 return 0; 288 return 0;
278} 289}
279 290
280int saa7146_i2c_transfer(struct saa7146_dev *dev, const struct i2c_msg *msgs, int num, int retries) 291static int saa7146_i2c_transfer(struct saa7146_dev *dev, const struct i2c_msg *msgs, int num, int retries)
281{ 292{
282 int i = 0, count = 0; 293 int i = 0, count = 0;
283 u32* buffer = dev->d_i2c.cpu_addr; 294 u32* buffer = dev->d_i2c.cpu_addr;
diff --git a/drivers/media/common/saa7146_vbi.c b/drivers/media/common/saa7146_vbi.c
index 063608462ebe..6103484e4442 100644
--- a/drivers/media/common/saa7146_vbi.c
+++ b/drivers/media/common/saa7146_vbi.c
@@ -165,7 +165,7 @@ static void saa7146_set_vbi_capture(struct saa7146_dev *dev, struct saa7146_buf
165 /* we don't wait here for the first field anymore. this is different from the video 165 /* we don't wait here for the first field anymore. this is different from the video
166 capture and might cause that the first buffer is only half filled (with only 166 capture and might cause that the first buffer is only half filled (with only
167 one field). but since this is some sort of streaming data, this is not that negative. 167 one field). but since this is some sort of streaming data, this is not that negative.
168 but by doing this, we can use the whole engine from video-buf.c... */ 168 but by doing this, we can use the whole engine from videobuf-dma-sg.c... */
169 169
170/* 170/*
171 WRITE_RPS1(CMD_PAUSE | CMD_OAN | CMD_SIG1 | e_wait); 171 WRITE_RPS1(CMD_PAUSE | CMD_OAN | CMD_SIG1 | e_wait);
@@ -239,6 +239,8 @@ static int buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,e
239 saa7146_dma_free(dev,q,buf); 239 saa7146_dma_free(dev,q,buf);
240 240
241 if (STATE_NEEDS_INIT == buf->vb.state) { 241 if (STATE_NEEDS_INIT == buf->vb.state) {
242 struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb);
243
242 buf->vb.width = llength; 244 buf->vb.width = llength;
243 buf->vb.height = lines; 245 buf->vb.height = lines;
244 buf->vb.size = size; 246 buf->vb.size = size;
@@ -250,7 +252,8 @@ static int buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,e
250 err = videobuf_iolock(q,&buf->vb, NULL); 252 err = videobuf_iolock(q,&buf->vb, NULL);
251 if (err) 253 if (err)
252 goto oops; 254 goto oops;
253 err = saa7146_pgtable_build_single(dev->pci, &buf->pt[2], buf->vb.dma.sglist, buf->vb.dma.sglen); 255 err = saa7146_pgtable_build_single(dev->pci, &buf->pt[2],
256 dma->sglist, dma->sglen);
254 if (0 != err) 257 if (0 != err)
255 return err; 258 return err;
256 } 259 }
@@ -404,7 +407,7 @@ static int vbi_open(struct saa7146_dev *dev, struct file *file)
404 fh->vbi_fmt.start[1] = 312; 407 fh->vbi_fmt.start[1] = 312;
405 fh->vbi_fmt.count[1] = 16; 408 fh->vbi_fmt.count[1] = 16;
406 409
407 videobuf_queue_init(&fh->vbi_q, &vbi_qops, 410 videobuf_queue_pci_init(&fh->vbi_q, &vbi_qops,
408 dev->pci, &dev->slock, 411 dev->pci, &dev->slock,
409 V4L2_BUF_TYPE_VBI_CAPTURE, 412 V4L2_BUF_TYPE_VBI_CAPTURE,
410 V4L2_FIELD_SEQ_TB, // FIXME: does this really work? 413 V4L2_FIELD_SEQ_TB, // FIXME: does this really work?
diff --git a/drivers/media/common/saa7146_video.c b/drivers/media/common/saa7146_video.c
index 664280c78ff2..f245a3b2ef47 100644
--- a/drivers/media/common/saa7146_video.c
+++ b/drivers/media/common/saa7146_video.c
@@ -594,8 +594,9 @@ static int set_control(struct saa7146_fh *fh, struct v4l2_control *c)
594static int saa7146_pgtable_build(struct saa7146_dev *dev, struct saa7146_buf *buf) 594static int saa7146_pgtable_build(struct saa7146_dev *dev, struct saa7146_buf *buf)
595{ 595{
596 struct pci_dev *pci = dev->pci; 596 struct pci_dev *pci = dev->pci;
597 struct scatterlist *list = buf->vb.dma.sglist; 597 struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb);
598 int length = buf->vb.dma.sglen; 598 struct scatterlist *list = dma->sglist;
599 int length = dma->sglen;
599 struct saa7146_format *sfmt = format_by_fourcc(dev,buf->fmt->pixelformat); 600 struct saa7146_format *sfmt = format_by_fourcc(dev,buf->fmt->pixelformat);
600 601
601 DEB_EE(("dev:%p, buf:%p, sg_len:%d\n",dev,buf,length)); 602 DEB_EE(("dev:%p, buf:%p, sg_len:%d\n",dev,buf,length));
@@ -655,7 +656,7 @@ static int saa7146_pgtable_build(struct saa7146_dev *dev, struct saa7146_buf *bu
655 656
656 /* if we have a user buffer, the first page may not be 657 /* if we have a user buffer, the first page may not be
657 aligned to a page boundary. */ 658 aligned to a page boundary. */
658 pt1->offset = buf->vb.dma.sglist->offset; 659 pt1->offset = list->offset;
659 pt2->offset = pt1->offset+o1; 660 pt2->offset = pt1->offset+o1;
660 pt3->offset = pt1->offset+o2; 661 pt3->offset = pt1->offset+o2;
661 662
@@ -1211,6 +1212,8 @@ int saa7146_video_do_ioctl(struct inode *inode, struct file *file, unsigned int
1211 mutex_unlock(&q->lock); 1212 mutex_unlock(&q->lock);
1212 return err; 1213 return err;
1213 } 1214 }
1215
1216 gbuffers = err;
1214 memset(mbuf,0,sizeof(*mbuf)); 1217 memset(mbuf,0,sizeof(*mbuf));
1215 mbuf->frames = gbuffers; 1218 mbuf->frames = gbuffers;
1216 mbuf->size = gbuffers * gbufsize; 1219 mbuf->size = gbuffers * gbufsize;
@@ -1411,7 +1414,7 @@ static int video_open(struct saa7146_dev *dev, struct file *file)
1411 sfmt = format_by_fourcc(dev,fh->video_fmt.pixelformat); 1414 sfmt = format_by_fourcc(dev,fh->video_fmt.pixelformat);
1412 fh->video_fmt.sizeimage = (fh->video_fmt.width * fh->video_fmt.height * sfmt->depth)/8; 1415 fh->video_fmt.sizeimage = (fh->video_fmt.width * fh->video_fmt.height * sfmt->depth)/8;
1413 1416
1414 videobuf_queue_init(&fh->video_q, &video_qops, 1417 videobuf_queue_pci_init(&fh->video_q, &video_qops,
1415 dev->pci, &dev->slock, 1418 dev->pci, &dev->slock,
1416 V4L2_BUF_TYPE_VIDEO_CAPTURE, 1419 V4L2_BUF_TYPE_VIDEO_CAPTURE,
1417 V4L2_FIELD_INTERLACED, 1420 V4L2_FIELD_INTERLACED,
diff --git a/drivers/media/dvb/bt8xx/bt878.c b/drivers/media/dvb/bt8xx/bt878.c
index df72b4b8ee10..eca602d9b3de 100644
--- a/drivers/media/dvb/bt8xx/bt878.c
+++ b/drivers/media/dvb/bt8xx/bt878.c
@@ -28,7 +28,6 @@
28 */ 28 */
29 29
30#include <linux/module.h> 30#include <linux/module.h>
31#include <linux/moduleparam.h>
32#include <linux/kernel.h> 31#include <linux/kernel.h>
33#include <linux/pci.h> 32#include <linux/pci.h>
34#include <asm/io.h> 33#include <asm/io.h>
diff --git a/drivers/media/dvb/bt8xx/bt878.h b/drivers/media/dvb/bt8xx/bt878.h
index f685bc129609..d593bc145628 100644
--- a/drivers/media/dvb/bt8xx/bt878.h
+++ b/drivers/media/dvb/bt8xx/bt878.h
@@ -149,11 +149,10 @@ void bt878_start(struct bt878 *bt, u32 controlreg, u32 op_sync_orin,
149void bt878_stop(struct bt878 *bt); 149void bt878_stop(struct bt878 *bt);
150 150
151#if defined(__powerpc__) /* big-endian */ 151#if defined(__powerpc__) /* big-endian */
152extern __inline__ void io_st_le32(volatile unsigned __iomem *addr, unsigned val) 152static inline void io_st_le32(volatile unsigned __iomem *addr, unsigned val)
153{ 153{
154 __asm__ __volatile__("stwbrx %1,0,%2":"=m"(*addr):"r"(val), 154 st_le32(addr, val);
155 "r"(addr)); 155 eieio();
156 __asm__ __volatile__("eieio":::"memory");
157} 156}
158 157
159#define bmtwrite(dat,adr) io_st_le32((adr),(dat)) 158#define bmtwrite(dat,adr) io_st_le32((adr),(dat))
diff --git a/drivers/media/dvb/bt8xx/dvb-bt8xx.c b/drivers/media/dvb/bt8xx/dvb-bt8xx.c
index 67613eb6fa3d..dedd30a8356b 100644
--- a/drivers/media/dvb/bt8xx/dvb-bt8xx.c
+++ b/drivers/media/dvb/bt8xx/dvb-bt8xx.c
@@ -21,7 +21,6 @@
21 21
22#include <linux/bitops.h> 22#include <linux/bitops.h>
23#include <linux/module.h> 23#include <linux/module.h>
24#include <linux/moduleparam.h>
25#include <linux/init.h> 24#include <linux/init.h>
26#include <linux/kernel.h> 25#include <linux/kernel.h>
27#include <linux/device.h> 26#include <linux/device.h>
diff --git a/drivers/media/dvb/cinergyT2/cinergyT2.c b/drivers/media/dvb/cinergyT2/cinergyT2.c
index 28929b618e20..5a12b5679556 100644
--- a/drivers/media/dvb/cinergyT2/cinergyT2.c
+++ b/drivers/media/dvb/cinergyT2/cinergyT2.c
@@ -548,19 +548,19 @@ static unsigned int cinergyt2_poll (struct file *file, struct poll_table_struct
548{ 548{
549 struct dvb_device *dvbdev = file->private_data; 549 struct dvb_device *dvbdev = file->private_data;
550 struct cinergyt2 *cinergyt2 = dvbdev->priv; 550 struct cinergyt2 *cinergyt2 = dvbdev->priv;
551 unsigned int mask = 0; 551 unsigned int mask = 0;
552 552
553 if (cinergyt2->disconnect_pending || mutex_lock_interruptible(&cinergyt2->sem)) 553 if (cinergyt2->disconnect_pending || mutex_lock_interruptible(&cinergyt2->sem))
554 return -ERESTARTSYS; 554 return -ERESTARTSYS;
555 555
556 poll_wait(file, &cinergyt2->poll_wq, wait); 556 poll_wait(file, &cinergyt2->poll_wq, wait);
557 557
558 if (cinergyt2->pending_fe_events != 0) 558 if (cinergyt2->pending_fe_events != 0)
559 mask |= (POLLIN | POLLRDNORM | POLLPRI); 559 mask |= (POLLIN | POLLRDNORM | POLLPRI);
560 560
561 mutex_unlock(&cinergyt2->sem); 561 mutex_unlock(&cinergyt2->sem);
562 562
563 return mask; 563 return mask;
564} 564}
565 565
566 566
@@ -1008,6 +1008,8 @@ static int cinergyt2_suspend (struct usb_interface *intf, pm_message_t state)
1008 cinergyt2_sleep(cinergyt2, 1); 1008 cinergyt2_sleep(cinergyt2, 1);
1009 mutex_unlock(&cinergyt2->sem); 1009 mutex_unlock(&cinergyt2->sem);
1010 1010
1011 mutex_unlock(&cinergyt2->wq_sem);
1012
1011 return 0; 1013 return 0;
1012} 1014}
1013 1015
diff --git a/drivers/media/dvb/dvb-core/dmxdev.c b/drivers/media/dvb/dvb-core/dmxdev.c
index 5394de2e4ce0..f94bc31e3b33 100644
--- a/drivers/media/dvb/dvb-core/dmxdev.c
+++ b/drivers/media/dvb/dvb-core/dmxdev.c
@@ -24,7 +24,6 @@
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/vmalloc.h> 25#include <linux/vmalloc.h>
26#include <linux/module.h> 26#include <linux/module.h>
27#include <linux/moduleparam.h>
28#include <linux/poll.h> 27#include <linux/poll.h>
29#include <linux/ioctl.h> 28#include <linux/ioctl.h>
30#include <linux/wait.h> 29#include <linux/wait.h>
diff --git a/drivers/media/dvb/dvb-core/dvb_ca_en50221.c b/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
index 4fadddb264d6..084a508a03da 100644
--- a/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
+++ b/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
@@ -32,11 +32,11 @@
32#include <linux/slab.h> 32#include <linux/slab.h>
33#include <linux/list.h> 33#include <linux/list.h>
34#include <linux/module.h> 34#include <linux/module.h>
35#include <linux/moduleparam.h>
36#include <linux/vmalloc.h> 35#include <linux/vmalloc.h>
37#include <linux/delay.h> 36#include <linux/delay.h>
38#include <linux/spinlock.h> 37#include <linux/spinlock.h>
39#include <linux/sched.h> 38#include <linux/sched.h>
39#include <linux/kthread.h>
40 40
41#include "dvb_ca_en50221.h" 41#include "dvb_ca_en50221.h"
42#include "dvb_ringbuffer.h" 42#include "dvb_ringbuffer.h"
@@ -140,13 +140,7 @@ struct dvb_ca_private {
140 wait_queue_head_t wait_queue; 140 wait_queue_head_t wait_queue;
141 141
142 /* PID of the monitoring thread */ 142 /* PID of the monitoring thread */
143 pid_t thread_pid; 143 struct task_struct *thread;
144
145 /* Wait queue used when shutting thread down */
146 wait_queue_head_t thread_queue;
147
148 /* Flag indicating when thread should exit */
149 unsigned int exit:1;
150 144
151 /* Flag indicating if the CA device is open */ 145 /* Flag indicating if the CA device is open */
152 unsigned int open:1; 146 unsigned int open:1;
@@ -902,28 +896,10 @@ static void dvb_ca_en50221_thread_wakeup(struct dvb_ca_private *ca)
902 896
903 ca->wakeup = 1; 897 ca->wakeup = 1;
904 mb(); 898 mb();
905 wake_up_interruptible(&ca->thread_queue); 899 wake_up_process(ca->thread);
906} 900}
907 901
908/** 902/**
909 * Used by the CA thread to determine if an early wakeup is necessary
910 *
911 * @param ca CA instance.
912 */
913static int dvb_ca_en50221_thread_should_wakeup(struct dvb_ca_private *ca)
914{
915 if (ca->wakeup) {
916 ca->wakeup = 0;
917 return 1;
918 }
919 if (ca->exit)
920 return 1;
921
922 return 0;
923}
924
925
926/**
927 * Update the delay used by the thread. 903 * Update the delay used by the thread.
928 * 904 *
929 * @param ca CA instance. 905 * @param ca CA instance.
@@ -982,7 +958,6 @@ static void dvb_ca_en50221_thread_update_delay(struct dvb_ca_private *ca)
982static int dvb_ca_en50221_thread(void *data) 958static int dvb_ca_en50221_thread(void *data)
983{ 959{
984 struct dvb_ca_private *ca = data; 960 struct dvb_ca_private *ca = data;
985 char name[15];
986 int slot; 961 int slot;
987 int flags; 962 int flags;
988 int status; 963 int status;
@@ -991,28 +966,17 @@ static int dvb_ca_en50221_thread(void *data)
991 966
992 dprintk("%s\n", __FUNCTION__); 967 dprintk("%s\n", __FUNCTION__);
993 968
994 /* setup kernel thread */
995 snprintf(name, sizeof(name), "kdvb-ca-%i:%i", ca->dvbdev->adapter->num, ca->dvbdev->id);
996
997 lock_kernel();
998 daemonize(name);
999 sigfillset(&current->blocked);
1000 unlock_kernel();
1001
1002 /* choose the correct initial delay */ 969 /* choose the correct initial delay */
1003 dvb_ca_en50221_thread_update_delay(ca); 970 dvb_ca_en50221_thread_update_delay(ca);
1004 971
1005 /* main loop */ 972 /* main loop */
1006 while (!ca->exit) { 973 while (!kthread_should_stop()) {
1007 /* sleep for a bit */ 974 /* sleep for a bit */
1008 if (!ca->wakeup) { 975 while (!ca->wakeup) {
1009 flags = wait_event_interruptible_timeout(ca->thread_queue, 976 set_current_state(TASK_INTERRUPTIBLE);
1010 dvb_ca_en50221_thread_should_wakeup(ca), 977 schedule_timeout(ca->delay);
1011 ca->delay); 978 if (kthread_should_stop())
1012 if ((flags == -ERESTARTSYS) || ca->exit) { 979 return 0;
1013 /* got signal or quitting */
1014 break;
1015 }
1016 } 980 }
1017 ca->wakeup = 0; 981 ca->wakeup = 0;
1018 982
@@ -1181,10 +1145,6 @@ static int dvb_ca_en50221_thread(void *data)
1181 } 1145 }
1182 } 1146 }
1183 1147
1184 /* completed */
1185 ca->thread_pid = 0;
1186 mb();
1187 wake_up_interruptible(&ca->thread_queue);
1188 return 0; 1148 return 0;
1189} 1149}
1190 1150
@@ -1536,8 +1496,10 @@ static int dvb_ca_en50221_io_open(struct inode *inode, struct file *file)
1536 return -EIO; 1496 return -EIO;
1537 1497
1538 err = dvb_generic_open(inode, file); 1498 err = dvb_generic_open(inode, file);
1539 if (err < 0) 1499 if (err < 0) {
1500 module_put(ca->pub->owner);
1540 return err; 1501 return err;
1502 }
1541 1503
1542 for (i = 0; i < ca->slot_count; i++) { 1504 for (i = 0; i < ca->slot_count; i++) {
1543 1505
@@ -1570,7 +1532,7 @@ static int dvb_ca_en50221_io_release(struct inode *inode, struct file *file)
1570{ 1532{
1571 struct dvb_device *dvbdev = file->private_data; 1533 struct dvb_device *dvbdev = file->private_data;
1572 struct dvb_ca_private *ca = dvbdev->priv; 1534 struct dvb_ca_private *ca = dvbdev->priv;
1573 int err = 0; 1535 int err;
1574 1536
1575 dprintk("%s\n", __FUNCTION__); 1537 dprintk("%s\n", __FUNCTION__);
1576 1538
@@ -1582,7 +1544,7 @@ static int dvb_ca_en50221_io_release(struct inode *inode, struct file *file)
1582 1544
1583 module_put(ca->pub->owner); 1545 module_put(ca->pub->owner);
1584 1546
1585 return 0; 1547 return err;
1586} 1548}
1587 1549
1588 1550
@@ -1682,9 +1644,6 @@ int dvb_ca_en50221_init(struct dvb_adapter *dvb_adapter,
1682 goto error; 1644 goto error;
1683 } 1645 }
1684 init_waitqueue_head(&ca->wait_queue); 1646 init_waitqueue_head(&ca->wait_queue);
1685 ca->thread_pid = 0;
1686 init_waitqueue_head(&ca->thread_queue);
1687 ca->exit = 0;
1688 ca->open = 0; 1647 ca->open = 0;
1689 ca->wakeup = 0; 1648 ca->wakeup = 0;
1690 ca->next_read_slot = 0; 1649 ca->next_read_slot = 0;
@@ -1710,14 +1669,14 @@ int dvb_ca_en50221_init(struct dvb_adapter *dvb_adapter,
1710 mb(); 1669 mb();
1711 1670
1712 /* create a kthread for monitoring this CA device */ 1671 /* create a kthread for monitoring this CA device */
1713 1672 ca->thread = kthread_run(dvb_ca_en50221_thread, ca, "kdvb-ca-%i:%i",
1714 ret = kernel_thread(dvb_ca_en50221_thread, ca, 0); 1673 ca->dvbdev->adapter->num, ca->dvbdev->id);
1715 1674 if (IS_ERR(ca->thread)) {
1716 if (ret < 0) { 1675 ret = PTR_ERR(ca->thread);
1717 printk("dvb_ca_init: failed to start kernel_thread (%d)\n", ret); 1676 printk("dvb_ca_init: failed to start kernel_thread (%d)\n",
1677 ret);
1718 goto error; 1678 goto error;
1719 } 1679 }
1720 ca->thread_pid = ret;
1721 return 0; 1680 return 0;
1722 1681
1723error: 1682error:
@@ -1748,17 +1707,7 @@ void dvb_ca_en50221_release(struct dvb_ca_en50221 *pubca)
1748 dprintk("%s\n", __FUNCTION__); 1707 dprintk("%s\n", __FUNCTION__);
1749 1708
1750 /* shutdown the thread if there was one */ 1709 /* shutdown the thread if there was one */
1751 if (ca->thread_pid) { 1710 kthread_stop(ca->thread);
1752 if (kill_proc(ca->thread_pid, 0, 1) == -ESRCH) {
1753 printk("dvb_ca_release adapter %d: thread PID %d already died\n",
1754 ca->dvbdev->adapter->num, ca->thread_pid);
1755 } else {
1756 ca->exit = 1;
1757 mb();
1758 dvb_ca_en50221_thread_wakeup(ca);
1759 wait_event_interruptible(ca->thread_queue, ca->thread_pid == 0);
1760 }
1761 }
1762 1711
1763 for (i = 0; i < ca->slot_count; i++) { 1712 for (i = 0; i < ca->slot_count; i++) {
1764 dvb_ca_en50221_slot_shutdown(ca, i); 1713 dvb_ca_en50221_slot_shutdown(ca, i);
diff --git a/drivers/media/dvb/dvb-core/dvb_demux.c b/drivers/media/dvb/dvb-core/dvb_demux.c
index cb6987fce26c..7959020f9317 100644
--- a/drivers/media/dvb/dvb-core/dvb_demux.c
+++ b/drivers/media/dvb/dvb-core/dvb_demux.c
@@ -373,13 +373,10 @@ static inline void dvb_dmx_swfilter_packet_type(struct dvb_demux_feed *feed,
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{
375 struct dvb_demux_feed *feed; 375 struct dvb_demux_feed *feed;
376 struct list_head *pos, *head = &demux->feed_list;
377 u16 pid = ts_pid(buf); 376 u16 pid = ts_pid(buf);
378 int dvr_done = 0; 377 int dvr_done = 0;
379 378
380 list_for_each(pos, head) { 379 list_for_each_entry(feed, &demux->feed_list, list_head) {
381 feed = list_entry(pos, struct dvb_demux_feed, list_head);
382
383 if ((feed->pid != pid) && (feed->pid != 0x2000)) 380 if ((feed->pid != pid) && (feed->pid != 0x2000))
384 continue; 381 continue;
385 382
diff --git a/drivers/media/dvb/dvb-core/dvb_frontend.c b/drivers/media/dvb/dvb-core/dvb_frontend.c
index b6c7f6610ec5..b203640ef1c5 100644
--- a/drivers/media/dvb/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb/dvb-core/dvb_frontend.c
@@ -32,7 +32,6 @@
32#include <linux/slab.h> 32#include <linux/slab.h>
33#include <linux/poll.h> 33#include <linux/poll.h>
34#include <linux/module.h> 34#include <linux/module.h>
35#include <linux/moduleparam.h>
36#include <linux/list.h> 35#include <linux/list.h>
37#include <linux/freezer.h> 36#include <linux/freezer.h>
38#include <linux/jiffies.h> 37#include <linux/jiffies.h>
@@ -43,7 +42,7 @@
43#include "dvbdev.h" 42#include "dvbdev.h"
44 43
45static int dvb_frontend_debug; 44static int dvb_frontend_debug;
46static int dvb_shutdown_timeout = 5; 45static int dvb_shutdown_timeout;
47static int dvb_force_auto_inversion; 46static int dvb_force_auto_inversion;
48static int dvb_override_tune_delay; 47static int dvb_override_tune_delay;
49static int dvb_powerdown_on_sleep = 1; 48static int dvb_powerdown_on_sleep = 1;
@@ -138,7 +137,7 @@ static void dvb_frontend_add_event(struct dvb_frontend *fe, fe_status_t status)
138 137
139 dprintk ("%s\n", __FUNCTION__); 138 dprintk ("%s\n", __FUNCTION__);
140 139
141 if (down_interruptible (&events->sem)) 140 if (mutex_lock_interruptible (&events->mtx))
142 return; 141 return;
143 142
144 wp = (events->eventw + 1) % MAX_EVENT; 143 wp = (events->eventw + 1) % MAX_EVENT;
@@ -159,7 +158,7 @@ static void dvb_frontend_add_event(struct dvb_frontend *fe, fe_status_t status)
159 158
160 events->eventw = wp; 159 events->eventw = wp;
161 160
162 up (&events->sem); 161 mutex_unlock(&events->mtx);
163 162
164 e->status = status; 163 e->status = status;
165 164
@@ -197,7 +196,7 @@ static int dvb_frontend_get_event(struct dvb_frontend *fe,
197 return ret; 196 return ret;
198 } 197 }
199 198
200 if (down_interruptible (&events->sem)) 199 if (mutex_lock_interruptible (&events->mtx))
201 return -ERESTARTSYS; 200 return -ERESTARTSYS;
202 201
203 memcpy (event, &events->events[events->eventr], 202 memcpy (event, &events->events[events->eventr],
@@ -205,7 +204,7 @@ static int dvb_frontend_get_event(struct dvb_frontend *fe,
205 204
206 events->eventr = (events->eventr + 1) % MAX_EVENT; 205 events->eventr = (events->eventr + 1) % MAX_EVENT;
207 206
208 up (&events->sem); 207 mutex_unlock(&events->mtx);
209 208
210 return 0; 209 return 0;
211} 210}
@@ -574,10 +573,9 @@ restart:
574 dvb_frontend_swzigzag(fe); 573 dvb_frontend_swzigzag(fe);
575 } 574 }
576 575
577 if (dvb_shutdown_timeout) { 576 if (dvb_powerdown_on_sleep) {
578 if (dvb_powerdown_on_sleep) 577 if (fe->ops.set_voltage)
579 if (fe->ops.set_voltage) 578 fe->ops.set_voltage(fe, SEC_VOLTAGE_OFF);
580 fe->ops.set_voltage(fe, SEC_VOLTAGE_OFF);
581 if (fe->ops.tuner_ops.sleep) { 579 if (fe->ops.tuner_ops.sleep) {
582 fe->ops.tuner_ops.sleep(fe); 580 fe->ops.tuner_ops.sleep(fe);
583 if (fe->ops.i2c_gate_ctrl) 581 if (fe->ops.i2c_gate_ctrl)
@@ -697,6 +695,65 @@ static int dvb_frontend_start(struct dvb_frontend *fe)
697 return 0; 695 return 0;
698} 696}
699 697
698static void dvb_frontend_get_frequeny_limits(struct dvb_frontend *fe,
699 u32 *freq_min, u32 *freq_max)
700{
701 *freq_min = max(fe->ops.info.frequency_min, fe->ops.tuner_ops.info.frequency_min);
702
703 if (fe->ops.info.frequency_max == 0)
704 *freq_max = fe->ops.tuner_ops.info.frequency_max;
705 else if (fe->ops.tuner_ops.info.frequency_max == 0)
706 *freq_max = fe->ops.info.frequency_max;
707 else
708 *freq_max = min(fe->ops.info.frequency_max, fe->ops.tuner_ops.info.frequency_max);
709
710 if (*freq_min == 0 || *freq_max == 0)
711 printk(KERN_WARNING "DVB: frontend %u frequency limits undefined - fix the driver\n",
712 fe->dvb->num);
713}
714
715static int dvb_frontend_check_parameters(struct dvb_frontend *fe,
716 struct dvb_frontend_parameters *parms)
717{
718 u32 freq_min;
719 u32 freq_max;
720
721 /* range check: frequency */
722 dvb_frontend_get_frequeny_limits(fe, &freq_min, &freq_max);
723 if ((freq_min && parms->frequency < freq_min) ||
724 (freq_max && parms->frequency > freq_max)) {
725 printk(KERN_WARNING "DVB: frontend %u frequency %u out of range (%u..%u)\n",
726 fe->dvb->num, parms->frequency, freq_min, freq_max);
727 return -EINVAL;
728 }
729
730 /* range check: symbol rate */
731 if (fe->ops.info.type == FE_QPSK) {
732 if ((fe->ops.info.symbol_rate_min &&
733 parms->u.qpsk.symbol_rate < fe->ops.info.symbol_rate_min) ||
734 (fe->ops.info.symbol_rate_max &&
735 parms->u.qpsk.symbol_rate > fe->ops.info.symbol_rate_max)) {
736 printk(KERN_WARNING "DVB: frontend %u symbol rate %u out of range (%u..%u)\n",
737 fe->dvb->num, parms->u.qpsk.symbol_rate,
738 fe->ops.info.symbol_rate_min, fe->ops.info.symbol_rate_max);
739 return -EINVAL;
740 }
741
742 } else if (fe->ops.info.type == FE_QAM) {
743 if ((fe->ops.info.symbol_rate_min &&
744 parms->u.qam.symbol_rate < fe->ops.info.symbol_rate_min) ||
745 (fe->ops.info.symbol_rate_max &&
746 parms->u.qam.symbol_rate > fe->ops.info.symbol_rate_max)) {
747 printk(KERN_WARNING "DVB: frontend %u symbol rate %u out of range (%u..%u)\n",
748 fe->dvb->num, parms->u.qam.symbol_rate,
749 fe->ops.info.symbol_rate_min, fe->ops.info.symbol_rate_max);
750 return -EINVAL;
751 }
752 }
753
754 return 0;
755}
756
700static int dvb_frontend_ioctl(struct inode *inode, struct file *file, 757static int dvb_frontend_ioctl(struct inode *inode, struct file *file,
701 unsigned int cmd, void *parg) 758 unsigned int cmd, void *parg)
702{ 759{
@@ -707,7 +764,7 @@ static int dvb_frontend_ioctl(struct inode *inode, struct file *file,
707 764
708 dprintk ("%s\n", __FUNCTION__); 765 dprintk ("%s\n", __FUNCTION__);
709 766
710 if (!fe || fepriv->exit) 767 if (fepriv->exit)
711 return -ENODEV; 768 return -ENODEV;
712 769
713 if ((file->f_flags & O_ACCMODE) == O_RDONLY && 770 if ((file->f_flags & O_ACCMODE) == O_RDONLY &&
@@ -722,6 +779,7 @@ static int dvb_frontend_ioctl(struct inode *inode, struct file *file,
722 case FE_GET_INFO: { 779 case FE_GET_INFO: {
723 struct dvb_frontend_info* info = parg; 780 struct dvb_frontend_info* info = parg;
724 memcpy(info, &fe->ops.info, sizeof(struct dvb_frontend_info)); 781 memcpy(info, &fe->ops.info, sizeof(struct dvb_frontend_info));
782 dvb_frontend_get_frequeny_limits(fe, &info->frequency_min, &info->frequency_max);
725 783
726 /* Force the CAN_INVERSION_AUTO bit on. If the frontend doesn't 784 /* Force the CAN_INVERSION_AUTO bit on. If the frontend doesn't
727 * do it, it is done for it. */ 785 * do it, it is done for it. */
@@ -883,6 +941,11 @@ static int dvb_frontend_ioctl(struct inode *inode, struct file *file,
883 case FE_SET_FRONTEND: { 941 case FE_SET_FRONTEND: {
884 struct dvb_frontend_tune_settings fetunesettings; 942 struct dvb_frontend_tune_settings fetunesettings;
885 943
944 if (dvb_frontend_check_parameters(fe, parg) < 0) {
945 err = -EINVAL;
946 break;
947 }
948
886 memcpy (&fepriv->parameters, parg, 949 memcpy (&fepriv->parameters, parg,
887 sizeof (struct dvb_frontend_parameters)); 950 sizeof (struct dvb_frontend_parameters));
888 951
@@ -992,18 +1055,15 @@ static int dvb_frontend_open(struct inode *inode, struct file *file)
992 1055
993 dprintk ("%s\n", __FUNCTION__); 1056 dprintk ("%s\n", __FUNCTION__);
994 1057
995 if ((ret = dvb_generic_open (inode, file)) < 0) 1058 if (dvbdev->users == -1 && fe->ops.ts_bus_ctrl) {
996 return ret; 1059 if ((ret = fe->ops.ts_bus_ctrl(fe, 1)) < 0)
997
998 if (fe->ops.ts_bus_ctrl) {
999 if ((ret = fe->ops.ts_bus_ctrl (fe, 1)) < 0) {
1000 dvb_generic_release (inode, file);
1001 return ret; 1060 return ret;
1002 }
1003 } 1061 }
1004 1062
1005 if ((file->f_flags & O_ACCMODE) != O_RDONLY) { 1063 if ((ret = dvb_generic_open (inode, file)) < 0)
1064 goto err1;
1006 1065
1066 if ((file->f_flags & O_ACCMODE) != O_RDONLY) {
1007 /* normal tune mode when opened R/W */ 1067 /* normal tune mode when opened R/W */
1008 fepriv->tune_mode_flags &= ~FE_TUNE_MODE_ONESHOT; 1068 fepriv->tune_mode_flags &= ~FE_TUNE_MODE_ONESHOT;
1009 fepriv->tone = -1; 1069 fepriv->tone = -1;
@@ -1011,13 +1071,20 @@ static int dvb_frontend_open(struct inode *inode, struct file *file)
1011 1071
1012 ret = dvb_frontend_start (fe); 1072 ret = dvb_frontend_start (fe);
1013 if (ret) 1073 if (ret)
1014 dvb_generic_release (inode, file); 1074 goto err2;
1015 1075
1016 /* empty event queue */ 1076 /* empty event queue */
1017 fepriv->events.eventr = fepriv->events.eventw = 0; 1077 fepriv->events.eventr = fepriv->events.eventw = 0;
1018 } 1078 }
1019 1079
1020 return ret; 1080 return ret;
1081
1082err2:
1083 dvb_generic_release(inode, file);
1084err1:
1085 if (dvbdev->users == -1 && fe->ops.ts_bus_ctrl)
1086 fe->ops.ts_bus_ctrl(fe, 0);
1087 return ret;
1021} 1088}
1022 1089
1023static int dvb_frontend_release(struct inode *inode, struct file *file) 1090static int dvb_frontend_release(struct inode *inode, struct file *file)
@@ -1032,16 +1099,18 @@ static int dvb_frontend_release(struct inode *inode, struct file *file)
1032 if ((file->f_flags & O_ACCMODE) != O_RDONLY) 1099 if ((file->f_flags & O_ACCMODE) != O_RDONLY)
1033 fepriv->release_jiffies = jiffies; 1100 fepriv->release_jiffies = jiffies;
1034 1101
1035 if (fe->ops.ts_bus_ctrl)
1036 fe->ops.ts_bus_ctrl (fe, 0);
1037
1038 ret = dvb_generic_release (inode, file); 1102 ret = dvb_generic_release (inode, file);
1039 1103
1040 if (dvbdev->users==-1 && fepriv->exit==1) { 1104 if (dvbdev->users == -1) {
1041 fops_put(file->f_op); 1105 if (fepriv->exit == 1) {
1042 file->f_op = NULL; 1106 fops_put(file->f_op);
1043 wake_up(&dvbdev->wait_queue); 1107 file->f_op = NULL;
1108 wake_up(&dvbdev->wait_queue);
1109 }
1110 if (fe->ops.ts_bus_ctrl)
1111 fe->ops.ts_bus_ctrl(fe, 0);
1044 } 1112 }
1113
1045 return ret; 1114 return ret;
1046} 1115}
1047 1116
@@ -1080,7 +1149,7 @@ int dvb_register_frontend(struct dvb_adapter* dvb,
1080 init_MUTEX (&fepriv->sem); 1149 init_MUTEX (&fepriv->sem);
1081 init_waitqueue_head (&fepriv->wait_queue); 1150 init_waitqueue_head (&fepriv->wait_queue);
1082 init_waitqueue_head (&fepriv->events.wait_queue); 1151 init_waitqueue_head (&fepriv->events.wait_queue);
1083 init_MUTEX (&fepriv->events.sem); 1152 mutex_init(&fepriv->events.mtx);
1084 fe->dvb = dvb; 1153 fe->dvb = dvb;
1085 fepriv->inversion = INVERSION_OFF; 1154 fepriv->inversion = INVERSION_OFF;
1086 1155
diff --git a/drivers/media/dvb/dvb-core/dvb_frontend.h b/drivers/media/dvb/dvb-core/dvb_frontend.h
index a770a87b9a93..a5262e852c82 100644
--- a/drivers/media/dvb/dvb-core/dvb_frontend.h
+++ b/drivers/media/dvb/dvb-core/dvb_frontend.h
@@ -35,6 +35,7 @@
35#include <linux/module.h> 35#include <linux/module.h>
36#include <linux/errno.h> 36#include <linux/errno.h>
37#include <linux/delay.h> 37#include <linux/delay.h>
38#include <linux/mutex.h>
38 39
39#include <linux/dvb/frontend.h> 40#include <linux/dvb/frontend.h>
40 41
@@ -61,6 +62,13 @@ struct dvb_tuner_info {
61 u32 bandwidth_step; 62 u32 bandwidth_step;
62}; 63};
63 64
65struct analog_parameters {
66 unsigned int frequency;
67 unsigned int mode;
68 unsigned int audmode;
69 u64 std;
70};
71
64struct dvb_tuner_ops { 72struct dvb_tuner_ops {
65 73
66 struct dvb_tuner_info info; 74 struct dvb_tuner_info info;
@@ -71,6 +79,7 @@ struct dvb_tuner_ops {
71 79
72 /** This is for simple PLLs - set all parameters in one go. */ 80 /** This is for simple PLLs - set all parameters in one go. */
73 int (*set_params)(struct dvb_frontend *fe, struct dvb_frontend_parameters *p); 81 int (*set_params)(struct dvb_frontend *fe, struct dvb_frontend_parameters *p);
82 int (*set_analog_params)(struct dvb_frontend *fe, struct analog_parameters *p);
74 83
75 /** This is support for demods like the mt352 - fills out the supplied buffer with what to write. */ 84 /** This is support for demods like the mt352 - fills out the supplied buffer with what to write. */
76 int (*calc_regs)(struct dvb_frontend *fe, struct dvb_frontend_parameters *p, u8 *buf, int buf_len); 85 int (*calc_regs)(struct dvb_frontend *fe, struct dvb_frontend_parameters *p, u8 *buf, int buf_len);
@@ -79,7 +88,9 @@ struct dvb_tuner_ops {
79 int (*get_bandwidth)(struct dvb_frontend *fe, u32 *bandwidth); 88 int (*get_bandwidth)(struct dvb_frontend *fe, u32 *bandwidth);
80 89
81#define TUNER_STATUS_LOCKED 1 90#define TUNER_STATUS_LOCKED 1
91#define TUNER_STATUS_STEREO 2
82 int (*get_status)(struct dvb_frontend *fe, u32 *status); 92 int (*get_status)(struct dvb_frontend *fe, u32 *status);
93 int (*get_rf_strength)(struct dvb_frontend *fe, u16 *strength);
83 94
84 /** These are provided seperately from set_params in order to facilitate silicon 95 /** These are provided seperately from set_params in order to facilitate silicon
85 * tuners which require sophisticated tuning loops, controlling each parameter seperately. */ 96 * tuners which require sophisticated tuning loops, controlling each parameter seperately. */
@@ -142,7 +153,7 @@ struct dvb_fe_events {
142 int eventr; 153 int eventr;
143 int overflow; 154 int overflow;
144 wait_queue_head_t wait_queue; 155 wait_queue_head_t wait_queue;
145 struct semaphore sem; 156 struct mutex mtx;
146}; 157};
147 158
148struct dvb_frontend { 159struct dvb_frontend {
diff --git a/drivers/media/dvb/dvb-core/dvb_net.c b/drivers/media/dvb/dvb-core/dvb_net.c
index bdd797071cb0..2117377c141d 100644
--- a/drivers/media/dvb/dvb-core/dvb_net.c
+++ b/drivers/media/dvb/dvb-core/dvb_net.c
@@ -357,11 +357,6 @@ static void dvb_net_ule( struct net_device *dev, const u8 *buf, size_t buf_len )
357 static unsigned char *ule_where = ule_hist, ule_dump = 0; 357 static unsigned char *ule_where = ule_hist, ule_dump = 0;
358#endif 358#endif
359 359
360 if (dev == NULL) {
361 printk( KERN_ERR "NO netdev struct!\n" );
362 return;
363 }
364
365 /* For all TS cells in current buffer. 360 /* For all TS cells in current buffer.
366 * Appearently, we are called for every single TS cell. 361 * Appearently, we are called for every single TS cell.
367 */ 362 */
@@ -800,8 +795,8 @@ static int dvb_net_ts_callback(const u8 *buffer1, size_t buffer1_len,
800} 795}
801 796
802 797
803static void dvb_net_sec(struct net_device *dev, const u8 *pkt, int 798static void dvb_net_sec(struct net_device *dev,
804pkt_len) 799 const u8 *pkt, int pkt_len)
805{ 800{
806 u8 *eth; 801 u8 *eth;
807 struct sk_buff *skb; 802 struct sk_buff *skb;
@@ -1446,18 +1441,9 @@ static int dvb_net_close(struct inode *inode, struct file *file)
1446 struct dvb_device *dvbdev = file->private_data; 1441 struct dvb_device *dvbdev = file->private_data;
1447 struct dvb_net *dvbnet = dvbdev->priv; 1442 struct dvb_net *dvbnet = dvbdev->priv;
1448 1443
1449 if (!dvbdev) 1444 dvb_generic_release(inode, file);
1450 return -ENODEV;
1451
1452 if ((file->f_flags & O_ACCMODE) == O_RDONLY) {
1453 dvbdev->readers++;
1454 } else {
1455 dvbdev->writers++;
1456 }
1457
1458 dvbdev->users++;
1459 1445
1460 if(dvbdev->users == 1 && dvbnet->exit==1) { 1446 if(dvbdev->users == 1 && dvbnet->exit == 1) {
1461 fops_put(file->f_op); 1447 fops_put(file->f_op);
1462 file->f_op = NULL; 1448 file->f_op = NULL;
1463 wake_up(&dvbdev->wait_queue); 1449 wake_up(&dvbdev->wait_queue);
diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
index 9ef0c00605ee..56231d8edc07 100644
--- a/drivers/media/dvb/dvb-core/dvbdev.c
+++ b/drivers/media/dvb/dvb-core/dvbdev.c
@@ -25,7 +25,6 @@
25#include <linux/errno.h> 25#include <linux/errno.h>
26#include <linux/string.h> 26#include <linux/string.h>
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/moduleparam.h>
29#include <linux/kernel.h> 28#include <linux/kernel.h>
30#include <linux/init.h> 29#include <linux/init.h>
31#include <linux/slab.h> 30#include <linux/slab.h>
@@ -59,18 +58,13 @@ static struct class *dvb_class;
59 58
60static struct dvb_device* dvbdev_find_device (int minor) 59static struct dvb_device* dvbdev_find_device (int minor)
61{ 60{
62 struct list_head *entry; 61 struct dvb_adapter *adap;
63 62
64 list_for_each (entry, &dvb_adapter_list) { 63 list_for_each_entry(adap, &dvb_adapter_list, list_head) {
65 struct list_head *entry0; 64 struct dvb_device *dev;
66 struct dvb_adapter *adap; 65 list_for_each_entry(dev, &adap->device_list, list_head)
67 adap = list_entry (entry, struct dvb_adapter, list_head);
68 list_for_each (entry0, &adap->device_list) {
69 struct dvb_device *dev;
70 dev = list_entry (entry0, struct dvb_device, list_head);
71 if (nums2minor(adap->num, dev->type, dev->id) == minor) 66 if (nums2minor(adap->num, dev->type, dev->id) == minor)
72 return dev; 67 return dev;
73 }
74 } 68 }
75 69
76 return NULL; 70 return NULL;
@@ -180,13 +174,10 @@ static int dvbdev_get_free_id (struct dvb_adapter *adap, int type)
180 u32 id = 0; 174 u32 id = 0;
181 175
182 while (id < DVB_MAX_IDS) { 176 while (id < DVB_MAX_IDS) {
183 struct list_head *entry; 177 struct dvb_device *dev;
184 list_for_each (entry, &adap->device_list) { 178 list_for_each_entry(dev, &adap->device_list, list_head)
185 struct dvb_device *dev;
186 dev = list_entry (entry, struct dvb_device, list_head);
187 if (dev->type == type && dev->id == id) 179 if (dev->type == type && dev->id == id)
188 goto skip; 180 goto skip;
189 }
190 return id; 181 return id;
191skip: 182skip:
192 id++; 183 id++;
@@ -200,7 +191,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
200{ 191{
201 struct dvb_device *dvbdev; 192 struct dvb_device *dvbdev;
202 struct file_operations *dvbdevfops; 193 struct file_operations *dvbdevfops;
203 struct class_device *clsdev; 194 struct device *clsdev;
204 int id; 195 int id;
205 196
206 mutex_lock(&dvbdev_register_lock); 197 mutex_lock(&dvbdev_register_lock);
@@ -242,10 +233,9 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
242 233
243 mutex_unlock(&dvbdev_register_lock); 234 mutex_unlock(&dvbdev_register_lock);
244 235
245 clsdev = class_device_create(dvb_class, NULL, MKDEV(DVB_MAJOR, 236 clsdev = device_create(dvb_class, adap->device,
246 nums2minor(adap->num, type, id)), 237 MKDEV(DVB_MAJOR, nums2minor(adap->num, type, id)),
247 adap->device, "dvb%d.%s%d", adap->num, 238 "dvb%d.%s%d", adap->num, dnames[type], id);
248 dnames[type], id);
249 if (IS_ERR(clsdev)) { 239 if (IS_ERR(clsdev)) {
250 printk(KERN_ERR "%s: failed to create device dvb%d.%s%d (%ld)\n", 240 printk(KERN_ERR "%s: failed to create device dvb%d.%s%d (%ld)\n",
251 __FUNCTION__, adap->num, dnames[type], id, PTR_ERR(clsdev)); 241 __FUNCTION__, adap->num, dnames[type], id, PTR_ERR(clsdev));
@@ -266,8 +256,8 @@ void dvb_unregister_device(struct dvb_device *dvbdev)
266 if (!dvbdev) 256 if (!dvbdev)
267 return; 257 return;
268 258
269 class_device_destroy(dvb_class, MKDEV(DVB_MAJOR, nums2minor(dvbdev->adapter->num, 259 device_destroy(dvb_class, MKDEV(DVB_MAJOR, nums2minor(dvbdev->adapter->num,
270 dvbdev->type, dvbdev->id))); 260 dvbdev->type, dvbdev->id)));
271 261
272 list_del (&dvbdev->list_head); 262 list_del (&dvbdev->list_head);
273 kfree (dvbdev->fops); 263 kfree (dvbdev->fops);
@@ -281,13 +271,10 @@ static int dvbdev_get_free_adapter_num (void)
281 int num = 0; 271 int num = 0;
282 272
283 while (num < DVB_MAX_ADAPTERS) { 273 while (num < DVB_MAX_ADAPTERS) {
284 struct list_head *entry; 274 struct dvb_adapter *adap;
285 list_for_each (entry, &dvb_adapter_list) { 275 list_for_each_entry(adap, &dvb_adapter_list, list_head)
286 struct dvb_adapter *adap;
287 adap = list_entry (entry, struct dvb_adapter, list_head);
288 if (adap->num == num) 276 if (adap->num == num)
289 goto skip; 277 goto skip;
290 }
291 return num; 278 return num;
292skip: 279skip:
293 num++; 280 num++;
diff --git a/drivers/media/dvb/dvb-usb/Kconfig b/drivers/media/dvb/dvb-usb/Kconfig
index 40e41f2f5afe..d73934dd4c57 100644
--- a/drivers/media/dvb/dvb-usb/Kconfig
+++ b/drivers/media/dvb/dvb-usb/Kconfig
@@ -74,6 +74,8 @@ config DVB_USB_DIB0700
74 select DVB_DIB7000M 74 select DVB_DIB7000M
75 select DVB_DIB3000MC 75 select DVB_DIB3000MC
76 select DVB_TUNER_MT2060 if !DVB_FE_CUSTOMISE 76 select DVB_TUNER_MT2060 if !DVB_FE_CUSTOMISE
77 select DVB_TUNER_MT2266 if !DVB_FE_CUSTOMISE
78 select DVB_TUNER_DIB0070
77 help 79 help
78 Support for USB2.0/1.1 DVB receivers based on the DiB0700 USB bridge. The 80 Support for USB2.0/1.1 DVB receivers based on the DiB0700 USB bridge. The
79 USB bridge is also present in devices having the DiB7700 DVB-T-USB 81 USB bridge is also present in devices having the DiB7700 DVB-T-USB
diff --git a/drivers/media/dvb/dvb-usb/dib0700.h b/drivers/media/dvb/dvb-usb/dib0700.h
index cda3adea24fb..4a903ea95896 100644
--- a/drivers/media/dvb/dvb-usb/dib0700.h
+++ b/drivers/media/dvb/dvb-usb/dib0700.h
@@ -30,17 +30,19 @@ extern int dvb_usb_dib0700_debug;
30 // 1 Byte: 4MSB(1 = enable streaming, 0 = disable streaming) 4LSB(Video Mode: 0 = MPEG2 188Bytes, 1 = Analog) 30 // 1 Byte: 4MSB(1 = enable streaming, 0 = disable streaming) 4LSB(Video Mode: 0 = MPEG2 188Bytes, 1 = Analog)
31 // 2 Byte: MPEG2 mode: 4MSB(1 = Master Mode, 0 = Slave Mode) 4LSB(Channel 1 = bit0, Channel 2 = bit1) 31 // 2 Byte: MPEG2 mode: 4MSB(1 = Master Mode, 0 = Slave Mode) 4LSB(Channel 1 = bit0, Channel 2 = bit1)
32 // 2 Byte: Analog mode: 4MSB(0 = 625 lines, 1 = 525 lines) 4LSB( " " ) 32 // 2 Byte: Analog mode: 4MSB(0 = 625 lines, 1 = 525 lines) 4LSB( " " )
33#define REQUEST_SET_RC 0x11
33#define REQUEST_GET_VERSION 0x15 34#define REQUEST_GET_VERSION 0x15
34 35
35struct dib0700_state { 36struct dib0700_state {
36 u8 channel_state; 37 u8 channel_state;
37 u16 mt2060_if1[2]; 38 u16 mt2060_if1[2];
38 39 u8 rc_toggle;
39 u8 is_dib7000pc; 40 u8 is_dib7000pc;
40}; 41};
41 42
42extern int dib0700_set_gpio(struct dvb_usb_device *, enum dib07x0_gpios gpio, u8 gpio_dir, u8 gpio_val); 43extern int dib0700_set_gpio(struct dvb_usb_device *, enum dib07x0_gpios gpio, u8 gpio_dir, u8 gpio_val);
43extern int dib0700_ctrl_clock(struct dvb_usb_device *d, u32 clk_MHz, u8 clock_out_gp3); 44extern 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);
44extern int dib0700_download_firmware(struct usb_device *udev, const struct firmware *fw); 46extern int dib0700_download_firmware(struct usb_device *udev, const struct firmware *fw);
45extern int dib0700_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff); 47extern int dib0700_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff);
46extern struct i2c_algorithm dib0700_i2c_algo; 48extern struct i2c_algorithm dib0700_i2c_algo;
@@ -50,5 +52,4 @@ extern int dib0700_identify_state(struct usb_device *udev, struct dvb_usb_device
50extern int dib0700_device_count; 52extern int dib0700_device_count;
51extern struct dvb_usb_device_properties dib0700_devices[]; 53extern struct dvb_usb_device_properties dib0700_devices[];
52extern struct usb_device_id dib0700_usb_id_table[]; 54extern struct usb_device_id dib0700_usb_id_table[];
53
54#endif 55#endif
diff --git a/drivers/media/dvb/dvb-usb/dib0700_core.c b/drivers/media/dvb/dvb-usb/dib0700_core.c
index dddf164f269a..3ea294eb96bd 100644
--- a/drivers/media/dvb/dvb-usb/dib0700_core.c
+++ b/drivers/media/dvb/dvb-usb/dib0700_core.c
@@ -13,6 +13,10 @@ 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;
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).");
19
16/* expecting rx buffer: request data[0] data[1] ... data[2] */ 20/* expecting rx buffer: request data[0] data[1] ... data[2] */
17static int dib0700_ctrl_wr(struct dvb_usb_device *d, u8 *tx, u8 txlen) 21static int dib0700_ctrl_wr(struct dvb_usb_device *d, u8 *tx, u8 txlen)
18{ 22{
@@ -32,7 +36,7 @@ static int dib0700_ctrl_wr(struct dvb_usb_device *d, u8 *tx, u8 txlen)
32} 36}
33 37
34/* expecting tx buffer: request data[0] ... data[n] (n <= 4) */ 38/* expecting tx buffer: request data[0] ... data[n] (n <= 4) */
35static int dib0700_ctrl_rd(struct dvb_usb_device *d, u8 *tx, u8 txlen, u8 *rx, u8 rxlen) 39int dib0700_ctrl_rd(struct dvb_usb_device *d, u8 *tx, u8 txlen, u8 *rx, u8 rxlen)
36{ 40{
37 u16 index, value; 41 u16 index, value;
38 int status; 42 int status;
@@ -260,14 +264,29 @@ int dib0700_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
260 return dib0700_ctrl_wr(adap->dev, b, 4); 264 return dib0700_ctrl_wr(adap->dev, b, 4);
261} 265}
262 266
267static int dib0700_rc_setup(struct dvb_usb_device *d)
268{
269 u8 rc_setup[3] = {REQUEST_SET_RC, dvb_usb_dib0700_ir_proto, 0};
270 int i = dib0700_ctrl_wr(d, rc_setup, 3);
271 if (i<0) {
272 err("ir protocol setup failed");
273 return -1;
274 }
275 return 0;
276}
277
263static int dib0700_probe(struct usb_interface *intf, 278static int dib0700_probe(struct usb_interface *intf,
264 const struct usb_device_id *id) 279 const struct usb_device_id *id)
265{ 280{
266 int i; 281 int i;
282 struct dvb_usb_device *dev;
267 283
268 for (i = 0; i < dib0700_device_count; i++) 284 for (i = 0; i < dib0700_device_count; i++)
269 if (dvb_usb_device_init(intf, &dib0700_devices[i], THIS_MODULE, NULL) == 0) 285 if (dvb_usb_device_init(intf, &dib0700_devices[i], THIS_MODULE, &dev) == 0)
286 {
287 dib0700_rc_setup(dev);
270 return 0; 288 return 0;
289 }
271 290
272 return -ENODEV; 291 return -ENODEV;
273} 292}
diff --git a/drivers/media/dvb/dvb-usb/dib0700_devices.c b/drivers/media/dvb/dvb-usb/dib0700_devices.c
index 2208757d9017..e8c4a8694532 100644
--- a/drivers/media/dvb/dvb-usb/dib0700_devices.c
+++ b/drivers/media/dvb/dvb-usb/dib0700_devices.c
@@ -4,7 +4,7 @@
4 * under the terms of the GNU General Public License as published by the Free 4 * under the terms of the GNU General Public License as published by the Free
5 * Software Foundation, version 2. 5 * Software Foundation, version 2.
6 * 6 *
7 * Copyright (C) 2005-6 DiBcom, SA 7 * Copyright (C) 2005-7 DiBcom, SA
8 */ 8 */
9#include "dib0700.h" 9#include "dib0700.h"
10 10
@@ -12,13 +12,19 @@
12#include "dib7000m.h" 12#include "dib7000m.h"
13#include "dib7000p.h" 13#include "dib7000p.h"
14#include "mt2060.h" 14#include "mt2060.h"
15#include "mt2266.h"
16#include "dib0070.h"
15 17
16static int force_lna_activation; 18static int force_lna_activation;
17module_param(force_lna_activation, int, 0644); 19module_param(force_lna_activation, int, 0644);
18MODULE_PARM_DESC(force_lna_activation, "force the activation of Low-Noise-Amplifyer(s) (LNA), " 20MODULE_PARM_DESC(force_lna_activation, "force the activation of Low-Noise-Amplifyer(s) (LNA), "
19 "if applicable for the device (default: 0=automatic/off)."); 21 "if applicable for the device (default: 0=automatic/off).");
20 22
21/* Hauppauge Nova-T 500 23struct dib0700_adapter_state {
24 int (*set_param_save) (struct dvb_frontend *, struct dvb_frontend_parameters *);
25};
26
27/* Hauppauge Nova-T 500 (aka Bristol)
22 * has a LNA on GPIO0 which is enabled by setting 1 */ 28 * has a LNA on GPIO0 which is enabled by setting 1 */
23static struct mt2060_config bristol_mt2060_config[2] = { 29static struct mt2060_config bristol_mt2060_config[2] = {
24 { 30 {
@@ -96,6 +102,321 @@ static int bristol_tuner_attach(struct dvb_usb_adapter *adap)
96 st->mt2060_if1[adap->id]) == NULL ? -ENODEV : 0; 102 st->mt2060_if1[adap->id]) == NULL ? -ENODEV : 0;
97} 103}
98 104
105/* STK7700D: Pinnacle/Terratec/Hauppauge Dual DVB-T Diversity */
106
107/* MT226x */
108static struct dibx000_agc_config stk7700d_7000p_mt2266_agc_config[2] = {
109 {
110 BAND_UHF, // band_caps
111
112 /* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=1, P_agc_inv_pwm1=1, P_agc_inv_pwm2=1,
113 * P_agc_inh_dc_rv_est=0, P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=2, P_agc_write=0 */
114 (0 << 15) | (0 << 14) | (1 << 11) | (1 << 10) | (1 << 9) | (0 << 8) | (3 << 5) | (0 << 4) | (5 << 1) | (0 << 0), // setup
115
116 1130, // inv_gain
117 21, // time_stabiliz
118
119 0, // alpha_level
120 118, // thlock
121
122 0, // wbd_inv
123 3530, // wbd_ref
124 1, // wbd_sel
125 0, // wbd_alpha
126
127 65535, // agc1_max
128 33770, // agc1_min
129 65535, // agc2_max
130 23592, // agc2_min
131
132 0, // agc1_pt1
133 62, // agc1_pt2
134 255, // agc1_pt3
135 64, // agc1_slope1
136 64, // agc1_slope2
137 132, // agc2_pt1
138 192, // agc2_pt2
139 80, // agc2_slope1
140 80, // agc2_slope2
141
142 17, // alpha_mant
143 27, // alpha_exp
144 23, // beta_mant
145 51, // beta_exp
146
147 1, // perform_agc_softsplit
148 }, {
149 BAND_VHF | BAND_LBAND, // band_caps
150
151 /* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=1, P_agc_inv_pwm1=1, P_agc_inv_pwm2=1,
152 * P_agc_inh_dc_rv_est=0, P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=2, P_agc_write=0 */
153 (0 << 15) | (0 << 14) | (1 << 11) | (1 << 10) | (1 << 9) | (0 << 8) | (3 << 5) | (0 << 4) | (2 << 1) | (0 << 0), // setup
154
155 2372, // inv_gain
156 21, // time_stabiliz
157
158 0, // alpha_level
159 118, // thlock
160
161 0, // wbd_inv
162 3530, // wbd_ref
163 1, // wbd_sel
164 0, // wbd_alpha
165
166 65535, // agc1_max
167 0, // agc1_min
168 65535, // agc2_max
169 23592, // agc2_min
170
171 0, // agc1_pt1
172 128, // agc1_pt2
173 128, // agc1_pt3
174 128, // agc1_slope1
175 0, // agc1_slope2
176 128, // agc2_pt1
177 253, // agc2_pt2
178 81, // agc2_slope1
179 0, // agc2_slope2
180
181 17, // alpha_mant
182 27, // alpha_exp
183 23, // beta_mant
184 51, // beta_exp
185
186 1, // perform_agc_softsplit
187 }
188};
189
190static struct dibx000_bandwidth_config stk7700d_mt2266_pll_config = {
191 60000, 30000, // internal, sampling
192 1, 8, 3, 1, 0, // pll_cfg: prediv, ratio, range, reset, bypass
193 0, 0, 1, 1, 2, // misc: refdiv, bypclk_div, IO_CLK_en_core, ADClkSrc, modulo
194 (3 << 14) | (1 << 12) | (524 << 0), // sad_cfg: refsel, sel, freq_15k
195 0, // ifreq
196 20452225, // timf
197};
198
199static struct dib7000p_config stk7700d_dib7000p_mt2266_config[] = {
200 { .output_mpeg2_in_188_bytes = 1,
201 .hostbus_diversity = 1,
202 .tuner_is_baseband = 1,
203
204 .agc_config_count = 2,
205 .agc = stk7700d_7000p_mt2266_agc_config,
206 .bw = &stk7700d_mt2266_pll_config,
207
208 .gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
209 .gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
210 .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
211 },
212 { .output_mpeg2_in_188_bytes = 1,
213 .hostbus_diversity = 1,
214 .tuner_is_baseband = 1,
215
216 .agc_config_count = 2,
217 .agc = stk7700d_7000p_mt2266_agc_config,
218 .bw = &stk7700d_mt2266_pll_config,
219
220 .gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
221 .gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
222 .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
223 }
224};
225
226static struct mt2266_config stk7700d_mt2266_config[2] = {
227 { .i2c_address = 0x60
228 },
229 { .i2c_address = 0x60
230 }
231};
232
233static int stk7700d_frontend_attach(struct dvb_usb_adapter *adap)
234{
235 if (adap->id == 0) {
236 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
237 msleep(10);
238 dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
239 dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
240 dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
241 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
242 msleep(10);
243 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
244 msleep(10);
245 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
246 dib7000p_i2c_enumeration(&adap->dev->i2c_adap,2,18,stk7700d_dib7000p_mt2266_config);
247 }
248
249 adap->fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap,0x80+(adap->id << 1),
250 &stk7700d_dib7000p_mt2266_config[adap->id]);
251
252 return adap->fe == NULL ? -ENODEV : 0;
253}
254
255static int stk7700d_tuner_attach(struct dvb_usb_adapter *adap)
256{
257 struct i2c_adapter *tun_i2c;
258 tun_i2c = dib7000p_get_i2c_master(adap->fe, DIBX000_I2C_INTERFACE_TUNER, 1);
259 return dvb_attach(mt2266_attach, adap->fe, tun_i2c,
260 &stk7700d_mt2266_config[adap->id]) == NULL ? -ENODEV : 0;;
261}
262
263#define DEFAULT_RC_INTERVAL 150
264
265static u8 rc_request[] = { REQUEST_POLL_RC, 0 };
266
267static int dib0700_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
268{
269 u8 key[4];
270 int i;
271 struct dvb_usb_rc_key *keymap = d->props.rc_key_map;
272 struct dib0700_state *st = d->priv;
273 *event = 0;
274 *state = REMOTE_NO_KEY_PRESSED;
275 i=dib0700_ctrl_rd(d,rc_request,2,key,4);
276 if (i<=0) {
277 err("RC Query Failed");
278 return -1;
279 }
280 if (key[0]==0 && key[1]==0 && key[2]==0 && key[3]==0) return 0;
281 if (key[3-1]!=st->rc_toggle) {
282 for (i=0;i<d->props.rc_key_map_size; i++) {
283 if (keymap[i].custom == key[3-2] && keymap[i].data == key[3-3]) {
284 *event = keymap[i].event;
285 *state = REMOTE_KEY_PRESSED;
286 st->rc_toggle=key[3-1];
287 return 0;
288 }
289 }
290 err("Unknown remote controller key : %2X %2X",(int)key[3-2],(int)key[3-3]);
291 }
292 return 0;
293}
294
295static struct dvb_usb_rc_key dib0700_rc_keys[] = {
296 /* Key codes for the tiny Pinnacle remote*/
297 { 0x07, 0x00, KEY_MUTE },
298 { 0x07, 0x01, KEY_MENU }, // Pinnacle logo
299 { 0x07, 0x39, KEY_POWER },
300 { 0x07, 0x03, KEY_VOLUMEUP },
301 { 0x07, 0x09, KEY_VOLUMEDOWN },
302 { 0x07, 0x06, KEY_CHANNELUP },
303 { 0x07, 0x0c, KEY_CHANNELDOWN },
304 { 0x07, 0x0f, KEY_1 },
305 { 0x07, 0x15, KEY_2 },
306 { 0x07, 0x10, KEY_3 },
307 { 0x07, 0x18, KEY_4 },
308 { 0x07, 0x1b, KEY_5 },
309 { 0x07, 0x1e, KEY_6 },
310 { 0x07, 0x11, KEY_7 },
311 { 0x07, 0x21, KEY_8 },
312 { 0x07, 0x12, KEY_9 },
313 { 0x07, 0x27, KEY_0 },
314 { 0x07, 0x24, KEY_SCREEN }, // 'Square' key
315 { 0x07, 0x2a, KEY_TEXT }, // 'T' key
316 { 0x07, 0x2d, KEY_REWIND },
317 { 0x07, 0x30, KEY_PLAY },
318 { 0x07, 0x33, KEY_FASTFORWARD },
319 { 0x07, 0x36, KEY_RECORD },
320 { 0x07, 0x3c, KEY_STOP },
321 { 0x07, 0x3f, KEY_CANCEL }, // '?' key
322 /* Key codes for the Terratec Cinergy DT XS Diversity, similar to cinergyT2.c */
323 { 0xeb, 0x01, KEY_POWER },
324 { 0xeb, 0x02, KEY_1 },
325 { 0xeb, 0x03, KEY_2 },
326 { 0xeb, 0x04, KEY_3 },
327 { 0xeb, 0x05, KEY_4 },
328 { 0xeb, 0x06, KEY_5 },
329 { 0xeb, 0x07, KEY_6 },
330 { 0xeb, 0x08, KEY_7 },
331 { 0xeb, 0x09, KEY_8 },
332 { 0xeb, 0x0a, KEY_9 },
333 { 0xeb, 0x0b, KEY_VIDEO },
334 { 0xeb, 0x0c, KEY_0 },
335 { 0xeb, 0x0d, KEY_REFRESH },
336 { 0xeb, 0x0f, KEY_EPG },
337 { 0xeb, 0x10, KEY_UP },
338 { 0xeb, 0x11, KEY_LEFT },
339 { 0xeb, 0x12, KEY_OK },
340 { 0xeb, 0x13, KEY_RIGHT },
341 { 0xeb, 0x14, KEY_DOWN },
342 { 0xeb, 0x16, KEY_INFO },
343 { 0xeb, 0x17, KEY_RED },
344 { 0xeb, 0x18, KEY_GREEN },
345 { 0xeb, 0x19, KEY_YELLOW },
346 { 0xeb, 0x1a, KEY_BLUE },
347 { 0xeb, 0x1b, KEY_CHANNELUP },
348 { 0xeb, 0x1c, KEY_VOLUMEUP },
349 { 0xeb, 0x1d, KEY_MUTE },
350 { 0xeb, 0x1e, KEY_VOLUMEDOWN },
351 { 0xeb, 0x1f, KEY_CHANNELDOWN },
352 { 0xeb, 0x40, KEY_PAUSE },
353 { 0xeb, 0x41, KEY_HOME },
354 { 0xeb, 0x42, KEY_MENU }, /* DVD Menu */
355 { 0xeb, 0x43, KEY_SUBTITLE },
356 { 0xeb, 0x44, KEY_TEXT }, /* Teletext */
357 { 0xeb, 0x45, KEY_DELETE },
358 { 0xeb, 0x46, KEY_TV },
359 { 0xeb, 0x47, KEY_DVD },
360 { 0xeb, 0x48, KEY_STOP },
361 { 0xeb, 0x49, KEY_VIDEO },
362 { 0xeb, 0x4a, KEY_AUDIO }, /* Music */
363 { 0xeb, 0x4b, KEY_SCREEN }, /* Pic */
364 { 0xeb, 0x4c, KEY_PLAY },
365 { 0xeb, 0x4d, KEY_BACK },
366 { 0xeb, 0x4e, KEY_REWIND },
367 { 0xeb, 0x4f, KEY_FASTFORWARD },
368 { 0xeb, 0x54, KEY_PREVIOUS },
369 { 0xeb, 0x58, KEY_RECORD },
370 { 0xeb, 0x5c, KEY_NEXT },
371
372 /* Key codes for the Haupauge WinTV Nova-TD, copied from nova-t-usb2.c (Nova-T USB2) */
373 { 0x1e, 0x00, KEY_0 },
374 { 0x1e, 0x01, KEY_1 },
375 { 0x1e, 0x02, KEY_2 },
376 { 0x1e, 0x03, KEY_3 },
377 { 0x1e, 0x04, KEY_4 },
378 { 0x1e, 0x05, KEY_5 },
379 { 0x1e, 0x06, KEY_6 },
380 { 0x1e, 0x07, KEY_7 },
381 { 0x1e, 0x08, KEY_8 },
382 { 0x1e, 0x09, KEY_9 },
383 { 0x1e, 0x0a, KEY_KPASTERISK },
384 { 0x1e, 0x0b, KEY_RED },
385 { 0x1e, 0x0c, KEY_RADIO },
386 { 0x1e, 0x0d, KEY_MENU },
387 { 0x1e, 0x0e, KEY_GRAVE }, /* # */
388 { 0x1e, 0x0f, KEY_MUTE },
389 { 0x1e, 0x10, KEY_VOLUMEUP },
390 { 0x1e, 0x11, KEY_VOLUMEDOWN },
391 { 0x1e, 0x12, KEY_CHANNEL },
392 { 0x1e, 0x14, KEY_UP },
393 { 0x1e, 0x15, KEY_DOWN },
394 { 0x1e, 0x16, KEY_LEFT },
395 { 0x1e, 0x17, KEY_RIGHT },
396 { 0x1e, 0x18, KEY_VIDEO },
397 { 0x1e, 0x19, KEY_AUDIO },
398 { 0x1e, 0x1a, KEY_MEDIA },
399 { 0x1e, 0x1b, KEY_EPG },
400 { 0x1e, 0x1c, KEY_TV },
401 { 0x1e, 0x1e, KEY_NEXT },
402 { 0x1e, 0x1f, KEY_BACK },
403 { 0x1e, 0x20, KEY_CHANNELUP },
404 { 0x1e, 0x21, KEY_CHANNELDOWN },
405 { 0x1e, 0x24, KEY_LAST }, /* Skip backwards */
406 { 0x1e, 0x25, KEY_OK },
407 { 0x1e, 0x29, KEY_BLUE},
408 { 0x1e, 0x2e, KEY_GREEN },
409 { 0x1e, 0x30, KEY_PAUSE },
410 { 0x1e, 0x32, KEY_REWIND },
411 { 0x1e, 0x34, KEY_FASTFORWARD },
412 { 0x1e, 0x35, KEY_PLAY },
413 { 0x1e, 0x36, KEY_STOP },
414 { 0x1e, 0x37, KEY_RECORD },
415 { 0x1e, 0x38, KEY_YELLOW },
416 { 0x1e, 0x3b, KEY_GOTO },
417 { 0x1e, 0x3d, KEY_POWER },
418};
419
99/* STK7700P: Hauppauge Nova-T Stick, AVerMedia Volar */ 420/* STK7700P: Hauppauge Nova-T Stick, AVerMedia Volar */
100static struct dibx000_agc_config stk7700p_7000m_mt2060_agc_config = { 421static struct dibx000_agc_config stk7700p_7000m_mt2060_agc_config = {
101 BAND_UHF | BAND_VHF, // band_caps 422 BAND_UHF | BAND_VHF, // band_caps
@@ -194,6 +515,7 @@ static struct dibx000_bandwidth_config stk7700p_pll_config = {
194 (3 << 14) | (1 << 12) | (524 << 0), // sad_cfg: refsel, sel, freq_15k 515 (3 << 14) | (1 << 12) | (524 << 0), // sad_cfg: refsel, sel, freq_15k
195 60258167, // ifreq 516 60258167, // ifreq
196 20452225, // timf 517 20452225, // timf
518 30000000, // xtal
197}; 519};
198 520
199static struct dib7000m_config stk7700p_dib7000m_config = { 521static struct dib7000m_config stk7700p_dib7000m_config = {
@@ -213,6 +535,7 @@ static struct dib7000m_config stk7700p_dib7000m_config = {
213static struct dib7000p_config stk7700p_dib7000p_config = { 535static struct dib7000p_config stk7700p_dib7000p_config = {
214 .output_mpeg2_in_188_bytes = 1, 536 .output_mpeg2_in_188_bytes = 1,
215 537
538 .agc_config_count = 1,
216 .agc = &stk7700p_7000p_mt2060_agc_config, 539 .agc = &stk7700p_7000p_mt2060_agc_config,
217 .bw = &stk7700p_pll_config, 540 .bw = &stk7700p_pll_config,
218 541
@@ -267,27 +590,245 @@ static int stk7700p_tuner_attach(struct dvb_usb_adapter *adap)
267 st->mt2060_if1[0]) == NULL ? -ENODEV : 0; 590 st->mt2060_if1[0]) == NULL ? -ENODEV : 0;
268} 591}
269 592
593/* DIB7070 generic */
594static struct dibx000_agc_config dib7070_agc_config = {
595 BAND_UHF | BAND_VHF | BAND_LBAND | BAND_SBAND,
596 /* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=5, P_agc_inv_pwm1=0, P_agc_inv_pwm2=0,
597 * P_agc_inh_dc_rv_est=0, P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=5, P_agc_write=0 */
598 (0 << 15) | (0 << 14) | (5 << 11) | (0 << 10) | (0 << 9) | (0 << 8) | (3 << 5) | (0 << 4) | (5 << 1) | (0 << 0), // setup
599
600 600, // inv_gain
601 10, // time_stabiliz
602
603 0, // alpha_level
604 118, // thlock
605
606 0, // wbd_inv
607 3530, // wbd_ref
608 1, // wbd_sel
609 5, // wbd_alpha
610
611 65535, // agc1_max
612 0, // agc1_min
613
614 65535, // agc2_max
615 0, // agc2_min
616
617 0, // agc1_pt1
618 40, // agc1_pt2
619 183, // agc1_pt3
620 206, // agc1_slope1
621 255, // agc1_slope2
622 72, // agc2_pt1
623 152, // agc2_pt2
624 88, // agc2_slope1
625 90, // agc2_slope2
626
627 17, // alpha_mant
628 27, // alpha_exp
629 23, // beta_mant
630 51, // beta_exp
631
632 0, // perform_agc_softsplit
633};
634
635static int dib7070_tuner_reset(struct dvb_frontend *fe, int onoff)
636{
637 return dib7000p_set_gpio(fe, 8, 0, !onoff);
638}
639
640static int dib7070_tuner_sleep(struct dvb_frontend *fe, int onoff)
641{
642 return dib7000p_set_gpio(fe, 9, 0, onoff);
643}
644
645static struct dib0070_config dib7070p_dib0070_config[2] = {
646 {
647 .i2c_address = DEFAULT_DIB0070_I2C_ADDRESS,
648 .reset = dib7070_tuner_reset,
649 .sleep = dib7070_tuner_sleep,
650 .clock_khz = 12000,
651 .clock_pad_drive = 4
652 }, {
653 .i2c_address = DEFAULT_DIB0070_I2C_ADDRESS,
654 .reset = dib7070_tuner_reset,
655 .sleep = dib7070_tuner_sleep,
656 .clock_khz = 12000,
657
658 }
659};
660
661static int dib7070_set_param_override(struct dvb_frontend *fe, struct dvb_frontend_parameters *fep)
662{
663 struct dvb_usb_adapter *adap = fe->dvb->priv;
664 struct dib0700_adapter_state *state = adap->priv;
665
666 u16 offset;
667 u8 band = BAND_OF_FREQUENCY(fep->frequency/1000);
668 switch (band) {
669 case BAND_VHF: offset = 950; break;
670 case BAND_UHF:
671 default: offset = 550; break;
672 }
673 deb_info("WBD for DiB7000P: %d\n", offset + dib0070_wbd_offset(fe));
674 dib7000p_set_wbd_ref(fe, offset + dib0070_wbd_offset(fe));
675 return state->set_param_save(fe, fep);
676}
677
678static int dib7070p_tuner_attach(struct dvb_usb_adapter *adap)
679{
680 struct dib0700_adapter_state *st = adap->priv;
681 struct i2c_adapter *tun_i2c = dib7000p_get_i2c_master(adap->fe, DIBX000_I2C_INTERFACE_TUNER, 1);
682
683 if (adap->id == 0) {
684 if (dvb_attach(dib0070_attach, adap->fe, tun_i2c, &dib7070p_dib0070_config[0]) == NULL)
685 return -ENODEV;
686 } else {
687 if (dvb_attach(dib0070_attach, adap->fe, tun_i2c, &dib7070p_dib0070_config[1]) == NULL)
688 return -ENODEV;
689 }
690
691 st->set_param_save = adap->fe->ops.tuner_ops.set_params;
692 adap->fe->ops.tuner_ops.set_params = dib7070_set_param_override;
693 return 0;
694}
695
696static struct dibx000_bandwidth_config dib7070_bw_config_12_mhz = {
697 60000, 15000, // internal, sampling
698 1, 20, 3, 1, 0, // pll_cfg: prediv, ratio, range, reset, bypass
699 0, 0, 1, 1, 2, // misc: refdiv, bypclk_div, IO_CLK_en_core, ADClkSrc, modulo
700 (3 << 14) | (1 << 12) | (524 << 0), // sad_cfg: refsel, sel, freq_15k
701 (0 << 25) | 0, // ifreq = 0.000000 MHz
702 20452225, // timf
703 12000000, // xtal_hz
704};
705
706static struct dib7000p_config dib7070p_dib7000p_config = {
707 .output_mpeg2_in_188_bytes = 1,
708
709 .agc_config_count = 1,
710 .agc = &dib7070_agc_config,
711 .bw = &dib7070_bw_config_12_mhz,
712
713 .gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
714 .gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
715 .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
716
717 .hostbus_diversity = 1,
718};
719
720/* STK7070P */
721static int stk7070p_frontend_attach(struct dvb_usb_adapter *adap)
722{
723 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
724 msleep(10);
725 dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
726 dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
727 dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
728 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
729
730 dib0700_ctrl_clock(adap->dev, 72, 1);
731
732 msleep(10);
733 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
734 msleep(10);
735 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
736
737 dib7000p_i2c_enumeration(&adap->dev->i2c_adap, 1, 18, &dib7070p_dib7000p_config);
738
739 adap->fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x80, &dib7070p_dib7000p_config);
740 return adap->fe == NULL ? -ENODEV : 0;
741}
742
743/* STK7070PD */
744static struct dib7000p_config stk7070pd_dib7000p_config[2] = {
745 {
746 .output_mpeg2_in_188_bytes = 1,
747
748 .agc_config_count = 1,
749 .agc = &dib7070_agc_config,
750 .bw = &dib7070_bw_config_12_mhz,
751
752 .gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
753 .gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
754 .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
755
756 .hostbus_diversity = 1,
757 }, {
758 .output_mpeg2_in_188_bytes = 1,
759
760 .agc_config_count = 1,
761 .agc = &dib7070_agc_config,
762 .bw = &dib7070_bw_config_12_mhz,
763
764 .gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
765 .gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
766 .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
767
768 .hostbus_diversity = 1,
769 }
770};
771
772static int stk7070pd_frontend_attach0(struct dvb_usb_adapter *adap)
773{
774 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
775 msleep(10);
776 dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
777 dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
778 dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
779 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
780
781 dib0700_ctrl_clock(adap->dev, 72, 1);
782
783 msleep(10);
784 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
785 msleep(10);
786 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
787
788 dib7000p_i2c_enumeration(&adap->dev->i2c_adap, 2, 18, stk7070pd_dib7000p_config);
789
790 adap->fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x80, &stk7070pd_dib7000p_config[0]);
791 return adap->fe == NULL ? -ENODEV : 0;
792}
793
794static int stk7070pd_frontend_attach1(struct dvb_usb_adapter *adap)
795{
796 adap->fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x82, &stk7070pd_dib7000p_config[1]);
797 return adap->fe == NULL ? -ENODEV : 0;
798}
799
800/* DVB-USB and USB stuff follows */
270struct usb_device_id dib0700_usb_id_table[] = { 801struct usb_device_id dib0700_usb_id_table[] = {
271 { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_STK7700P) }, 802/* 0 */ { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_STK7700P) },
272 { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_STK7700P_PC) }, 803 { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_STK7700P_PC) },
273 804
274 { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_500) }, 805 { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_500) },
275 { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_500_2) }, 806 { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_500_2) },
276 { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_STICK) }, 807 { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_STICK) },
277 { USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR) }, 808/* 5 */ { USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR) },
278 { USB_DEVICE(USB_VID_COMPRO, USB_PID_COMPRO_VIDEOMATE_U500) }, 809 { USB_DEVICE(USB_VID_COMPRO, USB_PID_COMPRO_VIDEOMATE_U500) },
279 { USB_DEVICE(USB_VID_UNIWILL, USB_PID_UNIWILL_STK7700P) }, 810 { USB_DEVICE(USB_VID_UNIWILL, USB_PID_UNIWILL_STK7700P) },
280 { USB_DEVICE(USB_VID_LEADTEK, USB_PID_WINFAST_DTV_DONGLE_STK7700P) }, 811 { USB_DEVICE(USB_VID_LEADTEK, USB_PID_WINFAST_DTV_DONGLE_STK7700P) },
281 { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_STICK_2) }, 812 { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_STICK_2) },
282 { USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR_2) }, 813/* 10 */{ USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR_2) },
283 { } /* Terminating entry */ 814 { USB_DEVICE(USB_VID_PINNACLE, USB_PID_PINNACLE_PCTV2000E) },
815 { USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_DT_XS_DIVERSITY) },
816 { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_TD_STICK) },
817 { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_STK7700D) },
818/* 15 */{ USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_STK7070P) },
819 { USB_DEVICE(USB_VID_PINNACLE, USB_PID_PINNACLE_PCTV_DVB_T_FLASH) },
820 { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_STK7070PD) },
821 { USB_DEVICE(USB_VID_PINNACLE, USB_PID_PINNACLE_PCTV_DUAL_DIVERSITY_DVB_T) },
822 { USB_DEVICE(USB_VID_COMPRO, USB_PID_COMPRO_VIDEOMATE_U500_PC) },
823/* 20 */{ USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_EXPRESS) },
824 { 0 } /* Terminating entry */
284}; 825};
285MODULE_DEVICE_TABLE(usb, dib0700_usb_id_table); 826MODULE_DEVICE_TABLE(usb, dib0700_usb_id_table);
286 827
287#define DIB0700_DEFAULT_DEVICE_PROPERTIES \ 828#define DIB0700_DEFAULT_DEVICE_PROPERTIES \
288 .caps = DVB_USB_IS_AN_I2C_ADAPTER, \ 829 .caps = DVB_USB_IS_AN_I2C_ADAPTER, \
289 .usb_ctrl = DEVICE_SPECIFIC, \ 830 .usb_ctrl = DEVICE_SPECIFIC, \
290 .firmware = "dvb-usb-dib0700-01.fw", \ 831 .firmware = "dvb-usb-dib0700-03-pre1.fw", \
291 .download_firmware = dib0700_download_firmware, \ 832 .download_firmware = dib0700_download_firmware, \
292 .no_reconnect = 1, \ 833 .no_reconnect = 1, \
293 .size_of_priv = sizeof(struct dib0700_state), \ 834 .size_of_priv = sizeof(struct dib0700_state), \
@@ -321,7 +862,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
321 }, 862 },
322 }, 863 },
323 864
324 .num_device_descs = 6, 865 .num_device_descs = 7,
325 .devices = { 866 .devices = {
326 { "DiBcom STK7700P reference design", 867 { "DiBcom STK7700P reference design",
327 { &dib0700_usb_id_table[0], &dib0700_usb_id_table[1] }, 868 { &dib0700_usb_id_table[0], &dib0700_usb_id_table[1] },
@@ -336,7 +877,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
336 { NULL }, 877 { NULL },
337 }, 878 },
338 { "Compro Videomate U500", 879 { "Compro Videomate U500",
339 { &dib0700_usb_id_table[6], NULL }, 880 { &dib0700_usb_id_table[6], &dib0700_usb_id_table[19] },
340 { NULL }, 881 { NULL },
341 }, 882 },
342 { "Uniwill STK7700P based (Hama and others)", 883 { "Uniwill STK7700P based (Hama and others)",
@@ -346,8 +887,17 @@ struct dvb_usb_device_properties dib0700_devices[] = {
346 { "Leadtek Winfast DTV Dongle (STK7700P based)", 887 { "Leadtek Winfast DTV Dongle (STK7700P based)",
347 { &dib0700_usb_id_table[8], NULL }, 888 { &dib0700_usb_id_table[8], NULL },
348 { NULL }, 889 { NULL },
890 },
891 { "AVerMedia AVerTV DVB-T Express",
892 { &dib0700_usb_id_table[20] },
893 { NULL },
349 } 894 }
350 } 895 },
896
897 .rc_interval = DEFAULT_RC_INTERVAL,
898 .rc_key_map = dib0700_rc_keys,
899 .rc_key_map_size = ARRAY_SIZE(dib0700_rc_keys),
900 .rc_query = dib0700_rc_query
351 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES, 901 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
352 902
353 .num_adapters = 2, 903 .num_adapters = 2,
@@ -371,8 +921,112 @@ struct dvb_usb_device_properties dib0700_devices[] = {
371 { &dib0700_usb_id_table[2], &dib0700_usb_id_table[3], NULL }, 921 { &dib0700_usb_id_table[2], &dib0700_usb_id_table[3], NULL },
372 { NULL }, 922 { NULL },
373 }, 923 },
924 },
925
926 .rc_interval = DEFAULT_RC_INTERVAL,
927 .rc_key_map = dib0700_rc_keys,
928 .rc_key_map_size = ARRAY_SIZE(dib0700_rc_keys),
929 .rc_query = dib0700_rc_query
930 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
931
932 .num_adapters = 2,
933 .adapter = {
934 {
935 .frontend_attach = stk7700d_frontend_attach,
936 .tuner_attach = stk7700d_tuner_attach,
937
938 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
939 }, {
940 .frontend_attach = stk7700d_frontend_attach,
941 .tuner_attach = stk7700d_tuner_attach,
942
943 DIB0700_DEFAULT_STREAMING_CONFIG(0x03),
944 }
945 },
946
947 .num_device_descs = 4,
948 .devices = {
949 { "Pinnacle PCTV 2000e",
950 { &dib0700_usb_id_table[11], NULL },
951 { NULL },
952 },
953 { "Terratec Cinergy DT XS Diversity",
954 { &dib0700_usb_id_table[12], NULL },
955 { NULL },
956 },
957 { "Hauppauge Nova-TD Stick/Elgato Eye-TV Diversity",
958 { &dib0700_usb_id_table[13], NULL },
959 { NULL },
960 },
961 { "DiBcom STK7700D reference design",
962 { &dib0700_usb_id_table[14], NULL },
963 { NULL },
964 },
965 },
966
967 .rc_interval = DEFAULT_RC_INTERVAL,
968 .rc_key_map = dib0700_rc_keys,
969 .rc_key_map_size = ARRAY_SIZE(dib0700_rc_keys),
970 .rc_query = dib0700_rc_query
971
972 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
973
974 .num_adapters = 1,
975 .adapter = {
976 {
977 .frontend_attach = stk7070p_frontend_attach,
978 .tuner_attach = dib7070p_tuner_attach,
979
980 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
981
982 .size_of_priv = sizeof(struct dib0700_adapter_state),
983 },
984 },
985
986 .num_device_descs = 2,
987 .devices = {
988 { "DiBcom STK7070P reference design",
989 { &dib0700_usb_id_table[15], NULL },
990 { NULL },
991 },
992 { "Pinnacle PCTV DVB-T Flash Stick",
993 { &dib0700_usb_id_table[16], NULL },
994 { NULL },
995 },
374 } 996 }
375 } 997 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
998
999 .num_adapters = 2,
1000 .adapter = {
1001 {
1002 .frontend_attach = stk7070pd_frontend_attach0,
1003 .tuner_attach = dib7070p_tuner_attach,
1004
1005 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
1006
1007 .size_of_priv = sizeof(struct dib0700_adapter_state),
1008 }, {
1009 .frontend_attach = stk7070pd_frontend_attach1,
1010 .tuner_attach = dib7070p_tuner_attach,
1011
1012 DIB0700_DEFAULT_STREAMING_CONFIG(0x03),
1013
1014 .size_of_priv = sizeof(struct dib0700_adapter_state),
1015 }
1016 },
1017
1018 .num_device_descs = 2,
1019 .devices = {
1020 { "DiBcom STK7070PD reference design",
1021 { &dib0700_usb_id_table[17], NULL },
1022 { NULL },
1023 },
1024 { "Pinnacle PCTV Dual DVB-T Diversity Stick",
1025 { &dib0700_usb_id_table[18], NULL },
1026 { NULL },
1027 },
1028 }
1029 },
376}; 1030};
377 1031
378int dib0700_device_count = ARRAY_SIZE(dib0700_devices); 1032int dib0700_device_count = ARRAY_SIZE(dib0700_devices);
diff --git a/drivers/media/dvb/dvb-usb/dtt200u.c b/drivers/media/dvb/dvb-usb/dtt200u.c
index 7dbe14321019..d86cf9bee91c 100644
--- a/drivers/media/dvb/dvb-usb/dtt200u.c
+++ b/drivers/media/dvb/dvb-usb/dtt200u.c
@@ -1,5 +1,5 @@
1/* DVB USB library compliant Linux driver for the WideView/ Yakumo/ Hama/ 1/* DVB USB library compliant Linux driver for the WideView/ Yakumo/ Hama/
2 * Typhoon/ Yuan DVB-T USB2.0 receiver. 2 * Typhoon/ Yuan/ Miglia DVB-T USB2.0 receiver.
3 * 3 *
4 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de) 4 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
5 * 5 *
@@ -96,6 +96,7 @@ static struct dvb_usb_device_properties dtt200u_properties;
96static struct dvb_usb_device_properties wt220u_fc_properties; 96static struct dvb_usb_device_properties wt220u_fc_properties;
97static struct dvb_usb_device_properties wt220u_properties; 97static struct dvb_usb_device_properties wt220u_properties;
98static struct dvb_usb_device_properties wt220u_zl0353_properties; 98static struct dvb_usb_device_properties wt220u_zl0353_properties;
99static struct dvb_usb_device_properties wt220u_miglia_properties;
99 100
100static int dtt200u_usb_probe(struct usb_interface *intf, 101static int dtt200u_usb_probe(struct usb_interface *intf,
101 const struct usb_device_id *id) 102 const struct usb_device_id *id)
@@ -103,7 +104,8 @@ static int dtt200u_usb_probe(struct usb_interface *intf,
103 if (dvb_usb_device_init(intf,&dtt200u_properties,THIS_MODULE,NULL) == 0 || 104 if (dvb_usb_device_init(intf,&dtt200u_properties,THIS_MODULE,NULL) == 0 ||
104 dvb_usb_device_init(intf,&wt220u_properties,THIS_MODULE,NULL) == 0 || 105 dvb_usb_device_init(intf,&wt220u_properties,THIS_MODULE,NULL) == 0 ||
105 dvb_usb_device_init(intf,&wt220u_fc_properties,THIS_MODULE,NULL) == 0 || 106 dvb_usb_device_init(intf,&wt220u_fc_properties,THIS_MODULE,NULL) == 0 ||
106 dvb_usb_device_init(intf,&wt220u_zl0353_properties,THIS_MODULE,NULL) == 0) 107 dvb_usb_device_init(intf,&wt220u_zl0353_properties,THIS_MODULE,NULL) == 0 ||
108 dvb_usb_device_init(intf,&wt220u_miglia_properties,THIS_MODULE,NULL) == 0)
107 return 0; 109 return 0;
108 110
109 return -ENODEV; 111 return -ENODEV;
@@ -119,6 +121,7 @@ static struct usb_device_id dtt200u_usb_table [] = {
119 { USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_WT220U_FC_COLD) }, 121 { USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_WT220U_FC_COLD) },
120 { USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_WT220U_FC_WARM) }, 122 { USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_WT220U_FC_WARM) },
121 { USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_WT220U_ZAP250_COLD) }, 123 { USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_WT220U_ZAP250_COLD) },
124 { USB_DEVICE(USB_VID_MIGLIA, USB_PID_WT220U_ZAP250_COLD) },
122 { 0 }, 125 { 0 },
123}; 126};
124MODULE_DEVICE_TABLE(usb, dtt200u_usb_table); 127MODULE_DEVICE_TABLE(usb, dtt200u_usb_table);
@@ -303,6 +306,25 @@ static struct dvb_usb_device_properties wt220u_zl0353_properties = {
303 } 306 }
304}; 307};
305 308
309static struct dvb_usb_device_properties wt220u_miglia_properties = {
310 .usb_ctrl = CYPRESS_FX2,
311 .firmware = "dvb-usb-wt220u-miglia-01.fw",
312
313 .num_adapters = 1,
314 .generic_bulk_ctrl_endpoint = 0x01,
315
316 .num_device_descs = 1,
317 .devices = {
318 { .name = "WideView WT-220U PenType Receiver (Miglia)",
319 .cold_ids = { &dtt200u_usb_table[9], NULL },
320 /* This device turns into WT220U_ZL0353_WARM when fw
321 has been uploaded */
322 .warm_ids = { NULL },
323 },
324 { NULL },
325 }
326};
327
306/* usb specific object needed to register this driver with the usb subsystem */ 328/* usb specific object needed to register this driver with the usb subsystem */
307static struct usb_driver dtt200u_usb_driver = { 329static struct usb_driver dtt200u_usb_driver = {
308 .name = "dvb_usb_dtt200u", 330 .name = "dvb_usb_dtt200u",
@@ -333,6 +355,6 @@ module_init(dtt200u_usb_module_init);
333module_exit(dtt200u_usb_module_exit); 355module_exit(dtt200u_usb_module_exit);
334 356
335MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>"); 357MODULE_AUTHOR("Patrick Boettcher <patrick.boettcher@desy.de>");
336MODULE_DESCRIPTION("Driver for the WideView/Yakumo/Hama/Typhoon/Club3D DVB-T USB2.0 devices"); 358MODULE_DESCRIPTION("Driver for the WideView/Yakumo/Hama/Typhoon/Club3D/Miglia DVB-T USB2.0 devices");
337MODULE_VERSION("1.0"); 359MODULE_VERSION("1.0");
338MODULE_LICENSE("GPL"); 360MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-ids.h b/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
index 4dfab02a8a0d..4fa3e895028a 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
@@ -12,7 +12,7 @@
12/* Vendor IDs */ 12/* Vendor IDs */
13#define USB_VID_ADSTECH 0x06e1 13#define USB_VID_ADSTECH 0x06e1
14#define USB_VID_AFATECH 0x15a4 14#define USB_VID_AFATECH 0x15a4
15#define USB_VID_ALCOR_MICRO 0x058f 15#define USB_VID_ALCOR_MICRO 0x058f
16#define USB_VID_ALINK 0x05e3 16#define USB_VID_ALINK 0x05e3
17#define USB_VID_ANCHOR 0x0547 17#define USB_VID_ANCHOR 0x0547
18#define USB_VID_ANUBIS_ELECTRONIC 0x10fd 18#define USB_VID_ANUBIS_ELECTRONIC 0x10fd
@@ -34,6 +34,7 @@
34#define USB_VID_LEADTEK 0x0413 34#define USB_VID_LEADTEK 0x0413
35#define USB_VID_LITEON 0x04ca 35#define USB_VID_LITEON 0x04ca
36#define USB_VID_MEDION 0x1660 36#define USB_VID_MEDION 0x1660
37#define USB_VID_MIGLIA 0x18f3
37#define USB_VID_MSI 0x0db0 38#define USB_VID_MSI 0x0db0
38#define USB_VID_OPERA1 0x695c 39#define USB_VID_OPERA1 0x695c
39#define USB_VID_PINNACLE 0x2304 40#define USB_VID_PINNACLE 0x2304
@@ -58,6 +59,7 @@
58#define USB_PID_COMPRO_DVBU2000_UNK_COLD 0x010c 59#define USB_PID_COMPRO_DVBU2000_UNK_COLD 0x010c
59#define USB_PID_COMPRO_DVBU2000_UNK_WARM 0x010d 60#define USB_PID_COMPRO_DVBU2000_UNK_WARM 0x010d
60#define USB_PID_COMPRO_VIDEOMATE_U500 0x1e78 61#define USB_PID_COMPRO_VIDEOMATE_U500 0x1e78
62#define USB_PID_COMPRO_VIDEOMATE_U500_PC 0x1e80
61#define USB_PID_DIBCOM_HOOK_DEFAULT 0x0064 63#define USB_PID_DIBCOM_HOOK_DEFAULT 0x0064
62#define USB_PID_DIBCOM_HOOK_DEFAULT_REENUM 0x0065 64#define USB_PID_DIBCOM_HOOK_DEFAULT_REENUM 0x0065
63#define USB_PID_DIBCOM_MOD3000_COLD 0x0bb8 65#define USB_PID_DIBCOM_MOD3000_COLD 0x0bb8
@@ -66,6 +68,9 @@
66#define USB_PID_DIBCOM_MOD3001_WARM 0x0bc7 68#define USB_PID_DIBCOM_MOD3001_WARM 0x0bc7
67#define USB_PID_DIBCOM_STK7700P 0x1e14 69#define USB_PID_DIBCOM_STK7700P 0x1e14
68#define USB_PID_DIBCOM_STK7700P_PC 0x1e78 70#define USB_PID_DIBCOM_STK7700P_PC 0x1e78
71#define USB_PID_DIBCOM_STK7700D 0x1ef0
72#define USB_PID_DIBCOM_STK7070P 0x1ebc
73#define USB_PID_DIBCOM_STK7070PD 0x1ebe
69#define USB_PID_DIBCOM_ANCHOR_2135_COLD 0x2131 74#define USB_PID_DIBCOM_ANCHOR_2135_COLD 0x2131
70#define USB_PID_DPOSH_M9206_COLD 0x9206 75#define USB_PID_DPOSH_M9206_COLD 0x9206
71#define USB_PID_DPOSH_M9206_WARM 0xa090 76#define USB_PID_DPOSH_M9206_WARM 0xa090
@@ -115,8 +120,17 @@
115#define USB_PID_HAUPPAUGE_NOVA_T_500_2 0x9950 120#define USB_PID_HAUPPAUGE_NOVA_T_500_2 0x9950
116#define USB_PID_HAUPPAUGE_NOVA_T_STICK 0x7050 121#define USB_PID_HAUPPAUGE_NOVA_T_STICK 0x7050
117#define USB_PID_HAUPPAUGE_NOVA_T_STICK_2 0x7060 122#define USB_PID_HAUPPAUGE_NOVA_T_STICK_2 0x7060
123#define USB_PID_HAUPPAUGE_NOVA_TD_STICK 0x9580
124#define USB_PID_AVERMEDIA_EXPRESS 0xb568
118#define USB_PID_AVERMEDIA_VOLAR 0xa807 125#define USB_PID_AVERMEDIA_VOLAR 0xa807
119#define USB_PID_AVERMEDIA_VOLAR_2 0xb808 126#define USB_PID_AVERMEDIA_VOLAR_2 0xb808
127#define USB_PID_TERRATEC_CINERGY_DT_XS_DIVERSITY 0x005a
128#define USB_PID_PINNACLE_PCTV2000E 0x022c
129#define USB_PID_PINNACLE_PCTV_DVB_T_FLASH 0x0228
130#define USB_PID_PINNACLE_PCTV_DUAL_DIVERSITY_DVB_T 0x0229
131#define USB_PID_PCTV_200E 0x020e
132#define USB_PID_PCTV_400E 0x020f
133#define USB_PID_PCTV_450E 0x0222
120#define USB_PID_NEBULA_DIGITV 0x0201 134#define USB_PID_NEBULA_DIGITV 0x0201
121#define USB_PID_DVICO_BLUEBIRD_LGDT 0xd820 135#define USB_PID_DVICO_BLUEBIRD_LGDT 0xd820
122#define USB_PID_DVICO_BLUEBIRD_LG064F_COLD 0xd500 136#define USB_PID_DVICO_BLUEBIRD_LG064F_COLD 0xd500
@@ -136,9 +150,6 @@
136#define USB_PID_MSI_MEGASKY580_55801 0x5581 150#define USB_PID_MSI_MEGASKY580_55801 0x5581
137#define USB_PID_KYE_DVB_T_COLD 0x701e 151#define USB_PID_KYE_DVB_T_COLD 0x701e
138#define USB_PID_KYE_DVB_T_WARM 0x701f 152#define USB_PID_KYE_DVB_T_WARM 0x701f
139#define USB_PID_PCTV_200E 0x020e
140#define USB_PID_PCTV_400E 0x020f
141#define USB_PID_PCTV_450E 0x0222
142#define USB_PID_LITEON_DVB_T_COLD 0xf000 153#define USB_PID_LITEON_DVB_T_COLD 0xf000
143#define USB_PID_LITEON_DVB_T_WARM 0xf001 154#define USB_PID_LITEON_DVB_T_WARM 0xf001
144#define USB_PID_DIGIVOX_MINI_SL_COLD 0xe360 155#define USB_PID_DIGIVOX_MINI_SL_COLD 0xe360
@@ -148,8 +159,11 @@
148#define USB_PID_WINFAST_DTV_DONGLE_COLD 0x6025 159#define USB_PID_WINFAST_DTV_DONGLE_COLD 0x6025
149#define USB_PID_WINFAST_DTV_DONGLE_WARM 0x6026 160#define USB_PID_WINFAST_DTV_DONGLE_WARM 0x6026
150#define USB_PID_WINFAST_DTV_DONGLE_STK7700P 0x6f00 161#define USB_PID_WINFAST_DTV_DONGLE_STK7700P 0x6f00
151#define USB_PID_GENPIX_8PSK_COLD 0x0200 162#define USB_PID_GENPIX_8PSK_REV_1_COLD 0x0200
152#define USB_PID_GENPIX_8PSK_WARM 0x0201 163#define USB_PID_GENPIX_8PSK_REV_1_WARM 0x0201
164#define USB_PID_GENPIX_8PSK_REV_2 0x0202
165#define USB_PID_GENPIX_SKYWALKER_1 0x0203
166#define USB_PID_GENPIX_SKYWALKER_CW3K 0x0204
153#define USB_PID_SIGMATEK_DVB_110 0x6610 167#define USB_PID_SIGMATEK_DVB_110 0x6610
154#define USB_PID_MSI_DIGI_VOX_MINI_II 0x1513 168#define USB_PID_MSI_DIGI_VOX_MINI_II 0x1513
155#define USB_PID_OPERA1_COLD 0x2830 169#define USB_PID_OPERA1_COLD 0x2830
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-init.c b/drivers/media/dvb/dvb-usb/dvb-usb-init.c
index ffdde83d1e77..cdd717c3fe45 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-init.c
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-init.c
@@ -24,7 +24,7 @@ MODULE_PARM_DESC(disable_rc_polling, "disable remote control polling (default: 0
24 24
25static int dvb_usb_force_pid_filter_usage; 25static 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(disable_rc_polling, "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)
30{ 30{
diff --git a/drivers/media/dvb/dvb-usb/gp8psk-fe.c b/drivers/media/dvb/dvb-usb/gp8psk-fe.c
index 6ccbdc9cd772..e37142d9271a 100644
--- a/drivers/media/dvb/dvb-usb/gp8psk-fe.c
+++ b/drivers/media/dvb/dvb-usb/gp8psk-fe.c
@@ -1,7 +1,8 @@
1/* DVB USB compliant Linux driver for the 1/* DVB USB compliant Linux driver for the
2 * - GENPIX 8pks/qpsk USB2.0 DVB-S module 2 * - GENPIX 8pks/qpsk/DCII USB2.0 DVB-S module
3 * 3 *
4 * Copyright (C) 2006 Alan Nisota (alannisota@gmail.com) 4 * Copyright (C) 2006,2007 Alan Nisota (alannisota@gmail.com)
5 * Copyright (C) 2006,2007 Genpix Electronics (genpix@genpix-electronics.com)
5 * 6 *
6 * Thanks to GENPIX for the sample code used to implement this module. 7 * Thanks to GENPIX for the sample code used to implement this module.
7 * 8 *
@@ -17,27 +18,39 @@
17 18
18struct gp8psk_fe_state { 19struct gp8psk_fe_state {
19 struct dvb_frontend fe; 20 struct dvb_frontend fe;
20
21 struct dvb_usb_device *d; 21 struct dvb_usb_device *d;
22 22 u8 lock;
23 u16 snr; 23 u16 snr;
24 24 unsigned long next_status_check;
25 unsigned long next_snr_check; 25 unsigned long status_check_interval;
26}; 26};
27 27
28static int gp8psk_fe_update_status(struct gp8psk_fe_state *st)
29{
30 u8 buf[6];
31 if (time_after(jiffies,st->next_status_check)) {
32 gp8psk_usb_in_op(st->d, GET_SIGNAL_LOCK, 0,0,&st->lock,1);
33 gp8psk_usb_in_op(st->d, GET_SIGNAL_STRENGTH, 0,0,buf,6);
34 st->snr = (buf[1]) << 8 | buf[0];
35 st->next_status_check = jiffies + (st->status_check_interval*HZ)/1000;
36 }
37 return 0;
38}
39
28static int gp8psk_fe_read_status(struct dvb_frontend* fe, fe_status_t *status) 40static int gp8psk_fe_read_status(struct dvb_frontend* fe, fe_status_t *status)
29{ 41{
30 struct gp8psk_fe_state *st = fe->demodulator_priv; 42 struct gp8psk_fe_state *st = fe->demodulator_priv;
31 u8 lock; 43 gp8psk_fe_update_status(st);
32 44
33 if (gp8psk_usb_in_op(st->d, GET_SIGNAL_LOCK, 0, 0, &lock,1)) 45 if (st->lock)
34 return -EINVAL;
35
36 if (lock)
37 *status = FE_HAS_LOCK | FE_HAS_SYNC | FE_HAS_VITERBI | FE_HAS_SIGNAL | FE_HAS_CARRIER; 46 *status = FE_HAS_LOCK | FE_HAS_SYNC | FE_HAS_VITERBI | FE_HAS_SIGNAL | FE_HAS_CARRIER;
38 else 47 else
39 *status = 0; 48 *status = 0;
40 49
50 if (*status & FE_HAS_LOCK)
51 st->status_check_interval = 1000;
52 else
53 st->status_check_interval = 100;
41 return 0; 54 return 0;
42} 55}
43 56
@@ -60,33 +73,29 @@ static int gp8psk_fe_read_unc_blocks(struct dvb_frontend* fe, u32 *unc)
60static int gp8psk_fe_read_snr(struct dvb_frontend* fe, u16 *snr) 73static int gp8psk_fe_read_snr(struct dvb_frontend* fe, u16 *snr)
61{ 74{
62 struct gp8psk_fe_state *st = fe->demodulator_priv; 75 struct gp8psk_fe_state *st = fe->demodulator_priv;
63 u8 buf[2]; 76 gp8psk_fe_update_status(st);
64 77 /* snr is reported in dBu*256 */
65 if (time_after(jiffies,st->next_snr_check)) { 78 *snr = st->snr;
66 gp8psk_usb_in_op(st->d,GET_SIGNAL_STRENGTH,0,0,buf,2);
67 *snr = (int)(buf[1]) << 8 | buf[0];
68 /* snr is reported in dBu*256 */
69 /* snr / 38.4 ~= 100% strength */
70 /* snr * 17 returns 100% strength as 65535 */
71 if (*snr <= 3855)
72 *snr = (*snr<<4) + *snr; // snr * 17
73 else
74 *snr = 65535;
75 st->next_snr_check = jiffies + (10*HZ)/1000;
76 } else {
77 *snr = st->snr;
78 }
79 return 0; 79 return 0;
80} 80}
81 81
82static int gp8psk_fe_read_signal_strength(struct dvb_frontend* fe, u16 *strength) 82static int gp8psk_fe_read_signal_strength(struct dvb_frontend* fe, u16 *strength)
83{ 83{
84 return gp8psk_fe_read_snr(fe, strength); 84 struct gp8psk_fe_state *st = fe->demodulator_priv;
85 gp8psk_fe_update_status(st);
86 /* snr is reported in dBu*256 */
87 /* snr / 38.4 ~= 100% strength */
88 /* snr * 17 returns 100% strength as 65535 */
89 if (st->snr > 0xf00)
90 *strength = 0xffff;
91 else
92 *strength = (st->snr << 4) + st->snr; /* snr*17 */
93 return 0;
85} 94}
86 95
87static int gp8psk_fe_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings *tune) 96static int gp8psk_fe_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings *tune)
88{ 97{
89 tune->min_delay_ms = 800; 98 tune->min_delay_ms = 200;
90 return 0; 99 return 0;
91} 100}
92 101
@@ -124,7 +133,9 @@ static int gp8psk_fe_set_frontend(struct dvb_frontend* fe,
124 133
125 gp8psk_usb_out_op(state->d,TUNE_8PSK,0,0,cmd,10); 134 gp8psk_usb_out_op(state->d,TUNE_8PSK,0,0,cmd,10);
126 135
127 state->next_snr_check = jiffies; 136 state->lock = 0;
137 state->next_status_check = jiffies;
138 state->status_check_interval = 200;
128 139
129 return 0; 140 return 0;
130} 141}
@@ -190,6 +201,12 @@ static int gp8psk_fe_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t volt
190 return 0; 201 return 0;
191} 202}
192 203
204static int gp8psk_fe_enable_high_lnb_voltage(struct dvb_frontend* fe, long onoff)
205{
206 struct gp8psk_fe_state* state = fe->demodulator_priv;
207 return gp8psk_usb_out_op(state->d, USE_EXTRA_VOLT, onoff, 0,NULL,0);
208}
209
193static int gp8psk_fe_send_legacy_dish_cmd (struct dvb_frontend* fe, unsigned long sw_cmd) 210static int gp8psk_fe_send_legacy_dish_cmd (struct dvb_frontend* fe, unsigned long sw_cmd)
194{ 211{
195 struct gp8psk_fe_state* state = fe->demodulator_priv; 212 struct gp8psk_fe_state* state = fe->demodulator_priv;
@@ -235,10 +252,10 @@ success:
235 252
236static struct dvb_frontend_ops gp8psk_fe_ops = { 253static struct dvb_frontend_ops gp8psk_fe_ops = {
237 .info = { 254 .info = {
238 .name = "Genpix 8psk-USB DVB-S", 255 .name = "Genpix 8psk-to-USB2 DVB-S",
239 .type = FE_QPSK, 256 .type = FE_QPSK,
240 .frequency_min = 950000, 257 .frequency_min = 800000,
241 .frequency_max = 2150000, 258 .frequency_max = 2250000,
242 .frequency_stepsize = 100, 259 .frequency_stepsize = 100,
243 .symbol_rate_min = 1000000, 260 .symbol_rate_min = 1000000,
244 .symbol_rate_max = 45000000, 261 .symbol_rate_max = 45000000,
@@ -269,4 +286,5 @@ static struct dvb_frontend_ops gp8psk_fe_ops = {
269 .set_tone = gp8psk_fe_set_tone, 286 .set_tone = gp8psk_fe_set_tone,
270 .set_voltage = gp8psk_fe_set_voltage, 287 .set_voltage = gp8psk_fe_set_voltage,
271 .dishnetwork_send_legacy_command = gp8psk_fe_send_legacy_dish_cmd, 288 .dishnetwork_send_legacy_command = gp8psk_fe_send_legacy_dish_cmd,
289 .enable_high_lnb_voltage = gp8psk_fe_enable_high_lnb_voltage
272}; 290};
diff --git a/drivers/media/dvb/dvb-usb/gp8psk.c b/drivers/media/dvb/dvb-usb/gp8psk.c
index 518d67fca5e8..92147ee3e14f 100644
--- a/drivers/media/dvb/dvb-usb/gp8psk.c
+++ b/drivers/media/dvb/dvb-usb/gp8psk.c
@@ -1,7 +1,8 @@
1/* DVB USB compliant Linux driver for the 1/* DVB USB compliant Linux driver for the
2 * - GENPIX 8pks/qpsk USB2.0 DVB-S module 2 * - GENPIX 8pks/qpsk/DCII USB2.0 DVB-S module
3 * 3 *
4 * Copyright (C) 2006 Alan Nisota (alannisota@gmail.com) 4 * Copyright (C) 2006,2007 Alan Nisota (alannisota@gmail.com)
5 * Copyright (C) 2006,2007 Genpix Electronics (genpix@genpix-electronics.com)
5 * 6 *
6 * Thanks to GENPIX for the sample code used to implement this module. 7 * Thanks to GENPIX for the sample code used to implement this module.
7 * 8 *
@@ -40,7 +41,7 @@ int gp8psk_usb_in_op(struct dvb_usb_device *d, u8 req, u16 value, u16 index, u8
40 } 41 }
41 42
42 if (ret < 0 || ret != blen) { 43 if (ret < 0 || ret != blen) {
43 warn("usb in operation failed."); 44 warn("usb in %d operation failed.", req);
44 ret = -EIO; 45 ret = -EIO;
45 } else 46 } else
46 ret = 0; 47 ret = 0;
@@ -97,10 +98,10 @@ static int gp8psk_load_bcm4500fw(struct dvb_usb_device *d)
97 if (gp8psk_usb_out_op(d, LOAD_BCM4500,1,0,NULL, 0)) 98 if (gp8psk_usb_out_op(d, LOAD_BCM4500,1,0,NULL, 0))
98 goto out_rel_fw; 99 goto out_rel_fw;
99 100
100 info("downloaidng bcm4500 firmware from file '%s'",bcm4500_firmware); 101 info("downloading bcm4500 firmware from file '%s'",bcm4500_firmware);
101 102
102 ptr = fw->data; 103 ptr = fw->data;
103 buf = kmalloc(512, GFP_KERNEL | GFP_DMA); 104 buf = kmalloc(64, GFP_KERNEL | GFP_DMA);
104 105
105 while (ptr[0] != 0xff) { 106 while (ptr[0] != 0xff) {
106 u16 buflen = ptr[0] + 4; 107 u16 buflen = ptr[0] + 4;
@@ -129,25 +130,34 @@ out_rel_fw:
129static int gp8psk_power_ctrl(struct dvb_usb_device *d, int onoff) 130static int gp8psk_power_ctrl(struct dvb_usb_device *d, int onoff)
130{ 131{
131 u8 status, buf; 132 u8 status, buf;
133 int gp_product_id = le16_to_cpu(d->udev->descriptor.idProduct);
134
132 if (onoff) { 135 if (onoff) {
133 gp8psk_usb_in_op(d, GET_8PSK_CONFIG,0,0,&status,1); 136 gp8psk_usb_in_op(d, GET_8PSK_CONFIG,0,0,&status,1);
134 if (! (status & 0x01)) /* started */ 137 if (! (status & bm8pskStarted)) { /* started */
138 if(gp_product_id == USB_PID_GENPIX_SKYWALKER_CW3K)
139 gp8psk_usb_out_op(d, CW3K_INIT, 1, 0, NULL, 0);
135 if (gp8psk_usb_in_op(d, BOOT_8PSK, 1, 0, &buf, 1)) 140 if (gp8psk_usb_in_op(d, BOOT_8PSK, 1, 0, &buf, 1))
136 return -EINVAL; 141 return -EINVAL;
142 }
137 143
138 if (! (status & 0x02)) /* BCM4500 firmware loaded */ 144 if (gp_product_id == USB_PID_GENPIX_8PSK_REV_1_WARM)
139 if(gp8psk_load_bcm4500fw(d)) 145 if (! (status & bm8pskFW_Loaded)) /* BCM4500 firmware loaded */
140 return EINVAL; 146 if(gp8psk_load_bcm4500fw(d))
147 return EINVAL;
141 148
142 if (! (status & 0x04)) /* LNB Power */ 149 if (! (status & bmIntersilOn)) /* LNB Power */
143 if (gp8psk_usb_in_op(d, START_INTERSIL, 1, 0, 150 if (gp8psk_usb_in_op(d, START_INTERSIL, 1, 0,
144 &buf, 1)) 151 &buf, 1))
145 return EINVAL; 152 return EINVAL;
146 153
147 /* Set DVB mode */ 154 /* Set DVB mode to 1 */
148 if(gp8psk_usb_out_op(d, SET_DVB_MODE, 1, 0, NULL, 0)) 155 if (gp_product_id == USB_PID_GENPIX_8PSK_REV_1_WARM)
149 return -EINVAL; 156 if (gp8psk_usb_out_op(d, SET_DVB_MODE, 1, 0, NULL, 0))
150 gp8psk_usb_in_op(d, GET_8PSK_CONFIG,0,0,&status,1); 157 return EINVAL;
158 /* Abort possible TS (if previous tune crashed) */
159 if (gp8psk_usb_out_op(d, ARM_TRANSFER, 0, 0, NULL, 0))
160 return EINVAL;
151 } else { 161 } else {
152 /* Turn off LNB power */ 162 /* Turn off LNB power */
153 if (gp8psk_usb_in_op(d, START_INTERSIL, 0, 0, &buf, 1)) 163 if (gp8psk_usb_in_op(d, START_INTERSIL, 0, 0, &buf, 1))
@@ -155,11 +165,28 @@ static int gp8psk_power_ctrl(struct dvb_usb_device *d, int onoff)
155 /* Turn off 8psk power */ 165 /* Turn off 8psk power */
156 if (gp8psk_usb_in_op(d, BOOT_8PSK, 0, 0, &buf, 1)) 166 if (gp8psk_usb_in_op(d, BOOT_8PSK, 0, 0, &buf, 1))
157 return -EINVAL; 167 return -EINVAL;
158 168 if(gp_product_id == USB_PID_GENPIX_SKYWALKER_CW3K)
169 gp8psk_usb_out_op(d, CW3K_INIT, 0, 0, NULL, 0);
159 } 170 }
160 return 0; 171 return 0;
161} 172}
162 173
174int gp8psk_bcm4500_reload(struct dvb_usb_device *d)
175{
176 u8 buf;
177 int gp_product_id = le16_to_cpu(d->udev->descriptor.idProduct);
178 /* Turn off 8psk power */
179 if (gp8psk_usb_in_op(d, BOOT_8PSK, 0, 0, &buf, 1))
180 return -EINVAL;
181 /* Turn On 8psk power */
182 if (gp8psk_usb_in_op(d, BOOT_8PSK, 1, 0, &buf, 1))
183 return -EINVAL;
184 /* load BCM4500 firmware */
185 if (gp_product_id == USB_PID_GENPIX_8PSK_REV_1_WARM)
186 if (gp8psk_load_bcm4500fw(d))
187 return EINVAL;
188 return 0;
189}
163 190
164static int gp8psk_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff) 191static int gp8psk_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
165{ 192{
@@ -177,12 +204,22 @@ static struct dvb_usb_device_properties gp8psk_properties;
177static int gp8psk_usb_probe(struct usb_interface *intf, 204static int gp8psk_usb_probe(struct usb_interface *intf,
178 const struct usb_device_id *id) 205 const struct usb_device_id *id)
179{ 206{
180 return dvb_usb_device_init(intf,&gp8psk_properties,THIS_MODULE,NULL); 207 int ret;
208 struct usb_device *udev = interface_to_usbdev(intf);
209 ret = dvb_usb_device_init(intf,&gp8psk_properties,THIS_MODULE,NULL);
210 if (ret == 0) {
211 info("found Genpix USB device pID = %x (hex)",
212 le16_to_cpu(udev->descriptor.idProduct));
213 }
214 return ret;
181} 215}
182 216
183static struct usb_device_id gp8psk_usb_table [] = { 217static struct usb_device_id gp8psk_usb_table [] = {
184 { USB_DEVICE(USB_VID_GENPIX, USB_PID_GENPIX_8PSK_COLD) }, 218 { USB_DEVICE(USB_VID_GENPIX, USB_PID_GENPIX_8PSK_REV_1_COLD) },
185 { USB_DEVICE(USB_VID_GENPIX, USB_PID_GENPIX_8PSK_WARM) }, 219 { USB_DEVICE(USB_VID_GENPIX, USB_PID_GENPIX_8PSK_REV_1_WARM) },
220 { USB_DEVICE(USB_VID_GENPIX, USB_PID_GENPIX_8PSK_REV_2) },
221 { USB_DEVICE(USB_VID_GENPIX, USB_PID_GENPIX_SKYWALKER_1) },
222 { USB_DEVICE(USB_VID_GENPIX, USB_PID_GENPIX_SKYWALKER_CW3K) },
186 { 0 }, 223 { 0 },
187}; 224};
188MODULE_DEVICE_TABLE(usb, gp8psk_usb_table); 225MODULE_DEVICE_TABLE(usb, gp8psk_usb_table);
@@ -213,12 +250,24 @@ static struct dvb_usb_device_properties gp8psk_properties = {
213 250
214 .generic_bulk_ctrl_endpoint = 0x01, 251 .generic_bulk_ctrl_endpoint = 0x01,
215 252
216 .num_device_descs = 1, 253 .num_device_descs = 4,
217 .devices = { 254 .devices = {
218 { .name = "Genpix 8PSK-USB DVB-S USB2.0 receiver", 255 { .name = "Genpix 8PSK-to-USB2 Rev.1 DVB-S receiver",
219 .cold_ids = { &gp8psk_usb_table[0], NULL }, 256 .cold_ids = { &gp8psk_usb_table[0], NULL },
220 .warm_ids = { &gp8psk_usb_table[1], NULL }, 257 .warm_ids = { &gp8psk_usb_table[1], NULL },
221 }, 258 },
259 { .name = "Genpix 8PSK-to-USB2 Rev.2 DVB-S receiver",
260 .cold_ids = { NULL },
261 .warm_ids = { &gp8psk_usb_table[2], NULL },
262 },
263 { .name = "Genpix SkyWalker-1 DVB-S receiver",
264 .cold_ids = { NULL },
265 .warm_ids = { &gp8psk_usb_table[3], NULL },
266 },
267 { .name = "Genpix SkyWalker-CW3K DVB-S receiver",
268 .cold_ids = { NULL },
269 .warm_ids = { &gp8psk_usb_table[4], NULL },
270 },
222 { NULL }, 271 { NULL },
223 } 272 }
224}; 273};
@@ -253,6 +302,6 @@ module_init(gp8psk_usb_module_init);
253module_exit(gp8psk_usb_module_exit); 302module_exit(gp8psk_usb_module_exit);
254 303
255MODULE_AUTHOR("Alan Nisota <alannisota@gamil.com>"); 304MODULE_AUTHOR("Alan Nisota <alannisota@gamil.com>");
256MODULE_DESCRIPTION("Driver for Genpix 8psk-USB DVB-S USB2.0"); 305MODULE_DESCRIPTION("Driver for Genpix 8psk-to-USB2 DVB-S");
257MODULE_VERSION("1.0"); 306MODULE_VERSION("1.1");
258MODULE_LICENSE("GPL"); 307MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/dvb-usb/gp8psk.h b/drivers/media/dvb/dvb-usb/gp8psk.h
index 3eba7061011c..e83a57506cfa 100644
--- a/drivers/media/dvb/dvb-usb/gp8psk.h
+++ b/drivers/media/dvb/dvb-usb/gp8psk.h
@@ -1,7 +1,8 @@
1/* DVB USB compliant Linux driver for the 1/* DVB USB compliant Linux driver for the
2 * - GENPIX 8pks/qpsk USB2.0 DVB-S module 2 * - GENPIX 8pks/qpsk/DCII USB2.0 DVB-S module
3 * 3 *
4 * Copyright (C) 2006 Alan Nisota (alannisota@gmail.com) 4 * Copyright (C) 2006 Alan Nisota (alannisota@gmail.com)
5 * Copyright (C) 2006,2007 Alan Nisota (alannisota@gmail.com)
5 * 6 *
6 * Thanks to GENPIX for the sample code used to implement this module. 7 * Thanks to GENPIX for the sample code used to implement this module.
7 * 8 *
@@ -30,21 +31,37 @@ extern int dvb_usb_gp8psk_debug;
30#define TH_COMMAND_IN 0xC0 31#define TH_COMMAND_IN 0xC0
31#define TH_COMMAND_OUT 0xC1 32#define TH_COMMAND_OUT 0xC1
32 33
33/* command bytes */ 34/* gp8psk commands */
34#define GET_8PSK_CONFIG 0x80 35
36#define GET_8PSK_CONFIG 0x80 /* in */
35#define SET_8PSK_CONFIG 0x81 37#define SET_8PSK_CONFIG 0x81
38#define I2C_WRITE 0x83
39#define I2C_READ 0x84
36#define ARM_TRANSFER 0x85 40#define ARM_TRANSFER 0x85
37#define TUNE_8PSK 0x86 41#define TUNE_8PSK 0x86
38#define GET_SIGNAL_STRENGTH 0x87 42#define GET_SIGNAL_STRENGTH 0x87 /* in */
39#define LOAD_BCM4500 0x88 43#define LOAD_BCM4500 0x88
40#define BOOT_8PSK 0x89 44#define BOOT_8PSK 0x89 /* in */
41#define START_INTERSIL 0x8A 45#define START_INTERSIL 0x8A /* in */
42#define SET_LNB_VOLTAGE 0x8B 46#define SET_LNB_VOLTAGE 0x8B
43#define SET_22KHZ_TONE 0x8C 47#define SET_22KHZ_TONE 0x8C
44#define SEND_DISEQC_COMMAND 0x8D 48#define SEND_DISEQC_COMMAND 0x8D
45#define SET_DVB_MODE 0x8E 49#define SET_DVB_MODE 0x8E
46#define SET_DN_SWITCH 0x8F 50#define SET_DN_SWITCH 0x8F
47#define GET_SIGNAL_LOCK 0x90 51#define GET_SIGNAL_LOCK 0x90 /* in */
52#define GET_SERIAL_NUMBER 0x93 /* in */
53#define USE_EXTRA_VOLT 0x94
54#define CW3K_INIT 0x9d
55
56/* PSK_configuration bits */
57#define bm8pskStarted 0x01
58#define bm8pskFW_Loaded 0x02
59#define bmIntersilOn 0x04
60#define bmDVBmode 0x08
61#define bm22kHz 0x10
62#define bmSEL18V 0x20
63#define bmDCtuned 0x40
64#define bmArmed 0x80
48 65
49/* Satellite modulation modes */ 66/* Satellite modulation modes */
50#define ADV_MOD_DVB_QPSK 0 /* DVB-S QPSK */ 67#define ADV_MOD_DVB_QPSK 0 /* DVB-S QPSK */
@@ -75,5 +92,6 @@ extern struct dvb_frontend * gp8psk_fe_attach(struct dvb_usb_device *d);
75extern int gp8psk_usb_in_op(struct dvb_usb_device *d, u8 req, u16 value, u16 index, u8 *b, int blen); 92extern int gp8psk_usb_in_op(struct dvb_usb_device *d, u8 req, u16 value, u16 index, u8 *b, int blen);
76extern int gp8psk_usb_out_op(struct dvb_usb_device *d, u8 req, u16 value, 93extern int gp8psk_usb_out_op(struct dvb_usb_device *d, u8 req, u16 value,
77 u16 index, u8 *b, int blen); 94 u16 index, u8 *b, int blen);
95extern int gp8psk_bcm4500_reload(struct dvb_usb_device *d);
78 96
79#endif 97#endif
diff --git a/drivers/media/dvb/dvb-usb/vp7045.c b/drivers/media/dvb/dvb-usb/vp7045.c
index 69a46b3607a2..5bbd2d5192f0 100644
--- a/drivers/media/dvb/dvb-usb/vp7045.c
+++ b/drivers/media/dvb/dvb-usb/vp7045.c
@@ -159,7 +159,7 @@ static int vp7045_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
159 return 0; 159 return 0;
160 } 160 }
161 161
162 for (i = 0; i < sizeof(vp7045_rc_keys)/sizeof(struct dvb_usb_rc_key); i++) 162 for (i = 0; i < ARRAY_SIZE(vp7045_rc_keys); i++)
163 if (vp7045_rc_keys[i].data == key) { 163 if (vp7045_rc_keys[i].data == key) {
164 *state = REMOTE_KEY_PRESSED; 164 *state = REMOTE_KEY_PRESSED;
165 *event = vp7045_rc_keys[i].event; 165 *event = vp7045_rc_keys[i].event;
diff --git a/drivers/media/dvb/frontends/Kconfig b/drivers/media/dvb/frontends/Kconfig
index ff448761dcef..59b9ed1f1aec 100644
--- a/drivers/media/dvb/frontends/Kconfig
+++ b/drivers/media/dvb/frontends/Kconfig
@@ -283,6 +283,14 @@ config DVB_LGDT330X
283 An ATSC 8VSB and QAM64/256 tuner module. Say Y when you want 283 An ATSC 8VSB and QAM64/256 tuner module. Say Y when you want
284 to support this frontend. 284 to support this frontend.
285 285
286config DVB_S5H1409
287 tristate "Samsung S5H1409 based"
288 depends on DVB_CORE && I2C
289 default m if DVB_FE_CUSTOMISE
290 help
291 An ATSC 8VSB and QAM64/256 tuner module. Say Y when you want
292 to support this frontend.
293
286comment "Tuners/PLL support" 294comment "Tuners/PLL support"
287 depends on DVB_CORE 295 depends on DVB_CORE
288 296
@@ -291,7 +299,7 @@ config DVB_PLL
291 depends on DVB_CORE && I2C 299 depends on DVB_CORE && I2C
292 default m if DVB_FE_CUSTOMISE 300 default m if DVB_FE_CUSTOMISE
293 help 301 help
294 This module driver a number of tuners based on PLL chips with a 302 This module drives a number of tuners based on PLL chips with a
295 common I2C interface. Say Y when you want to support these tuners. 303 common I2C interface. Say Y when you want to support these tuners.
296 304
297config DVB_TDA826X 305config DVB_TDA826X
@@ -322,6 +330,29 @@ config DVB_TUNER_MT2060
322 help 330 help
323 A driver for the silicon IF tuner MT2060 from Microtune. 331 A driver for the silicon IF tuner MT2060 from Microtune.
324 332
333config DVB_TUNER_MT2266
334 tristate "Microtune MT2266 silicon tuner"
335 depends on I2C
336 default m if DVB_FE_CUSTOMISE
337 help
338 A driver for the silicon baseband tuner MT2266 from Microtune.
339
340config DVB_TUNER_MT2131
341 tristate "Microtune MT2131 silicon tuner"
342 depends on I2C
343 default m if DVB_FE_CUSTOMISE
344 help
345 A driver for the silicon baseband tuner MT2131 from Microtune.
346
347config DVB_TUNER_DIB0070
348 tristate "DiBcom DiB0070 silicon base-band tuner"
349 depends on I2C
350 default m if DVB_FE_CUSTOMISE
351 help
352 A driver for the silicon baseband tuner DiB0070 from DiBcom.
353 This device is only used inside a SiP called togther with a
354 demodulator for now.
355
325comment "Miscellaneous devices" 356comment "Miscellaneous devices"
326 depends on DVB_CORE 357 depends on DVB_CORE
327 358
diff --git a/drivers/media/dvb/frontends/Makefile b/drivers/media/dvb/frontends/Makefile
index 156b062e02c4..4b8ad1f132aa 100644
--- a/drivers/media/dvb/frontends/Makefile
+++ b/drivers/media/dvb/frontends/Makefile
@@ -40,5 +40,9 @@ obj-$(CONFIG_DVB_TDA10086) += tda10086.o
40obj-$(CONFIG_DVB_TDA826X) += tda826x.o 40obj-$(CONFIG_DVB_TDA826X) += tda826x.o
41obj-$(CONFIG_DVB_TDA827X) += tda827x.o 41obj-$(CONFIG_DVB_TDA827X) += tda827x.o
42obj-$(CONFIG_DVB_TUNER_MT2060) += mt2060.o 42obj-$(CONFIG_DVB_TUNER_MT2060) += mt2060.o
43obj-$(CONFIG_DVB_TUNER_MT2266) += mt2266.o
44obj-$(CONFIG_DVB_TUNER_DIB0070) += dib0070.o
43obj-$(CONFIG_DVB_TUNER_QT1010) += qt1010.o 45obj-$(CONFIG_DVB_TUNER_QT1010) += qt1010.o
44obj-$(CONFIG_DVB_TUA6100) += tua6100.o 46obj-$(CONFIG_DVB_TUA6100) += tua6100.o
47obj-$(CONFIG_DVB_TUNER_MT2131) += mt2131.o
48obj-$(CONFIG_DVB_S5H1409) += s5h1409.o
diff --git a/drivers/media/dvb/frontends/bcm3510.c b/drivers/media/dvb/frontends/bcm3510.c
index baeb311de893..a913f49c062b 100644
--- a/drivers/media/dvb/frontends/bcm3510.c
+++ b/drivers/media/dvb/frontends/bcm3510.c
@@ -33,7 +33,6 @@
33 33
34#include <linux/init.h> 34#include <linux/init.h>
35#include <linux/module.h> 35#include <linux/module.h>
36#include <linux/moduleparam.h>
37#include <linux/device.h> 36#include <linux/device.h>
38#include <linux/firmware.h> 37#include <linux/firmware.h>
39#include <linux/jiffies.h> 38#include <linux/jiffies.h>
diff --git a/drivers/media/dvb/frontends/cx22700.c b/drivers/media/dvb/frontends/cx22700.c
index 13ad1bfae663..11a4968f18cb 100644
--- a/drivers/media/dvb/frontends/cx22700.c
+++ b/drivers/media/dvb/frontends/cx22700.c
@@ -23,7 +23,6 @@
23#include <linux/kernel.h> 23#include <linux/kernel.h>
24#include <linux/init.h> 24#include <linux/init.h>
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/moduleparam.h>
27#include <linux/string.h> 26#include <linux/string.h>
28#include <linux/slab.h> 27#include <linux/slab.h>
29#include "dvb_frontend.h" 28#include "dvb_frontend.h"
diff --git a/drivers/media/dvb/frontends/cx24110.c b/drivers/media/dvb/frontends/cx24110.c
index 10fc0c8316dd..b03d8283c37d 100644
--- a/drivers/media/dvb/frontends/cx24110.c
+++ b/drivers/media/dvb/frontends/cx24110.c
@@ -25,7 +25,6 @@
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/kernel.h> 26#include <linux/kernel.h>
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/moduleparam.h>
29#include <linux/init.h> 28#include <linux/init.h>
30 29
31#include "dvb_frontend.h" 30#include "dvb_frontend.h"
diff --git a/drivers/media/dvb/frontends/cx24123.c b/drivers/media/dvb/frontends/cx24123.c
index 0834c0677fef..d74fdbd63361 100644
--- a/drivers/media/dvb/frontends/cx24123.c
+++ b/drivers/media/dvb/frontends/cx24123.c
@@ -23,7 +23,6 @@
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/kernel.h> 24#include <linux/kernel.h>
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/moduleparam.h>
27#include <linux/init.h> 26#include <linux/init.h>
28 27
29#include "dvb_frontend.h" 28#include "dvb_frontend.h"
diff --git a/drivers/media/dvb/frontends/dib0070.c b/drivers/media/dvb/frontends/dib0070.c
new file mode 100644
index 000000000000..481eaa684157
--- /dev/null
+++ b/drivers/media/dvb/frontends/dib0070.c
@@ -0,0 +1,580 @@
1/*
2 * Linux-DVB Driver for DiBcom's DiB0070 base-band RF Tuner.
3 *
4 * Copyright (C) 2005-7 DiBcom (http://www.dibcom.fr/)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, version 2.
9 */
10#include <linux/kernel.h>
11#include <linux/i2c.h>
12
13#include "dvb_frontend.h"
14
15#include "dib0070.h"
16#include "dibx000_common.h"
17
18static int debug;
19module_param(debug, int, 0644);
20MODULE_PARM_DESC(debug, "turn on debugging (default: 0)");
21
22#define dprintk(args...) do { if (debug) { printk(KERN_DEBUG "DiB0070: "); printk(args); printk("\n"); } } while (0)
23
24#define DIB0070_P1D 0x00
25#define DIB0070_P1F 0x01
26#define DIB0070_P1G 0x03
27#define DIB0070S_P1A 0x02
28
29struct dib0070_state {
30 struct i2c_adapter *i2c;
31 struct dvb_frontend *fe;
32 const struct dib0070_config *cfg;
33 u16 wbd_ff_offset;
34 u8 revision;
35};
36
37static uint16_t dib0070_read_reg(struct dib0070_state *state, u8 reg)
38{
39 u8 b[2];
40 struct i2c_msg msg[2] = {
41 { .addr = state->cfg->i2c_address, .flags = 0, .buf = &reg, .len = 1 },
42 { .addr = state->cfg->i2c_address, .flags = I2C_M_RD, .buf = b, .len = 2 },
43 };
44 if (i2c_transfer(state->i2c, msg, 2) != 2) {
45 printk(KERN_WARNING "DiB0070 I2C read failed\n");
46 return 0;
47 }
48 return (b[0] << 8) | b[1];
49}
50
51static int dib0070_write_reg(struct dib0070_state *state, u8 reg, u16 val)
52{
53 u8 b[3] = { reg, val >> 8, val & 0xff };
54 struct i2c_msg msg = { .addr = state->cfg->i2c_address, .flags = 0, .buf = b, .len = 3 };
55 if (i2c_transfer(state->i2c, &msg, 1) != 1) {
56 printk(KERN_WARNING "DiB0070 I2C write failed\n");
57 return -EREMOTEIO;
58 }
59 return 0;
60}
61
62#define HARD_RESET(state) do { if (state->cfg->reset) { state->cfg->reset(state->fe,1); msleep(10); state->cfg->reset(state->fe,0); msleep(10); } } while (0)
63
64static int dib0070_set_bandwidth(struct dvb_frontend *fe, struct dvb_frontend_parameters *ch)
65{
66 struct dib0070_state *st = fe->tuner_priv;
67 u16 tmp = 0;
68 tmp = dib0070_read_reg(st, 0x02) & 0x3fff;
69
70 switch(BANDWIDTH_TO_KHZ(ch->u.ofdm.bandwidth)) {
71 case 8000:
72 tmp |= (0 << 14);
73 break;
74 case 7000:
75 tmp |= (1 << 14);
76 break;
77 case 6000:
78 tmp |= (2 << 14);
79 break;
80 case 5000:
81 default:
82 tmp |= (3 << 14);
83 break;
84 }
85 dib0070_write_reg(st, 0x02, tmp);
86 return 0;
87}
88
89static void dib0070_captrim(struct dib0070_state *st, u16 LO4)
90{
91 int8_t captrim, fcaptrim, step_sign, step;
92 u16 adc, adc_diff = 3000;
93
94
95
96 dib0070_write_reg(st, 0x0f, 0xed10);
97 dib0070_write_reg(st, 0x17, 0x0034);
98
99 dib0070_write_reg(st, 0x18, 0x0032);
100 msleep(2);
101
102 step = captrim = fcaptrim = 64;
103
104 do {
105 step /= 2;
106 dib0070_write_reg(st, 0x14, LO4 | captrim);
107 msleep(1);
108 adc = dib0070_read_reg(st, 0x19);
109
110 dprintk( "CAPTRIM=%hd; ADC = %hd (ADC) & %dmV", captrim, adc, (u32) adc*(u32)1800/(u32)1024);
111
112 if (adc >= 400) {
113 adc -= 400;
114 step_sign = -1;
115 } else {
116 adc = 400 - adc;
117 step_sign = 1;
118 }
119
120 if (adc < adc_diff) {
121 dprintk( "CAPTRIM=%hd is closer to target (%hd/%hd)", captrim, adc, adc_diff);
122 adc_diff = adc;
123 fcaptrim = captrim;
124
125
126
127 }
128 captrim += (step_sign * step);
129 } while (step >= 1);
130
131 dib0070_write_reg(st, 0x14, LO4 | fcaptrim);
132 dib0070_write_reg(st, 0x18, 0x07ff);
133}
134
135#define LPF 100 // define for the loop filter 100kHz by default 16-07-06
136#define LO4_SET_VCO_HFDIV(l, v, h) l |= ((v) << 11) | ((h) << 7)
137#define LO4_SET_SD(l, s) l |= ((s) << 14) | ((s) << 12)
138#define LO4_SET_CTRIM(l, c) l |= (c) << 10
139static int dib0070_tune_digital(struct dvb_frontend *fe, struct dvb_frontend_parameters *ch)
140{
141 struct dib0070_state *st = fe->tuner_priv;
142 u32 freq = ch->frequency/1000 + (BAND_OF_FREQUENCY(ch->frequency/1000) == BAND_VHF ? st->cfg->freq_offset_khz_vhf : st->cfg->freq_offset_khz_uhf);
143
144 u8 band = BAND_OF_FREQUENCY(freq), c;
145
146 /*******************VCO***********************************/
147 u16 lo4 = 0;
148
149 u8 REFDIV, PRESC = 2;
150 u32 FBDiv, Rest, FREF, VCOF_kHz;
151 u16 Num, Den;
152 /*******************FrontEnd******************************/
153 u16 value = 0;
154
155 dprintk( "Tuning for Band: %hd (%d kHz)", band, freq);
156
157
158 dib0070_write_reg(st, 0x17, 0x30);
159
160 dib0070_set_bandwidth(fe, ch); /* c is used as HF */
161 switch (st->revision) {
162 case DIB0070S_P1A:
163 switch (band) {
164 case BAND_LBAND:
165 LO4_SET_VCO_HFDIV(lo4, 1, 1);
166 c = 2;
167 break;
168 case BAND_SBAND:
169 LO4_SET_VCO_HFDIV(lo4, 0, 0);
170 LO4_SET_CTRIM(lo4, 1);;
171 c = 1;
172 break;
173 case BAND_UHF:
174 default:
175 if (freq < 570000) {
176 LO4_SET_VCO_HFDIV(lo4, 1, 3);
177 PRESC = 6; c = 6;
178 } else if (freq < 680000) {
179 LO4_SET_VCO_HFDIV(lo4, 0, 2);
180 c = 4;
181 } else {
182 LO4_SET_VCO_HFDIV(lo4, 1, 2);
183 c = 4;
184 }
185 break;
186 } break;
187
188 case DIB0070_P1G:
189 case DIB0070_P1F:
190 default:
191 switch (band) {
192 case BAND_FM:
193 LO4_SET_VCO_HFDIV(lo4, 0, 7);
194 c = 24;
195 break;
196 case BAND_LBAND:
197 LO4_SET_VCO_HFDIV(lo4, 1, 0);
198 c = 2;
199 break;
200 case BAND_VHF:
201 if (freq < 180000) {
202 LO4_SET_VCO_HFDIV(lo4, 0, 3);
203 c = 16;
204 } else if (freq < 190000) {
205 LO4_SET_VCO_HFDIV(lo4, 1, 3);
206 c = 16;
207 } else {
208 LO4_SET_VCO_HFDIV(lo4, 0, 6);
209 c = 12;
210 }
211 break;
212
213 case BAND_UHF:
214 default:
215 if (freq < 570000) {
216 LO4_SET_VCO_HFDIV(lo4, 1, 5);
217 c = 6;
218 } else if (freq < 700000) {
219 LO4_SET_VCO_HFDIV(lo4, 0, 1);
220 c = 4;
221 } else {
222 LO4_SET_VCO_HFDIV(lo4, 1, 1);
223 c = 4;
224 }
225 break;
226 }
227 break;
228 }
229
230 dprintk( "HFDIV code: %hd", (lo4 >> 7) & 0xf);
231 dprintk( "VCO = %hd", (lo4 >> 11) & 0x3);
232
233
234 VCOF_kHz = (c * freq) * 2;
235 dprintk( "VCOF in kHz: %d ((%hd*%d) << 1))",VCOF_kHz, c, freq);
236
237 switch (band) {
238 case BAND_VHF:
239 REFDIV = (u8) ((st->cfg->clock_khz + 9999) / 10000);
240 break;
241 case BAND_FM:
242 REFDIV = (u8) ((st->cfg->clock_khz) / 1000);
243 break;
244 default:
245 REFDIV = (u8) ( st->cfg->clock_khz / 10000);
246 break;
247 }
248 FREF = st->cfg->clock_khz / REFDIV;
249
250 dprintk( "REFDIV: %hd, FREF: %d", REFDIV, FREF);
251
252
253
254 switch (st->revision) {
255 case DIB0070S_P1A:
256 FBDiv = (VCOF_kHz / PRESC / FREF);
257 Rest = (VCOF_kHz / PRESC) - FBDiv * FREF;
258 break;
259
260 case DIB0070_P1G:
261 case DIB0070_P1F:
262 default:
263 FBDiv = (freq / (FREF / 2));
264 Rest = 2 * freq - FBDiv * FREF;
265 break;
266 }
267
268
269 if (Rest < LPF) Rest = 0;
270 else if (Rest < 2 * LPF) Rest = 2 * LPF;
271 else if (Rest > (FREF - LPF)) { Rest = 0 ; FBDiv += 1; }
272 else if (Rest > (FREF - 2 * LPF)) Rest = FREF - 2 * LPF;
273 Rest = (Rest * 6528) / (FREF / 10);
274 dprintk( "FBDIV: %d, Rest: %d", FBDiv, Rest);
275
276 Num = 0;
277 Den = 1;
278
279 if (Rest > 0) {
280 LO4_SET_SD(lo4, 1);
281 Den = 255;
282 Num = (u16)Rest;
283 }
284 dprintk( "Num: %hd, Den: %hd, SD: %hd",Num, Den, (lo4 >> 12) & 0x1);
285
286
287
288 dib0070_write_reg(st, 0x11, (u16)FBDiv);
289
290
291 dib0070_write_reg(st, 0x12, (Den << 8) | REFDIV);
292
293
294 dib0070_write_reg(st, 0x13, Num);
295
296
297 value = 0x0040 | 0x0020 | 0x0010 | 0x0008 | 0x0002 | 0x0001;
298
299 switch (band) {
300 case BAND_UHF: value |= 0x4000 | 0x0800; break;
301 case BAND_LBAND: value |= 0x2000 | 0x0400; break;
302 default: value |= 0x8000 | 0x1000; break;
303 }
304 dib0070_write_reg(st, 0x20, value);
305
306 dib0070_captrim(st, lo4);
307 if (st->revision == DIB0070S_P1A) {
308 if (band == BAND_SBAND)
309 dib0070_write_reg(st, 0x15, 0x16e2);
310 else
311 dib0070_write_reg(st, 0x15, 0x56e5);
312 }
313
314
315
316 switch (band) {
317 case BAND_UHF: value = 0x7c82; break;
318 case BAND_LBAND: value = 0x7c84; break;
319 default: value = 0x7c81; break;
320 }
321 dib0070_write_reg(st, 0x0f, value);
322 dib0070_write_reg(st, 0x06, 0x3fff);
323
324 /* Front End */
325 /* c == TUNE, value = SWITCH */
326 c = 0;
327 value = 0;
328 switch (band) {
329 case BAND_FM:
330 c = 0; value = 1;
331 break;
332
333 case BAND_VHF:
334 if (freq <= 180000) c = 0;
335 else if (freq <= 188200) c = 1;
336 else if (freq <= 196400) c = 2;
337 else c = 3;
338 value = 1;
339 break;
340
341 case BAND_LBAND:
342 if (freq <= 1500000) c = 0;
343 else if (freq <= 1600000) c = 1;
344 else c = 3;
345 break;
346
347 case BAND_SBAND:
348 c = 7;
349 dib0070_write_reg(st, 0x1d,0xFFFF);
350 break;
351
352 case BAND_UHF:
353 default:
354 if (st->cfg->flip_chip) {
355 if (freq <= 550000) c = 0;
356 else if (freq <= 590000) c = 1;
357 else if (freq <= 666000) c = 3;
358 else c = 5;
359 } else {
360 if (freq <= 550000) c = 2;
361 else if (freq <= 650000) c = 3;
362 else if (freq <= 750000) c = 5;
363 else if (freq <= 850000) c = 6;
364 else c = 7;
365 }
366 value = 2;
367 break;
368 }
369
370 /* default: LNA_MATCH=7, BIAS=3 */
371 dib0070_write_reg(st, 0x07, (value << 11) | (7 << 8) | (c << 3) | (3 << 0));
372 dib0070_write_reg(st, 0x08, (c << 10) | (3 << 7) | (127));
373 dib0070_write_reg(st, 0x0d, 0x0d80);
374
375
376 dib0070_write_reg(st, 0x18, 0x07ff);
377 dib0070_write_reg(st, 0x17, 0x0033);
378
379 return 0;
380}
381
382static int dib0070_wakeup(struct dvb_frontend *fe)
383{
384 struct dib0070_state *st = fe->tuner_priv;
385 if (st->cfg->sleep)
386 st->cfg->sleep(fe, 0);
387 return 0;
388}
389
390static int dib0070_sleep(struct dvb_frontend *fe)
391{
392 struct dib0070_state *st = fe->tuner_priv;
393 if (st->cfg->sleep)
394 st->cfg->sleep(fe, 1);
395 return 0;
396}
397
398static u16 dib0070_p1f_defaults[] =
399
400{
401 7, 0x02,
402 0x0008,
403 0x0000,
404 0x0000,
405 0x0000,
406 0x0000,
407 0x0002,
408 0x0100,
409
410 3, 0x0d,
411 0x0d80,
412 0x0001,
413 0x0000,
414
415 4, 0x11,
416 0x0000,
417 0x0103,
418 0x0000,
419 0x0000,
420
421 3, 0x16,
422 0x0004 | 0x0040,
423 0x0030,
424 0x07ff,
425
426 6, 0x1b,
427 0x4112,
428 0xff00,
429 0xc07f,
430 0x0000,
431 0x0180,
432 0x4000 | 0x0800 | 0x0040 | 0x0020 | 0x0010 | 0x0008 | 0x0002 | 0x0001,
433
434 0,
435};
436
437static void dib0070_wbd_calibration(struct dib0070_state *state)
438{
439 u16 wbd_offs;
440 dib0070_write_reg(state, 0x0f, 0x6d81);
441 dib0070_write_reg(state, 0x20, 0x0040 | 0x0020 | 0x0010 | 0x0008 | 0x0002 | 0x0001);
442 msleep(9);
443 wbd_offs = dib0070_read_reg(state, 0x19);
444 dib0070_write_reg(state, 0x20, 0);
445 state->wbd_ff_offset = ((wbd_offs * 8 * 18 / 33 + 1) / 2);
446 dprintk( "WBDStart = %d (Vargen) - FF = %hd", (u32) wbd_offs * 1800/1024, state->wbd_ff_offset);
447}
448
449u16 dib0070_wbd_offset(struct dvb_frontend *fe)
450{
451 struct dib0070_state *st = fe->tuner_priv;
452 return st->wbd_ff_offset;
453}
454
455EXPORT_SYMBOL(dib0070_wbd_offset);
456static int dib0070_set_ctrl_lo5(struct dvb_frontend *fe, u8 vco_bias_trim, u8 hf_div_trim, u8 cp_current, u8 third_order_filt)
457{
458 struct dib0070_state *state = fe->tuner_priv;
459 u16 lo5 = (third_order_filt << 14) | (0 << 13) | (1 << 12) | (3 << 9) | (cp_current << 6) | (hf_div_trim << 3) | (vco_bias_trim << 0);
460 dprintk( "CTRL_LO5: 0x%x", lo5);
461 return dib0070_write_reg(state, 0x15, lo5);
462}
463
464#define pgm_read_word(w) (*w)
465static int dib0070_reset(struct dib0070_state *state)
466{
467 u16 l, r, *n;
468
469 HARD_RESET(state);
470
471
472#ifndef FORCE_SBAND_TUNER
473 if ((dib0070_read_reg(state, 0x22) >> 9) & 0x1)
474 state->revision = (dib0070_read_reg(state, 0x1f) >> 8) & 0xff;
475 else
476#endif
477 state->revision = DIB0070S_P1A;
478
479 /* P1F or not */
480 dprintk( "Revision: %x", state->revision);
481
482 if (state->revision == DIB0070_P1D) {
483 dprintk( "Error: this driver is not to be used meant for P1D or earlier");
484 return -EINVAL;
485 }
486
487 n = (u16 *) dib0070_p1f_defaults;
488 l = pgm_read_word(n++);
489 while (l) {
490 r = pgm_read_word(n++);
491 do {
492 dib0070_write_reg(state, (u8)r, pgm_read_word(n++));
493 r++;
494 } while (--l);
495 l = pgm_read_word(n++);
496 }
497
498 if (state->cfg->force_crystal_mode != 0)
499 r = state->cfg->force_crystal_mode;
500 else if (state->cfg->clock_khz >= 24000)
501 r = 1;
502 else
503 r = 2;
504
505 r |= state->cfg->osc_buffer_state << 3;
506
507 dib0070_write_reg(state, 0x10, r);
508 dib0070_write_reg(state, 0x1f, (1 << 8) | ((state->cfg->clock_pad_drive & 0xf) << 4));
509
510 if (state->cfg->invert_iq) {
511 r = dib0070_read_reg(state, 0x02) & 0xffdf;
512 dib0070_write_reg(state, 0x02, r | (1 << 5));
513 }
514
515
516 if (state->revision == DIB0070S_P1A)
517 dib0070_set_ctrl_lo5(state->fe, 4, 7, 3, 1);
518 else
519 dib0070_set_ctrl_lo5(state->fe, 4, 4, 2, 0);
520
521 dib0070_write_reg(state, 0x01, (54 << 9) | 0xc8);
522 return 0;
523}
524
525
526static int dib0070_release(struct dvb_frontend *fe)
527{
528 kfree(fe->tuner_priv);
529 fe->tuner_priv = NULL;
530 return 0;
531}
532
533static struct dvb_tuner_ops dib0070_ops = {
534 .info = {
535 .name = "DiBcom DiB0070",
536 .frequency_min = 45000000,
537 .frequency_max = 860000000,
538 .frequency_step = 1000,
539 },
540 .release = dib0070_release,
541
542 .init = dib0070_wakeup,
543 .sleep = dib0070_sleep,
544 .set_params = dib0070_tune_digital,
545// .get_frequency = dib0070_get_frequency,
546// .get_bandwidth = dib0070_get_bandwidth
547};
548
549struct dvb_frontend * dib0070_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, struct dib0070_config *cfg)
550{
551 struct dib0070_state *state = kzalloc(sizeof(struct dib0070_state), GFP_KERNEL);
552 if (state == NULL)
553 return NULL;
554
555 state->cfg = cfg;
556 state->i2c = i2c;
557 state->fe = fe;
558 fe->tuner_priv = state;
559
560 if (dib0070_reset(state) != 0)
561 goto free_mem;
562
563 dib0070_wbd_calibration(state);
564
565 printk(KERN_INFO "DiB0070: successfully identified\n");
566 memcpy(&fe->ops.tuner_ops, &dib0070_ops, sizeof(struct dvb_tuner_ops));
567
568 fe->tuner_priv = state;
569 return fe;
570
571free_mem:
572 kfree(state);
573 fe->tuner_priv = NULL;
574 return NULL;
575}
576EXPORT_SYMBOL(dib0070_attach);
577
578MODULE_AUTHOR("Patrick Boettcher <pboettcher@dibcom.fr>");
579MODULE_DESCRIPTION("Driver for the DiBcom 0070 base-band RF Tuner");
580MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/frontends/dib0070.h b/drivers/media/dvb/frontends/dib0070.h
new file mode 100644
index 000000000000..786e37d33889
--- /dev/null
+++ b/drivers/media/dvb/frontends/dib0070.h
@@ -0,0 +1,44 @@
1/*
2 * Linux-DVB Driver for DiBcom's DiB0070 base-band RF Tuner.
3 *
4 * Copyright (C) 2005-7 DiBcom (http://www.dibcom.fr/)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, version 2.
9 */
10#ifndef DIB0070_H
11#define DIB0070_H
12
13struct dvb_frontend;
14struct i2c_adapter;
15
16#define DEFAULT_DIB0070_I2C_ADDRESS 0x60
17
18struct dib0070_config {
19 u8 i2c_address;
20
21 /* tuner pins controlled externally */
22 int (*reset) (struct dvb_frontend *, int);
23 int (*sleep) (struct dvb_frontend *, int);
24
25 /* offset in kHz */
26 int freq_offset_khz_uhf;
27 int freq_offset_khz_vhf;
28
29 u8 osc_buffer_state; /* 0= normal, 1= tri-state */
30 u32 clock_khz;
31 u8 clock_pad_drive; /* (Drive + 1) * 2mA */
32
33 u8 invert_iq; /* invert Q - in case I or Q is inverted on the board */
34
35 u8 force_crystal_mode; /* if == 0 -> decision is made in the driver default: <24 -> 2, >=24 -> 1 */
36
37 u8 flip_chip;
38};
39
40extern struct dvb_frontend * dib0070_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, struct dib0070_config *cfg);
41extern void dib0070_ctrl_agc_filter(struct dvb_frontend *, uint8_t open);
42extern u16 dib0070_wbd_offset(struct dvb_frontend *);
43
44#endif
diff --git a/drivers/media/dvb/frontends/dib3000mb.c b/drivers/media/dvb/frontends/dib3000mb.c
index b6adea5ffeb8..136b9d2164d7 100644
--- a/drivers/media/dvb/frontends/dib3000mb.c
+++ b/drivers/media/dvb/frontends/dib3000mb.c
@@ -23,7 +23,6 @@
23 23
24#include <linux/kernel.h> 24#include <linux/kernel.h>
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/moduleparam.h>
27#include <linux/init.h> 26#include <linux/init.h>
28#include <linux/delay.h> 27#include <linux/delay.h>
29#include <linux/string.h> 28#include <linux/string.h>
diff --git a/drivers/media/dvb/frontends/dib3000mc.c b/drivers/media/dvb/frontends/dib3000mc.c
index 054d7e6d9662..edae0be063f5 100644
--- a/drivers/media/dvb/frontends/dib3000mc.c
+++ b/drivers/media/dvb/frontends/dib3000mc.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Driver for DiBcom DiB3000MC/P-demodulator. 2 * Driver for DiBcom DiB3000MC/P-demodulator.
3 * 3 *
4 * Copyright (C) 2004-6 DiBcom (http://www.dibcom.fr/) 4 * Copyright (C) 2004-7 DiBcom (http://www.dibcom.fr/)
5 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de) 5 * Copyright (C) 2004-5 Patrick Boettcher (patrick.boettcher@desy.de)
6 * 6 *
7 * This code is partially based on the previous dib3000mc.c . 7 * This code is partially based on the previous dib3000mc.c .
@@ -13,10 +13,6 @@
13 13
14#include <linux/kernel.h> 14#include <linux/kernel.h>
15#include <linux/i2c.h> 15#include <linux/i2c.h>
16//#include <linux/init.h>
17//#include <linux/delay.h>
18//#include <linux/string.h>
19//#include <linux/slab.h>
20 16
21#include "dvb_frontend.h" 17#include "dvb_frontend.h"
22 18
@@ -26,7 +22,11 @@ static int debug;
26module_param(debug, int, 0644); 22module_param(debug, int, 0644);
27MODULE_PARM_DESC(debug, "turn on debugging (default: 0)"); 23MODULE_PARM_DESC(debug, "turn on debugging (default: 0)");
28 24
29#define dprintk(args...) do { if (debug) { printk(KERN_DEBUG "DiB3000MC/P:"); printk(args); } } while (0) 25static int buggy_sfn_workaround;
26module_param(buggy_sfn_workaround, int, 0644);
27MODULE_PARM_DESC(buggy_sfn_workaround, "Enable work-around for buggy SFNs (default: 0)");
28
29#define dprintk(args...) do { if (debug) { printk(KERN_DEBUG "DiB3000MC/P:"); printk(args); printk("\n"); } } while (0)
30 30
31struct dib3000mc_state { 31struct dib3000mc_state {
32 struct dvb_frontend demod; 32 struct dvb_frontend demod;
@@ -42,6 +42,8 @@ struct dib3000mc_state {
42 fe_bandwidth_t current_bandwidth; 42 fe_bandwidth_t current_bandwidth;
43 43
44 u16 dev_id; 44 u16 dev_id;
45
46 u8 sfn_workaround_active :1;
45}; 47};
46 48
47static u16 dib3000mc_read_word(struct dib3000mc_state *state, u16 reg) 49static u16 dib3000mc_read_word(struct dib3000mc_state *state, u16 reg)
@@ -71,7 +73,6 @@ static int dib3000mc_write_word(struct dib3000mc_state *state, u16 reg, u16 val)
71 return i2c_transfer(state->i2c_adap, &msg, 1) != 1 ? -EREMOTEIO : 0; 73 return i2c_transfer(state->i2c_adap, &msg, 1) != 1 ? -EREMOTEIO : 0;
72} 74}
73 75
74
75static int dib3000mc_identify(struct dib3000mc_state *state) 76static int dib3000mc_identify(struct dib3000mc_state *state)
76{ 77{
77 u16 value; 78 u16 value;
@@ -92,7 +93,7 @@ static int dib3000mc_identify(struct dib3000mc_state *state)
92 return 0; 93 return 0;
93} 94}
94 95
95static int dib3000mc_set_timing(struct dib3000mc_state *state, s16 nfft, u8 bw, u8 update_offset) 96static int dib3000mc_set_timing(struct dib3000mc_state *state, s16 nfft, u32 bw, u8 update_offset)
96{ 97{
97 u32 timf; 98 u32 timf;
98 99
@@ -103,7 +104,7 @@ static int dib3000mc_set_timing(struct dib3000mc_state *state, s16 nfft, u8 bw,
103 } else 104 } else
104 timf = state->timf; 105 timf = state->timf;
105 106
106 timf *= (BW_INDEX_TO_KHZ(bw) / 1000); 107 timf *= (bw / 1000);
107 108
108 if (update_offset) { 109 if (update_offset) {
109 s16 tim_offs = dib3000mc_read_word(state, 416); 110 s16 tim_offs = dib3000mc_read_word(state, 416);
@@ -111,17 +112,17 @@ static int dib3000mc_set_timing(struct dib3000mc_state *state, s16 nfft, u8 bw,
111 if (tim_offs & 0x2000) 112 if (tim_offs & 0x2000)
112 tim_offs -= 0x4000; 113 tim_offs -= 0x4000;
113 114
114 if (nfft == 0) 115 if (nfft == TRANSMISSION_MODE_2K)
115 tim_offs *= 4; 116 tim_offs *= 4;
116 117
117 timf += tim_offs; 118 timf += tim_offs;
118 state->timf = timf / (BW_INDEX_TO_KHZ(bw) / 1000); 119 state->timf = timf / (bw / 1000);
119 } 120 }
120 121
121 dprintk("timf: %d\n", timf); 122 dprintk("timf: %d\n", timf);
122 123
123 dib3000mc_write_word(state, 23, timf >> 16); 124 dib3000mc_write_word(state, 23, (u16) (timf >> 16));
124 dib3000mc_write_word(state, 24, timf & 0xffff); 125 dib3000mc_write_word(state, 24, (u16) (timf ) & 0xffff);
125 126
126 return 0; 127 return 0;
127} 128}
@@ -209,31 +210,30 @@ static int dib3000mc_set_output_mode(struct dib3000mc_state *state, int mode)
209 return ret; 210 return ret;
210} 211}
211 212
212static int dib3000mc_set_bandwidth(struct dvb_frontend *demod, u8 bw) 213static int dib3000mc_set_bandwidth(struct dib3000mc_state *state, u32 bw)
213{ 214{
214 struct dib3000mc_state *state = demod->demodulator_priv;
215 u16 bw_cfg[6] = { 0 }; 215 u16 bw_cfg[6] = { 0 };
216 u16 imp_bw_cfg[3] = { 0 }; 216 u16 imp_bw_cfg[3] = { 0 };
217 u16 reg; 217 u16 reg;
218 218
219/* settings here are for 27.7MHz */ 219/* settings here are for 27.7MHz */
220 switch (bw) { 220 switch (bw) {
221 case BANDWIDTH_8_MHZ: 221 case 8000:
222 bw_cfg[0] = 0x0019; bw_cfg[1] = 0x5c30; bw_cfg[2] = 0x0054; bw_cfg[3] = 0x88a0; bw_cfg[4] = 0x01a6; bw_cfg[5] = 0xab20; 222 bw_cfg[0] = 0x0019; bw_cfg[1] = 0x5c30; bw_cfg[2] = 0x0054; bw_cfg[3] = 0x88a0; bw_cfg[4] = 0x01a6; bw_cfg[5] = 0xab20;
223 imp_bw_cfg[0] = 0x04db; imp_bw_cfg[1] = 0x00db; imp_bw_cfg[2] = 0x00b7; 223 imp_bw_cfg[0] = 0x04db; imp_bw_cfg[1] = 0x00db; imp_bw_cfg[2] = 0x00b7;
224 break; 224 break;
225 225
226 case BANDWIDTH_7_MHZ: 226 case 7000:
227 bw_cfg[0] = 0x001c; bw_cfg[1] = 0xfba5; bw_cfg[2] = 0x0060; bw_cfg[3] = 0x9c25; bw_cfg[4] = 0x01e3; bw_cfg[5] = 0x0cb7; 227 bw_cfg[0] = 0x001c; bw_cfg[1] = 0xfba5; bw_cfg[2] = 0x0060; bw_cfg[3] = 0x9c25; bw_cfg[4] = 0x01e3; bw_cfg[5] = 0x0cb7;
228 imp_bw_cfg[0] = 0x04c0; imp_bw_cfg[1] = 0x00c0; imp_bw_cfg[2] = 0x00a0; 228 imp_bw_cfg[0] = 0x04c0; imp_bw_cfg[1] = 0x00c0; imp_bw_cfg[2] = 0x00a0;
229 break; 229 break;
230 230
231 case BANDWIDTH_6_MHZ: 231 case 6000:
232 bw_cfg[0] = 0x0021; bw_cfg[1] = 0xd040; bw_cfg[2] = 0x0070; bw_cfg[3] = 0xb62b; bw_cfg[4] = 0x0233; bw_cfg[5] = 0x8ed5; 232 bw_cfg[0] = 0x0021; bw_cfg[1] = 0xd040; bw_cfg[2] = 0x0070; bw_cfg[3] = 0xb62b; bw_cfg[4] = 0x0233; bw_cfg[5] = 0x8ed5;
233 imp_bw_cfg[0] = 0x04a5; imp_bw_cfg[1] = 0x00a5; imp_bw_cfg[2] = 0x0089; 233 imp_bw_cfg[0] = 0x04a5; imp_bw_cfg[1] = 0x00a5; imp_bw_cfg[2] = 0x0089;
234 break; 234 break;
235 235
236 case 255 /* BANDWIDTH_5_MHZ */: 236 case 5000:
237 bw_cfg[0] = 0x0028; bw_cfg[1] = 0x9380; bw_cfg[2] = 0x0087; bw_cfg[3] = 0x4100; bw_cfg[4] = 0x02a4; bw_cfg[5] = 0x4500; 237 bw_cfg[0] = 0x0028; bw_cfg[1] = 0x9380; bw_cfg[2] = 0x0087; bw_cfg[3] = 0x4100; bw_cfg[4] = 0x02a4; bw_cfg[5] = 0x4500;
238 imp_bw_cfg[0] = 0x0489; imp_bw_cfg[1] = 0x0089; imp_bw_cfg[2] = 0x0072; 238 imp_bw_cfg[0] = 0x0489; imp_bw_cfg[1] = 0x0089; imp_bw_cfg[2] = 0x0072;
239 break; 239 break;
@@ -257,7 +257,7 @@ static int dib3000mc_set_bandwidth(struct dvb_frontend *demod, u8 bw)
257 dib3000mc_write_word(state, reg, imp_bw_cfg[reg - 55]); 257 dib3000mc_write_word(state, reg, imp_bw_cfg[reg - 55]);
258 258
259 // Timing configuration 259 // Timing configuration
260 dib3000mc_set_timing(state, 0, bw, 0); 260 dib3000mc_set_timing(state, TRANSMISSION_MODE_2K, bw, 0);
261 261
262 return 0; 262 return 0;
263} 263}
@@ -276,7 +276,7 @@ static void dib3000mc_set_impulse_noise(struct dib3000mc_state *state, u8 mode,
276 for (i = 58; i < 87; i++) 276 for (i = 58; i < 87; i++)
277 dib3000mc_write_word(state, i, impulse_noise_val[i-58]); 277 dib3000mc_write_word(state, i, impulse_noise_val[i-58]);
278 278
279 if (nfft == 1) { 279 if (nfft == TRANSMISSION_MODE_8K) {
280 dib3000mc_write_word(state, 58, 0x3b); 280 dib3000mc_write_word(state, 58, 0x3b);
281 dib3000mc_write_word(state, 84, 0x00); 281 dib3000mc_write_word(state, 84, 0x00);
282 dib3000mc_write_word(state, 85, 0x8200); 282 dib3000mc_write_word(state, 85, 0x8200);
@@ -376,7 +376,7 @@ static int dib3000mc_init(struct dvb_frontend *demod)
376 // P_search_maxtrial=1 376 // P_search_maxtrial=1
377 dib3000mc_write_word(state, 5, 1); 377 dib3000mc_write_word(state, 5, 1);
378 378
379 dib3000mc_set_bandwidth(&state->demod, BANDWIDTH_8_MHZ); 379 dib3000mc_set_bandwidth(state, 8000);
380 380
381 // div_lock_mask 381 // div_lock_mask
382 dib3000mc_write_word(state, 4, 0x814); 382 dib3000mc_write_word(state, 4, 0x814);
@@ -397,7 +397,7 @@ static int dib3000mc_init(struct dvb_frontend *demod)
397 dib3000mc_write_word(state, 180, 0x2FF0); 397 dib3000mc_write_word(state, 180, 0x2FF0);
398 398
399 // Impulse noise configuration 399 // Impulse noise configuration
400 dib3000mc_set_impulse_noise(state, 0, 1); 400 dib3000mc_set_impulse_noise(state, 0, TRANSMISSION_MODE_8K);
401 401
402 // output mode set-up 402 // output mode set-up
403 dib3000mc_set_output_mode(state, OUTMODE_HIGH_Z); 403 dib3000mc_set_output_mode(state, OUTMODE_HIGH_Z);
@@ -423,13 +423,13 @@ static void dib3000mc_set_adp_cfg(struct dib3000mc_state *state, s16 qam)
423{ 423{
424 u16 cfg[4] = { 0 },reg; 424 u16 cfg[4] = { 0 },reg;
425 switch (qam) { 425 switch (qam) {
426 case 0: 426 case QPSK:
427 cfg[0] = 0x099a; cfg[1] = 0x7fae; cfg[2] = 0x0333; cfg[3] = 0x7ff0; 427 cfg[0] = 0x099a; cfg[1] = 0x7fae; cfg[2] = 0x0333; cfg[3] = 0x7ff0;
428 break; 428 break;
429 case 1: 429 case QAM_16:
430 cfg[0] = 0x023d; cfg[1] = 0x7fdf; cfg[2] = 0x00a4; cfg[3] = 0x7ff0; 430 cfg[0] = 0x023d; cfg[1] = 0x7fdf; cfg[2] = 0x00a4; cfg[3] = 0x7ff0;
431 break; 431 break;
432 case 2: 432 case QAM_64:
433 cfg[0] = 0x0148; cfg[1] = 0x7ff0; cfg[2] = 0x00a4; cfg[3] = 0x7ff8; 433 cfg[0] = 0x0148; cfg[1] = 0x7ff0; cfg[2] = 0x00a4; cfg[3] = 0x7ff8;
434 break; 434 break;
435 } 435 }
@@ -437,11 +437,11 @@ static void dib3000mc_set_adp_cfg(struct dib3000mc_state *state, s16 qam)
437 dib3000mc_write_word(state, reg, cfg[reg - 129]); 437 dib3000mc_write_word(state, reg, cfg[reg - 129]);
438} 438}
439 439
440static void dib3000mc_set_channel_cfg(struct dib3000mc_state *state, struct dibx000_ofdm_channel *chan, u16 seq) 440static void dib3000mc_set_channel_cfg(struct dib3000mc_state *state, struct dvb_frontend_parameters *ch, u16 seq)
441{ 441{
442 u16 tmp; 442 u16 value;
443 443 dib3000mc_set_bandwidth(state, BANDWIDTH_TO_KHZ(ch->u.ofdm.bandwidth));
444 dib3000mc_set_timing(state, chan->nfft, chan->Bw, 0); 444 dib3000mc_set_timing(state, ch->u.ofdm.transmission_mode, BANDWIDTH_TO_KHZ(ch->u.ofdm.bandwidth), 0);
445 445
446// if (boost) 446// if (boost)
447// dib3000mc_write_word(state, 100, (11 << 6) + 6); 447// dib3000mc_write_word(state, 100, (11 << 6) + 6);
@@ -455,7 +455,7 @@ static void dib3000mc_set_channel_cfg(struct dib3000mc_state *state, struct dibx
455 dib3000mc_write_word(state, 26, 0x6680); 455 dib3000mc_write_word(state, 26, 0x6680);
456 dib3000mc_write_word(state, 29, 0x1273); 456 dib3000mc_write_word(state, 29, 0x1273);
457 dib3000mc_write_word(state, 33, 5); 457 dib3000mc_write_word(state, 33, 5);
458 dib3000mc_set_adp_cfg(state, 1); 458 dib3000mc_set_adp_cfg(state, QAM_16);
459 dib3000mc_write_word(state, 133, 15564); 459 dib3000mc_write_word(state, 133, 15564);
460 460
461 dib3000mc_write_word(state, 12 , 0x0); 461 dib3000mc_write_word(state, 12 , 0x0);
@@ -470,52 +470,98 @@ static void dib3000mc_set_channel_cfg(struct dib3000mc_state *state, struct dibx
470 dib3000mc_write_word(state, 97,0); 470 dib3000mc_write_word(state, 97,0);
471 dib3000mc_write_word(state, 98,0); 471 dib3000mc_write_word(state, 98,0);
472 472
473 dib3000mc_set_impulse_noise(state, 0, chan->nfft); 473 dib3000mc_set_impulse_noise(state, 0, ch->u.ofdm.transmission_mode);
474
475 tmp = ((chan->nfft & 0x1) << 7) | (chan->guard << 5) | (chan->nqam << 3) | chan->vit_alpha;
476 dib3000mc_write_word(state, 0, tmp);
477 474
475 value = 0;
476 switch (ch->u.ofdm.transmission_mode) {
477 case TRANSMISSION_MODE_2K: value |= (0 << 7); break;
478 default:
479 case TRANSMISSION_MODE_8K: value |= (1 << 7); break;
480 }
481 switch (ch->u.ofdm.guard_interval) {
482 case GUARD_INTERVAL_1_32: value |= (0 << 5); break;
483 case GUARD_INTERVAL_1_16: value |= (1 << 5); break;
484 case GUARD_INTERVAL_1_4: value |= (3 << 5); break;
485 default:
486 case GUARD_INTERVAL_1_8: value |= (2 << 5); break;
487 }
488 switch (ch->u.ofdm.constellation) {
489 case QPSK: value |= (0 << 3); break;
490 case QAM_16: value |= (1 << 3); break;
491 default:
492 case QAM_64: value |= (2 << 3); break;
493 }
494 switch (HIERARCHY_1) {
495 case HIERARCHY_2: value |= 2; break;
496 case HIERARCHY_4: value |= 4; break;
497 default:
498 case HIERARCHY_1: value |= 1; break;
499 }
500 dib3000mc_write_word(state, 0, value);
478 dib3000mc_write_word(state, 5, (1 << 8) | ((seq & 0xf) << 4)); 501 dib3000mc_write_word(state, 5, (1 << 8) | ((seq & 0xf) << 4));
479 502
480 tmp = (chan->vit_hrch << 4) | (chan->vit_select_hp); 503 value = 0;
481 if (!chan->vit_hrch || (chan->vit_hrch && chan->vit_select_hp)) 504 if (ch->u.ofdm.hierarchy_information == 1)
482 tmp |= chan->vit_code_rate_hp << 1; 505 value |= (1 << 4);
483 else 506 if (1 == 1)
484 tmp |= chan->vit_code_rate_lp << 1; 507 value |= 1;
485 dib3000mc_write_word(state, 181, tmp); 508 switch ((ch->u.ofdm.hierarchy_information == 0 || 1 == 1) ? ch->u.ofdm.code_rate_HP : ch->u.ofdm.code_rate_LP) {
509 case FEC_2_3: value |= (2 << 1); break;
510 case FEC_3_4: value |= (3 << 1); break;
511 case FEC_5_6: value |= (5 << 1); break;
512 case FEC_7_8: value |= (7 << 1); break;
513 default:
514 case FEC_1_2: value |= (1 << 1); break;
515 }
516 dib3000mc_write_word(state, 181, value);
486 517
487 // diversity synchro delay 518 // diversity synchro delay add 50% SFN margin
488 tmp = dib3000mc_read_word(state, 180) & 0x000f; 519 switch (ch->u.ofdm.transmission_mode) {
489 tmp |= ((chan->nfft == 0) ? 64 : 256) * ((1 << (chan->guard)) * 3 / 2) << 4; // add 50% SFN margin 520 case TRANSMISSION_MODE_8K: value = 256; break;
490 dib3000mc_write_word(state, 180, tmp); 521 case TRANSMISSION_MODE_2K:
522 default: value = 64; break;
523 }
524 switch (ch->u.ofdm.guard_interval) {
525 case GUARD_INTERVAL_1_16: value *= 2; break;
526 case GUARD_INTERVAL_1_8: value *= 4; break;
527 case GUARD_INTERVAL_1_4: value *= 8; break;
528 default:
529 case GUARD_INTERVAL_1_32: value *= 1; break;
530 }
531 value <<= 4;
532 value |= dib3000mc_read_word(state, 180) & 0x000f;
533 dib3000mc_write_word(state, 180, value);
491 534
492 // restart demod 535 // restart demod
493 tmp = dib3000mc_read_word(state, 0); 536 value = dib3000mc_read_word(state, 0);
494 dib3000mc_write_word(state, 0, tmp | (1 << 9)); 537 dib3000mc_write_word(state, 0, value | (1 << 9));
495 dib3000mc_write_word(state, 0, tmp); 538 dib3000mc_write_word(state, 0, value);
496 539
497 msleep(30); 540 msleep(30);
498 541
499 dib3000mc_set_impulse_noise(state, state->cfg->impulse_noise_mode, chan->nfft); 542 dib3000mc_set_impulse_noise(state, state->cfg->impulse_noise_mode, ch->u.ofdm.transmission_mode);
500} 543}
501 544
502static int dib3000mc_autosearch_start(struct dvb_frontend *demod, struct dibx000_ofdm_channel *chan) 545static int dib3000mc_autosearch_start(struct dvb_frontend *demod, struct dvb_frontend_parameters *chan)
503{ 546{
504 struct dib3000mc_state *state = demod->demodulator_priv; 547 struct dib3000mc_state *state = demod->demodulator_priv;
505 u16 reg; 548 u16 reg;
506// u32 val; 549// u32 val;
507 struct dibx000_ofdm_channel fchan; 550 struct dvb_frontend_parameters schan;
508 551
509 INIT_OFDM_CHANNEL(&fchan); 552 schan = *chan;
510 fchan = *chan;
511 553
554 /* TODO what is that ? */
512 555
513 /* a channel for autosearch */ 556 /* a channel for autosearch */
514 fchan.nfft = 1; fchan.guard = 0; fchan.nqam = 2; 557 schan.u.ofdm.transmission_mode = TRANSMISSION_MODE_8K;
515 fchan.vit_alpha = 1; fchan.vit_code_rate_hp = 2; fchan.vit_code_rate_lp = 2; 558 schan.u.ofdm.guard_interval = GUARD_INTERVAL_1_32;
516 fchan.vit_hrch = 0; fchan.vit_select_hp = 1; 559 schan.u.ofdm.constellation = QAM_64;
560 schan.u.ofdm.code_rate_HP = FEC_2_3;
561 schan.u.ofdm.code_rate_LP = FEC_2_3;
562 schan.u.ofdm.hierarchy_information = 0;
517 563
518 dib3000mc_set_channel_cfg(state, &fchan, 11); 564 dib3000mc_set_channel_cfg(state, &schan, 11);
519 565
520 reg = dib3000mc_read_word(state, 0); 566 reg = dib3000mc_read_word(state, 0);
521 dib3000mc_write_word(state, 0, reg | (1 << 8)); 567 dib3000mc_write_word(state, 0, reg | (1 << 8));
@@ -539,7 +585,7 @@ static int dib3000mc_autosearch_is_irq(struct dvb_frontend *demod)
539 return 0; // still pending 585 return 0; // still pending
540} 586}
541 587
542static int dib3000mc_tune(struct dvb_frontend *demod, struct dibx000_ofdm_channel *ch) 588static int dib3000mc_tune(struct dvb_frontend *demod, struct dvb_frontend_parameters *ch)
543{ 589{
544 struct dib3000mc_state *state = demod->demodulator_priv; 590 struct dib3000mc_state *state = demod->demodulator_priv;
545 591
@@ -547,11 +593,17 @@ static int dib3000mc_tune(struct dvb_frontend *demod, struct dibx000_ofdm_channe
547 dib3000mc_set_channel_cfg(state, ch, 0); 593 dib3000mc_set_channel_cfg(state, ch, 0);
548 594
549 // activates isi 595 // activates isi
550 dib3000mc_write_word(state, 29, 0x1073); 596 if (state->sfn_workaround_active) {
551 597 dprintk("SFN workaround is active\n");
552 dib3000mc_set_adp_cfg(state, (u8)ch->nqam); 598 dib3000mc_write_word(state, 29, 0x1273);
599 dib3000mc_write_word(state, 108, 0x4000); // P_pha3_force_pha_shift
600 } else {
601 dib3000mc_write_word(state, 29, 0x1073);
602 dib3000mc_write_word(state, 108, 0x0000); // P_pha3_force_pha_shift
603 }
553 604
554 if (ch->nfft == 1) { 605 dib3000mc_set_adp_cfg(state, (u8)ch->u.ofdm.constellation);
606 if (ch->u.ofdm.transmission_mode == TRANSMISSION_MODE_8K) {
555 dib3000mc_write_word(state, 26, 38528); 607 dib3000mc_write_word(state, 26, 38528);
556 dib3000mc_write_word(state, 33, 8); 608 dib3000mc_write_word(state, 33, 8);
557 } else { 609 } else {
@@ -560,7 +612,7 @@ static int dib3000mc_tune(struct dvb_frontend *demod, struct dibx000_ofdm_channe
560 } 612 }
561 613
562 if (dib3000mc_read_word(state, 509) & 0x80) 614 if (dib3000mc_read_word(state, 509) & 0x80)
563 dib3000mc_set_timing(state, ch->nfft, ch->Bw, 1); 615 dib3000mc_set_timing(state, ch->u.ofdm.transmission_mode, BANDWIDTH_TO_KHZ(ch->u.ofdm.bandwidth), 1);
564 616
565 return 0; 617 return 0;
566} 618}
@@ -632,13 +684,12 @@ static int dib3000mc_set_frontend(struct dvb_frontend* fe,
632 struct dvb_frontend_parameters *fep) 684 struct dvb_frontend_parameters *fep)
633{ 685{
634 struct dib3000mc_state *state = fe->demodulator_priv; 686 struct dib3000mc_state *state = fe->demodulator_priv;
635 struct dibx000_ofdm_channel ch;
636
637 INIT_OFDM_CHANNEL(&ch);
638 FEP2DIB(fep,&ch);
639 687
640 state->current_bandwidth = fep->u.ofdm.bandwidth; 688 state->current_bandwidth = fep->u.ofdm.bandwidth;
641 dib3000mc_set_bandwidth(fe, fep->u.ofdm.bandwidth); 689 dib3000mc_set_bandwidth(state, BANDWIDTH_TO_KHZ(fep->u.ofdm.bandwidth));
690
691 /* maybe the parameter has been changed */
692 state->sfn_workaround_active = buggy_sfn_workaround;
642 693
643 if (fe->ops.tuner_ops.set_params) { 694 if (fe->ops.tuner_ops.set_params) {
644 fe->ops.tuner_ops.set_params(fe, fep); 695 fe->ops.tuner_ops.set_params(fe, fep);
@@ -651,7 +702,7 @@ static int dib3000mc_set_frontend(struct dvb_frontend* fe,
651 fep->u.ofdm.code_rate_HP == FEC_AUTO) { 702 fep->u.ofdm.code_rate_HP == FEC_AUTO) {
652 int i = 100, found; 703 int i = 100, found;
653 704
654 dib3000mc_autosearch_start(fe, &ch); 705 dib3000mc_autosearch_start(fe, fep);
655 do { 706 do {
656 msleep(1); 707 msleep(1);
657 found = dib3000mc_autosearch_is_irq(fe); 708 found = dib3000mc_autosearch_is_irq(fe);
@@ -662,13 +713,12 @@ static int dib3000mc_set_frontend(struct dvb_frontend* fe,
662 return 0; // no channel found 713 return 0; // no channel found
663 714
664 dib3000mc_get_frontend(fe, fep); 715 dib3000mc_get_frontend(fe, fep);
665 FEP2DIB(fep,&ch);
666 } 716 }
667 717
668 /* make this a config parameter */ 718 /* make this a config parameter */
669 dib3000mc_set_output_mode(state, OUTMODE_MPEG2_FIFO); 719 dib3000mc_set_output_mode(state, OUTMODE_MPEG2_FIFO);
670 720
671 return dib3000mc_tune(fe, &ch); 721 return dib3000mc_tune(fe, fep);
672} 722}
673 723
674static int dib3000mc_read_status(struct dvb_frontend *fe, fe_status_t *stat) 724static int dib3000mc_read_status(struct dvb_frontend *fe, fe_status_t *stat)
diff --git a/drivers/media/dvb/frontends/dib7000m.c b/drivers/media/dvb/frontends/dib7000m.c
index f64546c6aeb5..fb18441a8c57 100644
--- a/drivers/media/dvb/frontends/dib7000m.c
+++ b/drivers/media/dvb/frontends/dib7000m.c
@@ -2,7 +2,7 @@
2 * Linux-DVB Driver for DiBcom's DiB7000M and 2 * Linux-DVB Driver for DiBcom's DiB7000M and
3 * first generation DiB7000P-demodulator-family. 3 * first generation DiB7000P-demodulator-family.
4 * 4 *
5 * Copyright (C) 2005-6 DiBcom (http://www.dibcom.fr/) 5 * Copyright (C) 2005-7 DiBcom (http://www.dibcom.fr/)
6 * 6 *
7 * This program is free software; you can redistribute it and/or 7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as 8 * modify it under the terms of the GNU General Public License as
@@ -19,7 +19,7 @@ static int debug;
19module_param(debug, int, 0644); 19module_param(debug, int, 0644);
20MODULE_PARM_DESC(debug, "turn on debugging (default: 0)"); 20MODULE_PARM_DESC(debug, "turn on debugging (default: 0)");
21 21
22#define dprintk(args...) do { if (debug) { printk(KERN_DEBUG "DiB7000M:"); printk(args); } } while (0) 22#define dprintk(args...) do { if (debug) { printk(KERN_DEBUG "DiB7000M: "); printk(args); printk("\n"); } } while (0)
23 23
24struct dib7000m_state { 24struct dib7000m_state {
25 struct dvb_frontend demod; 25 struct dvb_frontend demod;
@@ -39,8 +39,16 @@ struct dib7000m_state {
39 fe_bandwidth_t current_bandwidth; 39 fe_bandwidth_t current_bandwidth;
40 struct dibx000_agc_config *current_agc; 40 struct dibx000_agc_config *current_agc;
41 u32 timf; 41 u32 timf;
42 u32 timf_default;
43 u32 internal_clk;
44
45 u8 div_force_off : 1;
46 u8 div_state : 1;
47 u16 div_sync_wait;
42 48
43 u16 revision; 49 u16 revision;
50
51 u8 agc_state;
44}; 52};
45 53
46enum dib7000m_power_mode { 54enum dib7000m_power_mode {
@@ -63,7 +71,7 @@ static u16 dib7000m_read_word(struct dib7000m_state *state, u16 reg)
63 }; 71 };
64 72
65 if (i2c_transfer(state->i2c_adap, msg, 2) != 2) 73 if (i2c_transfer(state->i2c_adap, msg, 2) != 2)
66 dprintk("i2c read error on %d\n",reg); 74 dprintk("i2c read error on %d",reg);
67 75
68 return (rb[0] << 8) | rb[1]; 76 return (rb[0] << 8) | rb[1];
69} 77}
@@ -79,6 +87,25 @@ static int dib7000m_write_word(struct dib7000m_state *state, u16 reg, u16 val)
79 }; 87 };
80 return i2c_transfer(state->i2c_adap, &msg, 1) != 1 ? -EREMOTEIO : 0; 88 return i2c_transfer(state->i2c_adap, &msg, 1) != 1 ? -EREMOTEIO : 0;
81} 89}
90static void dib7000m_write_tab(struct dib7000m_state *state, u16 *buf)
91{
92 u16 l = 0, r, *n;
93 n = buf;
94 l = *n++;
95 while (l) {
96 r = *n++;
97
98 if (state->reg_offs && (r >= 112 && r <= 331)) // compensate for 7000MC
99 r++;
100
101 do {
102 dib7000m_write_word(state, r, *n++);
103 r++;
104 } while (--l);
105 l = *n++;
106 }
107}
108
82static int dib7000m_set_output_mode(struct dib7000m_state *state, int mode) 109static int dib7000m_set_output_mode(struct dib7000m_state *state, int mode)
83{ 110{
84 int ret = 0; 111 int ret = 0;
@@ -89,8 +116,7 @@ static int dib7000m_set_output_mode(struct dib7000m_state *state, int mode)
89 fifo_threshold = 1792; 116 fifo_threshold = 1792;
90 smo_mode = (dib7000m_read_word(state, 294 + state->reg_offs) & 0x0010) | (1 << 1); 117 smo_mode = (dib7000m_read_word(state, 294 + state->reg_offs) & 0x0010) | (1 << 1);
91 118
92 dprintk("-I- Setting output mode for demod %p to %d\n", 119 dprintk( "setting output mode for demod %p to %d", &state->demod, mode);
93 &state->demod, mode);
94 120
95 switch (mode) { 121 switch (mode) {
96 case OUTMODE_MPEG2_PAR_GATED_CLK: // STBs with parallel gated clock 122 case OUTMODE_MPEG2_PAR_GATED_CLK: // STBs with parallel gated clock
@@ -117,7 +143,7 @@ static int dib7000m_set_output_mode(struct dib7000m_state *state, int mode)
117 outreg = 0; 143 outreg = 0;
118 break; 144 break;
119 default: 145 default:
120 dprintk("Unhandled output_mode passed to be set for demod %p\n",&state->demod); 146 dprintk( "Unhandled output_mode passed to be set for demod %p",&state->demod);
121 break; 147 break;
122 } 148 }
123 149
@@ -129,13 +155,20 @@ static int dib7000m_set_output_mode(struct dib7000m_state *state, int mode)
129 ret |= dib7000m_write_word(state, 1795, outreg); 155 ret |= dib7000m_write_word(state, 1795, outreg);
130 ret |= dib7000m_write_word(state, 1805, sram); 156 ret |= dib7000m_write_word(state, 1805, sram);
131 157
158 if (state->revision == 0x4003) {
159 u16 clk_cfg1 = dib7000m_read_word(state, 909) & 0xfffd;
160 if (mode == OUTMODE_DIVERSITY)
161 clk_cfg1 |= (1 << 1); // P_O_CLK_en
162 dib7000m_write_word(state, 909, clk_cfg1);
163 }
132 return ret; 164 return ret;
133} 165}
134 166
135static int dib7000m_set_power_mode(struct dib7000m_state *state, enum dib7000m_power_mode mode) 167static void dib7000m_set_power_mode(struct dib7000m_state *state, enum dib7000m_power_mode mode)
136{ 168{
137 /* by default everything is going to be powered off */ 169 /* by default everything is going to be powered off */
138 u16 reg_903 = 0xffff, reg_904 = 0xffff, reg_905 = 0xffff, reg_906 = 0x3fff; 170 u16 reg_903 = 0xffff, reg_904 = 0xffff, reg_905 = 0xffff, reg_906 = 0x3fff;
171 u8 offset = 0;
139 172
140 /* now, depending on the requested mode, we power on */ 173 /* now, depending on the requested mode, we power on */
141 switch (mode) { 174 switch (mode) {
@@ -170,16 +203,17 @@ static int dib7000m_set_power_mode(struct dib7000m_state *state, enum dib7000m_p
170 if (!state->cfg.mobile_mode) 203 if (!state->cfg.mobile_mode)
171 reg_904 |= (1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) | (1 << 1); 204 reg_904 |= (1 << 7) | (1 << 6) | (1 << 4) | (1 << 2) | (1 << 1);
172 205
173 /* P_sdio_select_clk = 0 on MC */ 206 /* P_sdio_select_clk = 0 on MC and after*/
174 if (state->revision != 0x4000) 207 if (state->revision != 0x4000)
175 reg_906 <<= 1; 208 reg_906 <<= 1;
176 209
177 dib7000m_write_word(state, 903, reg_903); 210 if (state->revision == 0x4003)
178 dib7000m_write_word(state, 904, reg_904); 211 offset = 1;
179 dib7000m_write_word(state, 905, reg_905);
180 dib7000m_write_word(state, 906, reg_906);
181 212
182 return 0; 213 dib7000m_write_word(state, 903 + offset, reg_903);
214 dib7000m_write_word(state, 904 + offset, reg_904);
215 dib7000m_write_word(state, 905 + offset, reg_905);
216 dib7000m_write_word(state, 906 + offset, reg_906);
183} 217}
184 218
185static int dib7000m_set_adc_state(struct dib7000m_state *state, enum dibx000_adc_states no) 219static int dib7000m_set_adc_state(struct dib7000m_state *state, enum dibx000_adc_states no)
@@ -230,34 +264,55 @@ static int dib7000m_set_adc_state(struct dib7000m_state *state, enum dibx000_adc
230 break; 264 break;
231 } 265 }
232 266
233// dprintk("-D- 913: %x, 914: %x\n", reg_913, reg_914); 267// dprintk( "913: %x, 914: %x", reg_913, reg_914);
234
235 ret |= dib7000m_write_word(state, 913, reg_913); 268 ret |= dib7000m_write_word(state, 913, reg_913);
236 ret |= dib7000m_write_word(state, 914, reg_914); 269 ret |= dib7000m_write_word(state, 914, reg_914);
237 270
238 return ret; 271 return ret;
239} 272}
240 273
241static int dib7000m_set_bandwidth(struct dvb_frontend *demod, u8 bw_idx) 274static int dib7000m_set_bandwidth(struct dib7000m_state *state, u32 bw)
242{ 275{
243 struct dib7000m_state *state = demod->demodulator_priv;
244 u32 timf; 276 u32 timf;
245 277
246 // store the current bandwidth for later use 278 // store the current bandwidth for later use
247 state->current_bandwidth = bw_idx; 279 state->current_bandwidth = bw;
248 280
249 if (state->timf == 0) { 281 if (state->timf == 0) {
250 dprintk("-D- Using default timf\n"); 282 dprintk( "using default timf");
251 timf = state->cfg.bw->timf; 283 timf = state->timf_default;
252 } else { 284 } else {
253 dprintk("-D- Using updated timf\n"); 285 dprintk( "using updated timf");
254 timf = state->timf; 286 timf = state->timf;
255 } 287 }
256 288
257 timf = timf * (BW_INDEX_TO_KHZ(bw_idx) / 100) / 80; 289 timf = timf * (bw / 50) / 160;
258 290
259 dib7000m_write_word(state, 23, (timf >> 16) & 0xffff); 291 dib7000m_write_word(state, 23, (u16) ((timf >> 16) & 0xffff));
260 dib7000m_write_word(state, 24, (timf ) & 0xffff); 292 dib7000m_write_word(state, 24, (u16) ((timf ) & 0xffff));
293
294 return 0;
295}
296
297static int dib7000m_set_diversity_in(struct dvb_frontend *demod, int onoff)
298{
299 struct dib7000m_state *state = demod->demodulator_priv;
300
301 if (state->div_force_off) {
302 dprintk( "diversity combination deactivated - forced by COFDM parameters");
303 onoff = 0;
304 }
305 state->div_state = (u8)onoff;
306
307 if (onoff) {
308 dib7000m_write_word(state, 263 + state->reg_offs, 6);
309 dib7000m_write_word(state, 264 + state->reg_offs, 6);
310 dib7000m_write_word(state, 266 + state->reg_offs, (state->div_sync_wait << 4) | (1 << 2) | (2 << 0));
311 } else {
312 dib7000m_write_word(state, 263 + state->reg_offs, 1);
313 dib7000m_write_word(state, 264 + state->reg_offs, 0);
314 dib7000m_write_word(state, 266 + state->reg_offs, 0);
315 }
261 316
262 return 0; 317 return 0;
263} 318}
@@ -266,7 +321,7 @@ static int dib7000m_sad_calib(struct dib7000m_state *state)
266{ 321{
267 322
268/* internal */ 323/* internal */
269// dib7000m_write_word(state, 928, (3 << 14) | (1 << 12) | (524 << 0)); // sampling clock of the SAD is written in set_bandwidth 324// dib7000m_write_word(state, 928, (3 << 14) | (1 << 12) | (524 << 0)); // sampling clock of the SAD is writting in set_bandwidth
270 dib7000m_write_word(state, 929, (0 << 1) | (0 << 0)); 325 dib7000m_write_word(state, 929, (0 << 1) | (0 << 0));
271 dib7000m_write_word(state, 930, 776); // 0.625*3.3 / 4096 326 dib7000m_write_word(state, 930, 776); // 0.625*3.3 / 4096
272 327
@@ -281,10 +336,10 @@ static int dib7000m_sad_calib(struct dib7000m_state *state)
281 336
282static void dib7000m_reset_pll_common(struct dib7000m_state *state, const struct dibx000_bandwidth_config *bw) 337static void dib7000m_reset_pll_common(struct dib7000m_state *state, const struct dibx000_bandwidth_config *bw)
283{ 338{
284 dib7000m_write_word(state, 18, ((bw->internal*1000) >> 16) & 0xffff); 339 dib7000m_write_word(state, 18, (u16) (((bw->internal*1000) >> 16) & 0xffff));
285 dib7000m_write_word(state, 19, (bw->internal*1000) & 0xffff); 340 dib7000m_write_word(state, 19, (u16) ( (bw->internal*1000) & 0xffff));
286 dib7000m_write_word(state, 21, (bw->ifreq >> 16) & 0xffff); 341 dib7000m_write_word(state, 21, (u16) ( (bw->ifreq >> 16) & 0xffff));
287 dib7000m_write_word(state, 22, bw->ifreq & 0xffff); 342 dib7000m_write_word(state, 22, (u16) ( bw->ifreq & 0xffff));
288 343
289 dib7000m_write_word(state, 928, bw->sad_cfg); 344 dib7000m_write_word(state, 928, bw->sad_cfg);
290} 345}
@@ -325,15 +380,19 @@ static void dib7000m_reset_pll(struct dib7000m_state *state)
325static void dib7000mc_reset_pll(struct dib7000m_state *state) 380static void dib7000mc_reset_pll(struct dib7000m_state *state)
326{ 381{
327 const struct dibx000_bandwidth_config *bw = state->cfg.bw; 382 const struct dibx000_bandwidth_config *bw = state->cfg.bw;
383 u16 clk_cfg1;
328 384
329 // clk_cfg0 385 // clk_cfg0
330 dib7000m_write_word(state, 907, (bw->pll_prediv << 8) | (bw->pll_ratio << 0)); 386 dib7000m_write_word(state, 907, (bw->pll_prediv << 8) | (bw->pll_ratio << 0));
331 387
332 // clk_cfg1 388 // clk_cfg1
333 //dib7000m_write_word(state, 908, (1 << 14) | (3 << 12) |(0 << 11) | 389 //dib7000m_write_word(state, 908, (1 << 14) | (3 << 12) |(0 << 11) |
334 dib7000m_write_word(state, 908, (0 << 14) | (3 << 12) |(0 << 11) | 390 clk_cfg1 = (0 << 14) | (3 << 12) |(0 << 11) |
335 (bw->IO_CLK_en_core << 10) | (bw->bypclk_div << 5) | (bw->enable_refdiv << 4) | 391 (bw->IO_CLK_en_core << 10) | (bw->bypclk_div << 5) | (bw->enable_refdiv << 4) |
336 (bw->pll_bypass << 3) | (bw->pll_range << 1) | (bw->pll_reset << 0)); 392 (1 << 3) | (bw->pll_range << 1) | (bw->pll_reset << 0);
393 dib7000m_write_word(state, 908, clk_cfg1);
394 clk_cfg1 = (clk_cfg1 & 0xfff7) | (bw->pll_bypass << 3);
395 dib7000m_write_word(state, 908, clk_cfg1);
337 396
338 // smpl_cfg 397 // smpl_cfg
339 dib7000m_write_word(state, 910, (1 << 12) | (2 << 10) | (bw->modulo << 8) | (bw->ADClkSrc << 7)); 398 dib7000m_write_word(state, 910, (1 << 12) | (2 << 10) | (bw->modulo << 8) | (bw->ADClkSrc << 7));
@@ -344,9 +403,6 @@ static void dib7000mc_reset_pll(struct dib7000m_state *state)
344static int dib7000m_reset_gpio(struct dib7000m_state *st) 403static int dib7000m_reset_gpio(struct dib7000m_state *st)
345{ 404{
346 /* reset the GPIOs */ 405 /* reset the GPIOs */
347 dprintk("-D- gpio dir: %x: gpio val: %x, gpio pwm pos: %x\n",
348 st->cfg.gpio_dir, st->cfg.gpio_val,st->cfg.gpio_pwm_pos);
349
350 dib7000m_write_word(st, 773, st->cfg.gpio_dir); 406 dib7000m_write_word(st, 773, st->cfg.gpio_dir);
351 dib7000m_write_word(st, 774, st->cfg.gpio_val); 407 dib7000m_write_word(st, 774, st->cfg.gpio_val);
352 408
@@ -358,6 +414,107 @@ static int dib7000m_reset_gpio(struct dib7000m_state *st)
358 return 0; 414 return 0;
359} 415}
360 416
417static u16 dib7000m_defaults_common[] =
418
419{
420 // auto search configuration
421 3, 2,
422 0x0004,
423 0x1000,
424 0x0814,
425
426 12, 6,
427 0x001b,
428 0x7740,
429 0x005b,
430 0x8d80,
431 0x01c9,
432 0xc380,
433 0x0000,
434 0x0080,
435 0x0000,
436 0x0090,
437 0x0001,
438 0xd4c0,
439
440 1, 26,
441 0x6680, // P_corm_thres Lock algorithms configuration
442
443 1, 170,
444 0x0410, // P_palf_alpha_regul, P_palf_filter_freeze, P_palf_filter_on
445
446 8, 173,
447 0,
448 0,
449 0,
450 0,
451 0,
452 0,
453 0,
454 0,
455
456 1, 182,
457 8192, // P_fft_nb_to_cut
458
459 2, 195,
460 0x0ccd, // P_pha3_thres
461 0, // P_cti_use_cpe, P_cti_use_prog
462
463 1, 205,
464 0x200f, // P_cspu_regul, P_cspu_win_cut
465
466 5, 214,
467 0x023d, // P_adp_regul_cnt
468 0x00a4, // P_adp_noise_cnt
469 0x00a4, // P_adp_regul_ext
470 0x7ff0, // P_adp_noise_ext
471 0x3ccc, // P_adp_fil
472
473 1, 226,
474 0, // P_2d_byp_ti_num
475
476 1, 255,
477 0x800, // P_equal_thres_wgn
478
479 1, 263,
480 0x0001,
481
482 1, 281,
483 0x0010, // P_fec_*
484
485 1, 294,
486 0x0062, // P_smo_mode, P_smo_rs_discard, P_smo_fifo_flush, P_smo_pid_parse, P_smo_error_discard
487
488 0
489};
490
491static u16 dib7000m_defaults[] =
492
493{
494 /* set ADC level to -16 */
495 11, 76,
496 (1 << 13) - 825 - 117,
497 (1 << 13) - 837 - 117,
498 (1 << 13) - 811 - 117,
499 (1 << 13) - 766 - 117,
500 (1 << 13) - 737 - 117,
501 (1 << 13) - 693 - 117,
502 (1 << 13) - 648 - 117,
503 (1 << 13) - 619 - 117,
504 (1 << 13) - 575 - 117,
505 (1 << 13) - 531 - 117,
506 (1 << 13) - 501 - 117,
507
508 // Tuner IO bank: max drive (14mA)
509 1, 912,
510 0x2c8a,
511
512 1, 1817,
513 1,
514
515 0,
516};
517
361static int dib7000m_demod_reset(struct dib7000m_state *state) 518static int dib7000m_demod_reset(struct dib7000m_state *state)
362{ 519{
363 dib7000m_set_power_mode(state, DIB7000M_POWER_ALL); 520 dib7000m_set_power_mode(state, DIB7000M_POWER_ALL);
@@ -382,22 +539,47 @@ static int dib7000m_demod_reset(struct dib7000m_state *state)
382 dib7000mc_reset_pll(state); 539 dib7000mc_reset_pll(state);
383 540
384 if (dib7000m_reset_gpio(state) != 0) 541 if (dib7000m_reset_gpio(state) != 0)
385 dprintk("-E- GPIO reset was not successful.\n"); 542 dprintk( "GPIO reset was not successful.");
386 543
387 if (dib7000m_set_output_mode(state, OUTMODE_HIGH_Z) != 0) 544 if (dib7000m_set_output_mode(state, OUTMODE_HIGH_Z) != 0)
388 dprintk("-E- OUTPUT_MODE could not be resetted.\n"); 545 dprintk( "OUTPUT_MODE could not be reset.");
389 546
390 /* unforce divstr regardless whether i2c enumeration was done or not */ 547 /* unforce divstr regardless whether i2c enumeration was done or not */
391 dib7000m_write_word(state, 1794, dib7000m_read_word(state, 1794) & ~(1 << 1) ); 548 dib7000m_write_word(state, 1794, dib7000m_read_word(state, 1794) & ~(1 << 1) );
392 549
393 dib7000m_set_bandwidth(&state->demod, BANDWIDTH_8_MHZ); 550 dib7000m_set_bandwidth(state, 8000);
394 551
395 dib7000m_set_adc_state(state, DIBX000_SLOW_ADC_ON); 552 dib7000m_set_adc_state(state, DIBX000_SLOW_ADC_ON);
396 dib7000m_sad_calib(state); 553 dib7000m_sad_calib(state);
397 dib7000m_set_adc_state(state, DIBX000_SLOW_ADC_OFF); 554 dib7000m_set_adc_state(state, DIBX000_SLOW_ADC_OFF);
398 555
556 if (state->cfg.dvbt_mode)
557 dib7000m_write_word(state, 1796, 0x0); // select DVB-T output
558
559 if (state->cfg.mobile_mode)
560 dib7000m_write_word(state, 261 + state->reg_offs, 2);
561 else
562 dib7000m_write_word(state, 224 + state->reg_offs, 1);
563
564 // P_iqc_alpha_pha, P_iqc_alpha_amp, P_iqc_dcc_alpha, ...
565 if(state->cfg.tuner_is_baseband)
566 dib7000m_write_word(state, 36, 0x0755);
567 else
568 dib7000m_write_word(state, 36, 0x1f55);
569
570 // P_divclksel=3 P_divbitsel=1
571 if (state->revision == 0x4000)
572 dib7000m_write_word(state, 909, (3 << 10) | (1 << 6));
573 else
574 dib7000m_write_word(state, 909, (3 << 4) | 1);
575
576 dib7000m_write_tab(state, dib7000m_defaults_common);
577 dib7000m_write_tab(state, dib7000m_defaults);
578
399 dib7000m_set_power_mode(state, DIB7000M_POWER_INTERFACE_ONLY); 579 dib7000m_set_power_mode(state, DIB7000M_POWER_INTERFACE_ONLY);
400 580
581 state->internal_clk = state->cfg.bw->internal;
582
401 return 0; 583 return 0;
402} 584}
403 585
@@ -427,7 +609,7 @@ static int dib7000m_agc_soft_split(struct dib7000m_state *state)
427 (agc - state->current_agc->split.min_thres) / 609 (agc - state->current_agc->split.min_thres) /
428 (state->current_agc->split.max_thres - state->current_agc->split.min_thres); 610 (state->current_agc->split.max_thres - state->current_agc->split.min_thres);
429 611
430 dprintk("AGC split_offset: %d\n",split_offset); 612 dprintk( "AGC split_offset: %d",split_offset);
431 613
432 // P_agc_force_split and P_agc_split_offset 614 // P_agc_force_split and P_agc_split_offset
433 return dib7000m_write_word(state, 103, (dib7000m_read_word(state, 103) & 0xff00) | split_offset); 615 return dib7000m_write_word(state, 103, (dib7000m_read_word(state, 103) & 0xff00) | split_offset);
@@ -435,35 +617,26 @@ static int dib7000m_agc_soft_split(struct dib7000m_state *state)
435 617
436static int dib7000m_update_lna(struct dib7000m_state *state) 618static int dib7000m_update_lna(struct dib7000m_state *state)
437{ 619{
438 int i;
439 u16 dyn_gain; 620 u16 dyn_gain;
440 621
441 // when there is no LNA to program return immediatly 622 if (state->cfg.update_lna) {
442 if (state->cfg.update_lna == NULL) 623 // read dyn_gain here (because it is demod-dependent and not fe)
443 return 0;
444
445 msleep(60);
446 for (i = 0; i < 20; i++) {
447 // read dyn_gain here (because it is demod-dependent and not tuner)
448 dyn_gain = dib7000m_read_word(state, 390); 624 dyn_gain = dib7000m_read_word(state, 390);
449 625
450 dprintk("agc global: %d\n", dyn_gain);
451
452 if (state->cfg.update_lna(&state->demod,dyn_gain)) { // LNA has changed 626 if (state->cfg.update_lna(&state->demod,dyn_gain)) { // LNA has changed
453 dib7000m_restart_agc(state); 627 dib7000m_restart_agc(state);
454 msleep(60); 628 return 1;
455 } else 629 }
456 break;
457 } 630 }
458 return 0; 631 return 0;
459} 632}
460 633
461static void dib7000m_set_agc_config(struct dib7000m_state *state, u8 band) 634static int dib7000m_set_agc_config(struct dib7000m_state *state, u8 band)
462{ 635{
463 struct dibx000_agc_config *agc = NULL; 636 struct dibx000_agc_config *agc = NULL;
464 int i; 637 int i;
465 if (state->current_band == band) 638 if (state->current_band == band && state->current_agc != NULL)
466 return; 639 return 0;
467 state->current_band = band; 640 state->current_band = band;
468 641
469 for (i = 0; i < state->cfg.agc_config_count; i++) 642 for (i = 0; i < state->cfg.agc_config_count; i++)
@@ -473,8 +646,8 @@ static void dib7000m_set_agc_config(struct dib7000m_state *state, u8 band)
473 } 646 }
474 647
475 if (agc == NULL) { 648 if (agc == NULL) {
476 dprintk("-E- No valid AGC configuration found for band 0x%02x\n",band); 649 dprintk( "no valid AGC configuration found for band 0x%02x",band);
477 return; 650 return -EINVAL;
478 } 651 }
479 652
480 state->current_agc = agc; 653 state->current_agc = agc;
@@ -489,7 +662,7 @@ static void dib7000m_set_agc_config(struct dib7000m_state *state, u8 band)
489 dib7000m_write_word(state, 98, (agc->alpha_mant << 5) | agc->alpha_exp); 662 dib7000m_write_word(state, 98, (agc->alpha_mant << 5) | agc->alpha_exp);
490 dib7000m_write_word(state, 99, (agc->beta_mant << 6) | agc->beta_exp); 663 dib7000m_write_word(state, 99, (agc->beta_mant << 6) | agc->beta_exp);
491 664
492 dprintk("-D- WBD: ref: %d, sel: %d, active: %d, alpha: %d\n", 665 dprintk( "WBD: ref: %d, sel: %d, active: %d, alpha: %d",
493 state->wbd_ref != 0 ? state->wbd_ref : agc->wbd_ref, agc->wbd_sel, !agc->perform_agc_softsplit, agc->wbd_sel); 666 state->wbd_ref != 0 ? state->wbd_ref : agc->wbd_ref, agc->wbd_sel, !agc->perform_agc_softsplit, agc->wbd_sel);
494 667
495 /* AGC continued */ 668 /* AGC continued */
@@ -510,7 +683,7 @@ static void dib7000m_set_agc_config(struct dib7000m_state *state, u8 band)
510 683
511 if (state->revision > 0x4000) { // settings for the MC 684 if (state->revision > 0x4000) { // settings for the MC
512 dib7000m_write_word(state, 71, agc->agc1_pt3); 685 dib7000m_write_word(state, 71, agc->agc1_pt3);
513// dprintk("-D- 929: %x %d %d\n", 686// dprintk( "929: %x %d %d",
514// (dib7000m_read_word(state, 929) & 0xffe3) | (agc->wbd_inv << 4) | (agc->wbd_sel << 2), agc->wbd_inv, agc->wbd_sel); 687// (dib7000m_read_word(state, 929) & 0xffe3) | (agc->wbd_inv << 4) | (agc->wbd_sel << 2), agc->wbd_inv, agc->wbd_sel);
515 dib7000m_write_word(state, 929, (dib7000m_read_word(state, 929) & 0xffe3) | (agc->wbd_inv << 4) | (agc->wbd_sel << 2)); 688 dib7000m_write_word(state, 929, (dib7000m_read_word(state, 929) & 0xffe3) | (agc->wbd_inv << 4) | (agc->wbd_sel << 2));
516 } else { 689 } else {
@@ -519,33 +692,160 @@ static void dib7000m_set_agc_config(struct dib7000m_state *state, u8 band)
519 for (i = 0; i < 9; i++) 692 for (i = 0; i < 9; i++)
520 dib7000m_write_word(state, 88 + i, b[i]); 693 dib7000m_write_word(state, 88 + i, b[i]);
521 } 694 }
695 return 0;
522} 696}
523 697
524static void dib7000m_update_timf_freq(struct dib7000m_state *state) 698static void dib7000m_update_timf(struct dib7000m_state *state)
525{ 699{
526 u32 timf = (dib7000m_read_word(state, 436) << 16) | dib7000m_read_word(state, 437); 700 u32 timf = (dib7000m_read_word(state, 436) << 16) | dib7000m_read_word(state, 437);
527 state->timf = timf * 80 / (BW_INDEX_TO_KHZ(state->current_bandwidth) / 100); 701 state->timf = timf * 160 / (state->current_bandwidth / 50);
528 dib7000m_write_word(state, 23, (u16) (timf >> 16)); 702 dib7000m_write_word(state, 23, (u16) (timf >> 16));
529 dib7000m_write_word(state, 24, (u16) (timf & 0xffff)); 703 dib7000m_write_word(state, 24, (u16) (timf & 0xffff));
530 dprintk("-D- Updated timf_frequency: %d (default: %d)\n",state->timf, state->cfg.bw->timf); 704 dprintk( "updated timf_frequency: %d (default: %d)",state->timf, state->timf_default);
705}
706
707static int dib7000m_agc_startup(struct dvb_frontend *demod, struct dvb_frontend_parameters *ch)
708{
709 struct dib7000m_state *state = demod->demodulator_priv;
710 u16 cfg_72 = dib7000m_read_word(state, 72);
711 int ret = -1;
712 u8 *agc_state = &state->agc_state;
713 u8 agc_split;
714
715 switch (state->agc_state) {
716 case 0:
717 // set power-up level: interf+analog+AGC
718 dib7000m_set_power_mode(state, DIB7000M_POWER_INTERF_ANALOG_AGC);
719 dib7000m_set_adc_state(state, DIBX000_ADC_ON);
720
721 if (dib7000m_set_agc_config(state, BAND_OF_FREQUENCY(ch->frequency/1000)) != 0)
722 return -1;
723
724 ret = 7; /* ADC power up */
725 (*agc_state)++;
726 break;
727
728 case 1:
729 /* AGC initialization */
730 if (state->cfg.agc_control)
731 state->cfg.agc_control(&state->demod, 1);
732
733 dib7000m_write_word(state, 75, 32768);
734 if (!state->current_agc->perform_agc_softsplit) {
735 /* we are using the wbd - so slow AGC startup */
736 dib7000m_write_word(state, 103, 1 << 8); /* force 0 split on WBD and restart AGC */
737 (*agc_state)++;
738 ret = 5;
739 } else {
740 /* default AGC startup */
741 (*agc_state) = 4;
742 /* wait AGC rough lock time */
743 ret = 7;
744 }
745
746 dib7000m_restart_agc(state);
747 break;
748
749 case 2: /* fast split search path after 5sec */
750 dib7000m_write_word(state, 72, cfg_72 | (1 << 4)); /* freeze AGC loop */
751 dib7000m_write_word(state, 103, 2 << 9); /* fast split search 0.25kHz */
752 (*agc_state)++;
753 ret = 14;
754 break;
755
756 case 3: /* split search ended */
757 agc_split = (u8)dib7000m_read_word(state, 392); /* store the split value for the next time */
758 dib7000m_write_word(state, 75, dib7000m_read_word(state, 390)); /* set AGC gain start value */
759
760 dib7000m_write_word(state, 72, cfg_72 & ~(1 << 4)); /* std AGC loop */
761 dib7000m_write_word(state, 103, (state->current_agc->wbd_alpha << 9) | agc_split); /* standard split search */
762
763 dib7000m_restart_agc(state);
764
765 dprintk( "SPLIT %p: %hd", demod, agc_split);
766
767 (*agc_state)++;
768 ret = 5;
769 break;
770
771 case 4: /* LNA startup */
772 /* wait AGC accurate lock time */
773 ret = 7;
774
775 if (dib7000m_update_lna(state))
776 // wait only AGC rough lock time
777 ret = 5;
778 else
779 (*agc_state)++;
780 break;
781
782 case 5:
783 dib7000m_agc_soft_split(state);
784
785 if (state->cfg.agc_control)
786 state->cfg.agc_control(&state->demod, 0);
787
788 (*agc_state)++;
789 break;
790
791 default:
792 break;
793 }
794 return ret;
531} 795}
532 796
533static void dib7000m_set_channel(struct dib7000m_state *state, struct dibx000_ofdm_channel *ch, u8 seq) 797static void dib7000m_set_channel(struct dib7000m_state *state, struct dvb_frontend_parameters *ch, u8 seq)
534{ 798{
535 u16 value, est[4]; 799 u16 value, est[4];
536 800
537 dib7000m_set_agc_config(state, BAND_OF_FREQUENCY(ch->RF_kHz)); 801 dib7000m_set_bandwidth(state, BANDWIDTH_TO_KHZ(ch->u.ofdm.bandwidth));
538 802
539 /* nfft, guard, qam, alpha */ 803 /* nfft, guard, qam, alpha */
540 dib7000m_write_word(state, 0, (ch->nfft << 7) | (ch->guard << 5) | (ch->nqam << 3) | (ch->vit_alpha)); 804 value = 0;
805 switch (ch->u.ofdm.transmission_mode) {
806 case TRANSMISSION_MODE_2K: value |= (0 << 7); break;
807 case /* 4K MODE */ 255: value |= (2 << 7); break;
808 default:
809 case TRANSMISSION_MODE_8K: value |= (1 << 7); break;
810 }
811 switch (ch->u.ofdm.guard_interval) {
812 case GUARD_INTERVAL_1_32: value |= (0 << 5); break;
813 case GUARD_INTERVAL_1_16: value |= (1 << 5); break;
814 case GUARD_INTERVAL_1_4: value |= (3 << 5); break;
815 default:
816 case GUARD_INTERVAL_1_8: value |= (2 << 5); break;
817 }
818 switch (ch->u.ofdm.constellation) {
819 case QPSK: value |= (0 << 3); break;
820 case QAM_16: value |= (1 << 3); break;
821 default:
822 case QAM_64: value |= (2 << 3); break;
823 }
824 switch (HIERARCHY_1) {
825 case HIERARCHY_2: value |= 2; break;
826 case HIERARCHY_4: value |= 4; break;
827 default:
828 case HIERARCHY_1: value |= 1; break;
829 }
830 dib7000m_write_word(state, 0, value);
541 dib7000m_write_word(state, 5, (seq << 4)); 831 dib7000m_write_word(state, 5, (seq << 4));
542 832
543 /* P_dintl_native, P_dintlv_inv, P_vit_hrch, P_vit_code_rate, P_vit_select_hp */ 833 /* P_dintl_native, P_dintlv_inv, P_hrch, P_code_rate, P_select_hp */
544 value = (ch->intlv_native << 6) | (ch->vit_hrch << 4) | (ch->vit_select_hp & 0x1); 834 value = 0;
545 if (ch->vit_hrch == 0 || ch->vit_select_hp == 1) 835 if (1 != 0)
546 value |= (ch->vit_code_rate_hp << 1); 836 value |= (1 << 6);
547 else 837 if (ch->u.ofdm.hierarchy_information == 1)
548 value |= (ch->vit_code_rate_lp << 1); 838 value |= (1 << 4);
839 if (1 == 1)
840 value |= 1;
841 switch ((ch->u.ofdm.hierarchy_information == 0 || 1 == 1) ? ch->u.ofdm.code_rate_HP : ch->u.ofdm.code_rate_LP) {
842 case FEC_2_3: value |= (2 << 1); break;
843 case FEC_3_4: value |= (3 << 1); break;
844 case FEC_5_6: value |= (5 << 1); break;
845 case FEC_7_8: value |= (7 << 1); break;
846 default:
847 case FEC_1_2: value |= (1 << 1); break;
848 }
549 dib7000m_write_word(state, 267 + state->reg_offs, value); 849 dib7000m_write_word(state, 267 + state->reg_offs, value);
550 850
551 /* offset loop parameters */ 851 /* offset loop parameters */
@@ -563,32 +863,38 @@ static void dib7000m_set_channel(struct dib7000m_state *state, struct dibx000_of
563 dib7000m_write_word(state, 33, (0 << 4) | 0x5); 863 dib7000m_write_word(state, 33, (0 << 4) | 0x5);
564 864
565 /* P_dvsy_sync_wait */ 865 /* P_dvsy_sync_wait */
566 switch (ch->nfft) { 866 switch (ch->u.ofdm.transmission_mode) {
567 case 1: value = 256; break; 867 case TRANSMISSION_MODE_8K: value = 256; break;
568 case 2: value = 128; break; 868 case /* 4K MODE */ 255: value = 128; break;
569 case 0: 869 case TRANSMISSION_MODE_2K:
570 default: value = 64; break; 870 default: value = 64; break;
571 } 871 }
572 value *= ((1 << (ch->guard)) * 3 / 2); // add 50% SFN margin 872 switch (ch->u.ofdm.guard_interval) {
573 value <<= 4; 873 case GUARD_INTERVAL_1_16: value *= 2; break;
874 case GUARD_INTERVAL_1_8: value *= 4; break;
875 case GUARD_INTERVAL_1_4: value *= 8; break;
876 default:
877 case GUARD_INTERVAL_1_32: value *= 1; break;
878 }
879 state->div_sync_wait = (value * 3) / 2 + 32; // add 50% SFN margin + compensate for one DVSY-fifo TODO
574 880
575 /* deactive the possibility of diversity reception if extended interleave - not for 7000MC */ 881 /* deactive the possibility of diversity reception if extended interleave - not for 7000MC */
576 /* P_dvsy_sync_mode = 0, P_dvsy_sync_enable=1, P_dvcb_comb_mode=2 */ 882 /* P_dvsy_sync_mode = 0, P_dvsy_sync_enable=1, P_dvcb_comb_mode=2 */
577 if (ch->intlv_native || state->revision > 0x4000) 883 if (1 == 1 || state->revision > 0x4000)
578 value |= (1 << 2) | (2 << 0); 884 state->div_force_off = 0;
579 else 885 else
580 value |= 0; 886 state->div_force_off = 1;
581 dib7000m_write_word(state, 266 + state->reg_offs, value); 887 dib7000m_set_diversity_in(&state->demod, state->div_state);
582 888
583 /* channel estimation fine configuration */ 889 /* channel estimation fine configuration */
584 switch (ch->nqam) { 890 switch (ch->u.ofdm.constellation) {
585 case 2: 891 case QAM_64:
586 est[0] = 0x0148; /* P_adp_regul_cnt 0.04 */ 892 est[0] = 0x0148; /* P_adp_regul_cnt 0.04 */
587 est[1] = 0xfff0; /* P_adp_noise_cnt -0.002 */ 893 est[1] = 0xfff0; /* P_adp_noise_cnt -0.002 */
588 est[2] = 0x00a4; /* P_adp_regul_ext 0.02 */ 894 est[2] = 0x00a4; /* P_adp_regul_ext 0.02 */
589 est[3] = 0xfff8; /* P_adp_noise_ext -0.001 */ 895 est[3] = 0xfff8; /* P_adp_noise_ext -0.001 */
590 break; 896 break;
591 case 1: 897 case QAM_16:
592 est[0] = 0x023d; /* P_adp_regul_cnt 0.07 */ 898 est[0] = 0x023d; /* P_adp_regul_cnt 0.07 */
593 est[1] = 0xffdf; /* P_adp_noise_cnt -0.004 */ 899 est[1] = 0xffdf; /* P_adp_noise_cnt -0.004 */
594 est[2] = 0x00a4; /* P_adp_regul_ext 0.02 */ 900 est[2] = 0x00a4; /* P_adp_regul_ext 0.02 */
@@ -604,70 +910,48 @@ static void dib7000m_set_channel(struct dib7000m_state *state, struct dibx000_of
604 for (value = 0; value < 4; value++) 910 for (value = 0; value < 4; value++)
605 dib7000m_write_word(state, 214 + value + state->reg_offs, est[value]); 911 dib7000m_write_word(state, 214 + value + state->reg_offs, est[value]);
606 912
607 // set power-up level: interf+analog+AGC
608 dib7000m_set_power_mode(state, DIB7000M_POWER_INTERF_ANALOG_AGC);
609 dib7000m_set_adc_state(state, DIBX000_ADC_ON);
610
611 msleep(7);
612
613 //AGC initialization
614 if (state->cfg.agc_control)
615 state->cfg.agc_control(&state->demod, 1);
616
617 dib7000m_restart_agc(state);
618
619 // wait AGC rough lock time
620 msleep(5);
621
622 dib7000m_update_lna(state);
623 dib7000m_agc_soft_split(state);
624
625 // wait AGC accurate lock time
626 msleep(7);
627
628 if (state->cfg.agc_control)
629 state->cfg.agc_control(&state->demod, 0);
630
631 // set power-up level: autosearch 913 // set power-up level: autosearch
632 dib7000m_set_power_mode(state, DIB7000M_POWER_COR4_DINTLV_ICIRM_EQUAL_CFROD); 914 dib7000m_set_power_mode(state, DIB7000M_POWER_COR4_DINTLV_ICIRM_EQUAL_CFROD);
633} 915}
634 916
635static int dib7000m_autosearch_start(struct dvb_frontend *demod, struct dibx000_ofdm_channel *ch) 917static int dib7000m_autosearch_start(struct dvb_frontend *demod, struct dvb_frontend_parameters *ch)
636{ 918{
637 struct dib7000m_state *state = demod->demodulator_priv; 919 struct dib7000m_state *state = demod->demodulator_priv;
638 struct dibx000_ofdm_channel auto_ch; 920 struct dvb_frontend_parameters schan;
639 int ret = 0; 921 int ret = 0;
640 u32 value; 922 u32 value, factor;
641 923
642 INIT_OFDM_CHANNEL(&auto_ch); 924 schan = *ch;
643 auto_ch.RF_kHz = ch->RF_kHz; 925
644 auto_ch.Bw = ch->Bw; 926 schan.u.ofdm.constellation = QAM_64;
645 auto_ch.nqam = 2; 927 schan.u.ofdm.guard_interval = GUARD_INTERVAL_1_32;
646 auto_ch.guard = 0; 928 schan.u.ofdm.transmission_mode = TRANSMISSION_MODE_8K;
647 auto_ch.nfft = 1; 929 schan.u.ofdm.code_rate_HP = FEC_2_3;
648 auto_ch.vit_alpha = 1; 930 schan.u.ofdm.code_rate_LP = FEC_3_4;
649 auto_ch.vit_select_hp = 1; 931 schan.u.ofdm.hierarchy_information = 0;
650 auto_ch.vit_code_rate_hp = 2; 932
651 auto_ch.vit_code_rate_lp = 3; 933 dib7000m_set_channel(state, &schan, 7);
652 auto_ch.vit_hrch = 0; 934
653 auto_ch.intlv_native = 1; 935 factor = BANDWIDTH_TO_KHZ(ch->u.ofdm.bandwidth);
654 936 if (factor >= 5000)
655 dib7000m_set_channel(state, &auto_ch, 7); 937 factor = 1;
938 else
939 factor = 6;
656 940
657 // always use the setting for 8MHz here lock_time for 7,6 MHz are longer 941 // always use the setting for 8MHz here lock_time for 7,6 MHz are longer
658 value = 30 * state->cfg.bw->internal; 942 value = 30 * state->internal_clk * factor;
659 ret |= dib7000m_write_word(state, 6, (u16) ((value >> 16) & 0xffff)); // lock0 wait time 943 ret |= dib7000m_write_word(state, 6, (u16) ((value >> 16) & 0xffff)); // lock0 wait time
660 ret |= dib7000m_write_word(state, 7, (u16) (value & 0xffff)); // lock0 wait time 944 ret |= dib7000m_write_word(state, 7, (u16) (value & 0xffff)); // lock0 wait time
661 value = 100 * state->cfg.bw->internal; 945 value = 100 * state->internal_clk * factor;
662 ret |= dib7000m_write_word(state, 8, (u16) ((value >> 16) & 0xffff)); // lock1 wait time 946 ret |= dib7000m_write_word(state, 8, (u16) ((value >> 16) & 0xffff)); // lock1 wait time
663 ret |= dib7000m_write_word(state, 9, (u16) (value & 0xffff)); // lock1 wait time 947 ret |= dib7000m_write_word(state, 9, (u16) (value & 0xffff)); // lock1 wait time
664 value = 500 * state->cfg.bw->internal; 948 value = 500 * state->internal_clk * factor;
665 ret |= dib7000m_write_word(state, 10, (u16) ((value >> 16) & 0xffff)); // lock2 wait time 949 ret |= dib7000m_write_word(state, 10, (u16) ((value >> 16) & 0xffff)); // lock2 wait time
666 ret |= dib7000m_write_word(state, 11, (u16) (value & 0xffff)); // lock2 wait time 950 ret |= dib7000m_write_word(state, 11, (u16) (value & 0xffff)); // lock2 wait time
667 951
668 // start search 952 // start search
669 value = dib7000m_read_word(state, 0); 953 value = dib7000m_read_word(state, 0);
670 ret |= dib7000m_write_word(state, 0, value | (1 << 9)); 954 ret |= dib7000m_write_word(state, 0, (u16) (value | (1 << 9)));
671 955
672 /* clear n_irq_pending */ 956 /* clear n_irq_pending */
673 if (state->revision == 0x4000) 957 if (state->revision == 0x4000)
@@ -685,12 +969,12 @@ static int dib7000m_autosearch_irq(struct dib7000m_state *state, u16 reg)
685 u16 irq_pending = dib7000m_read_word(state, reg); 969 u16 irq_pending = dib7000m_read_word(state, reg);
686 970
687 if (irq_pending & 0x1) { // failed 971 if (irq_pending & 0x1) { // failed
688 dprintk("#\n"); 972 dprintk( "autosearch failed");
689 return 1; 973 return 1;
690 } 974 }
691 975
692 if (irq_pending & 0x2) { // succeeded 976 if (irq_pending & 0x2) { // succeeded
693 dprintk("!\n"); 977 dprintk( "autosearch succeeded");
694 return 2; 978 return 2;
695 } 979 }
696 return 0; // still pending 980 return 0; // still pending
@@ -705,7 +989,7 @@ static int dib7000m_autosearch_is_irq(struct dvb_frontend *demod)
705 return dib7000m_autosearch_irq(state, 537); 989 return dib7000m_autosearch_irq(state, 537);
706} 990}
707 991
708static int dib7000m_tune(struct dvb_frontend *demod, struct dibx000_ofdm_channel *ch) 992static int dib7000m_tune(struct dvb_frontend *demod, struct dvb_frontend_parameters *ch)
709{ 993{
710 struct dib7000m_state *state = demod->demodulator_priv; 994 struct dib7000m_state *state = demod->demodulator_priv;
711 int ret = 0; 995 int ret = 0;
@@ -722,182 +1006,103 @@ static int dib7000m_tune(struct dvb_frontend *demod, struct dibx000_ofdm_channel
722 ret |= dib7000m_write_word(state, 898, 0x0000); 1006 ret |= dib7000m_write_word(state, 898, 0x0000);
723 msleep(45); 1007 msleep(45);
724 1008
725 ret |= dib7000m_set_power_mode(state, DIB7000M_POWER_COR4_CRY_ESRAM_MOUT_NUD); 1009 dib7000m_set_power_mode(state, DIB7000M_POWER_COR4_CRY_ESRAM_MOUT_NUD);
726 /* P_ctrl_inh_cor=0, P_ctrl_alpha_cor=4, P_ctrl_inh_isi=0, P_ctrl_alpha_isi=3, P_ctrl_inh_cor4=1, P_ctrl_alpha_cor4=3 */ 1010 /* P_ctrl_inh_cor=0, P_ctrl_alpha_cor=4, P_ctrl_inh_isi=0, P_ctrl_alpha_isi=3, P_ctrl_inh_cor4=1, P_ctrl_alpha_cor4=3 */
727 ret |= dib7000m_write_word(state, 29, (0 << 14) | (4 << 10) | (0 << 9) | (3 << 5) | (1 << 4) | (0x3)); 1011 ret |= dib7000m_write_word(state, 29, (0 << 14) | (4 << 10) | (0 << 9) | (3 << 5) | (1 << 4) | (0x3));
728 1012
729 // never achieved a lock with that bandwidth so far - wait for timfreq to update 1013 // never achieved a lock before - wait for timfreq to update
730 if (state->timf == 0) 1014 if (state->timf == 0)
731 msleep(200); 1015 msleep(200);
732 1016
733 //dump_reg(state); 1017 //dump_reg(state);
734 /* P_timf_alpha, P_corm_alpha=6, P_corm_thres=0x80 */ 1018 /* P_timf_alpha, P_corm_alpha=6, P_corm_thres=0x80 */
735 value = (6 << 8) | 0x80; 1019 value = (6 << 8) | 0x80;
736 switch (ch->nfft) { 1020 switch (ch->u.ofdm.transmission_mode) {
737 case 0: value |= (7 << 12); break; 1021 case TRANSMISSION_MODE_2K: value |= (7 << 12); break;
738 case 1: value |= (9 << 12); break; 1022 case /* 4K MODE */ 255: value |= (8 << 12); break;
739 case 2: value |= (8 << 12); break; 1023 default:
1024 case TRANSMISSION_MODE_8K: value |= (9 << 12); break;
740 } 1025 }
741 ret |= dib7000m_write_word(state, 26, value); 1026 ret |= dib7000m_write_word(state, 26, value);
742 1027
743 /* P_ctrl_freeze_pha_shift=0, P_ctrl_pha_off_max */ 1028 /* P_ctrl_freeze_pha_shift=0, P_ctrl_pha_off_max */
744 value = (0 << 4); 1029 value = (0 << 4);
745 switch (ch->nfft) { 1030 switch (ch->u.ofdm.transmission_mode) {
746 case 0: value |= 0x6; break; 1031 case TRANSMISSION_MODE_2K: value |= 0x6; break;
747 case 1: value |= 0x8; break; 1032 case /* 4K MODE */ 255: value |= 0x7; break;
748 case 2: value |= 0x7; break; 1033 default:
1034 case TRANSMISSION_MODE_8K: value |= 0x8; break;
749 } 1035 }
750 ret |= dib7000m_write_word(state, 32, value); 1036 ret |= dib7000m_write_word(state, 32, value);
751 1037
752 /* P_ctrl_sfreq_inh=0, P_ctrl_sfreq_step */ 1038 /* P_ctrl_sfreq_inh=0, P_ctrl_sfreq_step */
753 value = (0 << 4); 1039 value = (0 << 4);
754 switch (ch->nfft) { 1040 switch (ch->u.ofdm.transmission_mode) {
755 case 0: value |= 0x6; break; 1041 case TRANSMISSION_MODE_2K: value |= 0x6; break;
756 case 1: value |= 0x8; break; 1042 case /* 4K MODE */ 255: value |= 0x7; break;
757 case 2: value |= 0x7; break; 1043 default:
1044 case TRANSMISSION_MODE_8K: value |= 0x8; break;
758 } 1045 }
759 ret |= dib7000m_write_word(state, 33, value); 1046 ret |= dib7000m_write_word(state, 33, value);
760 1047
761 // we achieved a lock - it's time to update the osc freq 1048 // we achieved a lock - it's time to update the timf freq
762 if ((dib7000m_read_word(state, 535) >> 6) & 0x1) 1049 if ((dib7000m_read_word(state, 535) >> 6) & 0x1)
763 dib7000m_update_timf_freq(state); 1050 dib7000m_update_timf(state);
764 1051
1052 dib7000m_set_bandwidth(state, BANDWIDTH_TO_KHZ(ch->u.ofdm.bandwidth));
765 return ret; 1053 return ret;
766} 1054}
767 1055
768static int dib7000m_init(struct dvb_frontend *demod) 1056static int dib7000m_wakeup(struct dvb_frontend *demod)
769{ 1057{
770 struct dib7000m_state *state = demod->demodulator_priv; 1058 struct dib7000m_state *state = demod->demodulator_priv;
771 int ret = 0;
772 u8 o = state->reg_offs;
773 1059
774 dib7000m_set_power_mode(state, DIB7000M_POWER_ALL); 1060 dib7000m_set_power_mode(state, DIB7000M_POWER_ALL);
775 1061
776 if (dib7000m_set_adc_state(state, DIBX000_SLOW_ADC_ON) != 0) 1062 if (dib7000m_set_adc_state(state, DIBX000_SLOW_ADC_ON) != 0)
777 dprintk("-E- could not start Slow ADC\n"); 1063 dprintk( "could not start Slow ADC");
778
779 if (state->cfg.dvbt_mode)
780 dib7000m_write_word(state, 1796, 0x0); // select DVB-T output
781
782 if (state->cfg.mobile_mode)
783 ret |= dib7000m_write_word(state, 261 + o, 2);
784 else
785 ret |= dib7000m_write_word(state, 224 + o, 1);
786
787 ret |= dib7000m_write_word(state, 173 + o, 0);
788 ret |= dib7000m_write_word(state, 174 + o, 0);
789 ret |= dib7000m_write_word(state, 175 + o, 0);
790 ret |= dib7000m_write_word(state, 176 + o, 0);
791 ret |= dib7000m_write_word(state, 177 + o, 0);
792 ret |= dib7000m_write_word(state, 178 + o, 0);
793 ret |= dib7000m_write_word(state, 179 + o, 0);
794 ret |= dib7000m_write_word(state, 180 + o, 0);
795
796 // P_corm_thres Lock algorithms configuration
797 ret |= dib7000m_write_word(state, 26, 0x6680);
798
799 // P_palf_alpha_regul, P_palf_filter_freeze, P_palf_filter_on
800 ret |= dib7000m_write_word(state, 170 + o, 0x0410);
801 // P_fft_nb_to_cut
802 ret |= dib7000m_write_word(state, 182 + o, 8192);
803 // P_pha3_thres
804 ret |= dib7000m_write_word(state, 195 + o, 0x0ccd);
805 // P_cti_use_cpe, P_cti_use_prog
806 ret |= dib7000m_write_word(state, 196 + o, 0);
807 // P_cspu_regul, P_cspu_win_cut
808 ret |= dib7000m_write_word(state, 205 + o, 0x200f);
809 // P_adp_regul_cnt
810 ret |= dib7000m_write_word(state, 214 + o, 0x023d);
811 // P_adp_noise_cnt
812 ret |= dib7000m_write_word(state, 215 + o, 0x00a4);
813 // P_adp_regul_ext
814 ret |= dib7000m_write_word(state, 216 + o, 0x00a4);
815 // P_adp_noise_ext
816 ret |= dib7000m_write_word(state, 217 + o, 0x7ff0);
817 // P_adp_fil
818 ret |= dib7000m_write_word(state, 218 + o, 0x3ccc);
819
820 // P_2d_byp_ti_num
821 ret |= dib7000m_write_word(state, 226 + o, 0);
822
823 // P_fec_*
824 ret |= dib7000m_write_word(state, 281 + o, 0x0010);
825 // P_smo_mode, P_smo_rs_discard, P_smo_fifo_flush, P_smo_pid_parse, P_smo_error_discard
826 ret |= dib7000m_write_word(state, 294 + o,0x0062);
827
828 // P_iqc_alpha_pha, P_iqc_alpha_amp, P_iqc_dcc_alpha, ...
829 if(state->cfg.tuner_is_baseband)
830 ret |= dib7000m_write_word(state, 36, 0x0755);
831 else
832 ret |= dib7000m_write_word(state, 36, 0x1f55);
833
834 // auto search configuration
835 ret |= dib7000m_write_word(state, 2, 0x0004);
836 ret |= dib7000m_write_word(state, 3, 0x1000);
837 ret |= dib7000m_write_word(state, 4, 0x0814);
838 ret |= dib7000m_write_word(state, 6, 0x001b);
839 ret |= dib7000m_write_word(state, 7, 0x7740);
840 ret |= dib7000m_write_word(state, 8, 0x005b);
841 ret |= dib7000m_write_word(state, 9, 0x8d80);
842 ret |= dib7000m_write_word(state, 10, 0x01c9);
843 ret |= dib7000m_write_word(state, 11, 0xc380);
844 ret |= dib7000m_write_word(state, 12, 0x0000);
845 ret |= dib7000m_write_word(state, 13, 0x0080);
846 ret |= dib7000m_write_word(state, 14, 0x0000);
847 ret |= dib7000m_write_word(state, 15, 0x0090);
848 ret |= dib7000m_write_word(state, 16, 0x0001);
849 ret |= dib7000m_write_word(state, 17, 0xd4c0);
850 ret |= dib7000m_write_word(state, 263 + o,0x0001);
851
852 // P_divclksel=3 P_divbitsel=1
853 if (state->revision == 0x4000)
854 dib7000m_write_word(state, 909, (3 << 10) | (1 << 6));
855 else
856 dib7000m_write_word(state, 909, (3 << 4) | 1);
857
858 // Tuner IO bank: max drive (14mA)
859 ret |= dib7000m_write_word(state, 912 ,0x2c8a);
860 1064
861 ret |= dib7000m_write_word(state, 1817, 1); 1065 return 0;
862
863 return ret;
864} 1066}
865 1067
866static int dib7000m_sleep(struct dvb_frontend *demod) 1068static int dib7000m_sleep(struct dvb_frontend *demod)
867{ 1069{
868 struct dib7000m_state *st = demod->demodulator_priv; 1070 struct dib7000m_state *st = demod->demodulator_priv;
869 dib7000m_set_output_mode(st, OUTMODE_HIGH_Z); 1071 dib7000m_set_output_mode(st, OUTMODE_HIGH_Z);
870 return dib7000m_set_power_mode(st, DIB7000M_POWER_INTERFACE_ONLY) | 1072 dib7000m_set_power_mode(st, DIB7000M_POWER_INTERFACE_ONLY);
871 dib7000m_set_adc_state(st, DIBX000_SLOW_ADC_OFF) | 1073 return dib7000m_set_adc_state(st, DIBX000_SLOW_ADC_OFF) |
872 dib7000m_set_adc_state(st, DIBX000_ADC_OFF); 1074 dib7000m_set_adc_state(st, DIBX000_ADC_OFF);
873} 1075}
874 1076
875static int dib7000m_identify(struct dib7000m_state *state) 1077static int dib7000m_identify(struct dib7000m_state *state)
876{ 1078{
877 u16 value; 1079 u16 value;
1080
878 if ((value = dib7000m_read_word(state, 896)) != 0x01b3) { 1081 if ((value = dib7000m_read_word(state, 896)) != 0x01b3) {
879 dprintk("-E- DiB7000M: wrong Vendor ID (read=0x%x)\n",value); 1082 dprintk( "wrong Vendor ID (0x%x)",value);
880 return -EREMOTEIO; 1083 return -EREMOTEIO;
881 } 1084 }
882 1085
883 state->revision = dib7000m_read_word(state, 897); 1086 state->revision = dib7000m_read_word(state, 897);
884 if (state->revision != 0x4000 && 1087 if (state->revision != 0x4000 &&
885 state->revision != 0x4001 && 1088 state->revision != 0x4001 &&
886 state->revision != 0x4002) { 1089 state->revision != 0x4002 &&
887 dprintk("-E- DiB7000M: wrong Device ID (%x)\n",value); 1090 state->revision != 0x4003) {
1091 dprintk( "wrong Device ID (0x%x)",value);
888 return -EREMOTEIO; 1092 return -EREMOTEIO;
889 } 1093 }
890 1094
891 /* protect this driver to be used with 7000PC */ 1095 /* protect this driver to be used with 7000PC */
892 if (state->revision == 0x4000 && dib7000m_read_word(state, 769) == 0x4000) { 1096 if (state->revision == 0x4000 && dib7000m_read_word(state, 769) == 0x4000) {
893 dprintk("-E- DiB7000M: this driver does not work with DiB7000PC\n"); 1097 dprintk( "this driver does not work with DiB7000PC");
894 return -EREMOTEIO; 1098 return -EREMOTEIO;
895 } 1099 }
896 1100
897 switch (state->revision) { 1101 switch (state->revision) {
898 case 0x4000: dprintk("-I- found DiB7000MA/PA/MB/PB\n"); break; 1102 case 0x4000: dprintk( "found DiB7000MA/PA/MB/PB"); break;
899 case 0x4001: state->reg_offs = 1; dprintk("-I- found DiB7000HC\n"); break; 1103 case 0x4001: state->reg_offs = 1; dprintk( "found DiB7000HC"); break;
900 case 0x4002: state->reg_offs = 1; dprintk("-I- found DiB7000MC\n"); break; 1104 case 0x4002: state->reg_offs = 1; dprintk( "found DiB7000MC"); break;
1105 case 0x4003: state->reg_offs = 1; dprintk( "found DiB9000"); break;
901 } 1106 }
902 1107
903 return 0; 1108 return 0;
@@ -966,41 +1171,45 @@ static int dib7000m_set_frontend(struct dvb_frontend* fe,
966 struct dvb_frontend_parameters *fep) 1171 struct dvb_frontend_parameters *fep)
967{ 1172{
968 struct dib7000m_state *state = fe->demodulator_priv; 1173 struct dib7000m_state *state = fe->demodulator_priv;
969 struct dibx000_ofdm_channel ch; 1174 int time;
970
971 INIT_OFDM_CHANNEL(&ch);
972 FEP2DIB(fep,&ch);
973 1175
974 state->current_bandwidth = fep->u.ofdm.bandwidth; 1176 state->current_bandwidth = fep->u.ofdm.bandwidth;
975 dib7000m_set_bandwidth(fe, fep->u.ofdm.bandwidth); 1177 dib7000m_set_bandwidth(state, BANDWIDTH_TO_KHZ(fep->u.ofdm.bandwidth));
976 1178
977 if (fe->ops.tuner_ops.set_params) 1179 if (fe->ops.tuner_ops.set_params)
978 fe->ops.tuner_ops.set_params(fe, fep); 1180 fe->ops.tuner_ops.set_params(fe, fep);
979 1181
1182 /* start up the AGC */
1183 state->agc_state = 0;
1184 do {
1185 time = dib7000m_agc_startup(fe, fep);
1186 if (time != -1)
1187 msleep(time);
1188 } while (time != -1);
1189
980 if (fep->u.ofdm.transmission_mode == TRANSMISSION_MODE_AUTO || 1190 if (fep->u.ofdm.transmission_mode == TRANSMISSION_MODE_AUTO ||
981 fep->u.ofdm.guard_interval == GUARD_INTERVAL_AUTO || 1191 fep->u.ofdm.guard_interval == GUARD_INTERVAL_AUTO ||
982 fep->u.ofdm.constellation == QAM_AUTO || 1192 fep->u.ofdm.constellation == QAM_AUTO ||
983 fep->u.ofdm.code_rate_HP == FEC_AUTO) { 1193 fep->u.ofdm.code_rate_HP == FEC_AUTO) {
984 int i = 800, found; 1194 int i = 800, found;
985 1195
986 dib7000m_autosearch_start(fe, &ch); 1196 dib7000m_autosearch_start(fe, fep);
987 do { 1197 do {
988 msleep(1); 1198 msleep(1);
989 found = dib7000m_autosearch_is_irq(fe); 1199 found = dib7000m_autosearch_is_irq(fe);
990 } while (found == 0 && i--); 1200 } while (found == 0 && i--);
991 1201
992 dprintk("autosearch returns: %d\n",found); 1202 dprintk("autosearch returns: %d",found);
993 if (found == 0 || found == 1) 1203 if (found == 0 || found == 1)
994 return 0; // no channel found 1204 return 0; // no channel found
995 1205
996 dib7000m_get_frontend(fe, fep); 1206 dib7000m_get_frontend(fe, fep);
997 FEP2DIB(fep, &ch);
998 } 1207 }
999 1208
1000 /* make this a config parameter */ 1209 /* make this a config parameter */
1001 dib7000m_set_output_mode(state, OUTMODE_MPEG2_FIFO); 1210 dib7000m_set_output_mode(state, OUTMODE_MPEG2_FIFO);
1002 1211
1003 return dib7000m_tune(fe, &ch); 1212 return dib7000m_tune(fe, fep);
1004} 1213}
1005 1214
1006static int dib7000m_read_status(struct dvb_frontend *fe, fe_status_t *stat) 1215static int dib7000m_read_status(struct dvb_frontend *fe, fe_status_t *stat)
@@ -1087,7 +1296,7 @@ int dib7000m_i2c_enumeration(struct i2c_adapter *i2c, int no_of_demods, u8 defau
1087 if (dib7000m_identify(&st) != 0) { 1296 if (dib7000m_identify(&st) != 0) {
1088 st.i2c_addr = default_addr; 1297 st.i2c_addr = default_addr;
1089 if (dib7000m_identify(&st) != 0) { 1298 if (dib7000m_identify(&st) != 0) {
1090 dprintk("DiB7000M #%d: not identified\n", k); 1299 dprintk("DiB7000M #%d: not identified", k);
1091 return -EIO; 1300 return -EIO;
1092 } 1301 }
1093 } 1302 }
@@ -1100,7 +1309,7 @@ int dib7000m_i2c_enumeration(struct i2c_adapter *i2c, int no_of_demods, u8 defau
1100 /* set new i2c address and force divstart */ 1309 /* set new i2c address and force divstart */
1101 dib7000m_write_word(&st, 1794, (new_addr << 2) | 0x2); 1310 dib7000m_write_word(&st, 1794, (new_addr << 2) | 0x2);
1102 1311
1103 dprintk("IC %d initialized (to i2c_address 0x%x)\n", k, new_addr); 1312 dprintk("IC %d initialized (to i2c_address 0x%x)", k, new_addr);
1104 } 1313 }
1105 1314
1106 for (k = 0; k < no_of_demods; k++) { 1315 for (k = 0; k < no_of_demods; k++) {
@@ -1135,6 +1344,8 @@ struct dvb_frontend * dib7000m_attach(struct i2c_adapter *i2c_adap, u8 i2c_addr,
1135 demod->demodulator_priv = st; 1344 demod->demodulator_priv = st;
1136 memcpy(&st->demod.ops, &dib7000m_ops, sizeof(struct dvb_frontend_ops)); 1345 memcpy(&st->demod.ops, &dib7000m_ops, sizeof(struct dvb_frontend_ops));
1137 1346
1347 st->timf_default = cfg->bw->timf;
1348
1138 if (dib7000m_identify(st) != 0) 1349 if (dib7000m_identify(st) != 0)
1139 goto error; 1350 goto error;
1140 1351
@@ -1172,7 +1383,7 @@ static struct dvb_frontend_ops dib7000m_ops = {
1172 1383
1173 .release = dib7000m_release, 1384 .release = dib7000m_release,
1174 1385
1175 .init = dib7000m_init, 1386 .init = dib7000m_wakeup,
1176 .sleep = dib7000m_sleep, 1387 .sleep = dib7000m_sleep,
1177 1388
1178 .set_frontend = dib7000m_set_frontend, 1389 .set_frontend = dib7000m_set_frontend,
diff --git a/drivers/media/dvb/frontends/dib7000p.c b/drivers/media/dvb/frontends/dib7000p.c
index aece458cfe12..f45bcfc51cf8 100644
--- a/drivers/media/dvb/frontends/dib7000p.c
+++ b/drivers/media/dvb/frontends/dib7000p.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Linux-DVB Driver for DiBcom's second generation DiB7000P (PC). 2 * Linux-DVB Driver for DiBcom's second generation DiB7000P (PC).
3 * 3 *
4 * Copyright (C) 2005-6 DiBcom (http://www.dibcom.fr/) 4 * Copyright (C) 2005-7 DiBcom (http://www.dibcom.fr/)
5 * 5 *
6 * This program is free software; you can redistribute it and/or 6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as 7 * modify it under the terms of the GNU General Public License as
@@ -18,7 +18,11 @@ static int debug;
18module_param(debug, int, 0644); 18module_param(debug, int, 0644);
19MODULE_PARM_DESC(debug, "turn on debugging (default: 0)"); 19MODULE_PARM_DESC(debug, "turn on debugging (default: 0)");
20 20
21#define dprintk(args...) do { if (debug) { printk(KERN_DEBUG "DiB7000P:"); printk(args); } } while (0) 21static int buggy_sfn_workaround;
22module_param(buggy_sfn_workaround, int, 0644);
23MODULE_PARM_DESC(buggy_sfn_workaround, "Enable work-around for buggy SFNs (default: 0)");
24
25#define dprintk(args...) do { if (debug) { printk(KERN_DEBUG "DiB7000P: "); printk(args); printk("\n"); } } while (0)
22 26
23struct dib7000p_state { 27struct dib7000p_state {
24 struct dvb_frontend demod; 28 struct dvb_frontend demod;
@@ -36,12 +40,21 @@ struct dib7000p_state {
36 struct dibx000_agc_config *current_agc; 40 struct dibx000_agc_config *current_agc;
37 u32 timf; 41 u32 timf;
38 42
43 u8 div_force_off : 1;
44 u8 div_state : 1;
45 u16 div_sync_wait;
46
47 u8 agc_state;
48
39 u16 gpio_dir; 49 u16 gpio_dir;
40 u16 gpio_val; 50 u16 gpio_val;
51
52 u8 sfn_workaround_active :1;
41}; 53};
42 54
43enum dib7000p_power_mode { 55enum dib7000p_power_mode {
44 DIB7000P_POWER_ALL = 0, 56 DIB7000P_POWER_ALL = 0,
57 DIB7000P_POWER_ANALOG_ADC,
45 DIB7000P_POWER_INTERFACE_ONLY, 58 DIB7000P_POWER_INTERFACE_ONLY,
46}; 59};
47 60
@@ -55,7 +68,7 @@ static u16 dib7000p_read_word(struct dib7000p_state *state, u16 reg)
55 }; 68 };
56 69
57 if (i2c_transfer(state->i2c_adap, msg, 2) != 2) 70 if (i2c_transfer(state->i2c_adap, msg, 2) != 2)
58 dprintk("i2c read error on %d\n",reg); 71 dprintk("i2c read error on %d",reg);
59 72
60 return (rb[0] << 8) | rb[1]; 73 return (rb[0] << 8) | rb[1];
61} 74}
@@ -71,6 +84,22 @@ static int dib7000p_write_word(struct dib7000p_state *state, u16 reg, u16 val)
71 }; 84 };
72 return i2c_transfer(state->i2c_adap, &msg, 1) != 1 ? -EREMOTEIO : 0; 85 return i2c_transfer(state->i2c_adap, &msg, 1) != 1 ? -EREMOTEIO : 0;
73} 86}
87static void dib7000p_write_tab(struct dib7000p_state *state, u16 *buf)
88{
89 u16 l = 0, r, *n;
90 n = buf;
91 l = *n++;
92 while (l) {
93 r = *n++;
94
95 do {
96 dib7000p_write_word(state, r, *n++);
97 r++;
98 } while (--l);
99 l = *n++;
100 }
101}
102
74static int dib7000p_set_output_mode(struct dib7000p_state *state, int mode) 103static int dib7000p_set_output_mode(struct dib7000p_state *state, int mode)
75{ 104{
76 int ret = 0; 105 int ret = 0;
@@ -80,7 +109,7 @@ static int dib7000p_set_output_mode(struct dib7000p_state *state, int mode)
80 fifo_threshold = 1792; 109 fifo_threshold = 1792;
81 smo_mode = (dib7000p_read_word(state, 235) & 0x0010) | (1 << 1); 110 smo_mode = (dib7000p_read_word(state, 235) & 0x0010) | (1 << 1);
82 111
83 dprintk("-I- Setting output mode for demod %p to %d\n", 112 dprintk( "setting output mode for demod %p to %d",
84 &state->demod, mode); 113 &state->demod, mode);
85 114
86 switch (mode) { 115 switch (mode) {
@@ -104,11 +133,14 @@ static int dib7000p_set_output_mode(struct dib7000p_state *state, int mode)
104 fifo_threshold = 512; 133 fifo_threshold = 512;
105 outreg = (1 << 10) | (5 << 6); 134 outreg = (1 << 10) | (5 << 6);
106 break; 135 break;
136 case OUTMODE_ANALOG_ADC:
137 outreg = (1 << 10) | (3 << 6);
138 break;
107 case OUTMODE_HIGH_Z: // disable 139 case OUTMODE_HIGH_Z: // disable
108 outreg = 0; 140 outreg = 0;
109 break; 141 break;
110 default: 142 default:
111 dprintk("Unhandled output_mode passed to be set for demod %p\n",&state->demod); 143 dprintk( "Unhandled output_mode passed to be set for demod %p",&state->demod);
112 break; 144 break;
113 } 145 }
114 146
@@ -122,6 +154,30 @@ static int dib7000p_set_output_mode(struct dib7000p_state *state, int mode)
122 return ret; 154 return ret;
123} 155}
124 156
157static int dib7000p_set_diversity_in(struct dvb_frontend *demod, int onoff)
158{
159 struct dib7000p_state *state = demod->demodulator_priv;
160
161 if (state->div_force_off) {
162 dprintk( "diversity combination deactivated - forced by COFDM parameters");
163 onoff = 0;
164 }
165 state->div_state = (u8)onoff;
166
167 if (onoff) {
168 dib7000p_write_word(state, 204, 6);
169 dib7000p_write_word(state, 205, 16);
170 /* P_dvsy_sync_mode = 0, P_dvsy_sync_enable=1, P_dvcb_comb_mode=2 */
171 dib7000p_write_word(state, 207, (state->div_sync_wait << 4) | (1 << 2) | (2 << 0));
172 } else {
173 dib7000p_write_word(state, 204, 1);
174 dib7000p_write_word(state, 205, 0);
175 dib7000p_write_word(state, 207, 0);
176 }
177
178 return 0;
179}
180
125static int dib7000p_set_power_mode(struct dib7000p_state *state, enum dib7000p_power_mode mode) 181static int dib7000p_set_power_mode(struct dib7000p_state *state, enum dib7000p_power_mode mode)
126{ 182{
127 /* by default everything is powered off */ 183 /* by default everything is powered off */
@@ -134,10 +190,21 @@ static int dib7000p_set_power_mode(struct dib7000p_state *state, enum dib7000p_p
134 case DIB7000P_POWER_ALL: 190 case DIB7000P_POWER_ALL:
135 reg_774 = 0x0000; reg_775 = 0x0000; reg_776 = 0x0; reg_899 = 0x0; reg_1280 &= 0x01ff; 191 reg_774 = 0x0000; reg_775 = 0x0000; reg_776 = 0x0; reg_899 = 0x0; reg_1280 &= 0x01ff;
136 break; 192 break;
193
194 case DIB7000P_POWER_ANALOG_ADC:
195 /* dem, cfg, iqc, sad, agc */
196 reg_774 &= ~((1 << 15) | (1 << 14) | (1 << 11) | (1 << 10) | (1 << 9));
197 /* nud */
198 reg_776 &= ~((1 << 0));
199 /* Dout */
200 reg_1280 &= ~((1 << 11));
201 /* fall through wanted to enable the interfaces */
202
137 /* just leave power on the control-interfaces: GPIO and (I2C or SDIO) */ 203 /* just leave power on the control-interfaces: GPIO and (I2C or SDIO) */
138 case DIB7000P_POWER_INTERFACE_ONLY: /* TODO power up either SDIO or I2C */ 204 case DIB7000P_POWER_INTERFACE_ONLY: /* TODO power up either SDIO or I2C */
139 reg_1280 &= ~((1 << 14) | (1 << 13) | (1 << 12) | (1 << 10)); 205 reg_1280 &= ~((1 << 14) | (1 << 13) | (1 << 12) | (1 << 10));
140 break; 206 break;
207
141/* TODO following stuff is just converted from the dib7000-driver - check when is used what */ 208/* TODO following stuff is just converted from the dib7000-driver - check when is used what */
142 } 209 }
143 210
@@ -188,34 +255,31 @@ static void dib7000p_set_adc_state(struct dib7000p_state *state, enum dibx000_ad
188 break; 255 break;
189 } 256 }
190 257
191// dprintk("908: %x, 909: %x\n", reg_908, reg_909); 258// dprintk( "908: %x, 909: %x\n", reg_908, reg_909);
192 259
193 dib7000p_write_word(state, 908, reg_908); 260 dib7000p_write_word(state, 908, reg_908);
194 dib7000p_write_word(state, 909, reg_909); 261 dib7000p_write_word(state, 909, reg_909);
195} 262}
196 263
197static int dib7000p_set_bandwidth(struct dvb_frontend *demod, u8 BW_Idx) 264static int dib7000p_set_bandwidth(struct dib7000p_state *state, u32 bw)
198{ 265{
199 struct dib7000p_state *state = demod->demodulator_priv;
200 u32 timf; 266 u32 timf;
201 267
202 // store the current bandwidth for later use 268 // store the current bandwidth for later use
203 state->current_bandwidth = BW_Idx; 269 state->current_bandwidth = bw;
204 270
205 if (state->timf == 0) { 271 if (state->timf == 0) {
206 dprintk("-D- Using default timf\n"); 272 dprintk( "using default timf");
207 timf = state->cfg.bw->timf; 273 timf = state->cfg.bw->timf;
208 } else { 274 } else {
209 dprintk("-D- Using updated timf\n"); 275 dprintk( "using updated timf");
210 timf = state->timf; 276 timf = state->timf;
211 } 277 }
212 278
213 timf = timf * (BW_INDEX_TO_KHZ(BW_Idx) / 100) / 80; 279 timf = timf * (bw / 50) / 160;
214
215 dprintk("timf: %d\n",timf);
216 280
217 dib7000p_write_word(state, 23, (timf >> 16) & 0xffff); 281 dib7000p_write_word(state, 23, (u16) ((timf >> 16) & 0xffff));
218 dib7000p_write_word(state, 24, (timf ) & 0xffff); 282 dib7000p_write_word(state, 24, (u16) ((timf ) & 0xffff));
219 283
220 return 0; 284 return 0;
221} 285}
@@ -223,7 +287,7 @@ static int dib7000p_set_bandwidth(struct dvb_frontend *demod, u8 BW_Idx)
223static int dib7000p_sad_calib(struct dib7000p_state *state) 287static int dib7000p_sad_calib(struct dib7000p_state *state)
224{ 288{
225/* internal */ 289/* internal */
226// dib7000p_write_word(state, 72, (3 << 14) | (1 << 12) | (524 << 0)); // sampling clock of the SAD is written in set_bandwidth 290// dib7000p_write_word(state, 72, (3 << 14) | (1 << 12) | (524 << 0)); // sampling clock of the SAD is writting in set_bandwidth
227 dib7000p_write_word(state, 73, (0 << 1) | (0 << 0)); 291 dib7000p_write_word(state, 73, (0 << 1) | (0 << 0));
228 dib7000p_write_word(state, 74, 776); // 0.625*3.3 / 4096 292 dib7000p_write_word(state, 74, 776); // 0.625*3.3 / 4096
229 293
@@ -236,18 +300,37 @@ static int dib7000p_sad_calib(struct dib7000p_state *state)
236 return 0; 300 return 0;
237} 301}
238 302
303int dib7000p_set_wbd_ref(struct dvb_frontend *demod, u16 value)
304{
305 struct dib7000p_state *state = demod->demodulator_priv;
306 if (value > 4095)
307 value = 4095;
308 state->wbd_ref = value;
309 return dib7000p_write_word(state, 105, (dib7000p_read_word(state, 105) & 0xf000) | value);
310}
311
312EXPORT_SYMBOL(dib7000p_set_wbd_ref);
239static void dib7000p_reset_pll(struct dib7000p_state *state) 313static void dib7000p_reset_pll(struct dib7000p_state *state)
240{ 314{
241 struct dibx000_bandwidth_config *bw = &state->cfg.bw[0]; 315 struct dibx000_bandwidth_config *bw = &state->cfg.bw[0];
316 u16 clk_cfg0;
317
318 /* force PLL bypass */
319 clk_cfg0 = (1 << 15) | ((bw->pll_ratio & 0x3f) << 9) |
320 (bw->modulo << 7) | (bw->ADClkSrc << 6) | (bw->IO_CLK_en_core << 5) |
321 (bw->bypclk_div << 2) | (bw->enable_refdiv << 1) | (0 << 0);
242 322
323 dib7000p_write_word(state, 900, clk_cfg0);
324
325 /* P_pll_cfg */
243 dib7000p_write_word(state, 903, (bw->pll_prediv << 5) | (((bw->pll_ratio >> 6) & 0x3) << 3) | (bw->pll_range << 1) | bw->pll_reset); 326 dib7000p_write_word(state, 903, (bw->pll_prediv << 5) | (((bw->pll_ratio >> 6) & 0x3) << 3) | (bw->pll_range << 1) | bw->pll_reset);
244 dib7000p_write_word(state, 900, ((bw->pll_ratio & 0x3f) << 9) | (bw->pll_bypass << 15) | (bw->modulo << 7) | (bw->ADClkSrc << 6) | 327 clk_cfg0 = (bw->pll_bypass << 15) | (clk_cfg0 & 0x7fff);
245 (bw->IO_CLK_en_core << 5) | (bw->bypclk_div << 2) | (bw->enable_refdiv << 1) | (0 << 0)); 328 dib7000p_write_word(state, 900, clk_cfg0);
246 329
247 dib7000p_write_word(state, 18, ((bw->internal*1000) >> 16) & 0xffff); 330 dib7000p_write_word(state, 18, (u16) (((bw->internal*1000) >> 16) & 0xffff));
248 dib7000p_write_word(state, 19, (bw->internal*1000 ) & 0xffff); 331 dib7000p_write_word(state, 19, (u16) ( (bw->internal*1000 ) & 0xffff));
249 dib7000p_write_word(state, 21, (bw->ifreq >> 16) & 0xffff); 332 dib7000p_write_word(state, 21, (u16) ( (bw->ifreq >> 16) & 0xffff));
250 dib7000p_write_word(state, 22, (bw->ifreq ) & 0xffff); 333 dib7000p_write_word(state, 22, (u16) ( (bw->ifreq ) & 0xffff));
251 334
252 dib7000p_write_word(state, 72, bw->sad_cfg); 335 dib7000p_write_word(state, 72, bw->sad_cfg);
253} 336}
@@ -255,7 +338,7 @@ static void dib7000p_reset_pll(struct dib7000p_state *state)
255static int dib7000p_reset_gpio(struct dib7000p_state *st) 338static int dib7000p_reset_gpio(struct dib7000p_state *st)
256{ 339{
257 /* reset the GPIOs */ 340 /* reset the GPIOs */
258 dprintk("-D- gpio dir: %x: gpio val: %x, gpio pwm pos: %x\n",st->gpio_dir, st->gpio_val,st->cfg.gpio_pwm_pos); 341 dprintk( "gpio dir: %x: val: %x, pwm_pos: %x",st->gpio_dir, st->gpio_val,st->cfg.gpio_pwm_pos);
259 342
260 dib7000p_write_word(st, 1029, st->gpio_dir); 343 dib7000p_write_word(st, 1029, st->gpio_dir);
261 dib7000p_write_word(st, 1030, st->gpio_val); 344 dib7000p_write_word(st, 1030, st->gpio_val);
@@ -268,6 +351,120 @@ static int dib7000p_reset_gpio(struct dib7000p_state *st)
268 return 0; 351 return 0;
269} 352}
270 353
354static int dib7000p_cfg_gpio(struct dib7000p_state *st, u8 num, u8 dir, u8 val)
355{
356 st->gpio_dir = dib7000p_read_word(st, 1029);
357 st->gpio_dir &= ~(1 << num); /* reset the direction bit */
358 st->gpio_dir |= (dir & 0x1) << num; /* set the new direction */
359 dib7000p_write_word(st, 1029, st->gpio_dir);
360
361 st->gpio_val = dib7000p_read_word(st, 1030);
362 st->gpio_val &= ~(1 << num); /* reset the direction bit */
363 st->gpio_val |= (val & 0x01) << num; /* set the new value */
364 dib7000p_write_word(st, 1030, st->gpio_val);
365
366 return 0;
367}
368
369int dib7000p_set_gpio(struct dvb_frontend *demod, u8 num, u8 dir, u8 val)
370{
371 struct dib7000p_state *state = demod->demodulator_priv;
372 return dib7000p_cfg_gpio(state, num, dir, val);
373}
374
375EXPORT_SYMBOL(dib7000p_set_gpio);
376static u16 dib7000p_defaults[] =
377
378{
379 // auto search configuration
380 3, 2,
381 0x0004,
382 0x1000,
383 0x0814, /* Equal Lock */
384
385 12, 6,
386 0x001b,
387 0x7740,
388 0x005b,
389 0x8d80,
390 0x01c9,
391 0xc380,
392 0x0000,
393 0x0080,
394 0x0000,
395 0x0090,
396 0x0001,
397 0xd4c0,
398
399 1, 26,
400 0x6680, // P_timf_alpha=6, P_corm_alpha=6, P_corm_thres=128 default: 6,4,26
401
402 /* set ADC level to -16 */
403 11, 79,
404 (1 << 13) - 825 - 117,
405 (1 << 13) - 837 - 117,
406 (1 << 13) - 811 - 117,
407 (1 << 13) - 766 - 117,
408 (1 << 13) - 737 - 117,
409 (1 << 13) - 693 - 117,
410 (1 << 13) - 648 - 117,
411 (1 << 13) - 619 - 117,
412 (1 << 13) - 575 - 117,
413 (1 << 13) - 531 - 117,
414 (1 << 13) - 501 - 117,
415
416 1, 142,
417 0x0410, // P_palf_filter_on=1, P_palf_filter_freeze=0, P_palf_alpha_regul=16
418
419 /* disable power smoothing */
420 8, 145,
421 0,
422 0,
423 0,
424 0,
425 0,
426 0,
427 0,
428 0,
429
430 1, 154,
431 1 << 13, // P_fft_freq_dir=1, P_fft_nb_to_cut=0
432
433 1, 168,
434 0x0ccd, // P_pha3_thres, default 0x3000
435
436// 1, 169,
437// 0x0010, // P_cti_use_cpe=0, P_cti_use_prog=0, P_cti_win_len=16, default: 0x0010
438
439 1, 183,
440 0x200f, // P_cspu_regul=512, P_cspu_win_cut=15, default: 0x2005
441
442 5, 187,
443 0x023d, // P_adp_regul_cnt=573, default: 410
444 0x00a4, // P_adp_noise_cnt=
445 0x00a4, // P_adp_regul_ext
446 0x7ff0, // P_adp_noise_ext
447 0x3ccc, // P_adp_fil
448
449 1, 198,
450 0x800, // P_equal_thres_wgn
451
452 1, 222,
453 0x0010, // P_fec_ber_rs_len=2
454
455 1, 235,
456 0x0062, // P_smo_mode, P_smo_rs_discard, P_smo_fifo_flush, P_smo_pid_parse, P_smo_error_discard
457
458 2, 901,
459 0x0006, // P_clk_cfg1
460 (3 << 10) | (1 << 6), // P_divclksel=3 P_divbitsel=1
461
462 1, 905,
463 0x2c8e, // Tuner IO bank: max drive (14mA) + divout pads max drive
464
465 0,
466};
467
271static int dib7000p_demod_reset(struct dib7000p_state *state) 468static int dib7000p_demod_reset(struct dib7000p_state *state)
272{ 469{
273 dib7000p_set_power_mode(state, DIB7000P_POWER_ALL); 470 dib7000p_set_power_mode(state, DIB7000P_POWER_ALL);
@@ -292,111 +489,307 @@ static int dib7000p_demod_reset(struct dib7000p_state *state)
292 dib7000p_reset_pll(state); 489 dib7000p_reset_pll(state);
293 490
294 if (dib7000p_reset_gpio(state) != 0) 491 if (dib7000p_reset_gpio(state) != 0)
295 dprintk("-E- GPIO reset was not successful.\n"); 492 dprintk( "GPIO reset was not successful.");
296 493
297 if (dib7000p_set_output_mode(state, OUTMODE_HIGH_Z) != 0) 494 if (dib7000p_set_output_mode(state, OUTMODE_HIGH_Z) != 0)
298 dprintk("-E- OUTPUT_MODE could not be resetted.\n"); 495 dprintk( "OUTPUT_MODE could not be reset.");
299 496
300 /* unforce divstr regardless whether i2c enumeration was done or not */ 497 /* unforce divstr regardless whether i2c enumeration was done or not */
301 dib7000p_write_word(state, 1285, dib7000p_read_word(state, 1285) & ~(1 << 1) ); 498 dib7000p_write_word(state, 1285, dib7000p_read_word(state, 1285) & ~(1 << 1) );
302 499
500 dib7000p_set_bandwidth(state, 8000);
501
502 dib7000p_set_adc_state(state, DIBX000_SLOW_ADC_ON);
503 dib7000p_sad_calib(state);
504 dib7000p_set_adc_state(state, DIBX000_SLOW_ADC_OFF);
505
506 // P_iqc_alpha_pha, P_iqc_alpha_amp_dcc_alpha, ...
507 if(state->cfg.tuner_is_baseband)
508 dib7000p_write_word(state, 36,0x0755);
509 else
510 dib7000p_write_word(state, 36,0x1f55);
511
512 dib7000p_write_tab(state, dib7000p_defaults);
513
303 dib7000p_set_power_mode(state, DIB7000P_POWER_INTERFACE_ONLY); 514 dib7000p_set_power_mode(state, DIB7000P_POWER_INTERFACE_ONLY);
304 515
516
305 return 0; 517 return 0;
306} 518}
307 519
520static void dib7000p_pll_clk_cfg(struct dib7000p_state *state)
521{
522 u16 tmp = 0;
523 tmp = dib7000p_read_word(state, 903);
524 dib7000p_write_word(state, 903, (tmp | 0x1)); //pwr-up pll
525 tmp = dib7000p_read_word(state, 900);
526 dib7000p_write_word(state, 900, (tmp & 0x7fff) | (1 << 6)); //use High freq clock
527}
528
308static void dib7000p_restart_agc(struct dib7000p_state *state) 529static void dib7000p_restart_agc(struct dib7000p_state *state)
309{ 530{
310 // P_restart_iqc & P_restart_agc 531 // P_restart_iqc & P_restart_agc
311 dib7000p_write_word(state, 770, 0x0c00); 532 dib7000p_write_word(state, 770, (1 << 11) | (1 << 9));
312 dib7000p_write_word(state, 770, 0x0000); 533 dib7000p_write_word(state, 770, 0x0000);
313} 534}
314 535
315static void dib7000p_update_lna(struct dib7000p_state *state) 536static int dib7000p_update_lna(struct dib7000p_state *state)
316{ 537{
317 int i;
318 u16 dyn_gain; 538 u16 dyn_gain;
319 539
320 // when there is no LNA to program return immediatly 540 // when there is no LNA to program return immediatly
321 if (state->cfg.update_lna == NULL) 541 if (state->cfg.update_lna) {
322 return; 542 // read dyn_gain here (because it is demod-dependent and not fe)
323
324 for (i = 0; i < 5; i++) {
325 // read dyn_gain here (because it is demod-dependent and not tuner)
326 dyn_gain = dib7000p_read_word(state, 394); 543 dyn_gain = dib7000p_read_word(state, 394);
327
328 if (state->cfg.update_lna(&state->demod,dyn_gain)) { // LNA has changed 544 if (state->cfg.update_lna(&state->demod,dyn_gain)) { // LNA has changed
329 dib7000p_restart_agc(state); 545 dib7000p_restart_agc(state);
330 msleep(5); 546 return 1;
331 } else 547 }
548 }
549
550 return 0;
551}
552
553static int dib7000p_set_agc_config(struct dib7000p_state *state, u8 band)
554{
555 struct dibx000_agc_config *agc = NULL;
556 int i;
557 if (state->current_band == band && state->current_agc != NULL)
558 return 0;
559 state->current_band = band;
560
561 for (i = 0; i < state->cfg.agc_config_count; i++)
562 if (state->cfg.agc[i].band_caps & band) {
563 agc = &state->cfg.agc[i];
332 break; 564 break;
565 }
566
567 if (agc == NULL) {
568 dprintk( "no valid AGC configuration found for band 0x%02x",band);
569 return -EINVAL;
333 } 570 }
571
572 state->current_agc = agc;
573
574 /* AGC */
575 dib7000p_write_word(state, 75 , agc->setup );
576 dib7000p_write_word(state, 76 , agc->inv_gain );
577 dib7000p_write_word(state, 77 , agc->time_stabiliz );
578 dib7000p_write_word(state, 100, (agc->alpha_level << 12) | agc->thlock);
579
580 // Demod AGC loop configuration
581 dib7000p_write_word(state, 101, (agc->alpha_mant << 5) | agc->alpha_exp);
582 dib7000p_write_word(state, 102, (agc->beta_mant << 6) | agc->beta_exp);
583
584 /* AGC continued */
585 dprintk( "WBD: ref: %d, sel: %d, active: %d, alpha: %d",
586 state->wbd_ref != 0 ? state->wbd_ref : agc->wbd_ref, agc->wbd_sel, !agc->perform_agc_softsplit, agc->wbd_sel);
587
588 if (state->wbd_ref != 0)
589 dib7000p_write_word(state, 105, (agc->wbd_inv << 12) | state->wbd_ref);
590 else
591 dib7000p_write_word(state, 105, (agc->wbd_inv << 12) | agc->wbd_ref);
592
593 dib7000p_write_word(state, 106, (agc->wbd_sel << 13) | (agc->wbd_alpha << 9) | (agc->perform_agc_softsplit << 8));
594
595 dib7000p_write_word(state, 107, agc->agc1_max);
596 dib7000p_write_word(state, 108, agc->agc1_min);
597 dib7000p_write_word(state, 109, agc->agc2_max);
598 dib7000p_write_word(state, 110, agc->agc2_min);
599 dib7000p_write_word(state, 111, (agc->agc1_pt1 << 8) | agc->agc1_pt2);
600 dib7000p_write_word(state, 112, agc->agc1_pt3);
601 dib7000p_write_word(state, 113, (agc->agc1_slope1 << 8) | agc->agc1_slope2);
602 dib7000p_write_word(state, 114, (agc->agc2_pt1 << 8) | agc->agc2_pt2);
603 dib7000p_write_word(state, 115, (agc->agc2_slope1 << 8) | agc->agc2_slope2);
604 return 0;
334} 605}
335 606
336static void dib7000p_pll_clk_cfg(struct dib7000p_state *state) 607static int dib7000p_agc_startup(struct dvb_frontend *demod, struct dvb_frontend_parameters *ch)
337{ 608{
338 u16 tmp = 0; 609 struct dib7000p_state *state = demod->demodulator_priv;
339 tmp = dib7000p_read_word(state, 903); 610 int ret = -1;
340 dib7000p_write_word(state, 903, (tmp | 0x1)); //pwr-up pll 611 u8 *agc_state = &state->agc_state;
341 tmp = dib7000p_read_word(state, 900); 612 u8 agc_split;
342 dib7000p_write_word(state, 900, (tmp & 0x7fff) | (1 << 6)); //use High freq clock 613
614 switch (state->agc_state) {
615 case 0:
616 // set power-up level: interf+analog+AGC
617 dib7000p_set_power_mode(state, DIB7000P_POWER_ALL);
618 dib7000p_set_adc_state(state, DIBX000_ADC_ON);
619 dib7000p_pll_clk_cfg(state);
620
621 if (dib7000p_set_agc_config(state, BAND_OF_FREQUENCY(ch->frequency/1000)) != 0)
622 return -1;
623
624 ret = 7;
625 (*agc_state)++;
626 break;
627
628 case 1:
629 // AGC initialization
630 if (state->cfg.agc_control)
631 state->cfg.agc_control(&state->demod, 1);
632
633 dib7000p_write_word(state, 78, 32768);
634 if (!state->current_agc->perform_agc_softsplit) {
635 /* we are using the wbd - so slow AGC startup */
636 /* force 0 split on WBD and restart AGC */
637 dib7000p_write_word(state, 106, (state->current_agc->wbd_sel << 13) | (state->current_agc->wbd_alpha << 9) | (1 << 8));
638 (*agc_state)++;
639 ret = 5;
640 } else {
641 /* default AGC startup */
642 (*agc_state) = 4;
643 /* wait AGC rough lock time */
644 ret = 7;
645 }
646
647 dib7000p_restart_agc(state);
648 break;
649
650 case 2: /* fast split search path after 5sec */
651 dib7000p_write_word(state, 75, state->current_agc->setup | (1 << 4)); /* freeze AGC loop */
652 dib7000p_write_word(state, 106, (state->current_agc->wbd_sel << 13) | (2 << 9) | (0 << 8)); /* fast split search 0.25kHz */
653 (*agc_state)++;
654 ret = 14;
655 break;
656
657 case 3: /* split search ended */
658 agc_split = (u8)dib7000p_read_word(state, 396); /* store the split value for the next time */
659 dib7000p_write_word(state, 78, dib7000p_read_word(state, 394)); /* set AGC gain start value */
660
661 dib7000p_write_word(state, 75, state->current_agc->setup); /* std AGC loop */
662 dib7000p_write_word(state, 106, (state->current_agc->wbd_sel << 13) | (state->current_agc->wbd_alpha << 9) | agc_split); /* standard split search */
663
664 dib7000p_restart_agc(state);
665
666 dprintk( "SPLIT %p: %hd", demod, agc_split);
667
668 (*agc_state)++;
669 ret = 5;
670 break;
671
672 case 4: /* LNA startup */
673 // wait AGC accurate lock time
674 ret = 7;
675
676 if (dib7000p_update_lna(state))
677 // wait only AGC rough lock time
678 ret = 5;
679 else // nothing was done, go to the next state
680 (*agc_state)++;
681 break;
682
683 case 5:
684 if (state->cfg.agc_control)
685 state->cfg.agc_control(&state->demod, 0);
686 (*agc_state)++;
687 break;
688 default:
689 break;
690 }
691 return ret;
343} 692}
344 693
345static void dib7000p_update_timf_freq(struct dib7000p_state *state) 694static void dib7000p_update_timf(struct dib7000p_state *state)
346{ 695{
347 u32 timf = (dib7000p_read_word(state, 427) << 16) | dib7000p_read_word(state, 428); 696 u32 timf = (dib7000p_read_word(state, 427) << 16) | dib7000p_read_word(state, 428);
348 state->timf = timf * 80 / (BW_INDEX_TO_KHZ(state->current_bandwidth) / 100); 697 state->timf = timf * 160 / (state->current_bandwidth / 50);
349 dib7000p_write_word(state, 23, (u16) (timf >> 16)); 698 dib7000p_write_word(state, 23, (u16) (timf >> 16));
350 dib7000p_write_word(state, 24, (u16) (timf & 0xffff)); 699 dib7000p_write_word(state, 24, (u16) (timf & 0xffff));
351 dprintk("-D- Updated timf_frequency: %d (default: %d)\n",state->timf, state->cfg.bw->timf); 700 dprintk( "updated timf_frequency: %d (default: %d)",state->timf, state->cfg.bw->timf);
701
352} 702}
353 703
354static void dib7000p_set_channel(struct dib7000p_state *state, struct dibx000_ofdm_channel *ch, u8 seq) 704static void dib7000p_set_channel(struct dib7000p_state *state, struct dvb_frontend_parameters *ch, u8 seq)
355{ 705{
356 u16 tmp, est[4]; // reg_26, reg_32, reg_33, reg_187, reg_188, reg_189, reg_190, reg_207, reg_208; 706 u16 value, est[4];
707
708 dib7000p_set_bandwidth(state, BANDWIDTH_TO_KHZ(ch->u.ofdm.bandwidth));
357 709
358 /* nfft, guard, qam, alpha */ 710 /* nfft, guard, qam, alpha */
359 dib7000p_write_word(state, 0, (ch->nfft << 7) | (ch->guard << 5) | (ch->nqam << 3) | (ch->vit_alpha)); 711 value = 0;
712 switch (ch->u.ofdm.transmission_mode) {
713 case TRANSMISSION_MODE_2K: value |= (0 << 7); break;
714 case /* 4K MODE */ 255: value |= (2 << 7); break;
715 default:
716 case TRANSMISSION_MODE_8K: value |= (1 << 7); break;
717 }
718 switch (ch->u.ofdm.guard_interval) {
719 case GUARD_INTERVAL_1_32: value |= (0 << 5); break;
720 case GUARD_INTERVAL_1_16: value |= (1 << 5); break;
721 case GUARD_INTERVAL_1_4: value |= (3 << 5); break;
722 default:
723 case GUARD_INTERVAL_1_8: value |= (2 << 5); break;
724 }
725 switch (ch->u.ofdm.constellation) {
726 case QPSK: value |= (0 << 3); break;
727 case QAM_16: value |= (1 << 3); break;
728 default:
729 case QAM_64: value |= (2 << 3); break;
730 }
731 switch (HIERARCHY_1) {
732 case HIERARCHY_2: value |= 2; break;
733 case HIERARCHY_4: value |= 4; break;
734 default:
735 case HIERARCHY_1: value |= 1; break;
736 }
737 dib7000p_write_word(state, 0, value);
360 dib7000p_write_word(state, 5, (seq << 4) | 1); /* do not force tps, search list 0 */ 738 dib7000p_write_word(state, 5, (seq << 4) | 1); /* do not force tps, search list 0 */
361 739
362 /* P_dintl_native, P_dintlv_inv, P_vit_hrch, P_vit_code_rate, P_vit_select_hp */ 740 /* P_dintl_native, P_dintlv_inv, P_hrch, P_code_rate, P_select_hp */
363 tmp = (ch->intlv_native << 6) | (ch->vit_hrch << 4) | (ch->vit_select_hp & 0x1); 741 value = 0;
364 if (ch->vit_hrch == 0 || ch->vit_select_hp == 1) 742 if (1 != 0)
365 tmp |= (ch->vit_code_rate_hp << 1); 743 value |= (1 << 6);
366 else 744 if (ch->u.ofdm.hierarchy_information == 1)
367 tmp |= (ch->vit_code_rate_lp << 1); 745 value |= (1 << 4);
368 dib7000p_write_word(state, 208, tmp); 746 if (1 == 1)
747 value |= 1;
748 switch ((ch->u.ofdm.hierarchy_information == 0 || 1 == 1) ? ch->u.ofdm.code_rate_HP : ch->u.ofdm.code_rate_LP) {
749 case FEC_2_3: value |= (2 << 1); break;
750 case FEC_3_4: value |= (3 << 1); break;
751 case FEC_5_6: value |= (5 << 1); break;
752 case FEC_7_8: value |= (7 << 1); break;
753 default:
754 case FEC_1_2: value |= (1 << 1); break;
755 }
756 dib7000p_write_word(state, 208, value);
757
758 /* offset loop parameters */
759 dib7000p_write_word(state, 26, 0x6680); // timf(6xxx)
760 dib7000p_write_word(state, 32, 0x0003); // pha_off_max(xxx3)
761 dib7000p_write_word(state, 29, 0x1273); // isi
762 dib7000p_write_word(state, 33, 0x0005); // sfreq(xxx5)
369 763
370 /* P_dvsy_sync_wait */ 764 /* P_dvsy_sync_wait */
371 switch (ch->nfft) { 765 switch (ch->u.ofdm.transmission_mode) {
372 case 1: tmp = 256; break; 766 case TRANSMISSION_MODE_8K: value = 256; break;
373 case 2: tmp = 128; break; 767 case /* 4K MODE */ 255: value = 128; break;
374 case 0: 768 case TRANSMISSION_MODE_2K:
375 default: tmp = 64; break; 769 default: value = 64; break;
376 } 770 }
377 tmp *= ((1 << (ch->guard)) * 3 / 2); // add 50% SFN margin 771 switch (ch->u.ofdm.guard_interval) {
378 tmp <<= 4; 772 case GUARD_INTERVAL_1_16: value *= 2; break;
379 773 case GUARD_INTERVAL_1_8: value *= 4; break;
380 /* deactive the possibility of diversity reception if extended interleave */ 774 case GUARD_INTERVAL_1_4: value *= 8; break;
381 /* P_dvsy_sync_mode = 0, P_dvsy_sync_enable=1, P_dvcb_comb_mode=2 */ 775 default:
382 if (ch->intlv_native || ch->nfft == 1) 776 case GUARD_INTERVAL_1_32: value *= 1; break;
383 tmp |= (1 << 2) | (2 << 0); 777 }
384 dib7000p_write_word(state, 207, tmp); 778 state->div_sync_wait = (value * 3) / 2 + 32; // add 50% SFN margin + compensate for one DVSY-fifo TODO
385 779
386 dib7000p_write_word(state, 26, 0x6680); // timf(6xxx) 780 /* deactive the possibility of diversity reception if extended interleaver */
387 dib7000p_write_word(state, 29, 0x1273); // isi inh1273 on1073 781 state->div_force_off = !1 && ch->u.ofdm.transmission_mode != TRANSMISSION_MODE_8K;
388 dib7000p_write_word(state, 32, 0x0003); // pha_off_max(xxx3) 782 dib7000p_set_diversity_in(&state->demod, state->div_state);
389 dib7000p_write_word(state, 33, 0x0005); // sfreq(xxx5)
390 783
391 /* channel estimation fine configuration */ 784 /* channel estimation fine configuration */
392 switch (ch->nqam) { 785 switch (ch->u.ofdm.constellation) {
393 case 2: 786 case QAM_64:
394 est[0] = 0x0148; /* P_adp_regul_cnt 0.04 */ 787 est[0] = 0x0148; /* P_adp_regul_cnt 0.04 */
395 est[1] = 0xfff0; /* P_adp_noise_cnt -0.002 */ 788 est[1] = 0xfff0; /* P_adp_noise_cnt -0.002 */
396 est[2] = 0x00a4; /* P_adp_regul_ext 0.02 */ 789 est[2] = 0x00a4; /* P_adp_regul_ext 0.02 */
397 est[3] = 0xfff8; /* P_adp_noise_ext -0.001 */ 790 est[3] = 0xfff8; /* P_adp_noise_ext -0.001 */
398 break; 791 break;
399 case 1: 792 case QAM_16:
400 est[0] = 0x023d; /* P_adp_regul_cnt 0.07 */ 793 est[0] = 0x023d; /* P_adp_regul_cnt 0.07 */
401 est[1] = 0xffdf; /* P_adp_noise_cnt -0.004 */ 794 est[1] = 0xffdf; /* P_adp_noise_cnt -0.004 */
402 est[2] = 0x00a4; /* P_adp_regul_ext 0.02 */ 795 est[2] = 0x00a4; /* P_adp_regul_ext 0.02 */
@@ -409,66 +802,45 @@ static void dib7000p_set_channel(struct dib7000p_state *state, struct dibx000_of
409 est[3] = 0xfff8; /* P_adp_noise_ext -0.002 */ 802 est[3] = 0xfff8; /* P_adp_noise_ext -0.002 */
410 break; 803 break;
411 } 804 }
412 for (tmp = 0; tmp < 4; tmp++) 805 for (value = 0; value < 4; value++)
413 dib7000p_write_word(state, 187 + tmp, est[tmp]); 806 dib7000p_write_word(state, 187 + value, est[value]);
414
415 // set power-up level: interf+analog+AGC
416 dib7000p_set_power_mode(state, DIB7000P_POWER_ALL);
417 dib7000p_set_adc_state(state, DIBX000_ADC_ON);
418 dib7000p_pll_clk_cfg(state);
419 msleep(7);
420
421 // AGC initialization
422 if (state->cfg.agc_control)
423 state->cfg.agc_control(&state->demod, 1);
424
425 dib7000p_restart_agc(state);
426
427 // wait AGC rough lock time
428 msleep(5);
429
430 dib7000p_update_lna(state);
431
432 // wait AGC accurate lock time
433 msleep(7);
434 if (state->cfg.agc_control)
435 state->cfg.agc_control(&state->demod, 0);
436} 807}
437 808
438static int dib7000p_autosearch_start(struct dvb_frontend *demod, struct dibx000_ofdm_channel *ch) 809static int dib7000p_autosearch_start(struct dvb_frontend *demod, struct dvb_frontend_parameters *ch)
439{ 810{
440 struct dib7000p_state *state = demod->demodulator_priv; 811 struct dib7000p_state *state = demod->demodulator_priv;
441 struct dibx000_ofdm_channel auto_ch; 812 struct dvb_frontend_parameters schan;
442 u32 value; 813 u32 value, factor;
443 814
444 INIT_OFDM_CHANNEL(&auto_ch); 815 schan = *ch;
445 auto_ch.RF_kHz = ch->RF_kHz; 816 schan.u.ofdm.constellation = QAM_64;
446 auto_ch.Bw = ch->Bw; 817 schan.u.ofdm.guard_interval = GUARD_INTERVAL_1_32;
447 auto_ch.nqam = 2; 818 schan.u.ofdm.transmission_mode = TRANSMISSION_MODE_8K;
448 auto_ch.guard = 0; 819 schan.u.ofdm.code_rate_HP = FEC_2_3;
449 auto_ch.nfft = 1; 820 schan.u.ofdm.code_rate_LP = FEC_3_4;
450 auto_ch.vit_alpha = 1; 821 schan.u.ofdm.hierarchy_information = 0;
451 auto_ch.vit_select_hp = 1; 822
452 auto_ch.vit_code_rate_hp = 2; 823 dib7000p_set_channel(state, &schan, 7);
453 auto_ch.vit_code_rate_lp = 3; 824
454 auto_ch.vit_hrch = 0; 825 factor = BANDWIDTH_TO_KHZ(ch->u.ofdm.bandwidth);
455 auto_ch.intlv_native = 1; 826 if (factor >= 5000)
456 827 factor = 1;
457 dib7000p_set_channel(state, &auto_ch, 7); 828 else
829 factor = 6;
458 830
459 // always use the setting for 8MHz here lock_time for 7,6 MHz are longer 831 // always use the setting for 8MHz here lock_time for 7,6 MHz are longer
460 value = 30 * state->cfg.bw->internal; 832 value = 30 * state->cfg.bw->internal * factor;
461 dib7000p_write_word(state, 6, (u16) ((value >> 16) & 0xffff)); // lock0 wait time 833 dib7000p_write_word(state, 6, (u16) ((value >> 16) & 0xffff)); // lock0 wait time
462 dib7000p_write_word(state, 7, (u16) (value & 0xffff)); // lock0 wait time 834 dib7000p_write_word(state, 7, (u16) (value & 0xffff)); // lock0 wait time
463 value = 100 * state->cfg.bw->internal; 835 value = 100 * state->cfg.bw->internal * factor;
464 dib7000p_write_word(state, 8, (u16) ((value >> 16) & 0xffff)); // lock1 wait time 836 dib7000p_write_word(state, 8, (u16) ((value >> 16) & 0xffff)); // lock1 wait time
465 dib7000p_write_word(state, 9, (u16) (value & 0xffff)); // lock1 wait time 837 dib7000p_write_word(state, 9, (u16) (value & 0xffff)); // lock1 wait time
466 value = 500 * state->cfg.bw->internal; 838 value = 500 * state->cfg.bw->internal * factor;
467 dib7000p_write_word(state, 10, (u16) ((value >> 16) & 0xffff)); // lock2 wait time 839 dib7000p_write_word(state, 10, (u16) ((value >> 16) & 0xffff)); // lock2 wait time
468 dib7000p_write_word(state, 11, (u16) (value & 0xffff)); // lock2 wait time 840 dib7000p_write_word(state, 11, (u16) (value & 0xffff)); // lock2 wait time
469 841
470 value = dib7000p_read_word(state, 0); 842 value = dib7000p_read_word(state, 0);
471 dib7000p_write_word(state, 0, (1 << 9) | value); 843 dib7000p_write_word(state, 0, (u16) ((1 << 9) | value));
472 dib7000p_read_word(state, 1284); 844 dib7000p_read_word(state, 1284);
473 dib7000p_write_word(state, 0, (u16) value); 845 dib7000p_write_word(state, 0, (u16) value);
474 846
@@ -489,7 +861,95 @@ static int dib7000p_autosearch_is_irq(struct dvb_frontend *demod)
489 return 0; // still pending 861 return 0; // still pending
490} 862}
491 863
492static int dib7000p_tune(struct dvb_frontend *demod, struct dibx000_ofdm_channel *ch) 864static void dib7000p_spur_protect(struct dib7000p_state *state, u32 rf_khz, u32 bw)
865{
866 static s16 notch[]={16143, 14402, 12238, 9713, 6902, 3888, 759, -2392};
867 static u8 sine [] ={0, 2, 3, 5, 6, 8, 9, 11, 13, 14, 16, 17, 19, 20, 22,
868 24, 25, 27, 28, 30, 31, 33, 34, 36, 38, 39, 41, 42, 44, 45, 47, 48, 50, 51,
869 53, 55, 56, 58, 59, 61, 62, 64, 65, 67, 68, 70, 71, 73, 74, 76, 77, 79, 80,
870 82, 83, 85, 86, 88, 89, 91, 92, 94, 95, 97, 98, 99, 101, 102, 104, 105,
871 107, 108, 109, 111, 112, 114, 115, 117, 118, 119, 121, 122, 123, 125, 126,
872 128, 129, 130, 132, 133, 134, 136, 137, 138, 140, 141, 142, 144, 145, 146,
873 147, 149, 150, 151, 152, 154, 155, 156, 157, 159, 160, 161, 162, 164, 165,
874 166, 167, 168, 170, 171, 172, 173, 174, 175, 177, 178, 179, 180, 181, 182,
875 183, 184, 185, 186, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198,
876 199, 200, 201, 202, 203, 204, 205, 206, 207, 207, 208, 209, 210, 211, 212,
877 213, 214, 215, 215, 216, 217, 218, 219, 220, 220, 221, 222, 223, 224, 224,
878 225, 226, 227, 227, 228, 229, 229, 230, 231, 231, 232, 233, 233, 234, 235,
879 235, 236, 237, 237, 238, 238, 239, 239, 240, 241, 241, 242, 242, 243, 243,
880 244, 244, 245, 245, 245, 246, 246, 247, 247, 248, 248, 248, 249, 249, 249,
881 250, 250, 250, 251, 251, 251, 252, 252, 252, 252, 253, 253, 253, 253, 254,
882 254, 254, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
883 255, 255, 255, 255, 255, 255};
884
885 u32 xtal = state->cfg.bw->xtal_hz / 1000;
886 int f_rel = ( (rf_khz + xtal/2) / xtal) * xtal - rf_khz;
887 int k;
888 int coef_re[8],coef_im[8];
889 int bw_khz = bw;
890 u32 pha;
891
892 dprintk( "relative position of the Spur: %dk (RF: %dk, XTAL: %dk)", f_rel, rf_khz, xtal);
893
894
895 if (f_rel < -bw_khz/2 || f_rel > bw_khz/2)
896 return;
897
898 bw_khz /= 100;
899
900 dib7000p_write_word(state, 142 ,0x0610);
901
902 for (k = 0; k < 8; k++) {
903 pha = ((f_rel * (k+1) * 112 * 80/bw_khz) /1000) & 0x3ff;
904
905 if (pha==0) {
906 coef_re[k] = 256;
907 coef_im[k] = 0;
908 } else if(pha < 256) {
909 coef_re[k] = sine[256-(pha&0xff)];
910 coef_im[k] = sine[pha&0xff];
911 } else if (pha == 256) {
912 coef_re[k] = 0;
913 coef_im[k] = 256;
914 } else if (pha < 512) {
915 coef_re[k] = -sine[pha&0xff];
916 coef_im[k] = sine[256 - (pha&0xff)];
917 } else if (pha == 512) {
918 coef_re[k] = -256;
919 coef_im[k] = 0;
920 } else if (pha < 768) {
921 coef_re[k] = -sine[256-(pha&0xff)];
922 coef_im[k] = -sine[pha&0xff];
923 } else if (pha == 768) {
924 coef_re[k] = 0;
925 coef_im[k] = -256;
926 } else {
927 coef_re[k] = sine[pha&0xff];
928 coef_im[k] = -sine[256 - (pha&0xff)];
929 }
930
931 coef_re[k] *= notch[k];
932 coef_re[k] += (1<<14);
933 if (coef_re[k] >= (1<<24))
934 coef_re[k] = (1<<24) - 1;
935 coef_re[k] /= (1<<15);
936
937 coef_im[k] *= notch[k];
938 coef_im[k] += (1<<14);
939 if (coef_im[k] >= (1<<24))
940 coef_im[k] = (1<<24)-1;
941 coef_im[k] /= (1<<15);
942
943 dprintk( "PALF COEF: %d re: %d im: %d", k, coef_re[k], coef_im[k]);
944
945 dib7000p_write_word(state, 143, (0 << 14) | (k << 10) | (coef_re[k] & 0x3ff));
946 dib7000p_write_word(state, 144, coef_im[k] & 0x3ff);
947 dib7000p_write_word(state, 143, (1 << 14) | (k << 10) | (coef_re[k] & 0x3ff));
948 }
949 dib7000p_write_word(state,143 ,0);
950}
951
952static int dib7000p_tune(struct dvb_frontend *demod, struct dvb_frontend_parameters *ch)
493{ 953{
494 struct dib7000p_state *state = demod->demodulator_priv; 954 struct dib7000p_state *state = demod->demodulator_priv;
495 u16 tmp = 0; 955 u16 tmp = 0;
@@ -505,7 +965,15 @@ static int dib7000p_tune(struct dvb_frontend *demod, struct dibx000_ofdm_channel
505 msleep(45); 965 msleep(45);
506 966
507 /* P_ctrl_inh_cor=0, P_ctrl_alpha_cor=4, P_ctrl_inh_isi=0, P_ctrl_alpha_isi=3, P_ctrl_inh_cor4=1, P_ctrl_alpha_cor4=3 */ 967 /* P_ctrl_inh_cor=0, P_ctrl_alpha_cor=4, P_ctrl_inh_isi=0, P_ctrl_alpha_isi=3, P_ctrl_inh_cor4=1, P_ctrl_alpha_cor4=3 */
508 dib7000p_write_word(state, 29, (0 << 14) | (4 << 10) | (0 << 9) | (3 << 5) | (1 << 4) | (0x3)); 968 tmp = (0 << 14) | (4 << 10) | (0 << 9) | (3 << 5) | (1 << 4) | (0x3);
969 if (state->sfn_workaround_active) {
970 dprintk( "SFN workaround is active");
971 tmp |= (1 << 9);
972 dib7000p_write_word(state, 166, 0x4000); // P_pha3_force_pha_shift
973 } else {
974 dib7000p_write_word(state, 166, 0x0000); // P_pha3_force_pha_shift
975 }
976 dib7000p_write_word(state, 29, tmp);
509 977
510 // never achieved a lock with that bandwidth so far - wait for osc-freq to update 978 // never achieved a lock with that bandwidth so far - wait for osc-freq to update
511 if (state->timf == 0) 979 if (state->timf == 0)
@@ -515,28 +983,31 @@ static int dib7000p_tune(struct dvb_frontend *demod, struct dibx000_ofdm_channel
515 983
516 /* P_timf_alpha, P_corm_alpha=6, P_corm_thres=0x80 */ 984 /* P_timf_alpha, P_corm_alpha=6, P_corm_thres=0x80 */
517 tmp = (6 << 8) | 0x80; 985 tmp = (6 << 8) | 0x80;
518 switch (ch->nfft) { 986 switch (ch->u.ofdm.transmission_mode) {
519 case 0: tmp |= (7 << 12); break; 987 case TRANSMISSION_MODE_2K: tmp |= (7 << 12); break;
520 case 1: tmp |= (9 << 12); break; 988 case /* 4K MODE */ 255: tmp |= (8 << 12); break;
521 case 2: tmp |= (8 << 12); break; 989 default:
990 case TRANSMISSION_MODE_8K: tmp |= (9 << 12); break;
522 } 991 }
523 dib7000p_write_word(state, 26, tmp); /* timf_a(6xxx) */ 992 dib7000p_write_word(state, 26, tmp); /* timf_a(6xxx) */
524 993
525 /* P_ctrl_freeze_pha_shift=0, P_ctrl_pha_off_max */ 994 /* P_ctrl_freeze_pha_shift=0, P_ctrl_pha_off_max */
526 tmp = (0 << 4); 995 tmp = (0 << 4);
527 switch (ch->nfft) { 996 switch (ch->u.ofdm.transmission_mode) {
528 case 0: tmp |= 0x6; break; 997 case TRANSMISSION_MODE_2K: tmp |= 0x6; break;
529 case 1: tmp |= 0x8; break; 998 case /* 4K MODE */ 255: tmp |= 0x7; break;
530 case 2: tmp |= 0x7; break; 999 default:
1000 case TRANSMISSION_MODE_8K: tmp |= 0x8; break;
531 } 1001 }
532 dib7000p_write_word(state, 32, tmp); 1002 dib7000p_write_word(state, 32, tmp);
533 1003
534 /* P_ctrl_sfreq_inh=0, P_ctrl_sfreq_step */ 1004 /* P_ctrl_sfreq_inh=0, P_ctrl_sfreq_step */
535 tmp = (0 << 4); 1005 tmp = (0 << 4);
536 switch (ch->nfft) { 1006 switch (ch->u.ofdm.transmission_mode) {
537 case 0: tmp |= 0x6; break; 1007 case TRANSMISSION_MODE_2K: tmp |= 0x6; break;
538 case 1: tmp |= 0x8; break; 1008 case /* 4K MODE */ 255: tmp |= 0x7; break;
539 case 2: tmp |= 0x7; break; 1009 default:
1010 case TRANSMISSION_MODE_8K: tmp |= 0x8; break;
540 } 1011 }
541 dib7000p_write_word(state, 33, tmp); 1012 dib7000p_write_word(state, 33, tmp);
542 1013
@@ -552,131 +1023,21 @@ static int dib7000p_tune(struct dvb_frontend *demod, struct dibx000_ofdm_channel
552 1023
553 // we achieved a lock - it's time to update the osc freq 1024 // we achieved a lock - it's time to update the osc freq
554 if ((tmp >> 6) & 0x1) 1025 if ((tmp >> 6) & 0x1)
555 dib7000p_update_timf_freq(state); 1026 dib7000p_update_timf(state);
556 1027
1028 if (state->cfg.spur_protect)
1029 dib7000p_spur_protect(state, ch->frequency/1000, BANDWIDTH_TO_KHZ(ch->u.ofdm.bandwidth));
1030
1031 dib7000p_set_bandwidth(state, BANDWIDTH_TO_KHZ(ch->u.ofdm.bandwidth));
557 return 0; 1032 return 0;
558} 1033}
559 1034
560static int dib7000p_init(struct dvb_frontend *demod) 1035static int dib7000p_wakeup(struct dvb_frontend *demod)
561{ 1036{
562 struct dibx000_agc_config *agc;
563 struct dib7000p_state *state = demod->demodulator_priv; 1037 struct dib7000p_state *state = demod->demodulator_priv;
564 int ret = 0;
565
566 // Demodulator default configuration
567 agc = state->cfg.agc;
568
569 dib7000p_set_power_mode(state, DIB7000P_POWER_ALL); 1038 dib7000p_set_power_mode(state, DIB7000P_POWER_ALL);
570 dib7000p_set_adc_state(state, DIBX000_SLOW_ADC_ON); 1039 dib7000p_set_adc_state(state, DIBX000_SLOW_ADC_ON);
571 1040 return 0;
572 /* AGC */
573 ret |= dib7000p_write_word(state, 75 , agc->setup );
574 ret |= dib7000p_write_word(state, 76 , agc->inv_gain );
575 ret |= dib7000p_write_word(state, 77 , agc->time_stabiliz );
576 ret |= dib7000p_write_word(state, 100, (agc->alpha_level << 12) | agc->thlock);
577
578 // Demod AGC loop configuration
579 ret |= dib7000p_write_word(state, 101, (agc->alpha_mant << 5) | agc->alpha_exp);
580 ret |= dib7000p_write_word(state, 102, (agc->beta_mant << 6) | agc->beta_exp);
581
582 /* AGC continued */
583 dprintk("-D- WBD: ref: %d, sel: %d, active: %d, alpha: %d\n",
584 state->wbd_ref != 0 ? state->wbd_ref : agc->wbd_ref, agc->wbd_sel, !agc->perform_agc_softsplit, agc->wbd_sel);
585
586 if (state->wbd_ref != 0)
587 ret |= dib7000p_write_word(state, 105, (agc->wbd_inv << 12) | state->wbd_ref);
588 else
589 ret |= dib7000p_write_word(state, 105, (agc->wbd_inv << 12) | agc->wbd_ref);
590
591 ret |= dib7000p_write_word(state, 106, (agc->wbd_sel << 13) | (agc->wbd_alpha << 9) | (agc->perform_agc_softsplit << 8) );
592
593 ret |= dib7000p_write_word(state, 107, agc->agc1_max);
594 ret |= dib7000p_write_word(state, 108, agc->agc1_min);
595 ret |= dib7000p_write_word(state, 109, agc->agc2_max);
596 ret |= dib7000p_write_word(state, 110, agc->agc2_min);
597 ret |= dib7000p_write_word(state, 111, (agc->agc1_pt1 << 8) | agc->agc1_pt2 );
598 ret |= dib7000p_write_word(state, 112, agc->agc1_pt3);
599 ret |= dib7000p_write_word(state, 113, (agc->agc1_slope1 << 8) | agc->agc1_slope2);
600 ret |= dib7000p_write_word(state, 114, (agc->agc2_pt1 << 8) | agc->agc2_pt2);
601 ret |= dib7000p_write_word(state, 115, (agc->agc2_slope1 << 8) | agc->agc2_slope2);
602
603 /* disable power smoothing */
604 ret |= dib7000p_write_word(state, 145, 0);
605 ret |= dib7000p_write_word(state, 146, 0);
606 ret |= dib7000p_write_word(state, 147, 0);
607 ret |= dib7000p_write_word(state, 148, 0);
608 ret |= dib7000p_write_word(state, 149, 0);
609 ret |= dib7000p_write_word(state, 150, 0);
610 ret |= dib7000p_write_word(state, 151, 0);
611 ret |= dib7000p_write_word(state, 152, 0);
612
613 // P_timf_alpha=6, P_corm_alpha=6, P_corm_thres=128 default: 6,4,26
614 ret |= dib7000p_write_word(state, 26 ,0x6680);
615
616 // P_palf_filter_on=1, P_palf_filter_freeze=0, P_palf_alpha_regul=16
617 ret |= dib7000p_write_word(state, 142,0x0410);
618 // P_fft_freq_dir=1, P_fft_nb_to_cut=0
619 ret |= dib7000p_write_word(state, 154,1 << 13);
620 // P_pha3_thres, default 0x3000
621 ret |= dib7000p_write_word(state, 168,0x0ccd);
622 // P_cti_use_cpe=0, P_cti_use_prog=0, P_cti_win_len=16, default: 0x0010
623 //ret |= dib7000p_write_word(state, 169,0x0010);
624 // P_cspu_regul=512, P_cspu_win_cut=15, default: 0x2005
625 ret |= dib7000p_write_word(state, 183,0x200f);
626 // P_adp_regul_cnt=573, default: 410
627 ret |= dib7000p_write_word(state, 187,0x023d);
628 // P_adp_noise_cnt=
629 ret |= dib7000p_write_word(state, 188,0x00a4);
630 // P_adp_regul_ext
631 ret |= dib7000p_write_word(state, 189,0x00a4);
632 // P_adp_noise_ext
633 ret |= dib7000p_write_word(state, 190,0x7ff0);
634 // P_adp_fil
635 ret |= dib7000p_write_word(state, 191,0x3ccc);
636
637 ret |= dib7000p_write_word(state, 222,0x0010);
638 // P_smo_mode, P_smo_rs_discard, P_smo_fifo_flush, P_smo_pid_parse, P_smo_error_discard
639 ret |= dib7000p_write_word(state, 235,0x0062);
640
641 // P_iqc_alpha_pha, P_iqc_alpha_amp_dcc_alpha, ...
642 if(state->cfg.tuner_is_baseband)
643 ret |= dib7000p_write_word(state, 36,0x0755);
644 else
645 ret |= dib7000p_write_word(state, 36,0x1f55);
646
647 // auto search configuration
648 ret |= dib7000p_write_word(state, 2 ,0x0004);
649 ret |= dib7000p_write_word(state, 3 ,0x1000);
650
651 /* Equal Lock */
652 ret |= dib7000p_write_word(state, 4 ,0x0814);
653
654 ret |= dib7000p_write_word(state, 6 ,0x001b);
655 ret |= dib7000p_write_word(state, 7 ,0x7740);
656 ret |= dib7000p_write_word(state, 8 ,0x005b);
657 ret |= dib7000p_write_word(state, 9 ,0x8d80);
658 ret |= dib7000p_write_word(state, 10 ,0x01c9);
659 ret |= dib7000p_write_word(state, 11 ,0xc380);
660 ret |= dib7000p_write_word(state, 12 ,0x0000);
661 ret |= dib7000p_write_word(state, 13 ,0x0080);
662 ret |= dib7000p_write_word(state, 14 ,0x0000);
663 ret |= dib7000p_write_word(state, 15 ,0x0090);
664 ret |= dib7000p_write_word(state, 16 ,0x0001);
665 ret |= dib7000p_write_word(state, 17 ,0xd4c0);
666
667 // P_clk_cfg1
668 ret |= dib7000p_write_word(state, 901, 0x0006);
669
670 // P_divclksel=3 P_divbitsel=1
671 ret |= dib7000p_write_word(state, 902, (3 << 10) | (1 << 6));
672
673 // Tuner IO bank: max drive (14mA) + divout pads max drive
674 ret |= dib7000p_write_word(state, 905, 0x2c8e);
675
676 ret |= dib7000p_set_bandwidth(&state->demod, BANDWIDTH_8_MHZ);
677 dib7000p_sad_calib(state);
678
679 return ret;
680} 1041}
681 1042
682static int dib7000p_sleep(struct dvb_frontend *demod) 1043static int dib7000p_sleep(struct dvb_frontend *demod)
@@ -688,16 +1049,16 @@ static int dib7000p_sleep(struct dvb_frontend *demod)
688static int dib7000p_identify(struct dib7000p_state *st) 1049static int dib7000p_identify(struct dib7000p_state *st)
689{ 1050{
690 u16 value; 1051 u16 value;
691 dprintk("-I- DiB7000PC: checking demod on I2C address: %d (%x)\n", 1052 dprintk( "checking demod on I2C address: %d (%x)",
692 st->i2c_addr, st->i2c_addr); 1053 st->i2c_addr, st->i2c_addr);
693 1054
694 if ((value = dib7000p_read_word(st, 768)) != 0x01b3) { 1055 if ((value = dib7000p_read_word(st, 768)) != 0x01b3) {
695 dprintk("-E- DiB7000PC: wrong Vendor ID (read=0x%x)\n",value); 1056 dprintk( "wrong Vendor ID (read=0x%x)",value);
696 return -EREMOTEIO; 1057 return -EREMOTEIO;
697 } 1058 }
698 1059
699 if ((value = dib7000p_read_word(st, 769)) != 0x4000) { 1060 if ((value = dib7000p_read_word(st, 769)) != 0x4000) {
700 dprintk("-E- DiB7000PC: wrong Device ID (%x)\n",value); 1061 dprintk( "wrong Device ID (%x)",value);
701 return -EREMOTEIO; 1062 return -EREMOTEIO;
702 } 1063 }
703 1064
@@ -767,41 +1128,48 @@ static int dib7000p_set_frontend(struct dvb_frontend* fe,
767 struct dvb_frontend_parameters *fep) 1128 struct dvb_frontend_parameters *fep)
768{ 1129{
769 struct dib7000p_state *state = fe->demodulator_priv; 1130 struct dib7000p_state *state = fe->demodulator_priv;
770 struct dibx000_ofdm_channel ch; 1131 int time;
771
772 INIT_OFDM_CHANNEL(&ch);
773 FEP2DIB(fep,&ch);
774 1132
775 state->current_bandwidth = fep->u.ofdm.bandwidth; 1133 state->current_bandwidth = fep->u.ofdm.bandwidth;
776 dib7000p_set_bandwidth(fe, fep->u.ofdm.bandwidth); 1134 dib7000p_set_bandwidth(state, BANDWIDTH_TO_KHZ(fep->u.ofdm.bandwidth));
1135
1136 /* maybe the parameter has been changed */
1137 state->sfn_workaround_active = buggy_sfn_workaround;
777 1138
778 if (fe->ops.tuner_ops.set_params) 1139 if (fe->ops.tuner_ops.set_params)
779 fe->ops.tuner_ops.set_params(fe, fep); 1140 fe->ops.tuner_ops.set_params(fe, fep);
780 1141
1142 /* start up the AGC */
1143 state->agc_state = 0;
1144 do {
1145 time = dib7000p_agc_startup(fe, fep);
1146 if (time != -1)
1147 msleep(time);
1148 } while (time != -1);
1149
781 if (fep->u.ofdm.transmission_mode == TRANSMISSION_MODE_AUTO || 1150 if (fep->u.ofdm.transmission_mode == TRANSMISSION_MODE_AUTO ||
782 fep->u.ofdm.guard_interval == GUARD_INTERVAL_AUTO || 1151 fep->u.ofdm.guard_interval == GUARD_INTERVAL_AUTO ||
783 fep->u.ofdm.constellation == QAM_AUTO || 1152 fep->u.ofdm.constellation == QAM_AUTO ||
784 fep->u.ofdm.code_rate_HP == FEC_AUTO) { 1153 fep->u.ofdm.code_rate_HP == FEC_AUTO) {
785 int i = 800, found; 1154 int i = 800, found;
786 1155
787 dib7000p_autosearch_start(fe, &ch); 1156 dib7000p_autosearch_start(fe, fep);
788 do { 1157 do {
789 msleep(1); 1158 msleep(1);
790 found = dib7000p_autosearch_is_irq(fe); 1159 found = dib7000p_autosearch_is_irq(fe);
791 } while (found == 0 && i--); 1160 } while (found == 0 && i--);
792 1161
793 dprintk("autosearch returns: %d\n",found); 1162 dprintk("autosearch returns: %d",found);
794 if (found == 0 || found == 1) 1163 if (found == 0 || found == 1)
795 return 0; // no channel found 1164 return 0; // no channel found
796 1165
797 dib7000p_get_frontend(fe, fep); 1166 dib7000p_get_frontend(fe, fep);
798 FEP2DIB(fep, &ch);
799 } 1167 }
800 1168
801 /* make this a config parameter */ 1169 /* make this a config parameter */
802 dib7000p_set_output_mode(state, OUTMODE_MPEG2_FIFO); 1170 dib7000p_set_output_mode(state, OUTMODE_MPEG2_FIFO);
803 1171
804 return dib7000p_tune(fe, &ch); 1172 return dib7000p_tune(fe, fep);
805} 1173}
806 1174
807static int dib7000p_read_status(struct dvb_frontend *fe, fe_status_t *stat) 1175static int dib7000p_read_status(struct dvb_frontend *fe, fe_status_t *stat)
@@ -879,7 +1247,7 @@ int dib7000pc_detection(struct i2c_adapter *i2c_adap)
879 1247
880 if (i2c_transfer(i2c_adap, msg, 2) == 2) 1248 if (i2c_transfer(i2c_adap, msg, 2) == 2)
881 if (rx[0] == 0x01 && rx[1] == 0xb3) { 1249 if (rx[0] == 0x01 && rx[1] == 0xb3) {
882 dprintk("-D- DiB7000PC detected\n"); 1250 dprintk("-D- DiB7000PC detected");
883 return 1; 1251 return 1;
884 } 1252 }
885 1253
@@ -887,11 +1255,11 @@ int dib7000pc_detection(struct i2c_adapter *i2c_adap)
887 1255
888 if (i2c_transfer(i2c_adap, msg, 2) == 2) 1256 if (i2c_transfer(i2c_adap, msg, 2) == 2)
889 if (rx[0] == 0x01 && rx[1] == 0xb3) { 1257 if (rx[0] == 0x01 && rx[1] == 0xb3) {
890 dprintk("-D- DiB7000PC detected\n"); 1258 dprintk("-D- DiB7000PC detected");
891 return 1; 1259 return 1;
892 } 1260 }
893 1261
894 dprintk("-D- DiB7000PC not detected\n"); 1262 dprintk("-D- DiB7000PC not detected");
895 return 0; 1263 return 0;
896} 1264}
897EXPORT_SYMBOL(dib7000pc_detection); 1265EXPORT_SYMBOL(dib7000pc_detection);
@@ -929,7 +1297,7 @@ int dib7000p_i2c_enumeration(struct i2c_adapter *i2c, int no_of_demods, u8 defau
929 /* set new i2c address and force divstart */ 1297 /* set new i2c address and force divstart */
930 dib7000p_write_word(&st, 1285, (new_addr << 2) | 0x2); 1298 dib7000p_write_word(&st, 1285, (new_addr << 2) | 0x2);
931 1299
932 dprintk("IC %d initialized (to i2c_address 0x%x)\n", k, new_addr); 1300 dprintk("IC %d initialized (to i2c_address 0x%x)", k, new_addr);
933 } 1301 }
934 1302
935 for (k = 0; k < no_of_demods; k++) { 1303 for (k = 0; k < no_of_demods; k++) {
@@ -1000,7 +1368,7 @@ static struct dvb_frontend_ops dib7000p_ops = {
1000 1368
1001 .release = dib7000p_release, 1369 .release = dib7000p_release,
1002 1370
1003 .init = dib7000p_init, 1371 .init = dib7000p_wakeup,
1004 .sleep = dib7000p_sleep, 1372 .sleep = dib7000p_sleep,
1005 1373
1006 .set_frontend = dib7000p_set_frontend, 1374 .set_frontend = dib7000p_set_frontend,
diff --git a/drivers/media/dvb/frontends/dib7000p.h b/drivers/media/dvb/frontends/dib7000p.h
index 79465cf1aced..eefcac8b5244 100644
--- a/drivers/media/dvb/frontends/dib7000p.h
+++ b/drivers/media/dvb/frontends/dib7000p.h
@@ -9,6 +9,7 @@ struct dib7000p_config {
9 u8 tuner_is_baseband; 9 u8 tuner_is_baseband;
10 int (*update_lna) (struct dvb_frontend *, u16 agc_global); 10 int (*update_lna) (struct dvb_frontend *, u16 agc_global);
11 11
12 u8 agc_config_count;
12 struct dibx000_agc_config *agc; 13 struct dibx000_agc_config *agc;
13 struct dibx000_bandwidth_config *bw; 14 struct dibx000_bandwidth_config *bw;
14 15
@@ -27,20 +28,19 @@ struct dib7000p_config {
27 28
28 u8 quartz_direct; 29 u8 quartz_direct;
29 30
31 u8 spur_protect;
32
30 int (*agc_control) (struct dvb_frontend *, u8 before); 33 int (*agc_control) (struct dvb_frontend *, u8 before);
31}; 34};
32 35
33#define DEFAULT_DIB7000P_I2C_ADDRESS 18 36#define DEFAULT_DIB7000P_I2C_ADDRESS 18
34 37
35extern struct dvb_frontend * dib7000p_attach(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib7000p_config *cfg); 38extern struct dvb_frontend * dib7000p_attach(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib7000p_config *cfg);
39extern int dib7000p_i2c_enumeration(struct i2c_adapter *i2c, int no_of_demods, u8 default_addr, struct dib7000p_config cfg[]);
40
36extern struct i2c_adapter * dib7000p_get_i2c_master(struct dvb_frontend *, enum dibx000_i2c_interface, int); 41extern struct i2c_adapter * dib7000p_get_i2c_master(struct dvb_frontend *, enum dibx000_i2c_interface, int);
37extern int dib7000pc_detection(struct i2c_adapter *i2c_adap); 42extern int dib7000pc_detection(struct i2c_adapter *i2c_adap);
38 43extern int dib7000p_set_gpio(struct dvb_frontend *, u8 num, u8 dir, u8 val);
39/* TODO 44extern int dib7000p_set_wbd_ref(struct dvb_frontend *, u16 value);
40extern INT dib7000p_set_gpio(struct dibDemod *demod, UCHAR num, UCHAR dir, UCHAR val);
41extern INT dib7000p_enable_vbg_voltage(struct dibDemod *demod);
42extern void dib7000p_set_hostbus_diversity(struct dibDemod *demod, UCHAR onoff);
43extern USHORT dib7000p_get_current_agc_global(struct dibDemod *demod);
44*/
45 45
46#endif 46#endif
diff --git a/drivers/media/dvb/frontends/dibx000_common.h b/drivers/media/dvb/frontends/dibx000_common.h
index a1df604366c3..5e17275afd25 100644
--- a/drivers/media/dvb/frontends/dibx000_common.h
+++ b/drivers/media/dvb/frontends/dibx000_common.h
@@ -111,6 +111,8 @@ struct dibx000_bandwidth_config {
111 111
112 u32 ifreq; 112 u32 ifreq;
113 u32 timf; 113 u32 timf;
114
115 u32 xtal_hz;
114}; 116};
115 117
116enum dibx000_adc_states { 118enum dibx000_adc_states {
@@ -122,56 +124,17 @@ enum dibx000_adc_states {
122 DIBX000_VBG_DISABLE, 124 DIBX000_VBG_DISABLE,
123}; 125};
124 126
125#define BW_INDEX_TO_KHZ(v) ( (v) == BANDWIDTH_8_MHZ ? 8000 : \ 127#define BANDWIDTH_TO_KHZ(v) ( (v) == BANDWIDTH_8_MHZ ? 8000 : \
126 (v) == BANDWIDTH_7_MHZ ? 7000 : \ 128 (v) == BANDWIDTH_7_MHZ ? 7000 : \
127 (v) == BANDWIDTH_6_MHZ ? 6000 : 8000 ) 129 (v) == BANDWIDTH_6_MHZ ? 6000 : 8000 )
128 130
129/* Chip output mode. */ 131/* Chip output mode. */
130#define OUTMODE_HIGH_Z 0 132#define OUTMODE_HIGH_Z 0
131#define OUTMODE_MPEG2_PAR_GATED_CLK 1 133#define OUTMODE_MPEG2_PAR_GATED_CLK 1
132#define OUTMODE_MPEG2_PAR_CONT_CLK 2 134#define OUTMODE_MPEG2_PAR_CONT_CLK 2
133#define OUTMODE_MPEG2_SERIAL 7 135#define OUTMODE_MPEG2_SERIAL 7
134#define OUTMODE_DIVERSITY 4 136#define OUTMODE_DIVERSITY 4
135#define OUTMODE_MPEG2_FIFO 5 137#define OUTMODE_MPEG2_FIFO 5
136 138#define OUTMODE_ANALOG_ADC 6
137/* I hope I can get rid of the following kludge in the near future */
138struct dibx000_ofdm_channel {
139 u32 RF_kHz;
140 u8 Bw;
141 s16 nfft;
142 s16 guard;
143 s16 nqam;
144 s16 vit_hrch;
145 s16 vit_select_hp;
146 s16 vit_alpha;
147 s16 vit_code_rate_hp;
148 s16 vit_code_rate_lp;
149 u8 intlv_native;
150};
151
152#define FEP2DIB(fep,ch) \
153 (ch)->RF_kHz = (fep)->frequency / 1000; \
154 (ch)->Bw = (fep)->u.ofdm.bandwidth; \
155 (ch)->nfft = (fep)->u.ofdm.transmission_mode == TRANSMISSION_MODE_AUTO ? -1 : (fep)->u.ofdm.transmission_mode; \
156 (ch)->guard = (fep)->u.ofdm.guard_interval == GUARD_INTERVAL_AUTO ? -1 : (fep)->u.ofdm.guard_interval; \
157 (ch)->nqam = (fep)->u.ofdm.constellation == QAM_AUTO ? -1 : (fep)->u.ofdm.constellation == QAM_64 ? 2 : (fep)->u.ofdm.constellation; \
158 (ch)->vit_hrch = 0; /* linux-dvb is not prepared for HIERARCHICAL TRANSMISSION */ \
159 (ch)->vit_select_hp = 1; \
160 (ch)->vit_alpha = 1; \
161 (ch)->vit_code_rate_hp = (fep)->u.ofdm.code_rate_HP == FEC_AUTO ? -1 : (fep)->u.ofdm.code_rate_HP; \
162 (ch)->vit_code_rate_lp = (fep)->u.ofdm.code_rate_LP == FEC_AUTO ? -1 : (fep)->u.ofdm.code_rate_LP; \
163 (ch)->intlv_native = 1;
164
165#define INIT_OFDM_CHANNEL(ch) do {\
166 (ch)->Bw = 0; \
167 (ch)->nfft = -1; \
168 (ch)->guard = -1; \
169 (ch)->nqam = -1; \
170 (ch)->vit_hrch = -1; \
171 (ch)->vit_select_hp = -1; \
172 (ch)->vit_alpha = -1; \
173 (ch)->vit_code_rate_hp = -1; \
174 (ch)->vit_code_rate_lp = -1; \
175} while (0)
176 139
177#endif 140#endif
diff --git a/drivers/media/dvb/frontends/dvb-pll.c b/drivers/media/dvb/frontends/dvb-pll.c
index 11f7d5939bd9..8c8d7342d0b3 100644
--- a/drivers/media/dvb/frontends/dvb-pll.c
+++ b/drivers/media/dvb/frontends/dvb-pll.c
@@ -24,12 +24,48 @@
24 24
25#include "dvb-pll.h" 25#include "dvb-pll.h"
26 26
27struct dvb_pll_priv {
28 /* pll number */
29 int nr;
30
31 /* i2c details */
32 int pll_i2c_address;
33 struct i2c_adapter *i2c;
34
35 /* the PLL descriptor */
36 struct dvb_pll_desc *pll_desc;
37
38 /* cached frequency/bandwidth */
39 u32 frequency;
40 u32 bandwidth;
41};
42
43#define DVB_PLL_MAX 64
44
45static unsigned int dvb_pll_devcount;
46
47static int debug = 0;
48module_param(debug, int, 0644);
49MODULE_PARM_DESC(debug, "enable verbose debug messages");
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] =
56 { [ 0 ... (DVB_PLL_MAX-1) ] = DVB_PLL_UNDEFINED };
57module_param_array(id, int, NULL, 0644);
58MODULE_PARM_DESC(id, "force pll id to use (DEBUG ONLY)");
59
60/* ----------------------------------------------------------- */
61
27struct dvb_pll_desc { 62struct dvb_pll_desc {
28 char *name; 63 char *name;
29 u32 min; 64 u32 min;
30 u32 max; 65 u32 max;
31 u32 iffreq; 66 u32 iffreq;
32 void (*set)(u8 *buf, const struct dvb_frontend_parameters *params); 67 void (*set)(struct dvb_frontend *fe, u8 *buf,
68 const struct dvb_frontend_parameters *params);
33 u8 *initdata; 69 u8 *initdata;
34 u8 *sleepdata; 70 u8 *sleepdata;
35 int count; 71 int count;
@@ -89,7 +125,7 @@ static struct dvb_pll_desc dvb_pll_thomson_dtt7610 = {
89 }, 125 },
90}; 126};
91 127
92static void thomson_dtt759x_bw(u8 *buf, 128static void thomson_dtt759x_bw(struct dvb_frontend *fe, u8 *buf,
93 const struct dvb_frontend_parameters *params) 129 const struct dvb_frontend_parameters *params)
94{ 130{
95 if (BANDWIDTH_7_MHZ == params->u.ofdm.bandwidth) 131 if (BANDWIDTH_7_MHZ == params->u.ofdm.bandwidth)
@@ -210,7 +246,8 @@ static struct dvb_pll_desc dvb_pll_env57h1xd5 = {
210/* Philips TDA6650/TDA6651 246/* Philips TDA6650/TDA6651
211 * used in Panasonic ENV77H11D5 247 * used in Panasonic ENV77H11D5
212 */ 248 */
213static void tda665x_bw(u8 *buf, const struct dvb_frontend_parameters *params) 249static void tda665x_bw(struct dvb_frontend *fe, u8 *buf,
250 const struct dvb_frontend_parameters *params)
214{ 251{
215 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) 252 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ)
216 buf[3] |= 0x08; 253 buf[3] |= 0x08;
@@ -243,7 +280,8 @@ static struct dvb_pll_desc dvb_pll_tda665x = {
243/* Infineon TUA6034 280/* Infineon TUA6034
244 * used in LG TDTP E102P 281 * used in LG TDTP E102P
245 */ 282 */
246static void tua6034_bw(u8 *buf, const struct dvb_frontend_parameters *params) 283static void tua6034_bw(struct dvb_frontend *fe, u8 *buf,
284 const struct dvb_frontend_parameters *params)
247{ 285{
248 if (BANDWIDTH_7_MHZ != params->u.ofdm.bandwidth) 286 if (BANDWIDTH_7_MHZ != params->u.ofdm.bandwidth)
249 buf[3] |= 0x08; 287 buf[3] |= 0x08;
@@ -283,7 +321,8 @@ static struct dvb_pll_desc dvb_pll_lg_tdvs_h06xf = {
283/* Philips FMD1216ME 321/* Philips FMD1216ME
284 * used in Medion Hybrid PCMCIA card and USB Box 322 * used in Medion Hybrid PCMCIA card and USB Box
285 */ 323 */
286static void fmd1216me_bw(u8 *buf, const struct dvb_frontend_parameters *params) 324static void fmd1216me_bw(struct dvb_frontend *fe, u8 *buf,
325 const struct dvb_frontend_parameters *params)
287{ 326{
288 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ && 327 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ &&
289 params->frequency >= 158870000) 328 params->frequency >= 158870000)
@@ -313,7 +352,8 @@ static struct dvb_pll_desc dvb_pll_fmd1216me = {
313/* ALPS TDED4 352/* ALPS TDED4
314 * used in Nebula-Cards and USB boxes 353 * used in Nebula-Cards and USB boxes
315 */ 354 */
316static void tded4_bw(u8 *buf, const struct dvb_frontend_parameters *params) 355static void tded4_bw(struct dvb_frontend *fe, u8 *buf,
356 const struct dvb_frontend_parameters *params)
317{ 357{
318 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) 358 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ)
319 buf[3] |= 0x04; 359 buf[3] |= 0x04;
@@ -354,16 +394,35 @@ static struct dvb_pll_desc dvb_pll_tdhu2 = {
354/* Philips TUV1236D 394/* Philips TUV1236D
355 * used in ATI HDTV Wonder 395 * used in ATI HDTV Wonder
356 */ 396 */
357static void tuv1236d_rf(u8 *buf, const struct dvb_frontend_parameters *params) 397static void tuv1236d_rf(struct dvb_frontend *fe, u8 *buf,
398 const struct dvb_frontend_parameters *params)
358{ 399{
359 switch (params->u.vsb.modulation) { 400 struct dvb_pll_priv *priv = fe->tuner_priv;
360 case QAM_64: 401 unsigned int new_rf = input[priv->nr];
361 case QAM_256: 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:
362 buf[3] |= 0x08; 417 buf[3] |= 0x08;
363 break; 418 break;
364 case VSB_8: 419 case 2:
365 default:
366 buf[3] &= ~0x08; 420 buf[3] &= ~0x08;
421 break;
422 default:
423 printk(KERN_WARNING
424 "%s: unhandled rf input selection: %d",
425 __FUNCTION__, new_rf);
367 } 426 }
368} 427}
369 428
@@ -420,7 +479,8 @@ static struct dvb_pll_desc dvb_pll_philips_sd1878_tda8261 = {
420/* 479/*
421 * Philips TD1316 Tuner. 480 * Philips TD1316 Tuner.
422 */ 481 */
423static void td1316_bw(u8 *buf, const struct dvb_frontend_parameters *params) 482static void td1316_bw(struct dvb_frontend *fe, u8 *buf,
483 const struct dvb_frontend_parameters *params)
424{ 484{
425 u8 band; 485 u8 band;
426 486
@@ -474,7 +534,8 @@ static struct dvb_pll_desc dvb_pll_thomson_fe6600 = {
474 } 534 }
475}; 535};
476 536
477static void opera1_bw(u8 *buf, const struct dvb_frontend_parameters *params) 537static void opera1_bw(struct dvb_frontend *fe, u8 *buf,
538 const struct dvb_frontend_parameters *params)
478{ 539{
479 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ) 540 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ)
480 buf[2] |= 0x08; 541 buf[2] |= 0x08;
@@ -546,30 +607,13 @@ static struct dvb_pll_desc *pll_list[] = {
546}; 607};
547 608
548/* ----------------------------------------------------------- */ 609/* ----------------------------------------------------------- */
549
550struct dvb_pll_priv {
551 /* i2c details */
552 int pll_i2c_address;
553 struct i2c_adapter *i2c;
554
555 /* the PLL descriptor */
556 struct dvb_pll_desc *pll_desc;
557
558 /* cached frequency/bandwidth */
559 u32 frequency;
560 u32 bandwidth;
561};
562
563/* ----------------------------------------------------------- */
564/* code */ 610/* code */
565 611
566static int debug = 0; 612static int dvb_pll_configure(struct dvb_frontend *fe, u8 *buf,
567module_param(debug, int, 0644);
568MODULE_PARM_DESC(debug, "enable verbose debug messages");
569
570static int dvb_pll_configure(struct dvb_pll_desc *desc, u8 *buf,
571 const struct dvb_frontend_parameters *params) 613 const struct dvb_frontend_parameters *params)
572{ 614{
615 struct dvb_pll_priv *priv = fe->tuner_priv;
616 struct dvb_pll_desc *desc = priv->pll_desc;
573 u32 div; 617 u32 div;
574 int i; 618 int i;
575 619
@@ -597,7 +641,7 @@ static int dvb_pll_configure(struct dvb_pll_desc *desc, u8 *buf,
597 buf[3] = desc->entries[i].cb; 641 buf[3] = desc->entries[i].cb;
598 642
599 if (desc->set) 643 if (desc->set)
600 desc->set(buf, params); 644 desc->set(fe, buf, params);
601 645
602 if (debug) 646 if (debug)
603 printk("pll: %s: div=%d | buf=0x%02x,0x%02x,0x%02x,0x%02x\n", 647 printk("pll: %s: div=%d | buf=0x%02x,0x%02x,0x%02x,0x%02x\n",
@@ -654,7 +698,7 @@ static int dvb_pll_set_params(struct dvb_frontend *fe,
654 if (priv->i2c == NULL) 698 if (priv->i2c == NULL)
655 return -EINVAL; 699 return -EINVAL;
656 700
657 if ((result = dvb_pll_configure(priv->pll_desc, buf, params)) < 0) 701 if ((result = dvb_pll_configure(fe, buf, params)) < 0)
658 return result; 702 return result;
659 else 703 else
660 frequency = result; 704 frequency = result;
@@ -682,7 +726,7 @@ static int dvb_pll_calc_regs(struct dvb_frontend *fe,
682 if (buf_len < 5) 726 if (buf_len < 5)
683 return -EINVAL; 727 return -EINVAL;
684 728
685 if ((result = dvb_pll_configure(priv->pll_desc, buf+1, params)) < 0) 729 if ((result = dvb_pll_configure(fe, buf+1, params)) < 0)
686 return result; 730 return result;
687 else 731 else
688 frequency = result; 732 frequency = result;
@@ -755,6 +799,10 @@ struct dvb_frontend *dvb_pll_attach(struct dvb_frontend *fe, int pll_addr,
755 int ret; 799 int ret;
756 struct dvb_pll_desc *desc; 800 struct dvb_pll_desc *desc;
757 801
802 if ((id[dvb_pll_devcount] > DVB_PLL_UNDEFINED) &&
803 (id[dvb_pll_devcount] < ARRAY_SIZE(pll_list)))
804 pll_desc_id = id[dvb_pll_devcount];
805
758 BUG_ON(pll_desc_id < 1 || pll_desc_id >= ARRAY_SIZE(pll_list)); 806 BUG_ON(pll_desc_id < 1 || pll_desc_id >= ARRAY_SIZE(pll_list));
759 807
760 desc = pll_list[pll_desc_id]; 808 desc = pll_list[pll_desc_id];
@@ -777,6 +825,7 @@ struct dvb_frontend *dvb_pll_attach(struct dvb_frontend *fe, int pll_addr,
777 priv->pll_i2c_address = pll_addr; 825 priv->pll_i2c_address = pll_addr;
778 priv->i2c = i2c; 826 priv->i2c = i2c;
779 priv->pll_desc = desc; 827 priv->pll_desc = desc;
828 priv->nr = dvb_pll_devcount++;
780 829
781 memcpy(&fe->ops.tuner_ops, &dvb_pll_tuner_ops, 830 memcpy(&fe->ops.tuner_ops, &dvb_pll_tuner_ops,
782 sizeof(struct dvb_tuner_ops)); 831 sizeof(struct dvb_tuner_ops));
@@ -791,6 +840,30 @@ struct dvb_frontend *dvb_pll_attach(struct dvb_frontend *fe, int pll_addr,
791 fe->ops.tuner_ops.sleep = NULL; 840 fe->ops.tuner_ops.sleep = NULL;
792 841
793 fe->tuner_priv = priv; 842 fe->tuner_priv = priv;
843
844 if ((debug) || (id[priv->nr] == pll_desc_id)) {
845 printk("dvb-pll[%d]", priv->nr);
846 if (i2c != NULL)
847 printk(" %d-%04x", i2c_adapter_id(i2c), pll_addr);
848 printk(": id# %d (%s) attached, %s\n", pll_desc_id, desc->name,
849 id[priv->nr] == pll_desc_id ?
850 "insmod option" : "autodetected");
851 }
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
794 return fe; 867 return fe;
795} 868}
796EXPORT_SYMBOL(dvb_pll_attach); 869EXPORT_SYMBOL(dvb_pll_attach);
diff --git a/drivers/media/dvb/frontends/dvb_dummy_fe.c b/drivers/media/dvb/frontends/dvb_dummy_fe.c
index 6271b1e7f6ab..fed09dfb2b7c 100644
--- a/drivers/media/dvb/frontends/dvb_dummy_fe.c
+++ b/drivers/media/dvb/frontends/dvb_dummy_fe.c
@@ -20,7 +20,6 @@
20 */ 20 */
21 21
22#include <linux/module.h> 22#include <linux/module.h>
23#include <linux/moduleparam.h>
24#include <linux/init.h> 23#include <linux/init.h>
25#include <linux/string.h> 24#include <linux/string.h>
26#include <linux/slab.h> 25#include <linux/slab.h>
diff --git a/drivers/media/dvb/frontends/isl6421.c b/drivers/media/dvb/frontends/isl6421.c
index c967148a5945..684c8ec166cb 100644
--- a/drivers/media/dvb/frontends/isl6421.c
+++ b/drivers/media/dvb/frontends/isl6421.c
@@ -29,7 +29,6 @@
29#include <linux/init.h> 29#include <linux/init.h>
30#include <linux/kernel.h> 30#include <linux/kernel.h>
31#include <linux/module.h> 31#include <linux/module.h>
32#include <linux/moduleparam.h>
33#include <linux/string.h> 32#include <linux/string.h>
34#include <linux/slab.h> 33#include <linux/slab.h>
35 34
diff --git a/drivers/media/dvb/frontends/l64781.c b/drivers/media/dvb/frontends/l64781.c
index 1aeacb1c4af7..443d9045d4c9 100644
--- a/drivers/media/dvb/frontends/l64781.c
+++ b/drivers/media/dvb/frontends/l64781.c
@@ -23,7 +23,6 @@
23#include <linux/init.h> 23#include <linux/init.h>
24#include <linux/kernel.h> 24#include <linux/kernel.h>
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/moduleparam.h>
27#include <linux/string.h> 26#include <linux/string.h>
28#include <linux/slab.h> 27#include <linux/slab.h>
29#include "dvb_frontend.h" 28#include "dvb_frontend.h"
diff --git a/drivers/media/dvb/frontends/lgdt330x.c b/drivers/media/dvb/frontends/lgdt330x.c
index e25286e2d431..bdc9fa88b86a 100644
--- a/drivers/media/dvb/frontends/lgdt330x.c
+++ b/drivers/media/dvb/frontends/lgdt330x.c
@@ -35,7 +35,6 @@
35 35
36#include <linux/kernel.h> 36#include <linux/kernel.h>
37#include <linux/module.h> 37#include <linux/module.h>
38#include <linux/moduleparam.h>
39#include <linux/init.h> 38#include <linux/init.h>
40#include <linux/delay.h> 39#include <linux/delay.h>
41#include <linux/string.h> 40#include <linux/string.h>
diff --git a/drivers/media/dvb/frontends/lnbp21.c b/drivers/media/dvb/frontends/lnbp21.c
index 2d2f58c26226..76f935d9755a 100644
--- a/drivers/media/dvb/frontends/lnbp21.c
+++ b/drivers/media/dvb/frontends/lnbp21.c
@@ -28,7 +28,6 @@
28#include <linux/init.h> 28#include <linux/init.h>
29#include <linux/kernel.h> 29#include <linux/kernel.h>
30#include <linux/module.h> 30#include <linux/module.h>
31#include <linux/moduleparam.h>
32#include <linux/string.h> 31#include <linux/string.h>
33#include <linux/slab.h> 32#include <linux/slab.h>
34 33
diff --git a/drivers/media/dvb/frontends/mt2060.c b/drivers/media/dvb/frontends/mt2060.c
index 450fad8d9b65..1305b0e63ce5 100644
--- a/drivers/media/dvb/frontends/mt2060.c
+++ b/drivers/media/dvb/frontends/mt2060.c
@@ -22,7 +22,6 @@
22/* In that file, frequencies are expressed in kiloHertz to avoid 32 bits overflows */ 22/* In that file, frequencies are expressed in kiloHertz to avoid 32 bits overflows */
23 23
24#include <linux/module.h> 24#include <linux/module.h>
25#include <linux/moduleparam.h>
26#include <linux/delay.h> 25#include <linux/delay.h>
27#include <linux/dvb/frontend.h> 26#include <linux/dvb/frontend.h>
28#include <linux/i2c.h> 27#include <linux/i2c.h>
diff --git a/drivers/media/dvb/frontends/mt2131.c b/drivers/media/dvb/frontends/mt2131.c
new file mode 100644
index 000000000000..4b93931de4e1
--- /dev/null
+++ b/drivers/media/dvb/frontends/mt2131.c
@@ -0,0 +1,314 @@
1/*
2 * Driver for Microtune MT2131 "QAM/8VSB single chip tuner"
3 *
4 * Copyright (c) 2006 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/delay.h>
24#include <linux/dvb/frontend.h>
25#include <linux/i2c.h>
26
27#include "dvb_frontend.h"
28
29#include "mt2131.h"
30#include "mt2131_priv.h"
31
32static int debug;
33module_param(debug, int, 0644);
34MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
35
36#define dprintk(level,fmt, arg...) if (debug >= level) \
37 printk(KERN_INFO "%s: " fmt, "mt2131", ## arg)
38
39static u8 mt2131_config1[] = {
40 0x01,
41 0x50, 0x00, 0x50, 0x80, 0x00, 0x49, 0xfa, 0x88,
42 0x08, 0x77, 0x41, 0x04, 0x00, 0x00, 0x00, 0x32,
43 0x7f, 0xda, 0x4c, 0x00, 0x10, 0xaa, 0x78, 0x80,
44 0xff, 0x68, 0xa0, 0xff, 0xdd, 0x00, 0x00
45};
46
47static u8 mt2131_config2[] = {
48 0x10,
49 0x7f, 0xc8, 0x0a, 0x5f, 0x00, 0x04
50};
51
52static int mt2131_readreg(struct mt2131_priv *priv, u8 reg, u8 *val)
53{
54 struct i2c_msg msg[2] = {
55 { .addr = priv->cfg->i2c_address, .flags = 0,
56 .buf = &reg, .len = 1 },
57 { .addr = priv->cfg->i2c_address, .flags = I2C_M_RD,
58 .buf = val, .len = 1 },
59 };
60
61 if (i2c_transfer(priv->i2c, msg, 2) != 2) {
62 printk(KERN_WARNING "mt2131 I2C read failed\n");
63 return -EREMOTEIO;
64 }
65 return 0;
66}
67
68static int mt2131_writereg(struct mt2131_priv *priv, u8 reg, u8 val)
69{
70 u8 buf[2] = { reg, val };
71 struct i2c_msg msg = { .addr = priv->cfg->i2c_address, .flags = 0,
72 .buf = buf, .len = 2 };
73
74 if (i2c_transfer(priv->i2c, &msg, 1) != 1) {
75 printk(KERN_WARNING "mt2131 I2C write failed\n");
76 return -EREMOTEIO;
77 }
78 return 0;
79}
80
81static int mt2131_writeregs(struct mt2131_priv *priv,u8 *buf, u8 len)
82{
83 struct i2c_msg msg = { .addr = priv->cfg->i2c_address,
84 .flags = 0, .buf = buf, .len = len };
85
86 if (i2c_transfer(priv->i2c, &msg, 1) != 1) {
87 printk(KERN_WARNING "mt2131 I2C write failed (len=%i)\n",
88 (int)len);
89 return -EREMOTEIO;
90 }
91 return 0;
92}
93
94static int mt2131_set_params(struct dvb_frontend *fe,
95 struct dvb_frontend_parameters *params)
96{
97 struct mt2131_priv *priv;
98 int ret=0, i;
99 u32 freq;
100 u8 if_band_center;
101 u32 f_lo1, f_lo2;
102 u32 div1, num1, div2, num2;
103 u8 b[8];
104 u8 lockval = 0;
105
106 priv = fe->tuner_priv;
107 if (fe->ops.info.type == FE_OFDM)
108 priv->bandwidth = params->u.ofdm.bandwidth;
109 else
110 priv->bandwidth = 0;
111
112 freq = params->frequency / 1000; // Hz -> kHz
113 dprintk(1, "%s() freq=%d\n", __FUNCTION__, freq);
114
115 f_lo1 = freq + MT2131_IF1 * 1000;
116 f_lo1 = (f_lo1 / 250) * 250;
117 f_lo2 = f_lo1 - freq - MT2131_IF2;
118
119 priv->frequency = (f_lo1 - f_lo2 - MT2131_IF2) * 1000,
120
121 /* Frequency LO1 = 16MHz * (DIV1 + NUM1/8192 ) */
122 num1 = f_lo1 * 64 / (MT2131_FREF / 128);
123 div1 = num1 / 8192;
124 num1 &= 0x1fff;
125
126 /* Frequency LO2 = 16MHz * (DIV2 + NUM2/8192 ) */
127 num2 = f_lo2 * 64 / (MT2131_FREF / 128);
128 div2 = num2 / 8192;
129 num2 &= 0x1fff;
130
131 if (freq <= 82500) if_band_center = 0x00; else
132 if (freq <= 137500) if_band_center = 0x01; else
133 if (freq <= 192500) if_band_center = 0x02; else
134 if (freq <= 247500) if_band_center = 0x03; else
135 if (freq <= 302500) if_band_center = 0x04; else
136 if (freq <= 357500) if_band_center = 0x05; else
137 if (freq <= 412500) if_band_center = 0x06; else
138 if (freq <= 467500) if_band_center = 0x07; else
139 if (freq <= 522500) if_band_center = 0x08; else
140 if (freq <= 577500) if_band_center = 0x09; else
141 if (freq <= 632500) if_band_center = 0x0A; else
142 if (freq <= 687500) if_band_center = 0x0B; else
143 if (freq <= 742500) if_band_center = 0x0C; else
144 if (freq <= 797500) if_band_center = 0x0D; else
145 if (freq <= 852500) if_band_center = 0x0E; else
146 if (freq <= 907500) if_band_center = 0x0F; else
147 if (freq <= 962500) if_band_center = 0x10; else
148 if (freq <= 1017500) if_band_center = 0x11; else
149 if (freq <= 1072500) if_band_center = 0x12; else if_band_center = 0x13;
150
151 b[0] = 1;
152 b[1] = (num1 >> 5) & 0xFF;
153 b[2] = (num1 & 0x1F);
154 b[3] = div1;
155 b[4] = (num2 >> 5) & 0xFF;
156 b[5] = num2 & 0x1F;
157 b[6] = div2;
158
159 dprintk(1, "IF1: %dMHz IF2: %dMHz\n", MT2131_IF1, MT2131_IF2);
160 dprintk(1, "PLL freq=%dkHz band=%d\n", (int)freq, (int)if_band_center);
161 dprintk(1, "PLL f_lo1=%dkHz f_lo2=%dkHz\n", (int)f_lo1, (int)f_lo2);
162 dprintk(1, "PLL div1=%d num1=%d div2=%d num2=%d\n",
163 (int)div1, (int)num1, (int)div2, (int)num2);
164 dprintk(1, "PLL [1..6]: %2x %2x %2x %2x %2x %2x\n",
165 (int)b[1], (int)b[2], (int)b[3], (int)b[4], (int)b[5],
166 (int)b[6]);
167
168 ret = mt2131_writeregs(priv,b,7);
169 if (ret < 0)
170 return ret;
171
172 mt2131_writereg(priv, 0x0b, if_band_center);
173
174 /* Wait for lock */
175 i = 0;
176 do {
177 mt2131_readreg(priv, 0x08, &lockval);
178 if ((lockval & 0x88) == 0x88)
179 break;
180 msleep(4);
181 i++;
182 } while (i < 10);
183
184 return ret;
185}
186
187static int mt2131_get_frequency(struct dvb_frontend *fe, u32 *frequency)
188{
189 struct mt2131_priv *priv = fe->tuner_priv;
190 dprintk(1, "%s()\n", __FUNCTION__);
191 *frequency = priv->frequency;
192 return 0;
193}
194
195static int mt2131_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
196{
197 struct mt2131_priv *priv = fe->tuner_priv;
198 dprintk(1, "%s()\n", __FUNCTION__);
199 *bandwidth = priv->bandwidth;
200 return 0;
201}
202
203static int mt2131_get_status(struct dvb_frontend *fe, u32 *status)
204{
205 struct mt2131_priv *priv = fe->tuner_priv;
206 u8 lock_status = 0;
207 u8 afc_status = 0;
208
209 *status = 0;
210
211 mt2131_readreg(priv, 0x08, &lock_status);
212 if ((lock_status & 0x88) == 0x88)
213 *status = TUNER_STATUS_LOCKED;
214
215 mt2131_readreg(priv, 0x09, &afc_status);
216 dprintk(1, "%s() - LO Status = 0x%x, AFC Status = 0x%x\n",
217 __FUNCTION__, lock_status, afc_status);
218
219 return 0;
220}
221
222static int mt2131_init(struct dvb_frontend *fe)
223{
224 struct mt2131_priv *priv = fe->tuner_priv;
225 int ret;
226 dprintk(1, "%s()\n", __FUNCTION__);
227
228 if ((ret = mt2131_writeregs(priv, mt2131_config1,
229 sizeof(mt2131_config1))) < 0)
230 return ret;
231
232 mt2131_writereg(priv, 0x0b, 0x09);
233 mt2131_writereg(priv, 0x15, 0x47);
234 mt2131_writereg(priv, 0x07, 0xf2);
235 mt2131_writereg(priv, 0x0b, 0x01);
236
237 if ((ret = mt2131_writeregs(priv, mt2131_config2,
238 sizeof(mt2131_config2))) < 0)
239 return ret;
240
241 return ret;
242}
243
244static int mt2131_release(struct dvb_frontend *fe)
245{
246 dprintk(1, "%s()\n", __FUNCTION__);
247 kfree(fe->tuner_priv);
248 fe->tuner_priv = NULL;
249 return 0;
250}
251
252static const struct dvb_tuner_ops mt2131_tuner_ops = {
253 .info = {
254 .name = "Microtune MT2131",
255 .frequency_min = 48000000,
256 .frequency_max = 860000000,
257 .frequency_step = 50000,
258 },
259
260 .release = mt2131_release,
261 .init = mt2131_init,
262
263 .set_params = mt2131_set_params,
264 .get_frequency = mt2131_get_frequency,
265 .get_bandwidth = mt2131_get_bandwidth,
266 .get_status = mt2131_get_status
267};
268
269struct dvb_frontend * mt2131_attach(struct dvb_frontend *fe,
270 struct i2c_adapter *i2c,
271 struct mt2131_config *cfg, u16 if1)
272{
273 struct mt2131_priv *priv = NULL;
274 u8 id = 0;
275
276 dprintk(1, "%s()\n", __FUNCTION__);
277
278 priv = kzalloc(sizeof(struct mt2131_priv), GFP_KERNEL);
279 if (priv == NULL)
280 return NULL;
281
282 priv->cfg = cfg;
283 priv->bandwidth = 6000000; /* 6MHz */
284 priv->i2c = i2c;
285
286 if (mt2131_readreg(priv, 0, &id) != 0) {
287 kfree(priv);
288 return NULL;
289 }
290 if ( (id != 0x3E) && (id != 0x3F) ) {
291 printk(KERN_ERR "MT2131: Device not found at addr 0x%02x\n",
292 cfg->i2c_address);
293 kfree(priv);
294 return NULL;
295 }
296
297 printk(KERN_INFO "MT2131: successfully identified at address 0x%02x\n",
298 cfg->i2c_address);
299 memcpy(&fe->ops.tuner_ops, &mt2131_tuner_ops,
300 sizeof(struct dvb_tuner_ops));
301
302 fe->tuner_priv = priv;
303 return fe;
304}
305EXPORT_SYMBOL(mt2131_attach);
306
307MODULE_AUTHOR("Steven Toth");
308MODULE_DESCRIPTION("Microtune MT2131 silicon tuner driver");
309MODULE_LICENSE("GPL");
310
311/*
312 * Local variables:
313 * c-basic-offset: 8
314 */
diff --git a/drivers/media/dvb/frontends/mt2131.h b/drivers/media/dvb/frontends/mt2131.h
new file mode 100644
index 000000000000..1e4ffe7dc8c8
--- /dev/null
+++ b/drivers/media/dvb/frontends/mt2131.h
@@ -0,0 +1,54 @@
1/*
2 * Driver for Microtune MT2131 "QAM/8VSB single chip tuner"
3 *
4 * Copyright (c) 2006 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#ifndef __MT2131_H__
23#define __MT2131_H__
24
25struct dvb_frontend;
26struct i2c_adapter;
27
28struct mt2131_config {
29 u8 i2c_address;
30 u8 clock_out; /* 0 = off, 1 = CLK/4, 2 = CLK/2, 3 = CLK/1 */
31};
32
33#if defined(CONFIG_DVB_TUNER_MT2131) || (defined(CONFIG_DVB_TUNER_MT2131_MODULE) && defined(MODULE))
34extern struct dvb_frontend* mt2131_attach(struct dvb_frontend *fe,
35 struct i2c_adapter *i2c,
36 struct mt2131_config *cfg,
37 u16 if1);
38#else
39static inline struct dvb_frontend* mt2131_attach(struct dvb_frontend *fe,
40 struct i2c_adapter *i2c,
41 struct mt2131_config *cfg,
42 u16 if1)
43{
44 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
45 return NULL;
46}
47#endif /* CONFIG_DVB_TUNER_MT2131 */
48
49#endif /* __MT2131_H__ */
50
51/*
52 * Local variables:
53 * c-basic-offset: 8
54 */
diff --git a/drivers/media/dvb/frontends/mt2131_priv.h b/drivers/media/dvb/frontends/mt2131_priv.h
new file mode 100644
index 000000000000..e930759c2c00
--- /dev/null
+++ b/drivers/media/dvb/frontends/mt2131_priv.h
@@ -0,0 +1,49 @@
1/*
2 * Driver for Microtune MT2131 "QAM/8VSB single chip tuner"
3 *
4 * Copyright (c) 2006 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#ifndef __MT2131_PRIV_H__
23#define __MT2131_PRIV_H__
24
25/* Regs */
26#define MT2131_PWR 0x07
27#define MT2131_UPC_1 0x0b
28#define MT2131_AGC_RL 0x10
29#define MT2131_MISC_2 0x15
30
31/* frequency values in KHz */
32#define MT2131_IF1 1220
33#define MT2131_IF2 44000
34#define MT2131_FREF 16000
35
36struct mt2131_priv {
37 struct mt2131_config *cfg;
38 struct i2c_adapter *i2c;
39
40 u32 frequency;
41 u32 bandwidth;
42};
43
44#endif /* __MT2131_PRIV_H__ */
45
46/*
47 * Local variables:
48 * c-basic-offset: 8
49 */
diff --git a/drivers/media/dvb/frontends/mt2266.c b/drivers/media/dvb/frontends/mt2266.c
new file mode 100644
index 000000000000..03fe8265745f
--- /dev/null
+++ b/drivers/media/dvb/frontends/mt2266.c
@@ -0,0 +1,287 @@
1/*
2 * Driver for Microtune MT2266 "Direct conversion low power broadband tuner"
3 *
4 * Copyright (c) 2007 Olivier DANET <odanet@caramail.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
17#include <linux/module.h>
18#include <linux/delay.h>
19#include <linux/dvb/frontend.h>
20#include <linux/i2c.h>
21
22#include "dvb_frontend.h"
23#include "mt2266.h"
24
25#define I2C_ADDRESS 0x60
26
27#define REG_PART_REV 0
28#define REG_TUNE 1
29#define REG_BAND 6
30#define REG_BANDWIDTH 8
31#define REG_LOCK 0x12
32
33#define PART_REV 0x85
34
35struct mt2266_priv {
36 struct mt2266_config *cfg;
37 struct i2c_adapter *i2c;
38
39 u32 frequency;
40 u32 bandwidth;
41};
42
43/* Here, frequencies are expressed in kiloHertz to avoid 32 bits overflows */
44
45static int debug;
46module_param(debug, int, 0644);
47MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
48
49#define dprintk(args...) do { if (debug) {printk(KERN_DEBUG "MT2266: " args); printk("\n"); }} while (0)
50
51// Reads a single register
52static int mt2266_readreg(struct mt2266_priv *priv, u8 reg, u8 *val)
53{
54 struct i2c_msg msg[2] = {
55 { .addr = priv->cfg->i2c_address, .flags = 0, .buf = &reg, .len = 1 },
56 { .addr = priv->cfg->i2c_address, .flags = I2C_M_RD, .buf = val, .len = 1 },
57 };
58 if (i2c_transfer(priv->i2c, msg, 2) != 2) {
59 printk(KERN_WARNING "MT2266 I2C read failed\n");
60 return -EREMOTEIO;
61 }
62 return 0;
63}
64
65// Writes a single register
66static int mt2266_writereg(struct mt2266_priv *priv, u8 reg, u8 val)
67{
68 u8 buf[2] = { reg, val };
69 struct i2c_msg msg = {
70 .addr = priv->cfg->i2c_address, .flags = 0, .buf = buf, .len = 2
71 };
72 if (i2c_transfer(priv->i2c, &msg, 1) != 1) {
73 printk(KERN_WARNING "MT2266 I2C write failed\n");
74 return -EREMOTEIO;
75 }
76 return 0;
77}
78
79// Writes a set of consecutive registers
80static int mt2266_writeregs(struct mt2266_priv *priv,u8 *buf, u8 len)
81{
82 struct i2c_msg msg = {
83 .addr = priv->cfg->i2c_address, .flags = 0, .buf = buf, .len = len
84 };
85 if (i2c_transfer(priv->i2c, &msg, 1) != 1) {
86 printk(KERN_WARNING "MT2266 I2C write failed (len=%i)\n",(int)len);
87 return -EREMOTEIO;
88 }
89 return 0;
90}
91
92// Initialisation sequences
93static u8 mt2266_init1[] = {
94 REG_TUNE,
95 0x00, 0x00, 0x28, 0x00, 0x52, 0x99, 0x3f };
96
97static u8 mt2266_init2[] = {
98 0x17, 0x6d, 0x71, 0x61, 0xc0, 0xbf, 0xff, 0xdc, 0x00, 0x0a,
99 0xd4, 0x03, 0x64, 0x64, 0x64, 0x64, 0x22, 0xaa, 0xf2, 0x1e, 0x80, 0x14, 0x01, 0x01, 0x01, 0x01,
100 0x01, 0x01, 0x7f, 0x5e, 0x3f, 0xff, 0xff, 0xff, 0x00, 0x77, 0x0f, 0x2d };
101
102static u8 mt2266_init_8mhz[] = {
103 REG_BANDWIDTH,
104 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22 };
105
106static u8 mt2266_init_7mhz[] = {
107 REG_BANDWIDTH,
108 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32 };
109
110static u8 mt2266_init_6mhz[] = {
111 REG_BANDWIDTH,
112 0xa7, 0xa7, 0xa7, 0xa7, 0xa7, 0xa7, 0xa7, 0xa7 };
113
114#define FREF 30000 // Quartz oscillator 30 MHz
115
116static int mt2266_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
117{
118 struct mt2266_priv *priv;
119 int ret=0;
120 u32 freq;
121 u32 tune;
122 u8 lnaband;
123 u8 b[10];
124 int i;
125
126 priv = fe->tuner_priv;
127
128 mt2266_writereg(priv,0x17,0x6d);
129 mt2266_writereg(priv,0x1c,0xff);
130
131 freq = params->frequency / 1000; // Hz -> kHz
132 priv->bandwidth = (fe->ops.info.type == FE_OFDM) ? params->u.ofdm.bandwidth : 0;
133 priv->frequency = freq * 1000;
134 tune=2 * freq * (8192/16) / (FREF/16);
135
136 if (freq <= 495000) lnaband = 0xEE; else
137 if (freq <= 525000) lnaband = 0xDD; else
138 if (freq <= 550000) lnaband = 0xCC; else
139 if (freq <= 580000) lnaband = 0xBB; else
140 if (freq <= 605000) lnaband = 0xAA; else
141 if (freq <= 630000) lnaband = 0x99; else
142 if (freq <= 655000) lnaband = 0x88; else
143 if (freq <= 685000) lnaband = 0x77; else
144 if (freq <= 710000) lnaband = 0x66; else
145 if (freq <= 735000) lnaband = 0x55; else
146 if (freq <= 765000) lnaband = 0x44; else
147 if (freq <= 802000) lnaband = 0x33; else
148 if (freq <= 840000) lnaband = 0x22; else lnaband = 0x11;
149
150 msleep(100);
151 mt2266_writeregs(priv,(params->u.ofdm.bandwidth==BANDWIDTH_6_MHZ)?mt2266_init_6mhz:
152 (params->u.ofdm.bandwidth==BANDWIDTH_7_MHZ)?mt2266_init_7mhz:
153 mt2266_init_8mhz,sizeof(mt2266_init_8mhz));
154
155 b[0] = REG_TUNE;
156 b[1] = (tune >> 8) & 0x1F;
157 b[2] = tune & 0xFF;
158 b[3] = tune >> 13;
159 mt2266_writeregs(priv,b,4);
160
161 dprintk("set_parms: tune=%d band=%d",(int)tune,(int)lnaband);
162 dprintk("set_parms: [1..3]: %2x %2x %2x",(int)b[1],(int)b[2],(int)b[3]);
163
164 b[0] = 0x05;
165 b[1] = 0x62;
166 b[2] = lnaband;
167 mt2266_writeregs(priv,b,3);
168
169 //Waits for pll lock or timeout
170 i = 0;
171 do {
172 mt2266_readreg(priv,REG_LOCK,b);
173 if ((b[0] & 0x40)==0x40)
174 break;
175 msleep(10);
176 i++;
177 } while (i<10);
178 dprintk("Lock when i=%i",(int)i);
179 return ret;
180}
181
182static void mt2266_calibrate(struct mt2266_priv *priv)
183{
184 mt2266_writereg(priv,0x11,0x03);
185 mt2266_writereg(priv,0x11,0x01);
186
187 mt2266_writeregs(priv,mt2266_init1,sizeof(mt2266_init1));
188 mt2266_writeregs(priv,mt2266_init2,sizeof(mt2266_init2));
189
190 mt2266_writereg(priv,0x33,0x5e);
191 mt2266_writereg(priv,0x10,0x10);
192 mt2266_writereg(priv,0x10,0x00);
193
194 mt2266_writeregs(priv,mt2266_init_8mhz,sizeof(mt2266_init_8mhz));
195
196 msleep(25);
197 mt2266_writereg(priv,0x17,0x6d);
198 mt2266_writereg(priv,0x1c,0x00);
199 msleep(75);
200 mt2266_writereg(priv,0x17,0x6d);
201 mt2266_writereg(priv,0x1c,0xff);
202}
203
204static int mt2266_get_frequency(struct dvb_frontend *fe, u32 *frequency)
205{
206 struct mt2266_priv *priv = fe->tuner_priv;
207 *frequency = priv->frequency;
208 return 0;
209}
210
211static int mt2266_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
212{
213 struct mt2266_priv *priv = fe->tuner_priv;
214 *bandwidth = priv->bandwidth;
215 return 0;
216}
217
218static int mt2266_init(struct dvb_frontend *fe)
219{
220 struct mt2266_priv *priv = fe->tuner_priv;
221 mt2266_writereg(priv,0x17,0x6d);
222 mt2266_writereg(priv,0x1c,0xff);
223 return 0;
224}
225
226static int mt2266_sleep(struct dvb_frontend *fe)
227{
228 struct mt2266_priv *priv = fe->tuner_priv;
229 mt2266_writereg(priv,0x17,0x6d);
230 mt2266_writereg(priv,0x1c,0x00);
231 return 0;
232}
233
234static int mt2266_release(struct dvb_frontend *fe)
235{
236 kfree(fe->tuner_priv);
237 fe->tuner_priv = NULL;
238 return 0;
239}
240
241static const struct dvb_tuner_ops mt2266_tuner_ops = {
242 .info = {
243 .name = "Microtune MT2266",
244 .frequency_min = 470000000,
245 .frequency_max = 860000000,
246 .frequency_step = 50000,
247 },
248 .release = mt2266_release,
249 .init = mt2266_init,
250 .sleep = mt2266_sleep,
251 .set_params = mt2266_set_params,
252 .get_frequency = mt2266_get_frequency,
253 .get_bandwidth = mt2266_get_bandwidth
254};
255
256struct dvb_frontend * mt2266_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, struct mt2266_config *cfg)
257{
258 struct mt2266_priv *priv = NULL;
259 u8 id = 0;
260
261 priv = kzalloc(sizeof(struct mt2266_priv), GFP_KERNEL);
262 if (priv == NULL)
263 return NULL;
264
265 priv->cfg = cfg;
266 priv->i2c = i2c;
267
268 if (mt2266_readreg(priv,0,&id) != 0) {
269 kfree(priv);
270 return NULL;
271 }
272 if (id != PART_REV) {
273 kfree(priv);
274 return NULL;
275 }
276 printk(KERN_INFO "MT2266: successfully identified\n");
277 memcpy(&fe->ops.tuner_ops, &mt2266_tuner_ops, sizeof(struct dvb_tuner_ops));
278
279 fe->tuner_priv = priv;
280 mt2266_calibrate(priv);
281 return fe;
282}
283EXPORT_SYMBOL(mt2266_attach);
284
285MODULE_AUTHOR("Olivier DANET");
286MODULE_DESCRIPTION("Microtune MT2266 silicon tuner driver");
287MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/frontends/mt2266.h b/drivers/media/dvb/frontends/mt2266.h
new file mode 100644
index 000000000000..f31dd613ad37
--- /dev/null
+++ b/drivers/media/dvb/frontends/mt2266.h
@@ -0,0 +1,37 @@
1/*
2 * Driver for Microtune MT2266 "Direct conversion low power broadband tuner"
3 *
4 * Copyright (c) 2007 Olivier DANET <odanet@caramail.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
17#ifndef MT2266_H
18#define MT2266_H
19
20struct dvb_frontend;
21struct i2c_adapter;
22
23struct mt2266_config {
24 u8 i2c_address;
25};
26
27#if defined(CONFIG_DVB_TUNER_MT2266) || (defined(CONFIG_DVB_TUNER_MT2266_MODULE) && defined(MODULE))
28extern struct dvb_frontend * mt2266_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, struct mt2266_config *cfg);
29#else
30static inline struct dvb_frontend * mt2266_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, struct mt2266_config *cfg)
31{
32 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
33 return NULL;
34}
35#endif // CONFIG_DVB_TUNER_MT2266
36
37#endif
diff --git a/drivers/media/dvb/frontends/mt312.c b/drivers/media/dvb/frontends/mt312.c
index 1ef821825641..0606b9a5b616 100644
--- a/drivers/media/dvb/frontends/mt312.c
+++ b/drivers/media/dvb/frontends/mt312.c
@@ -28,7 +28,6 @@
28#include <linux/init.h> 28#include <linux/init.h>
29#include <linux/kernel.h> 29#include <linux/kernel.h>
30#include <linux/module.h> 30#include <linux/module.h>
31#include <linux/moduleparam.h>
32#include <linux/string.h> 31#include <linux/string.h>
33#include <linux/slab.h> 32#include <linux/slab.h>
34 33
diff --git a/drivers/media/dvb/frontends/mt352.c b/drivers/media/dvb/frontends/mt352.c
index 87e31ca7e108..5dd9b731f6f2 100644
--- a/drivers/media/dvb/frontends/mt352.c
+++ b/drivers/media/dvb/frontends/mt352.c
@@ -32,7 +32,6 @@
32 32
33#include <linux/kernel.h> 33#include <linux/kernel.h>
34#include <linux/module.h> 34#include <linux/module.h>
35#include <linux/moduleparam.h>
36#include <linux/init.h> 35#include <linux/init.h>
37#include <linux/delay.h> 36#include <linux/delay.h>
38#include <linux/string.h> 37#include <linux/string.h>
diff --git a/drivers/media/dvb/frontends/nxt200x.c b/drivers/media/dvb/frontends/nxt200x.c
index ddc84899cf86..fcf964fe1d6b 100644
--- a/drivers/media/dvb/frontends/nxt200x.c
+++ b/drivers/media/dvb/frontends/nxt200x.c
@@ -44,7 +44,6 @@
44#include <linux/kernel.h> 44#include <linux/kernel.h>
45#include <linux/init.h> 45#include <linux/init.h>
46#include <linux/module.h> 46#include <linux/module.h>
47#include <linux/moduleparam.h>
48#include <linux/slab.h> 47#include <linux/slab.h>
49#include <linux/string.h> 48#include <linux/string.h>
50 49
diff --git a/drivers/media/dvb/frontends/or51132.c b/drivers/media/dvb/frontends/or51132.c
index 3cc8b444b8f2..b314a1f2deed 100644
--- a/drivers/media/dvb/frontends/or51132.c
+++ b/drivers/media/dvb/frontends/or51132.c
@@ -36,7 +36,6 @@
36 36
37#include <linux/kernel.h> 37#include <linux/kernel.h>
38#include <linux/module.h> 38#include <linux/module.h>
39#include <linux/moduleparam.h>
40#include <linux/init.h> 39#include <linux/init.h>
41#include <linux/delay.h> 40#include <linux/delay.h>
42#include <linux/string.h> 41#include <linux/string.h>
diff --git a/drivers/media/dvb/frontends/or51211.c b/drivers/media/dvb/frontends/or51211.c
index f46d5a46683a..f02bd9445955 100644
--- a/drivers/media/dvb/frontends/or51211.c
+++ b/drivers/media/dvb/frontends/or51211.c
@@ -32,7 +32,6 @@
32 32
33#include <linux/kernel.h> 33#include <linux/kernel.h>
34#include <linux/module.h> 34#include <linux/module.h>
35#include <linux/moduleparam.h>
36#include <linux/device.h> 35#include <linux/device.h>
37#include <linux/firmware.h> 36#include <linux/firmware.h>
38#include <linux/string.h> 37#include <linux/string.h>
diff --git a/drivers/media/dvb/frontends/s5h1409.c b/drivers/media/dvb/frontends/s5h1409.c
new file mode 100644
index 000000000000..30e8a705fad4
--- /dev/null
+++ b/drivers/media/dvb/frontends/s5h1409.c
@@ -0,0 +1,729 @@
1/*
2 Samsung S5H1409 VSB/QAM demodulator driver
3
4 Copyright (C) 2006 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 "s5h1409.h"
31
32struct s5h1409_state {
33
34 struct i2c_adapter* i2c;
35
36 /* configuration settings */
37 const struct s5h1409_config* config;
38
39 struct dvb_frontend frontend;
40
41 /* previous uncorrected block counter */
42 fe_modulation_t current_modulation;
43
44 u32 current_frequency;
45};
46
47static int debug = 0;
48#define dprintk if (debug) printk
49
50/* Register values to initialise the demod, this will set VSB by default */
51static struct init_tab {
52 u8 reg;
53 u16 data;
54} init_tab[] = {
55 { 0x00, 0x0071, },
56 { 0x01, 0x3213, },
57 { 0x09, 0x0025, },
58 { 0x1c, 0x001d, },
59 { 0x1f, 0x002d, },
60 { 0x20, 0x001d, },
61 { 0x22, 0x0022, },
62 { 0x23, 0x0020, },
63 { 0x29, 0x110f, },
64 { 0x2a, 0x10b4, },
65 { 0x2b, 0x10ae, },
66 { 0x2c, 0x0031, },
67 { 0x31, 0x010d, },
68 { 0x32, 0x0100, },
69 { 0x44, 0x0510, },
70 { 0x54, 0x0104, },
71 { 0x58, 0x2222, },
72 { 0x59, 0x1162, },
73 { 0x5a, 0x3211, },
74 { 0x5d, 0x0370, },
75 { 0x5e, 0x0296, },
76 { 0x61, 0x0010, },
77 { 0x63, 0x4a00, },
78 { 0x65, 0x0800, },
79 { 0x71, 0x0003, },
80 { 0x72, 0x0470, },
81 { 0x81, 0x0002, },
82 { 0x82, 0x0600, },
83 { 0x86, 0x0002, },
84 { 0x8a, 0x2c38, },
85 { 0x8b, 0x2a37, },
86 { 0x92, 0x302f, },
87 { 0x93, 0x3332, },
88 { 0x96, 0x000c, },
89 { 0x99, 0x0101, },
90 { 0x9c, 0x2e37, },
91 { 0x9d, 0x2c37, },
92 { 0x9e, 0x2c37, },
93 { 0xab, 0x0100, },
94 { 0xac, 0x1003, },
95 { 0xad, 0x103f, },
96 { 0xe2, 0x0100, },
97 { 0x28, 0x1010, },
98 { 0xb1, 0x000e, },
99};
100
101/* VSB SNR lookup table */
102static struct vsb_snr_tab {
103 u16 val;
104 u16 data;
105} vsb_snr_tab[] = {
106 { 1023, 770, },
107 { 923, 300, },
108 { 918, 295, },
109 { 915, 290, },
110 { 911, 285, },
111 { 906, 280, },
112 { 901, 275, },
113 { 896, 270, },
114 { 891, 265, },
115 { 885, 260, },
116 { 879, 255, },
117 { 873, 250, },
118 { 864, 245, },
119 { 858, 240, },
120 { 850, 235, },
121 { 841, 230, },
122 { 832, 225, },
123 { 823, 220, },
124 { 812, 215, },
125 { 802, 210, },
126 { 788, 205, },
127 { 778, 200, },
128 { 767, 195, },
129 { 753, 190, },
130 { 740, 185, },
131 { 725, 180, },
132 { 707, 175, },
133 { 689, 170, },
134 { 671, 165, },
135 { 656, 160, },
136 { 637, 155, },
137 { 616, 150, },
138 { 542, 145, },
139 { 519, 140, },
140 { 507, 135, },
141 { 497, 130, },
142 { 492, 125, },
143 { 474, 120, },
144 { 300, 111, },
145 { 0, 0, },
146};
147
148/* QAM64 SNR lookup table */
149static struct qam64_snr_tab {
150 u16 val;
151 u16 data;
152} qam64_snr_tab[] = {
153 { 12, 300, },
154 { 15, 290, },
155 { 18, 280, },
156 { 22, 270, },
157 { 23, 268, },
158 { 24, 266, },
159 { 25, 264, },
160 { 27, 262, },
161 { 28, 260, },
162 { 29, 258, },
163 { 30, 256, },
164 { 32, 254, },
165 { 33, 252, },
166 { 34, 250, },
167 { 35, 249, },
168 { 36, 248, },
169 { 37, 247, },
170 { 38, 246, },
171 { 39, 245, },
172 { 40, 244, },
173 { 41, 243, },
174 { 42, 241, },
175 { 43, 240, },
176 { 44, 239, },
177 { 45, 238, },
178 { 46, 237, },
179 { 47, 236, },
180 { 48, 235, },
181 { 49, 234, },
182 { 50, 233, },
183 { 51, 232, },
184 { 52, 231, },
185 { 53, 230, },
186 { 55, 229, },
187 { 56, 228, },
188 { 57, 227, },
189 { 58, 226, },
190 { 59, 225, },
191 { 60, 224, },
192 { 62, 223, },
193 { 63, 222, },
194 { 65, 221, },
195 { 66, 220, },
196 { 68, 219, },
197 { 69, 218, },
198 { 70, 217, },
199 { 72, 216, },
200 { 73, 215, },
201 { 75, 214, },
202 { 76, 213, },
203 { 78, 212, },
204 { 80, 211, },
205 { 81, 210, },
206 { 83, 209, },
207 { 84, 208, },
208 { 85, 207, },
209 { 87, 206, },
210 { 89, 205, },
211 { 91, 204, },
212 { 93, 203, },
213 { 95, 202, },
214 { 96, 201, },
215 { 104, 200, },
216};
217
218/* QAM256 SNR lookup table */
219static struct qam256_snr_tab {
220 u16 val;
221 u16 data;
222} qam256_snr_tab[] = {
223 { 12, 400, },
224 { 13, 390, },
225 { 15, 380, },
226 { 17, 360, },
227 { 19, 350, },
228 { 22, 348, },
229 { 23, 346, },
230 { 24, 344, },
231 { 25, 342, },
232 { 26, 340, },
233 { 27, 336, },
234 { 28, 334, },
235 { 29, 332, },
236 { 30, 330, },
237 { 31, 328, },
238 { 32, 326, },
239 { 33, 325, },
240 { 34, 322, },
241 { 35, 320, },
242 { 37, 318, },
243 { 39, 316, },
244 { 40, 314, },
245 { 41, 312, },
246 { 42, 310, },
247 { 43, 308, },
248 { 46, 306, },
249 { 47, 304, },
250 { 49, 302, },
251 { 51, 300, },
252 { 53, 298, },
253 { 54, 297, },
254 { 55, 296, },
255 { 56, 295, },
256 { 57, 294, },
257 { 59, 293, },
258 { 60, 292, },
259 { 61, 291, },
260 { 63, 290, },
261 { 64, 289, },
262 { 65, 288, },
263 { 66, 287, },
264 { 68, 286, },
265 { 69, 285, },
266 { 71, 284, },
267 { 72, 283, },
268 { 74, 282, },
269 { 75, 281, },
270 { 76, 280, },
271 { 77, 279, },
272 { 78, 278, },
273 { 81, 277, },
274 { 83, 276, },
275 { 84, 275, },
276 { 86, 274, },
277 { 87, 273, },
278 { 89, 272, },
279 { 90, 271, },
280 { 92, 270, },
281 { 93, 269, },
282 { 95, 268, },
283 { 96, 267, },
284 { 98, 266, },
285 { 100, 265, },
286 { 102, 264, },
287 { 104, 263, },
288 { 105, 262, },
289 { 106, 261, },
290 { 110, 260, },
291};
292
293/* 8 bit registers, 16 bit values */
294static int s5h1409_writereg(struct s5h1409_state* state, u8 reg, u16 data)
295{
296 int ret;
297 u8 buf [] = { reg, data >> 8, data & 0xff };
298
299 struct i2c_msg msg = { .addr = state->config->demod_address,
300 .flags = 0, .buf = buf, .len = 3 };
301
302 ret = i2c_transfer(state->i2c, &msg, 1);
303
304 if (ret != 1)
305 printk("%s: writereg error (reg == 0x%02x, val == 0x%04x, "
306 "ret == %i)\n", __FUNCTION__, reg, data, ret);
307
308 return (ret != 1) ? -1 : 0;
309}
310
311static u16 s5h1409_readreg(struct s5h1409_state* state, u8 reg)
312{
313 int ret;
314 u8 b0 [] = { reg };
315 u8 b1 [] = { 0, 0 };
316
317 struct i2c_msg msg [] = {
318 { .addr = state->config->demod_address, .flags = 0,
319 .buf = b0, .len = 1 },
320 { .addr = state->config->demod_address, .flags = I2C_M_RD,
321 .buf = b1, .len = 2 } };
322
323 ret = i2c_transfer(state->i2c, msg, 2);
324
325 if (ret != 2)
326 printk("%s: readreg error (ret == %i)\n", __FUNCTION__, ret);
327 return (b1[0] << 8) | b1[1];
328}
329
330static int s5h1409_softreset(struct dvb_frontend* fe)
331{
332 struct s5h1409_state* state = fe->demodulator_priv;
333
334 dprintk("%s()\n", __FUNCTION__);
335
336 s5h1409_writereg(state, 0xf5, 0);
337 s5h1409_writereg(state, 0xf5, 1);
338 return 0;
339}
340
341static int s5h1409_set_if_freq(struct dvb_frontend* fe, int KHz)
342{
343 struct s5h1409_state* state = fe->demodulator_priv;
344 int ret = 0;
345
346 dprintk("%s(%d KHz)\n", __FUNCTION__, KHz);
347
348 if( (KHz == 44000) || (KHz == 5380) ) {
349 s5h1409_writereg(state, 0x87, 0x01be);
350 s5h1409_writereg(state, 0x88, 0x0436);
351 s5h1409_writereg(state, 0x89, 0x054d);
352 } else {
353 printk("%s() Invalid arg = %d KHz\n", __FUNCTION__, KHz);
354 ret = -1;
355 }
356
357 return ret;
358}
359
360static int s5h1409_set_spectralinversion(struct dvb_frontend* fe, int inverted)
361{
362 struct s5h1409_state* state = fe->demodulator_priv;
363
364 dprintk("%s()\n", __FUNCTION__);
365
366 if(inverted == 1)
367 return s5h1409_writereg(state, 0x1b, 0x1101); /* Inverted */
368 else
369 return s5h1409_writereg(state, 0x1b, 0x0110); /* Normal */
370}
371
372static int s5h1409_enable_modulation(struct dvb_frontend* fe,
373 fe_modulation_t m)
374{
375 struct s5h1409_state* state = fe->demodulator_priv;
376
377 dprintk("%s(0x%08x)\n", __FUNCTION__, m);
378
379 switch(m) {
380 case VSB_8:
381 dprintk("%s() VSB_8\n", __FUNCTION__);
382 s5h1409_writereg(state, 0xf4, 0);
383 break;
384 case QAM_64:
385 dprintk("%s() QAM_64\n", __FUNCTION__);
386 s5h1409_writereg(state, 0xf4, 1);
387 s5h1409_writereg(state, 0x85, 0x100);
388 break;
389 case QAM_256:
390 dprintk("%s() QAM_256\n", __FUNCTION__);
391 s5h1409_writereg(state, 0xf4, 1);
392 s5h1409_writereg(state, 0x85, 0x101);
393 break;
394 default:
395 dprintk("%s() Invalid modulation\n", __FUNCTION__);
396 return -EINVAL;
397 }
398
399 state->current_modulation = m;
400 s5h1409_softreset(fe);
401
402 return 0;
403}
404
405static int s5h1409_i2c_gate_ctrl(struct dvb_frontend* fe, int enable)
406{
407 struct s5h1409_state* state = fe->demodulator_priv;
408
409 dprintk("%s(%d)\n", __FUNCTION__, enable);
410
411 if (enable)
412 return s5h1409_writereg(state, 0xf3, 1);
413 else
414 return s5h1409_writereg(state, 0xf3, 0);
415}
416
417static int s5h1409_set_gpio(struct dvb_frontend* fe, int enable)
418{
419 struct s5h1409_state* state = fe->demodulator_priv;
420
421 dprintk("%s(%d)\n", __FUNCTION__, enable);
422
423 if (enable)
424 return s5h1409_writereg(state, 0xe3, 0x1100);
425 else
426 return s5h1409_writereg(state, 0xe3, 0);
427}
428
429static int s5h1409_sleep(struct dvb_frontend* fe, int enable)
430{
431 struct s5h1409_state* state = fe->demodulator_priv;
432
433 dprintk("%s(%d)\n", __FUNCTION__, enable);
434
435 return s5h1409_writereg(state, 0xf2, enable);
436}
437
438static int s5h1409_register_reset(struct dvb_frontend* fe)
439{
440 struct s5h1409_state* state = fe->demodulator_priv;
441
442 dprintk("%s()\n", __FUNCTION__);
443
444 return s5h1409_writereg(state, 0xfa, 0);
445}
446
447/* Talk to the demod, set the FEC, GUARD, QAM settings etc */
448static int s5h1409_set_frontend (struct dvb_frontend* fe,
449 struct dvb_frontend_parameters *p)
450{
451 struct s5h1409_state* state = fe->demodulator_priv;
452
453 dprintk("%s(frequency=%d)\n", __FUNCTION__, p->frequency);
454
455 s5h1409_softreset(fe);
456
457 state->current_frequency = p->frequency;
458
459 s5h1409_enable_modulation(fe, p->u.vsb.modulation);
460
461 if (fe->ops.tuner_ops.set_params) {
462 if (fe->ops.i2c_gate_ctrl) fe->ops.i2c_gate_ctrl(fe, 1);
463 fe->ops.tuner_ops.set_params(fe, p);
464 if (fe->ops.i2c_gate_ctrl) fe->ops.i2c_gate_ctrl(fe, 0);
465 }
466
467 return 0;
468}
469
470/* Reset the demod hardware and reset all of the configuration registers
471 to a default state. */
472static int s5h1409_init (struct dvb_frontend* fe)
473{
474 int i;
475
476 struct s5h1409_state* state = fe->demodulator_priv;
477 dprintk("%s()\n", __FUNCTION__);
478
479 s5h1409_sleep(fe, 0);
480 s5h1409_register_reset(fe);
481
482 for (i=0; i < ARRAY_SIZE(init_tab); i++)
483 s5h1409_writereg(state, init_tab[i].reg, init_tab[i].data);
484
485 /* The datasheet says that after initialisation, VSB is default */
486 state->current_modulation = VSB_8;
487
488 if (state->config->output_mode == S5H1409_SERIAL_OUTPUT)
489 s5h1409_writereg(state, 0xab, 0x100); /* Serial */
490 else
491 s5h1409_writereg(state, 0xab, 0x0); /* Parallel */
492
493 s5h1409_set_spectralinversion(fe, state->config->inversion);
494 s5h1409_set_if_freq(fe, state->config->if_freq);
495 s5h1409_set_gpio(fe, state->config->gpio);
496 s5h1409_softreset(fe);
497
498 /* Note: Leaving the I2C gate open here. */
499 s5h1409_i2c_gate_ctrl(fe, 1);
500
501 return 0;
502}
503
504static int s5h1409_read_status(struct dvb_frontend* fe, fe_status_t* status)
505{
506 struct s5h1409_state* state = fe->demodulator_priv;
507 u16 reg;
508 u32 tuner_status = 0;
509
510 *status = 0;
511
512 /* Get the demodulator status */
513 reg = s5h1409_readreg(state, 0xf1);
514 if(reg & 0x1000)
515 *status |= FE_HAS_VITERBI;
516 if(reg & 0x8000)
517 *status |= FE_HAS_LOCK | FE_HAS_SYNC;
518
519 switch(state->config->status_mode) {
520 case S5H1409_DEMODLOCKING:
521 if (*status & FE_HAS_VITERBI)
522 *status |= FE_HAS_CARRIER | FE_HAS_SIGNAL;
523 break;
524 case S5H1409_TUNERLOCKING:
525 /* Get the tuner status */
526 if (fe->ops.tuner_ops.get_status) {
527 if (fe->ops.i2c_gate_ctrl)
528 fe->ops.i2c_gate_ctrl(fe, 1);
529
530 fe->ops.tuner_ops.get_status(fe, &tuner_status);
531
532 if (fe->ops.i2c_gate_ctrl)
533 fe->ops.i2c_gate_ctrl(fe, 0);
534 }
535 if (tuner_status)
536 *status |= FE_HAS_CARRIER | FE_HAS_SIGNAL;
537 break;
538 }
539
540 dprintk("%s() status 0x%08x\n", __FUNCTION__, *status);
541
542 return 0;
543}
544
545static int s5h1409_qam256_lookup_snr(struct dvb_frontend* fe, u16* snr, u16 v)
546{
547 int i, ret = -EINVAL;
548 dprintk("%s()\n", __FUNCTION__);
549
550 for (i=0; i < ARRAY_SIZE(qam256_snr_tab); i++) {
551 if (v < qam256_snr_tab[i].val) {
552 *snr = qam256_snr_tab[i].data;
553 ret = 0;
554 break;
555 }
556 }
557 return ret;
558}
559
560static int s5h1409_qam64_lookup_snr(struct dvb_frontend* fe, u16* snr, u16 v)
561{
562 int i, ret = -EINVAL;
563 dprintk("%s()\n", __FUNCTION__);
564
565 for (i=0; i < ARRAY_SIZE(qam64_snr_tab); i++) {
566 if (v < qam64_snr_tab[i].val) {
567 *snr = qam64_snr_tab[i].data;
568 ret = 0;
569 break;
570 }
571 }
572 return ret;
573}
574
575static int s5h1409_vsb_lookup_snr(struct dvb_frontend* fe, u16* snr, u16 v)
576{
577 int i, ret = -EINVAL;
578 dprintk("%s()\n", __FUNCTION__);
579
580 for (i=0; i < ARRAY_SIZE(vsb_snr_tab); i++) {
581 if (v > vsb_snr_tab[i].val) {
582 *snr = vsb_snr_tab[i].data;
583 ret = 0;
584 break;
585 }
586 }
587 dprintk("%s() snr=%d\n", __FUNCTION__, *snr);
588 return ret;
589}
590
591static int s5h1409_read_snr(struct dvb_frontend* fe, u16* snr)
592{
593 struct s5h1409_state* state = fe->demodulator_priv;
594 u16 reg;
595 dprintk("%s()\n", __FUNCTION__);
596
597 reg = s5h1409_readreg(state, 0xf1) & 0x1ff;
598
599 switch(state->current_modulation) {
600 case QAM_64:
601 return s5h1409_qam64_lookup_snr(fe, snr, reg);
602 case QAM_256:
603 return s5h1409_qam256_lookup_snr(fe, snr, reg);
604 case VSB_8:
605 return s5h1409_vsb_lookup_snr(fe, snr, reg);
606 default:
607 break;
608 }
609
610 return -EINVAL;
611}
612
613static int s5h1409_read_signal_strength(struct dvb_frontend* fe,
614 u16* signal_strength)
615{
616 return s5h1409_read_snr(fe, signal_strength);
617}
618
619static int s5h1409_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
620{
621 struct s5h1409_state* state = fe->demodulator_priv;
622
623 *ucblocks = s5h1409_readreg(state, 0xb5);
624
625 return 0;
626}
627
628static int s5h1409_read_ber(struct dvb_frontend* fe, u32* ber)
629{
630 return s5h1409_read_ucblocks(fe, ber);
631}
632
633static int s5h1409_get_frontend(struct dvb_frontend* fe,
634 struct dvb_frontend_parameters *p)
635{
636 struct s5h1409_state* state = fe->demodulator_priv;
637
638 p->frequency = state->current_frequency;
639 p->u.vsb.modulation = state->current_modulation;
640
641 return 0;
642}
643
644static int s5h1409_get_tune_settings(struct dvb_frontend* fe,
645 struct dvb_frontend_tune_settings *tune)
646{
647 tune->min_delay_ms = 1000;
648 return 0;
649}
650
651static void s5h1409_release(struct dvb_frontend* fe)
652{
653 struct s5h1409_state* state = fe->demodulator_priv;
654 kfree(state);
655}
656
657static struct dvb_frontend_ops s5h1409_ops;
658
659struct dvb_frontend* s5h1409_attach(const struct s5h1409_config* config,
660 struct i2c_adapter* i2c)
661{
662 struct s5h1409_state* state = NULL;
663
664 /* allocate memory for the internal state */
665 state = kmalloc(sizeof(struct s5h1409_state), GFP_KERNEL);
666 if (state == NULL)
667 goto error;
668
669 /* setup the state */
670 state->config = config;
671 state->i2c = i2c;
672 state->current_modulation = 0;
673
674 /* check if the demod exists */
675 if (s5h1409_readreg(state, 0x04) != 0x0066)
676 goto error;
677
678 /* create dvb_frontend */
679 memcpy(&state->frontend.ops, &s5h1409_ops,
680 sizeof(struct dvb_frontend_ops));
681 state->frontend.demodulator_priv = state;
682
683 /* Note: Leaving the I2C gate open here. */
684 s5h1409_writereg(state, 0xf3, 1);
685
686 return &state->frontend;
687
688error:
689 kfree(state);
690 return NULL;
691}
692
693static struct dvb_frontend_ops s5h1409_ops = {
694
695 .info = {
696 .name = "Samsung S5H1409 QAM/8VSB Frontend",
697 .type = FE_ATSC,
698 .frequency_min = 54000000,
699 .frequency_max = 858000000,
700 .frequency_stepsize = 62500,
701 .caps = FE_CAN_QAM_64 | FE_CAN_QAM_256 | FE_CAN_8VSB
702 },
703
704 .init = s5h1409_init,
705 .i2c_gate_ctrl = s5h1409_i2c_gate_ctrl,
706 .set_frontend = s5h1409_set_frontend,
707 .get_frontend = s5h1409_get_frontend,
708 .get_tune_settings = s5h1409_get_tune_settings,
709 .read_status = s5h1409_read_status,
710 .read_ber = s5h1409_read_ber,
711 .read_signal_strength = s5h1409_read_signal_strength,
712 .read_snr = s5h1409_read_snr,
713 .read_ucblocks = s5h1409_read_ucblocks,
714 .release = s5h1409_release,
715};
716
717module_param(debug, int, 0644);
718MODULE_PARM_DESC(debug, "Enable verbose debug messages");
719
720MODULE_DESCRIPTION("Samsung S5H1409 QAM-B/ATSC Demodulator driver");
721MODULE_AUTHOR("Steven Toth");
722MODULE_LICENSE("GPL");
723
724EXPORT_SYMBOL(s5h1409_attach);
725
726/*
727 * Local variables:
728 * c-basic-offset: 8
729 */
diff --git a/drivers/media/dvb/frontends/s5h1409.h b/drivers/media/dvb/frontends/s5h1409.h
new file mode 100644
index 000000000000..20f9af1af445
--- /dev/null
+++ b/drivers/media/dvb/frontends/s5h1409.h
@@ -0,0 +1,73 @@
1/*
2 Samsung S5H1409 VSB/QAM demodulator driver
3
4 Copyright (C) 2006 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 __S5H1409_H__
23#define __S5H1409_H__
24
25#include <linux/dvb/frontend.h>
26
27struct s5h1409_config
28{
29 /* the demodulator's i2c address */
30 u8 demod_address;
31
32 /* serial/parallel output */
33#define S5H1409_PARALLEL_OUTPUT 0
34#define S5H1409_SERIAL_OUTPUT 1
35 u8 output_mode;
36
37 /* GPIO Setting */
38#define S5H1409_GPIO_OFF 0
39#define S5H1409_GPIO_ON 1
40 u8 gpio;
41
42 /* IF Freq in KHz */
43 u16 if_freq;
44
45 /* Spectral Inversion */
46#define S5H1409_INVERSION_OFF 0
47#define S5H1409_INVERSION_ON 1
48 u8 inversion;
49
50 /* Return lock status based on tuner lock, or demod lock */
51#define S5H1409_TUNERLOCKING 0
52#define S5H1409_DEMODLOCKING 1
53 u8 status_mode;
54};
55
56#if defined(CONFIG_DVB_S5H1409) || (defined(CONFIG_DVB_S5H1409_MODULE) && defined(MODULE))
57extern struct dvb_frontend* s5h1409_attach(const struct s5h1409_config* config,
58 struct i2c_adapter* i2c);
59#else
60static inline struct dvb_frontend* s5h1409_attach(const struct s5h1409_config* config,
61 struct i2c_adapter* i2c)
62{
63 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
64 return NULL;
65}
66#endif /* CONFIG_DVB_S5H1409 */
67
68#endif /* __S5H1409_H__ */
69
70/*
71 * Local variables:
72 * c-basic-offset: 8
73 */
diff --git a/drivers/media/dvb/frontends/sp8870.c b/drivers/media/dvb/frontends/sp8870.c
index d98fd5c2e13e..da876f7bfe32 100644
--- a/drivers/media/dvb/frontends/sp8870.c
+++ b/drivers/media/dvb/frontends/sp8870.c
@@ -29,7 +29,6 @@
29 29
30#include <linux/init.h> 30#include <linux/init.h>
31#include <linux/module.h> 31#include <linux/module.h>
32#include <linux/moduleparam.h>
33#include <linux/device.h> 32#include <linux/device.h>
34#include <linux/firmware.h> 33#include <linux/firmware.h>
35#include <linux/delay.h> 34#include <linux/delay.h>
diff --git a/drivers/media/dvb/frontends/sp887x.c b/drivers/media/dvb/frontends/sp887x.c
index 5c2f8f4e0ae5..1aa2539f5099 100644
--- a/drivers/media/dvb/frontends/sp887x.c
+++ b/drivers/media/dvb/frontends/sp887x.c
@@ -12,7 +12,6 @@
12 12
13#include <linux/init.h> 13#include <linux/init.h>
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/moduleparam.h>
16#include <linux/device.h> 15#include <linux/device.h>
17#include <linux/firmware.h> 16#include <linux/firmware.h>
18#include <linux/string.h> 17#include <linux/string.h>
diff --git a/drivers/media/dvb/frontends/stv0297.c b/drivers/media/dvb/frontends/stv0297.c
index 9a343972ff50..17e5cb561cd8 100644
--- a/drivers/media/dvb/frontends/stv0297.c
+++ b/drivers/media/dvb/frontends/stv0297.c
@@ -680,8 +680,8 @@ static struct dvb_frontend_ops stv0297_ops = {
680 .info = { 680 .info = {
681 .name = "ST STV0297 DVB-C", 681 .name = "ST STV0297 DVB-C",
682 .type = FE_QAM, 682 .type = FE_QAM,
683 .frequency_min = 64000000, 683 .frequency_min = 47000000,
684 .frequency_max = 1300000000, 684 .frequency_max = 862000000,
685 .frequency_stepsize = 62500, 685 .frequency_stepsize = 62500,
686 .symbol_rate_min = 870000, 686 .symbol_rate_min = 870000,
687 .symbol_rate_max = 11700000, 687 .symbol_rate_max = 11700000,
diff --git a/drivers/media/dvb/frontends/stv0299.c b/drivers/media/dvb/frontends/stv0299.c
index 6c607302c1b6..035dd7ba6519 100644
--- a/drivers/media/dvb/frontends/stv0299.c
+++ b/drivers/media/dvb/frontends/stv0299.c
@@ -45,7 +45,6 @@
45#include <linux/init.h> 45#include <linux/init.h>
46#include <linux/kernel.h> 46#include <linux/kernel.h>
47#include <linux/module.h> 47#include <linux/module.h>
48#include <linux/moduleparam.h>
49#include <linux/string.h> 48#include <linux/string.h>
50#include <linux/slab.h> 49#include <linux/slab.h>
51#include <linux/jiffies.h> 50#include <linux/jiffies.h>
diff --git a/drivers/media/dvb/frontends/tda10021.c b/drivers/media/dvb/frontends/tda10021.c
index e725f612a6b7..4cd9e82c4669 100644
--- a/drivers/media/dvb/frontends/tda10021.c
+++ b/drivers/media/dvb/frontends/tda10021.c
@@ -439,8 +439,8 @@ static struct dvb_frontend_ops tda10021_ops = {
439 .name = "Philips TDA10021 DVB-C", 439 .name = "Philips TDA10021 DVB-C",
440 .type = FE_QAM, 440 .type = FE_QAM,
441 .frequency_stepsize = 62500, 441 .frequency_stepsize = 62500,
442 .frequency_min = 51000000, 442 .frequency_min = 47000000,
443 .frequency_max = 858000000, 443 .frequency_max = 862000000,
444 .symbol_rate_min = (XIN/2)/64, /* SACLK/64 == (XIN/2)/64 */ 444 .symbol_rate_min = (XIN/2)/64, /* SACLK/64 == (XIN/2)/64 */
445 .symbol_rate_max = (XIN/2)/4, /* SACLK/4 */ 445 .symbol_rate_max = (XIN/2)/4, /* SACLK/4 */
446 #if 0 446 #if 0
diff --git a/drivers/media/dvb/frontends/tda10023.c b/drivers/media/dvb/frontends/tda10023.c
index 4bb06f97938b..364bc01971a0 100644
--- a/drivers/media/dvb/frontends/tda10023.c
+++ b/drivers/media/dvb/frontends/tda10023.c
@@ -215,12 +215,6 @@ static int tda10023_set_symbolrate (struct tda10023_state* state, u32 sr)
215 s16 SFIL=0; 215 s16 SFIL=0;
216 u16 NDEC = 0; 216 u16 NDEC = 0;
217 217
218 if (sr > (SYSCLK/(2*4)))
219 sr=SYSCLK/(2*4);
220
221 if (sr<870000)
222 sr=870000;
223
224 if (sr < (u32)(SYSCLK/98.40)) { 218 if (sr < (u32)(SYSCLK/98.40)) {
225 NDEC=3; 219 NDEC=3;
226 SFIL=1; 220 SFIL=1;
@@ -506,8 +500,8 @@ static struct dvb_frontend_ops tda10023_ops = {
506 .name = "Philips TDA10023 DVB-C", 500 .name = "Philips TDA10023 DVB-C",
507 .type = FE_QAM, 501 .type = FE_QAM,
508 .frequency_stepsize = 62500, 502 .frequency_stepsize = 62500,
509 .frequency_min = 51000000, 503 .frequency_min = 47000000,
510 .frequency_max = 858000000, 504 .frequency_max = 862000000,
511 .symbol_rate_min = (SYSCLK/2)/64, /* SACLK/64 == (SYSCLK/2)/64 */ 505 .symbol_rate_min = (SYSCLK/2)/64, /* SACLK/64 == (SYSCLK/2)/64 */
512 .symbol_rate_max = (SYSCLK/2)/4, /* SACLK/4 */ 506 .symbol_rate_max = (SYSCLK/2)/4, /* SACLK/4 */
513 .caps = 0x400 | //FE_CAN_QAM_4 507 .caps = 0x400 | //FE_CAN_QAM_4
diff --git a/drivers/media/dvb/frontends/tda1004x.c b/drivers/media/dvb/frontends/tda1004x.c
index 33a84372c9e6..8415a8a5247a 100644
--- a/drivers/media/dvb/frontends/tda1004x.c
+++ b/drivers/media/dvb/frontends/tda1004x.c
@@ -31,7 +31,6 @@
31 31
32#include <linux/init.h> 32#include <linux/init.h>
33#include <linux/module.h> 33#include <linux/module.h>
34#include <linux/moduleparam.h>
35#include <linux/device.h> 34#include <linux/device.h>
36#include <linux/jiffies.h> 35#include <linux/jiffies.h>
37#include <linux/string.h> 36#include <linux/string.h>
diff --git a/drivers/media/dvb/frontends/tda10086.c b/drivers/media/dvb/frontends/tda10086.c
index 0f2d4b415560..9a8ddc537f8f 100644
--- a/drivers/media/dvb/frontends/tda10086.c
+++ b/drivers/media/dvb/frontends/tda10086.c
@@ -22,7 +22,6 @@
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/moduleparam.h>
26#include <linux/device.h> 25#include <linux/device.h>
27#include <linux/jiffies.h> 26#include <linux/jiffies.h>
28#include <linux/string.h> 27#include <linux/string.h>
diff --git a/drivers/media/dvb/frontends/tda8083.c b/drivers/media/dvb/frontends/tda8083.c
index 67415c9db6f7..011b74f798a0 100644
--- a/drivers/media/dvb/frontends/tda8083.c
+++ b/drivers/media/dvb/frontends/tda8083.c
@@ -27,7 +27,6 @@
27#include <linux/init.h> 27#include <linux/init.h>
28#include <linux/kernel.h> 28#include <linux/kernel.h>
29#include <linux/module.h> 29#include <linux/module.h>
30#include <linux/moduleparam.h>
31#include <linux/string.h> 30#include <linux/string.h>
32#include <linux/slab.h> 31#include <linux/slab.h>
33#include <linux/jiffies.h> 32#include <linux/jiffies.h>
@@ -443,12 +442,12 @@ static struct dvb_frontend_ops tda8083_ops = {
443 .info = { 442 .info = {
444 .name = "Philips TDA8083 DVB-S", 443 .name = "Philips TDA8083 DVB-S",
445 .type = FE_QPSK, 444 .type = FE_QPSK,
446 .frequency_min = 950000, /* FIXME: guessed! */ 445 .frequency_min = 920000, /* TDA8060 */
447 .frequency_max = 1400000, /* FIXME: guessed! */ 446 .frequency_max = 2200000, /* TDA8060 */
448 .frequency_stepsize = 125, /* kHz for QPSK frontends */ 447 .frequency_stepsize = 125, /* kHz for QPSK frontends */
449 /* .frequency_tolerance = ???,*/ 448 /* .frequency_tolerance = ???,*/
450 .symbol_rate_min = 1000000, /* FIXME: guessed! */ 449 .symbol_rate_min = 12000000,
451 .symbol_rate_max = 45000000, /* FIXME: guessed! */ 450 .symbol_rate_max = 30000000,
452 /* .symbol_rate_tolerance = ???,*/ 451 /* .symbol_rate_tolerance = ???,*/
453 .caps = FE_CAN_INVERSION_AUTO | 452 .caps = FE_CAN_INVERSION_AUTO |
454 FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 | 453 FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
diff --git a/drivers/media/dvb/frontends/ves1820.c b/drivers/media/dvb/frontends/ves1820.c
index 9b57576bfeb4..066b73b75698 100644
--- a/drivers/media/dvb/frontends/ves1820.c
+++ b/drivers/media/dvb/frontends/ves1820.c
@@ -410,8 +410,8 @@ static struct dvb_frontend_ops ves1820_ops = {
410 .name = "VLSI VES1820 DVB-C", 410 .name = "VLSI VES1820 DVB-C",
411 .type = FE_QAM, 411 .type = FE_QAM,
412 .frequency_stepsize = 62500, 412 .frequency_stepsize = 62500,
413 .frequency_min = 51000000, 413 .frequency_min = 47000000,
414 .frequency_max = 858000000, 414 .frequency_max = 862000000,
415 .caps = FE_CAN_QAM_16 | 415 .caps = FE_CAN_QAM_16 |
416 FE_CAN_QAM_32 | 416 FE_CAN_QAM_32 |
417 FE_CAN_QAM_64 | 417 FE_CAN_QAM_64 |
diff --git a/drivers/media/dvb/frontends/zl10353.c b/drivers/media/dvb/frontends/zl10353.c
index 245f9b7dddfa..a97a7fd2c891 100644
--- a/drivers/media/dvb/frontends/zl10353.c
+++ b/drivers/media/dvb/frontends/zl10353.c
@@ -21,7 +21,6 @@
21 21
22#include <linux/kernel.h> 22#include <linux/kernel.h>
23#include <linux/module.h> 23#include <linux/module.h>
24#include <linux/moduleparam.h>
25#include <linux/init.h> 24#include <linux/init.h>
26#include <linux/delay.h> 25#include <linux/delay.h>
27#include <linux/string.h> 26#include <linux/string.h>
diff --git a/drivers/media/dvb/ttpci/av7110.c b/drivers/media/dvb/ttpci/av7110.c
index 8178832d14a8..8b8144f77a73 100644
--- a/drivers/media/dvb/ttpci/av7110.c
+++ b/drivers/media/dvb/ttpci/av7110.c
@@ -40,7 +40,6 @@
40#include <linux/smp_lock.h> 40#include <linux/smp_lock.h>
41 41
42#include <linux/kernel.h> 42#include <linux/kernel.h>
43#include <linux/moduleparam.h>
44#include <linux/sched.h> 43#include <linux/sched.h>
45#include <linux/types.h> 44#include <linux/types.h>
46#include <linux/fcntl.h> 45#include <linux/fcntl.h>
@@ -1543,7 +1542,7 @@ static int get_firmware(struct av7110* av7110)
1543 } 1542 }
1544 1543
1545 /* check if the firmware is available */ 1544 /* check if the firmware is available */
1546 av7110->bin_fw = (unsigned char *) vmalloc(fw->size); 1545 av7110->bin_fw = vmalloc(fw->size);
1547 if (NULL == av7110->bin_fw) { 1546 if (NULL == av7110->bin_fw) {
1548 dprintk(1, "out of memory\n"); 1547 dprintk(1, "out of memory\n");
1549 release_firmware(fw); 1548 release_firmware(fw);
diff --git a/drivers/media/dvb/ttpci/av7110_hw.c b/drivers/media/dvb/ttpci/av7110_hw.c
index 515e8232e020..a468aa2e4854 100644
--- a/drivers/media/dvb/ttpci/av7110_hw.c
+++ b/drivers/media/dvb/ttpci/av7110_hw.c
@@ -978,24 +978,24 @@ static int OSDSetColor(struct av7110 *av7110, u8 color, u8 r, u8 g, u8 b, u8 ble
978 978
979static int OSDSetPalette(struct av7110 *av7110, u32 __user * colors, u8 first, u8 last) 979static int OSDSetPalette(struct av7110 *av7110, u32 __user * colors, u8 first, u8 last)
980{ 980{
981 int i; 981 int i;
982 int length = last - first + 1; 982 int length = last - first + 1;
983 983
984 if (length * 4 > DATA_BUFF3_SIZE) 984 if (length * 4 > DATA_BUFF3_SIZE)
985 return -EINVAL; 985 return -EINVAL;
986 986
987 for (i = 0; i < length; i++) { 987 for (i = 0; i < length; i++) {
988 u32 color, blend, yuv; 988 u32 color, blend, yuv;
989 989
990 if (get_user(color, colors + i)) 990 if (get_user(color, colors + i))
991 return -EFAULT; 991 return -EFAULT;
992 blend = (color & 0xF0000000) >> 4; 992 blend = (color & 0xF0000000) >> 4;
993 yuv = blend ? RGB2YUV(color & 0xFF, (color >> 8) & 0xFF, 993 yuv = blend ? RGB2YUV(color & 0xFF, (color >> 8) & 0xFF,
994 (color >> 16) & 0xFF) | blend : 0; 994 (color >> 16) & 0xFF) | blend : 0;
995 yuv = ((yuv & 0xFFFF0000) >> 16) | ((yuv & 0x0000FFFF) << 16); 995 yuv = ((yuv & 0xFFFF0000) >> 16) | ((yuv & 0x0000FFFF) << 16);
996 wdebi(av7110, DEBINOSWAP, DATA_BUFF3_BASE + i * 4, yuv, 4); 996 wdebi(av7110, DEBINOSWAP, DATA_BUFF3_BASE + i * 4, yuv, 4);
997 } 997 }
998 return av7110_fw_cmd(av7110, COMTYPE_OSD, Set_Palette, 4, 998 return av7110_fw_cmd(av7110, COMTYPE_OSD, Set_Palette, 4,
999 av7110->osdwin, 999 av7110->osdwin,
1000 bpp2pal[av7110->osdbpp[av7110->osdwin]], 1000 bpp2pal[av7110->osdbpp[av7110->osdwin]],
1001 first, last); 1001 first, last);
diff --git a/drivers/media/dvb/ttpci/av7110_ir.c b/drivers/media/dvb/ttpci/av7110_ir.c
index 6322800ee12b..5d19c402dad1 100644
--- a/drivers/media/dvb/ttpci/av7110_ir.c
+++ b/drivers/media/dvb/ttpci/av7110_ir.c
@@ -25,7 +25,6 @@
25#include <linux/types.h> 25#include <linux/types.h>
26#include <linux/init.h> 26#include <linux/init.h>
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/moduleparam.h>
29#include <linux/proc_fs.h> 28#include <linux/proc_fs.h>
30#include <linux/kernel.h> 29#include <linux/kernel.h>
31#include <asm/bitops.h> 30#include <asm/bitops.h>
@@ -280,7 +279,7 @@ static int av7110_ir_write_proc(struct file *file, const char __user *buffer,
280 if (count < size) 279 if (count < size)
281 return -EINVAL; 280 return -EINVAL;
282 281
283 page = (char *) vmalloc(size); 282 page = vmalloc(size);
284 if (!page) 283 if (!page)
285 return -ENOMEM; 284 return -ENOMEM;
286 285
diff --git a/drivers/media/dvb/ttpci/av7110_v4l.c b/drivers/media/dvb/ttpci/av7110_v4l.c
index 87afaebc0703..76cca003252f 100644
--- a/drivers/media/dvb/ttpci/av7110_v4l.c
+++ b/drivers/media/dvb/ttpci/av7110_v4l.c
@@ -129,23 +129,25 @@ static struct v4l2_input inputs[4] = {
129 129
130static int ves1820_writereg(struct saa7146_dev *dev, u8 addr, u8 reg, u8 data) 130static int ves1820_writereg(struct saa7146_dev *dev, u8 addr, u8 reg, u8 data)
131{ 131{
132 struct av7110 *av7110 = dev->ext_priv;
132 u8 buf[] = { 0x00, reg, data }; 133 u8 buf[] = { 0x00, reg, data };
133 struct i2c_msg msg = { .addr = addr, .flags = 0, .buf = buf, .len = 3 }; 134 struct i2c_msg msg = { .addr = addr, .flags = 0, .buf = buf, .len = 3 };
134 135
135 dprintk(4, "dev: %p\n", dev); 136 dprintk(4, "dev: %p\n", dev);
136 137
137 if (1 != saa7146_i2c_transfer(dev, &msg, 1, 1)) 138 if (1 != i2c_transfer(&av7110->i2c_adap, &msg, 1))
138 return -1; 139 return -1;
139 return 0; 140 return 0;
140} 141}
141 142
142static int tuner_write(struct saa7146_dev *dev, u8 addr, u8 data [4]) 143static int tuner_write(struct saa7146_dev *dev, u8 addr, u8 data [4])
143{ 144{
145 struct av7110 *av7110 = dev->ext_priv;
144 struct i2c_msg msg = { .addr = addr, .flags = 0, .buf = data, .len = 4 }; 146 struct i2c_msg msg = { .addr = addr, .flags = 0, .buf = data, .len = 4 };
145 147
146 dprintk(4, "dev: %p\n", dev); 148 dprintk(4, "dev: %p\n", dev);
147 149
148 if (1 != saa7146_i2c_transfer(dev, &msg, 1, 1)) 150 if (1 != i2c_transfer(&av7110->i2c_adap, &msg, 1))
149 return -1; 151 return -1;
150 return 0; 152 return 0;
151} 153}
diff --git a/drivers/media/dvb/ttpci/budget-av.c b/drivers/media/dvb/ttpci/budget-av.c
index 0aee7a13a070..3439c9864f67 100644
--- a/drivers/media/dvb/ttpci/budget-av.c
+++ b/drivers/media/dvb/ttpci/budget-av.c
@@ -1232,7 +1232,7 @@ static struct saa7146_ext_vv vv_data = {
1232 .capabilities = 0, // perhaps later: V4L2_CAP_VBI_CAPTURE, but that need tweaking with the saa7113 1232 .capabilities = 0, // perhaps later: V4L2_CAP_VBI_CAPTURE, but that need tweaking with the saa7113
1233 .flags = 0, 1233 .flags = 0,
1234 .stds = &standard[0], 1234 .stds = &standard[0],
1235 .num_stds = sizeof(standard) / sizeof(struct saa7146_standard), 1235 .num_stds = ARRAY_SIZE(standard),
1236 .ioctls = &ioctls[0], 1236 .ioctls = &ioctls[0],
1237 .ioctl = av_ioctl, 1237 .ioctl = av_ioctl,
1238}; 1238};
diff --git a/drivers/media/dvb/ttpci/budget-ci.c b/drivers/media/dvb/ttpci/budget-ci.c
index 873c3ba296f2..509349211d4f 100644
--- a/drivers/media/dvb/ttpci/budget-ci.c
+++ b/drivers/media/dvb/ttpci/budget-ci.c
@@ -214,7 +214,6 @@ static int msp430_ir_init(struct budget_ci *budget_ci)
214 case 0x100f: 214 case 0x100f:
215 case 0x1011: 215 case 0x1011:
216 case 0x1012: 216 case 0x1012:
217 case 0x1017:
218 /* The hauppauge keymap is a superset of these remotes */ 217 /* The hauppauge keymap is a superset of these remotes */
219 ir_input_init(input_dev, &budget_ci->ir.state, 218 ir_input_init(input_dev, &budget_ci->ir.state,
220 IR_TYPE_RC5, ir_codes_hauppauge_new); 219 IR_TYPE_RC5, ir_codes_hauppauge_new);
@@ -225,6 +224,7 @@ static int msp430_ir_init(struct budget_ci *budget_ci)
225 budget_ci->ir.rc5_device = rc5_device; 224 budget_ci->ir.rc5_device = rc5_device;
226 break; 225 break;
227 case 0x1010: 226 case 0x1010:
227 case 0x1017:
228 /* for the Technotrend 1500 bundled remote */ 228 /* for the Technotrend 1500 bundled remote */
229 ir_input_init(input_dev, &budget_ci->ir.state, 229 ir_input_init(input_dev, &budget_ci->ir.state,
230 IR_TYPE_RC5, ir_codes_tt_1500); 230 IR_TYPE_RC5, ir_codes_tt_1500);
diff --git a/drivers/media/dvb/ttpci/budget-core.c b/drivers/media/dvb/ttpci/budget-core.c
index b611f2b1f8bc..0252081f013c 100644
--- a/drivers/media/dvb/ttpci/budget-core.c
+++ b/drivers/media/dvb/ttpci/budget-core.c
@@ -34,7 +34,6 @@
34 * the project's page is at http://www.linuxtv.org/dvb/ 34 * the project's page is at http://www.linuxtv.org/dvb/
35 */ 35 */
36 36
37#include <linux/moduleparam.h>
38 37
39#include "budget.h" 38#include "budget.h"
40#include "ttpci-eeprom.h" 39#include "ttpci-eeprom.h"
diff --git a/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c b/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c
index b60cdc93d6db..288e79f2cb0f 100644
--- a/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c
+++ b/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c
@@ -13,7 +13,6 @@
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include <linux/wait.h> 14#include <linux/wait.h>
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/moduleparam.h>
17#include <linux/usb.h> 16#include <linux/usb.h>
18#include <linux/delay.h> 17#include <linux/delay.h>
19#include <linux/time.h> 18#include <linux/time.h>
diff --git a/drivers/media/dvb/ttusb-dec/ttusb_dec.c b/drivers/media/dvb/ttusb-dec/ttusb_dec.c
index 78c98b089975..5e691fd79904 100644
--- a/drivers/media/dvb/ttusb-dec/ttusb_dec.c
+++ b/drivers/media/dvb/ttusb-dec/ttusb_dec.c
@@ -22,7 +22,6 @@
22 22
23#include <linux/list.h> 23#include <linux/list.h>
24#include <linux/module.h> 24#include <linux/module.h>
25#include <linux/moduleparam.h>
26#include <linux/pci.h> 25#include <linux/pci.h>
27#include <linux/slab.h> 26#include <linux/slab.h>
28#include <linux/spinlock.h> 27#include <linux/spinlock.h>
diff --git a/drivers/media/radio/Kconfig b/drivers/media/radio/Kconfig
index f8bf9fe37d36..11e962f1a97f 100644
--- a/drivers/media/radio/Kconfig
+++ b/drivers/media/radio/Kconfig
@@ -111,11 +111,16 @@ config RADIO_AZTECH_PORT
111 jumper sets the card to 0x358. 111 jumper sets the card to 0x358.
112 112
113config RADIO_GEMTEK 113config RADIO_GEMTEK
114 tristate "GemTek Radio Card support" 114 tristate "GemTek Radio card (or compatible) support"
115 depends on ISA && VIDEO_V4L2 115 depends on ISA && VIDEO_V4L2
116 ---help--- 116 ---help---
117 Choose Y here if you have this FM radio card, and then fill in the 117 Choose Y here if you have this FM radio card, and then fill in the
118 port address below. 118 I/O port address and settings below. The following cards either have
119 GemTek Radio tuner or are rebranded GemTek Radio cards:
120
121 - Sound Vision 16 Gold with FM Radio
122 - Typhoon Radio card (some models)
123 - Hama Radio card
119 124
120 In order to control your radio card, you will need to use programs 125 In order to control your radio card, you will need to use programs
121 that are compatible with the Video For Linux API. Information on 126 that are compatible with the Video For Linux API. Information on
@@ -126,14 +131,25 @@ config RADIO_GEMTEK
126 module will be called radio-gemtek. 131 module will be called radio-gemtek.
127 132
128config RADIO_GEMTEK_PORT 133config RADIO_GEMTEK_PORT
129 hex "GemTek i/o port (0x20c, 0x30c, 0x24c or 0x34c)" 134 hex "Fixed I/O port (0x20c, 0x30c, 0x24c, 0x34c, 0c24c or 0x28c)"
130 depends on RADIO_GEMTEK=y 135 depends on RADIO_GEMTEK=y
131 default "34c" 136 default "34c"
132 help 137 help
133 Enter either 0x20c, 0x30c, 0x24c or 0x34c here. The card default is 138 Enter either 0x20c, 0x30c, 0x24c or 0x34c here. The card default is
134 0x34c, if you haven't changed the jumper setting on the card. On 139 0x34c, if you haven't changed the jumper setting on the card. On
135 Sound Vision 16 Gold PnP with FM Radio (ESS1869+FM Gemtek), the I/O 140 Sound Vision 16 Gold PnP with FM Radio (ESS1869+FM Gemtek), the I/O
136 port is 0x28c. 141 port is 0x20c, 0x248 or 0x28c.
142 If automatic I/O port probing is enabled this port will be used only
143 in case of automatic probing failure, ie. as a fallback.
144
145config RADIO_GEMTEK_PROBE
146 bool "Automatic I/O port probing"
147 depends on RADIO_GEMTEK=y
148 default y
149 help
150 Say Y here to enable automatic probing for GemTek Radio card. The
151 following ports will be probed: 0x20c, 0x30c, 0x24c, 0x34c, 0x248 and
152 0x28c.
137 153
138config RADIO_GEMTEK_PCI 154config RADIO_GEMTEK_PCI
139 tristate "GemTek PCI Radio Card support" 155 tristate "GemTek PCI Radio Card support"
diff --git a/drivers/media/radio/radio-gemtek.c b/drivers/media/radio/radio-gemtek.c
index eab8c80a2e47..0c963db03614 100644
--- a/drivers/media/radio/radio-gemtek.c
+++ b/drivers/media/radio/radio-gemtek.c
@@ -26,143 +26,383 @@
26#include <media/v4l2-common.h> 26#include <media/v4l2-common.h>
27#include <linux/spinlock.h> 27#include <linux/spinlock.h>
28 28
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,3)
31#define RADIO_BANNER "GemTek Radio card driver: v0.0.3"
31 32
32static struct v4l2_queryctrl radio_qctrl[] = { 33/*
33 { 34 * Module info.
34 .id = V4L2_CID_AUDIO_MUTE, 35 */
35 .name = "Mute", 36
36 .minimum = 0, 37MODULE_AUTHOR("Jonas Munsin, Pekka Seppänen <pexu@kapsi.fi>");
37 .maximum = 1, 38MODULE_DESCRIPTION("A driver for the GemTek Radio card.");
38 .default_value = 1, 39MODULE_LICENSE("GPL");
39 .type = V4L2_CTRL_TYPE_BOOLEAN, 40
40 },{ 41/*
41 .id = V4L2_CID_AUDIO_VOLUME, 42 * Module params.
42 .name = "Volume", 43 */
43 .minimum = 0,
44 .maximum = 65535,
45 .step = 65535,
46 .default_value = 0xff,
47 .type = V4L2_CTRL_TYPE_INTEGER,
48 }
49};
50 44
51#ifndef CONFIG_RADIO_GEMTEK_PORT 45#ifndef CONFIG_RADIO_GEMTEK_PORT
52#define CONFIG_RADIO_GEMTEK_PORT -1 46#define CONFIG_RADIO_GEMTEK_PORT -1
53#endif 47#endif
48#ifndef CONFIG_RADIO_GEMTEK_PROBE
49#define CONFIG_RADIO_GEMTEK_PROBE 1
50#endif
54 51
55static int io = CONFIG_RADIO_GEMTEK_PORT; 52static int io = CONFIG_RADIO_GEMTEK_PORT;
56static int radio_nr = -1; 53static int probe = CONFIG_RADIO_GEMTEK_PROBE;
57static spinlock_t lock; 54static int hardmute;
55static int shutdown = 1;
56static int keepmuted = 1;
57static int initmute = 1;
58static int radio_nr = -1;
58 59
59struct gemtek_device 60module_param(io, int, 0444);
60{ 61MODULE_PARM_DESC(io, "Force I/O port for the GemTek Radio card if automatic"
61 int port; 62 "probing is disabled or fails. The most common I/O ports are: 0x20c "
62 unsigned long curfreq; 63 "0x30c, 0x24c or 0x34c (0x20c, 0x248 and 0x28c have been reported to "
64 " work for the combined sound/radiocard).");
65
66module_param(probe, bool, 0444);
67MODULE_PARM_DESC(probe, "Enable automatic device probing. Note: only the most "
68 "common I/O ports used by the card are probed.");
69
70module_param(hardmute, bool, 0644);
71MODULE_PARM_DESC(hardmute, "Enable `hard muting' by shutting down PLL, may "
72 "reduce static noise.");
73
74module_param(shutdown, bool, 0644);
75MODULE_PARM_DESC(shutdown, "Enable shutting down PLL and muting line when "
76 "module is unloaded.");
77
78module_param(keepmuted, bool, 0644);
79MODULE_PARM_DESC(keepmuted, "Keep card muted even when frequency is changed.");
80
81module_param(initmute, bool, 0444);
82MODULE_PARM_DESC(initmute, "Mute card when module is loaded.");
83
84module_param(radio_nr, int, 0444);
85
86/*
87 * Functions for controlling the card.
88 */
89#define GEMTEK_LOWFREQ (87*16000)
90#define GEMTEK_HIGHFREQ (108*16000)
91
92/*
93 * Frequency calculation constants. Intermediate frequency 10.52 MHz (nominal
94 * value 10.7 MHz), reference divisor 6.39 kHz (nominal 6.25 kHz).
95 */
96#define FSCALE 8
97#define IF_OFFSET ((unsigned int)(10.52 * 16000 * (1<<FSCALE)))
98#define REF_FREQ ((unsigned int)(6.39 * 16 * (1<<FSCALE)))
99
100#define GEMTEK_CK 0x01 /* Clock signal */
101#define GEMTEK_DA 0x02 /* Serial data */
102#define GEMTEK_CE 0x04 /* Chip enable */
103#define GEMTEK_NS 0x08 /* No signal */
104#define GEMTEK_MT 0x10 /* Line mute */
105#define GEMTEK_STDF_3_125_KHZ 0x01 /* Standard frequency 3.125 kHz */
106#define GEMTEK_PLL_OFF 0x07 /* PLL off */
107
108#define BU2614_BUS_SIZE 32 /* BU2614 / BU2614FS bus size */
109
110#define SHORT_DELAY 5 /* usec */
111#define LONG_DELAY 75 /* usec */
112
113struct gemtek_device {
114 unsigned long lastfreq;
63 int muted; 115 int muted;
116 u32 bu2614data;
64}; 117};
65 118
119#define BU2614_FREQ_BITS 16 /* D0..D15, Frequency data */
120#define BU2614_PORT_BITS 3 /* P0..P2, Output port control data */
121#define BU2614_VOID_BITS 4 /* unused */
122#define BU2614_FMES_BITS 1 /* CT, Frequency measurement beginning data */
123#define BU2614_STDF_BITS 3 /* R0..R2, Standard frequency data */
124#define BU2614_SWIN_BITS 1 /* S, Switch between FMIN / AMIN */
125#define BU2614_SWAL_BITS 1 /* PS, Swallow counter division (AMIN only)*/
126#define BU2614_VOID2_BITS 1 /* unused */
127#define BU2614_FMUN_BITS 1 /* GT, Frequency measurement time & unlock */
128#define BU2614_TEST_BITS 1 /* TS, Test data is input */
129
130#define BU2614_FREQ_SHIFT 0
131#define BU2614_PORT_SHIFT (BU2614_FREQ_BITS + BU2614_FREQ_SHIFT)
132#define BU2614_VOID_SHIFT (BU2614_PORT_BITS + BU2614_PORT_SHIFT)
133#define BU2614_FMES_SHIFT (BU2614_VOID_BITS + BU2614_VOID_SHIFT)
134#define BU2614_STDF_SHIFT (BU2614_FMES_BITS + BU2614_FMES_SHIFT)
135#define BU2614_SWIN_SHIFT (BU2614_STDF_BITS + BU2614_STDF_SHIFT)
136#define BU2614_SWAL_SHIFT (BU2614_SWIN_BITS + BU2614_SWIN_SHIFT)
137#define BU2614_VOID2_SHIFT (BU2614_SWAL_BITS + BU2614_SWAL_SHIFT)
138#define BU2614_FMUN_SHIFT (BU2614_VOID2_BITS + BU2614_VOID2_SHIFT)
139#define BU2614_TEST_SHIFT (BU2614_FMUN_BITS + BU2614_FMUN_SHIFT)
140
141#define MKMASK(field) (((1<<BU2614_##field##_BITS) - 1) << \
142 BU2614_##field##_SHIFT)
143#define BU2614_PORT_MASK MKMASK(PORT)
144#define BU2614_FREQ_MASK MKMASK(FREQ)
145#define BU2614_VOID_MASK MKMASK(VOID)
146#define BU2614_FMES_MASK MKMASK(FMES)
147#define BU2614_STDF_MASK MKMASK(STDF)
148#define BU2614_SWIN_MASK MKMASK(SWIN)
149#define BU2614_SWAL_MASK MKMASK(SWAL)
150#define BU2614_VOID2_MASK MKMASK(VOID2)
151#define BU2614_FMUN_MASK MKMASK(FMUN)
152#define BU2614_TEST_MASK MKMASK(TEST)
66 153
67/* local things */ 154static struct gemtek_device gemtek_unit;
68 155
69/* the correct way to mute the gemtek may be to write the last written 156static spinlock_t lock;
70 * frequency || 0x10, but just writing 0x10 once seems to do it as well 157
158/*
159 * Set data which will be sent to BU2614FS.
71 */ 160 */
72static void gemtek_mute(struct gemtek_device *dev) 161#define gemtek_bu2614_set(dev, field, data) ((dev)->bu2614data = \
162 ((dev)->bu2614data & ~field##_MASK) | ((data) << field##_SHIFT))
163
164/*
165 * Transmit settings to BU2614FS over GemTek IC.
166 */
167static void gemtek_bu2614_transmit(struct gemtek_device *dev)
73{ 168{
74 if(dev->muted) 169 int i, bit, q, mute;
75 return; 170
76 spin_lock(&lock); 171 spin_lock(&lock);
77 outb(0x10, io); 172
173 mute = dev->muted ? GEMTEK_MT : 0x00;
174
175 outb_p(mute | GEMTEK_DA | GEMTEK_CK, io);
176 udelay(SHORT_DELAY);
177 outb_p(mute | GEMTEK_CE | GEMTEK_DA | GEMTEK_CK, io);
178 udelay(LONG_DELAY);
179
180 for (i = 0, q = dev->bu2614data; i < 32; i++, q >>= 1) {
181 bit = (q & 1) ? GEMTEK_DA : 0;
182 outb_p(mute | GEMTEK_CE | bit, io);
183 udelay(SHORT_DELAY);
184 outb_p(mute | GEMTEK_CE | bit | GEMTEK_CK, io);
185 udelay(SHORT_DELAY);
186 }
187
188 outb_p(mute | GEMTEK_DA | GEMTEK_CK, io);
189 udelay(SHORT_DELAY);
190 outb_p(mute | GEMTEK_CE | GEMTEK_DA | GEMTEK_CK, io);
191 udelay(LONG_DELAY);
192
78 spin_unlock(&lock); 193 spin_unlock(&lock);
79 dev->muted = 1;
80} 194}
81 195
82static void gemtek_unmute(struct gemtek_device *dev) 196/*
197 * Calculate divisor from FM-frequency for BU2614FS (3.125 KHz STDF expected).
198 */
199static unsigned long gemtek_convfreq(unsigned long freq)
83{ 200{
84 if(dev->muted == 0) 201 return ((freq<<FSCALE) + IF_OFFSET + REF_FREQ/2) / REF_FREQ;
202}
203
204/*
205 * Set FM-frequency.
206 */
207static void gemtek_setfreq(struct gemtek_device *dev, unsigned long freq)
208{
209
210 if (keepmuted && hardmute && dev->muted)
85 return; 211 return;
86 spin_lock(&lock); 212
87 outb(0x20, io); 213 if (freq < GEMTEK_LOWFREQ)
88 spin_unlock(&lock); 214 freq = GEMTEK_LOWFREQ;
215 else if (freq > GEMTEK_HIGHFREQ)
216 freq = GEMTEK_HIGHFREQ;
217
218 dev->lastfreq = freq;
89 dev->muted = 0; 219 dev->muted = 0;
220
221 gemtek_bu2614_set(dev, BU2614_PORT, 0);
222 gemtek_bu2614_set(dev, BU2614_FMES, 0);
223 gemtek_bu2614_set(dev, BU2614_SWIN, 0); /* FM-mode */
224 gemtek_bu2614_set(dev, BU2614_SWAL, 0);
225 gemtek_bu2614_set(dev, BU2614_FMUN, 1); /* GT bit set */
226 gemtek_bu2614_set(dev, BU2614_TEST, 0);
227
228 gemtek_bu2614_set(dev, BU2614_STDF, GEMTEK_STDF_3_125_KHZ);
229 gemtek_bu2614_set(dev, BU2614_FREQ, gemtek_convfreq(freq));
230
231 gemtek_bu2614_transmit(dev);
90} 232}
91 233
92static void zero(void) 234/*
235 * Set mute flag.
236 */
237static void gemtek_mute(struct gemtek_device *dev)
93{ 238{
94 outb_p(0x04, io); 239 int i;
95 udelay(5); 240 dev->muted = 1;
96 outb_p(0x05, io); 241
97 udelay(5); 242 if (hardmute) {
243 /* Turn off PLL, disable data output */
244 gemtek_bu2614_set(dev, BU2614_PORT, 0);
245 gemtek_bu2614_set(dev, BU2614_FMES, 0); /* CT bit off */
246 gemtek_bu2614_set(dev, BU2614_SWIN, 0); /* FM-mode */
247 gemtek_bu2614_set(dev, BU2614_SWAL, 0);
248 gemtek_bu2614_set(dev, BU2614_FMUN, 0); /* GT bit off */
249 gemtek_bu2614_set(dev, BU2614_TEST, 0);
250 gemtek_bu2614_set(dev, BU2614_STDF, GEMTEK_PLL_OFF);
251 gemtek_bu2614_set(dev, BU2614_FREQ, 0);
252 gemtek_bu2614_transmit(dev);
253 } else {
254 spin_lock(&lock);
255
256 /* Read bus contents (CE, CK and DA). */
257 i = inb_p(io);
258 /* Write it back with mute flag set. */
259 outb_p((i >> 5) | GEMTEK_MT, io);
260 udelay(SHORT_DELAY);
261
262 spin_unlock(&lock);
263 }
98} 264}
99 265
100static void one(void) 266/*
267 * Unset mute flag.
268 */
269static void gemtek_unmute(struct gemtek_device *dev)
101{ 270{
102 outb_p(0x06, io); 271 int i;
103 udelay(5); 272 dev->muted = 0;
104 outb_p(0x07, io); 273
105 udelay(5); 274 if (hardmute) {
275 /* Turn PLL back on. */
276 gemtek_setfreq(dev, dev->lastfreq);
277 } else {
278 spin_lock(&lock);
279
280 i = inb_p(io);
281 outb_p(i >> 5, io);
282 udelay(SHORT_DELAY);
283
284 spin_unlock(&lock);
285 }
106} 286}
107 287
108static int gemtek_setfreq(struct gemtek_device *dev, unsigned long freq) 288/*
289 * Get signal strength (= stereo status).
290 */
291static inline int gemtek_getsigstr(void)
109{ 292{
110 int i; 293 return inb_p(io) & GEMTEK_NS ? 0 : 1;
294}
111 295
112/* freq = 78.25*((float)freq/16000.0 + 10.52); */ 296/*
297 * Check if requested card acts like GemTek Radio card.
298 */
299static int gemtek_verify(int port)
300{
301 static int verified = -1;
302 int i, q;
113 303
114 freq /= 16; 304 if (verified == port)
115 freq += 10520; 305 return 1;
116 freq *= 7825;
117 freq /= 100000;
118 306
119 spin_lock(&lock); 307 spin_lock(&lock);
120 308
121 /* 2 start bits */ 309 q = inb_p(port); /* Read bus contents before probing. */
122 outb_p(0x03, io); 310 /* Try to turn on CE, CK and DA respectively and check if card responds
123 udelay(5); 311 properly. */
124 outb_p(0x07, io); 312 for (i = 0; i < 3; ++i) {
125 udelay(5); 313 outb_p(1 << i, port);
314 udelay(SHORT_DELAY);
126 315
127 /* 28 frequency bits (lsb first) */ 316 if ((inb_p(port) & (~GEMTEK_NS)) != (0x17 | (1 << (i + 5)))) {
128 for (i = 0; i < 14; i++) 317 spin_unlock(&lock);
129 if (freq & (1 << i)) 318 return 0;
130 one(); 319 }
131 else 320 }
132 zero(); 321 outb_p(q >> 5, port); /* Write bus contents back. */
133 /* 36 unknown bits */ 322 udelay(SHORT_DELAY);
134 for (i = 0; i < 11; i++)
135 zero();
136 one();
137 for (i = 0; i < 4; i++)
138 zero();
139 one();
140 zero();
141
142 /* 2 end bits */
143 outb_p(0x03, io);
144 udelay(5);
145 outb_p(0x07, io);
146 udelay(5);
147 323
148 spin_unlock(&lock); 324 spin_unlock(&lock);
325 verified = port;
149 326
150 return 0; 327 return 1;
151} 328}
152 329
153static int gemtek_getsigstr(struct gemtek_device *dev) 330/*
331 * Automatic probing for card.
332 */
333static int gemtek_probe(void)
154{ 334{
155 spin_lock(&lock); 335 int ioports[] = { 0x20c, 0x30c, 0x24c, 0x34c, 0x248, 0x28c };
156 inb(io); 336 int i;
157 udelay(5); 337
158 spin_unlock(&lock); 338 if (!probe) {
159 if (inb(io) & 8) /* bit set = no signal present */ 339 printk(KERN_INFO "Automatic device probing disabled.\n");
160 return 0; 340 return -1;
161 return 1; /* signal present */ 341 }
342
343 printk(KERN_INFO "Automatic device probing enabled.\n");
344
345 for (i = 0; i < ARRAY_SIZE(ioports); ++i) {
346 printk(KERN_INFO "Trying I/O port 0x%x...\n", ioports[i]);
347
348 if (!request_region(ioports[i], 1, "gemtek-probe")) {
349 printk(KERN_WARNING "I/O port 0x%x busy!\n",
350 ioports[i]);
351 continue;
352 }
353
354 if (gemtek_verify(ioports[i])) {
355 printk(KERN_INFO "Card found from I/O port "
356 "0x%x!\n", ioports[i]);
357
358 release_region(ioports[i], 1);
359
360 io = ioports[i];
361 return io;
362 }
363
364 release_region(ioports[i], 1);
365 }
366
367 printk(KERN_ERR "Automatic probing failed!\n");
368
369 return -1;
162} 370}
163 371
164static int vidioc_querycap(struct file *file, void *priv, 372/*
165 struct v4l2_capability *v) 373 * Video 4 Linux stuff.
374 */
375
376static struct v4l2_queryctrl radio_qctrl[] = {
377 {
378 .id = V4L2_CID_AUDIO_MUTE,
379 .name = "Mute",
380 .minimum = 0,
381 .maximum = 1,
382 .default_value = 1,
383 .type = V4L2_CTRL_TYPE_BOOLEAN,
384 }, {
385 .id = V4L2_CID_AUDIO_VOLUME,
386 .name = "Volume",
387 .minimum = 0,
388 .maximum = 65535,
389 .step = 65535,
390 .default_value = 0xff,
391 .type = V4L2_CTRL_TYPE_INTEGER,
392 }
393};
394
395static struct file_operations gemtek_fops = {
396 .owner = THIS_MODULE,
397 .open = video_exclusive_open,
398 .release = video_exclusive_release,
399 .ioctl = video_ioctl2,
400 .compat_ioctl = v4l_compat_ioctl32,
401 .llseek = no_llseek
402};
403
404static int vidioc_querycap(struct file *file, void *priv,
405 struct v4l2_capability *v)
166{ 406{
167 strlcpy(v->driver, "radio-gemtek", sizeof(v->driver)); 407 strlcpy(v->driver, "radio-gemtek", sizeof(v->driver));
168 strlcpy(v->card, "GemTek", sizeof(v->card)); 408 strlcpy(v->card, "GemTek", sizeof(v->card));
@@ -172,28 +412,29 @@ static int vidioc_querycap(struct file *file, void *priv,
172 return 0; 412 return 0;
173} 413}
174 414
175static int vidioc_g_tuner(struct file *file, void *priv, 415static int vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *v)
176 struct v4l2_tuner *v)
177{ 416{
178 struct video_device *dev = video_devdata(file);
179 struct gemtek_device *rt = dev->priv;
180
181 if (v->index > 0) 417 if (v->index > 0)
182 return -EINVAL; 418 return -EINVAL;
183 419
184 strcpy(v->name, "FM"); 420 strcpy(v->name, "FM");
185 v->type = V4L2_TUNER_RADIO; 421 v->type = V4L2_TUNER_RADIO;
186 v->rangelow = (87*16000); 422 v->rangelow = GEMTEK_LOWFREQ;
187 v->rangehigh = (108*16000); 423 v->rangehigh = GEMTEK_HIGHFREQ;
188 v->rxsubchans = V4L2_TUNER_SUB_MONO; 424 v->capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO;
189 v->capability = V4L2_TUNER_CAP_LOW; 425 v->signal = 0xffff * gemtek_getsigstr();
190 v->audmode = V4L2_TUNER_MODE_MONO; 426 if (v->signal) {
191 v->signal = 0xffff*gemtek_getsigstr(rt); 427 v->audmode = V4L2_TUNER_MODE_STEREO;
428 v->rxsubchans = V4L2_TUNER_SUB_STEREO;
429 } else {
430 v->audmode = V4L2_TUNER_MODE_MONO;
431 v->rxsubchans = V4L2_TUNER_SUB_MONO;
432 }
433
192 return 0; 434 return 0;
193} 435}
194 436
195static int vidioc_s_tuner(struct file *file, void *priv, 437static int vidioc_s_tuner(struct file *file, void *priv, struct v4l2_tuner *v)
196 struct v4l2_tuner *v)
197{ 438{
198 if (v->index > 0) 439 if (v->index > 0)
199 return -EINVAL; 440 return -EINVAL;
@@ -201,38 +442,35 @@ static int vidioc_s_tuner(struct file *file, void *priv,
201} 442}
202 443
203static int vidioc_s_frequency(struct file *file, void *priv, 444static int vidioc_s_frequency(struct file *file, void *priv,
204 struct v4l2_frequency *f) 445 struct v4l2_frequency *f)
205{ 446{
206 struct video_device *dev = video_devdata(file); 447 struct video_device *dev = video_devdata(file);
207 struct gemtek_device *rt = dev->priv; 448 struct gemtek_device *rt = dev->priv;
208 449
209 rt->curfreq = f->frequency; 450 gemtek_setfreq(rt, f->frequency);
210 /* needs to be called twice in order for getsigstr to work */ 451
211 gemtek_setfreq(rt, rt->curfreq);
212 gemtek_setfreq(rt, rt->curfreq);
213 return 0; 452 return 0;
214} 453}
215 454
216static int vidioc_g_frequency(struct file *file, void *priv, 455static int vidioc_g_frequency(struct file *file, void *priv,
217 struct v4l2_frequency *f) 456 struct v4l2_frequency *f)
218{ 457{
219 struct video_device *dev = video_devdata(file); 458 struct video_device *dev = video_devdata(file);
220 struct gemtek_device *rt = dev->priv; 459 struct gemtek_device *rt = dev->priv;
221 460
222 f->type = V4L2_TUNER_RADIO; 461 f->type = V4L2_TUNER_RADIO;
223 f->frequency = rt->curfreq; 462 f->frequency = rt->lastfreq;
224 return 0; 463 return 0;
225} 464}
226 465
227static int vidioc_queryctrl(struct file *file, void *priv, 466static int vidioc_queryctrl(struct file *file, void *priv,
228 struct v4l2_queryctrl *qc) 467 struct v4l2_queryctrl *qc)
229{ 468{
230 int i; 469 int i;
231 470
232 for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) { 471 for (i = 0; i < ARRAY_SIZE(radio_qctrl); ++i) {
233 if (qc->id && qc->id == radio_qctrl[i].id) { 472 if (qc->id && qc->id == radio_qctrl[i].id) {
234 memcpy(qc, &(radio_qctrl[i]), 473 memcpy(qc, &(radio_qctrl[i]), sizeof(*qc));
235 sizeof(*qc));
236 return 0; 474 return 0;
237 } 475 }
238 } 476 }
@@ -240,7 +478,7 @@ static int vidioc_queryctrl(struct file *file, void *priv,
240} 478}
241 479
242static int vidioc_g_ctrl(struct file *file, void *priv, 480static int vidioc_g_ctrl(struct file *file, void *priv,
243 struct v4l2_control *ctrl) 481 struct v4l2_control *ctrl)
244{ 482{
245 struct video_device *dev = video_devdata(file); 483 struct video_device *dev = video_devdata(file);
246 struct gemtek_device *rt = dev->priv; 484 struct gemtek_device *rt = dev->priv;
@@ -260,7 +498,7 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
260} 498}
261 499
262static int vidioc_s_ctrl(struct file *file, void *priv, 500static int vidioc_s_ctrl(struct file *file, void *priv,
263 struct v4l2_control *ctrl) 501 struct v4l2_control *ctrl)
264{ 502{
265 struct video_device *dev = video_devdata(file); 503 struct video_device *dev = video_devdata(file);
266 struct gemtek_device *rt = dev->priv; 504 struct gemtek_device *rt = dev->priv;
@@ -282,8 +520,7 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
282 return -EINVAL; 520 return -EINVAL;
283} 521}
284 522
285static int vidioc_g_audio (struct file *file, void *priv, 523static int vidioc_g_audio(struct file *file, void *priv, struct v4l2_audio *a)
286 struct v4l2_audio *a)
287{ 524{
288 if (a->index > 1) 525 if (a->index > 1)
289 return -EINVAL; 526 return -EINVAL;
@@ -306,99 +543,102 @@ static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
306 return 0; 543 return 0;
307} 544}
308 545
309static int vidioc_s_audio(struct file *file, void *priv, 546static int vidioc_s_audio(struct file *file, void *priv, struct v4l2_audio *a)
310 struct v4l2_audio *a)
311{ 547{
312 if (a->index != 0) 548 if (a->index != 0)
313 return -EINVAL; 549 return -EINVAL;
314 return 0; 550 return 0;
315} 551}
316 552
317static struct gemtek_device gemtek_unit; 553static struct video_device gemtek_radio = {
318 554 .owner = THIS_MODULE,
319static const struct file_operations gemtek_fops = { 555 .name = "GemTek Radio card",
320 .owner = THIS_MODULE, 556 .type = VID_TYPE_TUNER,
321 .open = video_exclusive_open, 557 .hardware = VID_HARDWARE_GEMTEK,
322 .release = video_exclusive_release, 558 .fops = &gemtek_fops,
323 .ioctl = video_ioctl2, 559 .vidioc_querycap = vidioc_querycap,
324 .compat_ioctl = v4l_compat_ioctl32, 560 .vidioc_g_tuner = vidioc_g_tuner,
325 .llseek = no_llseek, 561 .vidioc_s_tuner = vidioc_s_tuner,
562 .vidioc_g_audio = vidioc_g_audio,
563 .vidioc_s_audio = vidioc_s_audio,
564 .vidioc_g_input = vidioc_g_input,
565 .vidioc_s_input = vidioc_s_input,
566 .vidioc_g_frequency = vidioc_g_frequency,
567 .vidioc_s_frequency = vidioc_s_frequency,
568 .vidioc_queryctrl = vidioc_queryctrl,
569 .vidioc_g_ctrl = vidioc_g_ctrl,
570 .vidioc_s_ctrl = vidioc_s_ctrl
326}; 571};
327 572
328static struct video_device gemtek_radio= 573/*
329{ 574 * Initialization / cleanup related stuff.
330 .owner = THIS_MODULE, 575 */
331 .name = "GemTek radio",
332 .type = VID_TYPE_TUNER,
333 .fops = &gemtek_fops,
334 .vidioc_querycap = vidioc_querycap,
335 .vidioc_g_tuner = vidioc_g_tuner,
336 .vidioc_s_tuner = vidioc_s_tuner,
337 .vidioc_g_audio = vidioc_g_audio,
338 .vidioc_s_audio = vidioc_s_audio,
339 .vidioc_g_input = vidioc_g_input,
340 .vidioc_s_input = vidioc_s_input,
341 .vidioc_g_frequency = vidioc_g_frequency,
342 .vidioc_s_frequency = vidioc_s_frequency,
343 .vidioc_queryctrl = vidioc_queryctrl,
344 .vidioc_g_ctrl = vidioc_g_ctrl,
345 .vidioc_s_ctrl = vidioc_s_ctrl,
346};
347 576
577/*
578 * Initilize card.
579 */
348static int __init gemtek_init(void) 580static int __init gemtek_init(void)
349{ 581{
350 if(io==-1) 582 printk(KERN_INFO RADIO_BANNER "\n");
351 {
352 printk(KERN_ERR "You must set an I/O address with io=0x20c, io=0x30c, io=0x24c or io=0x34c (io=0x020c or io=0x248 for the combined sound/radiocard)\n");
353 return -EINVAL;
354 }
355 583
356 if (!request_region(io, 4, "gemtek")) 584 spin_lock_init(&lock);
357 {
358 printk(KERN_ERR "gemtek: port 0x%x already in use\n", io);
359 return -EBUSY;
360 }
361 585
362 gemtek_radio.priv=&gemtek_unit; 586 gemtek_probe();
587 if (io) {
588 if (!request_region(io, 1, "gemtek")) {
589 printk(KERN_ERR "I/O port 0x%x already in use.\n", io);
590 return -EBUSY;
591 }
363 592
364 if(video_register_device(&gemtek_radio, VFL_TYPE_RADIO, radio_nr)==-1) 593 if (!gemtek_verify(io))
365 { 594 printk(KERN_WARNING "Card at I/O port 0x%x does not "
366 release_region(io, 4); 595 "respond properly, check your "
596 "configuration.\n", io);
597 else
598 printk(KERN_INFO "Using I/O port 0x%x.\n", io);
599 } else if (probe) {
600 printk(KERN_ERR "Automatic probing failed and no "
601 "fixed I/O port defined.\n");
602 return -ENODEV;
603 } else {
604 printk(KERN_ERR "Automatic probing disabled but no fixed "
605 "I/O port defined.");
367 return -EINVAL; 606 return -EINVAL;
368 } 607 }
369 printk(KERN_INFO "GemTek Radio Card driver.\n");
370 608
371 spin_lock_init(&lock); 609 gemtek_radio.priv = &gemtek_unit;
372 610
373 /* this is _maybe_ unnecessary */ 611 if (video_register_device(&gemtek_radio, VFL_TYPE_RADIO,
374 outb(0x01, io); 612 radio_nr) == -1) {
613 release_region(io, 1);
614 return -EBUSY;
615 }
375 616
376 /* mute card - prevents noisy bootups */ 617 /* Set defaults */
377 gemtek_unit.muted = 0; 618 gemtek_unit.lastfreq = GEMTEK_LOWFREQ;
378 gemtek_mute(&gemtek_unit); 619 gemtek_unit.bu2614data = 0;
620
621 if (initmute)
622 gemtek_mute(&gemtek_unit);
379 623
380 return 0; 624 return 0;
381} 625}
382 626
383MODULE_AUTHOR("Jonas Munsin"); 627/*
384MODULE_DESCRIPTION("A driver for the GemTek Radio Card"); 628 * Module cleanup
385MODULE_LICENSE("GPL"); 629 */
386 630static void __exit gemtek_exit(void)
387module_param(io, int, 0);
388MODULE_PARM_DESC(io, "I/O address of the GemTek card (0x20c, 0x30c, 0x24c or 0x34c (0x20c or 0x248 have been reported to work for the combined sound/radiocard)).");
389module_param(radio_nr, int, 0);
390
391static void __exit gemtek_cleanup(void)
392{ 631{
632 if (shutdown) {
633 hardmute = 1; /* Turn off PLL */
634 gemtek_mute(&gemtek_unit);
635 } else {
636 printk(KERN_INFO "Module unloaded but card not muted!\n");
637 }
638
393 video_unregister_device(&gemtek_radio); 639 video_unregister_device(&gemtek_radio);
394 release_region(io,4); 640 release_region(io, 1);
395} 641}
396 642
397module_init(gemtek_init); 643module_init(gemtek_init);
398module_exit(gemtek_cleanup); 644module_exit(gemtek_exit);
399
400/*
401 Local variables:
402 compile-command: "gcc -c -DMODVERSIONS -D__KERNEL__ -DMODULE -O6 -Wall -Wstrict-prototypes -I /home/blp/tmp/linux-2.1.111-rtrack/include radio-rtrack2.c"
403 End:
404*/
diff --git a/drivers/media/radio/radio-terratec.c b/drivers/media/radio/radio-terratec.c
index 7e1911c3d54e..535ffe8c8102 100644
--- a/drivers/media/radio/radio-terratec.c
+++ b/drivers/media/radio/radio-terratec.c
@@ -173,7 +173,7 @@ static int tt_setfreq(struct tt_device *dev, unsigned long freq1)
173 i--; 173 i--;
174 p--; 174 p--;
175 temp = temp/2; 175 temp = temp/2;
176 } 176 }
177 177
178 spin_lock(&lock); 178 spin_lock(&lock);
179 179
diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index e204e7b4028a..2e571eb9313a 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -148,6 +148,15 @@ config VIDEO_WM8739
148 To compile this driver as a module, choose M here: the 148 To compile this driver as a module, choose M here: the
149 module will be called wm8739. 149 module will be called wm8739.
150 150
151config VIDEO_VP27SMPX
152 tristate "Panasonic VP27s internal MPX"
153 depends on VIDEO_V4L2 && I2C && EXPERIMENTAL
154 ---help---
155 Support for the internal MPX of the Panasonic VP27s tuner.
156
157 To compile this driver as a module, choose M here: the
158 module will be called vp27smpx.
159
151comment "Video decoders" 160comment "Video decoders"
152 161
153config VIDEO_BT819 162config VIDEO_BT819
@@ -197,6 +206,13 @@ config VIDEO_OV7670
197 OV7670 VGA camera. It currently only works with the M88ALP01 206 OV7670 VGA camera. It currently only works with the M88ALP01
198 controller. 207 controller.
199 208
209config VIDEO_TCM825X
210 tristate "TCM825x camera sensor support"
211 depends on I2C && VIDEO_V4L2
212 ---help---
213 This is a driver for the Toshiba TCM825x VGA camera sensor.
214 It is used for example in Nokia N800.
215
200config VIDEO_SAA7110 216config VIDEO_SAA7110
201 tristate "Philips SAA7110 video decoder" 217 tristate "Philips SAA7110 video decoder"
202 depends on VIDEO_V4L1 && I2C 218 depends on VIDEO_V4L1 && I2C
@@ -348,7 +364,7 @@ endmenu # encoder / decoder chips
348config VIDEO_VIVI 364config VIDEO_VIVI
349 tristate "Virtual Video Driver" 365 tristate "Virtual Video Driver"
350 depends on VIDEO_V4L2 && !SPARC32 && !SPARC64 && PCI 366 depends on VIDEO_V4L2 && !SPARC32 && !SPARC64 && PCI
351 select VIDEO_BUF 367 select VIDEOBUF_VMALLOC
352 default n 368 default n
353 ---help--- 369 ---help---
354 Enables a virtual video driver. This device shows a color bar 370 Enables a virtual video driver. This device shows a color bar
@@ -489,15 +505,6 @@ config TUNER_3036
489 Say Y here to include support for Philips SAB3036 compatible tuners. 505 Say Y here to include support for Philips SAB3036 compatible tuners.
490 If in doubt, say N. 506 If in doubt, say N.
491 507
492config TUNER_TEA5761
493 bool "TEA 5761 radio tuner (EXPERIMENTAL)"
494 depends on EXPERIMENTAL
495 depends on I2C
496 select VIDEO_TUNER
497 help
498 Say Y here to include support for Philips TEA5761 radio tuner.
499 If in doubt, say N.
500
501config VIDEO_VINO 508config VIDEO_VINO
502 tristate "SGI Vino Video For Linux (EXPERIMENTAL)" 509 tristate "SGI Vino Video For Linux (EXPERIMENTAL)"
503 depends on I2C && SGI_IP22 && EXPERIMENTAL && VIDEO_V4L2 510 depends on I2C && SGI_IP22 && EXPERIMENTAL && VIDEO_V4L2
@@ -661,6 +668,8 @@ config VIDEO_HEXIUM_GEMINI
661 668
662source "drivers/media/video/cx88/Kconfig" 669source "drivers/media/video/cx88/Kconfig"
663 670
671source "drivers/media/video/cx23885/Kconfig"
672
664source "drivers/media/video/ivtv/Kconfig" 673source "drivers/media/video/ivtv/Kconfig"
665 674
666config VIDEO_M32R_AR 675config VIDEO_M32R_AR
diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile
index 10b4d4469016..b5a064163e03 100644
--- a/drivers/media/video/Makefile
+++ b/drivers/media/video/Makefile
@@ -4,14 +4,12 @@
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 tuner-simple.o \ 7tuner-objs := tuner-core.o tuner-types.o tda9887.o
8 mt20xx.o tda8290.o tea5767.o tda9887.o
9
10tuner-$(CONFIG_TUNER_TEA5761) += tea5761.o
11 8
12msp3400-objs := msp3400-driver.o msp3400-kthreads.o 9msp3400-objs := msp3400-driver.o msp3400-kthreads.o
13 10
14obj-$(CONFIG_VIDEO_DEV) += videodev.o v4l2-common.o compat_ioctl32.o 11obj-$(CONFIG_VIDEO_DEV) += videodev.o v4l2-common.o compat_ioctl32.o \
12 v4l2-int-device.o
15 13
16ifeq ($(CONFIG_VIDEO_V4L1_COMPAT),y) 14ifeq ($(CONFIG_VIDEO_V4L1_COMPAT),y)
17 obj-$(CONFIG_VIDEO_DEV) += v4l1-compat.o 15 obj-$(CONFIG_VIDEO_DEV) += v4l1-compat.o
@@ -63,7 +61,6 @@ obj-$(CONFIG_VIDEO_CPIA_USB) += cpia_usb.o
63obj-$(CONFIG_VIDEO_MEYE) += meye.o 61obj-$(CONFIG_VIDEO_MEYE) += meye.o
64obj-$(CONFIG_VIDEO_SAA7134) += saa7134/ 62obj-$(CONFIG_VIDEO_SAA7134) += saa7134/
65obj-$(CONFIG_VIDEO_CX88) += cx88/ 63obj-$(CONFIG_VIDEO_CX88) += cx88/
66obj-$(CONFIG_VIDEO_IVTV) += ivtv/
67obj-$(CONFIG_VIDEO_EM28XX) += em28xx/ 64obj-$(CONFIG_VIDEO_EM28XX) += em28xx/
68obj-$(CONFIG_VIDEO_USBVISION) += usbvision/ 65obj-$(CONFIG_VIDEO_USBVISION) += usbvision/
69obj-$(CONFIG_VIDEO_TVP5150) += tvp5150.o 66obj-$(CONFIG_VIDEO_TVP5150) += tvp5150.o
@@ -73,6 +70,7 @@ obj-$(CONFIG_VIDEO_CS53L32A) += cs53l32a.o
73obj-$(CONFIG_VIDEO_TLV320AIC23B) += tlv320aic23b.o 70obj-$(CONFIG_VIDEO_TLV320AIC23B) += tlv320aic23b.o
74obj-$(CONFIG_VIDEO_WM8775) += wm8775.o 71obj-$(CONFIG_VIDEO_WM8775) += wm8775.o
75obj-$(CONFIG_VIDEO_WM8739) += wm8739.o 72obj-$(CONFIG_VIDEO_WM8739) += wm8739.o
73obj-$(CONFIG_VIDEO_VP27SMPX) += vp27smpx.o
76obj-$(CONFIG_VIDEO_OVCAMCHIP) += ovcamchip/ 74obj-$(CONFIG_VIDEO_OVCAMCHIP) += ovcamchip/
77obj-$(CONFIG_VIDEO_CPIA2) += cpia2/ 75obj-$(CONFIG_VIDEO_CPIA2) += cpia2/
78obj-$(CONFIG_VIDEO_MXB) += mxb.o 76obj-$(CONFIG_VIDEO_MXB) += mxb.o
@@ -82,8 +80,17 @@ obj-$(CONFIG_VIDEO_DPC) += dpc7146.o
82obj-$(CONFIG_TUNER_3036) += tuner-3036.o 80obj-$(CONFIG_TUNER_3036) += tuner-3036.o
83 81
84obj-$(CONFIG_VIDEO_TUNER) += tuner.o 82obj-$(CONFIG_VIDEO_TUNER) += tuner.o
85obj-$(CONFIG_VIDEO_BUF) += video-buf.o 83
86obj-$(CONFIG_VIDEO_BUF_DVB) += video-buf-dvb.o 84obj-$(CONFIG_TUNER_SIMPLE) += tuner-simple.o
85obj-$(CONFIG_TUNER_MT20XX) += mt20xx.o
86obj-$(CONFIG_TUNER_TDA8290) += tda8290.o
87obj-$(CONFIG_TUNER_TEA5767) += tea5767.o
88obj-$(CONFIG_TUNER_TEA5761) += tea5761.o
89
90obj-$(CONFIG_VIDEOBUF_GEN) += videobuf-core.o
91obj-$(CONFIG_VIDEOBUF_DMA_SG) += videobuf-dma-sg.o
92obj-$(CONFIG_VIDEOBUF_VMALLOC) += videobuf-vmalloc.o
93obj-$(CONFIG_VIDEOBUF_DVB) += videobuf-dvb.o
87obj-$(CONFIG_VIDEO_BTCX) += btcx-risc.o 94obj-$(CONFIG_VIDEO_BTCX) += btcx-risc.o
88obj-$(CONFIG_VIDEO_TVEEPROM) += tveeprom.o 95obj-$(CONFIG_VIDEO_TVEEPROM) += tveeprom.o
89 96
@@ -97,6 +104,8 @@ obj-$(CONFIG_VIDEO_CX2341X) += cx2341x.o
97obj-$(CONFIG_VIDEO_CAFE_CCIC) += cafe_ccic.o 104obj-$(CONFIG_VIDEO_CAFE_CCIC) += cafe_ccic.o
98obj-$(CONFIG_VIDEO_OV7670) += ov7670.o 105obj-$(CONFIG_VIDEO_OV7670) += ov7670.o
99 106
107obj-$(CONFIG_VIDEO_TCM825X) += tcm825x.o
108
100obj-$(CONFIG_USB_DABUSB) += dabusb.o 109obj-$(CONFIG_USB_DABUSB) += dabusb.o
101obj-$(CONFIG_USB_OV511) += ov511.o 110obj-$(CONFIG_USB_OV511) += ov511.o
102obj-$(CONFIG_USB_SE401) += se401.o 111obj-$(CONFIG_USB_SE401) += se401.o
@@ -114,6 +123,9 @@ obj-$(CONFIG_USB_KONICAWC) += usbvideo/
114obj-$(CONFIG_USB_VICAM) += usbvideo/ 123obj-$(CONFIG_USB_VICAM) += usbvideo/
115obj-$(CONFIG_USB_QUICKCAM_MESSENGER) += usbvideo/ 124obj-$(CONFIG_USB_QUICKCAM_MESSENGER) += usbvideo/
116 125
126obj-$(CONFIG_VIDEO_IVTV) += ivtv/
127
117obj-$(CONFIG_VIDEO_VIVI) += vivi.o 128obj-$(CONFIG_VIDEO_VIVI) += vivi.o
129obj-$(CONFIG_VIDEO_CX23885) += cx23885/
118 130
119EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core 131EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
diff --git a/drivers/media/video/arv.c b/drivers/media/video/arv.c
index 649f52f9ad27..19e9929ffa0f 100644
--- a/drivers/media/video/arv.c
+++ b/drivers/media/video/arv.c
@@ -23,7 +23,6 @@
23#include <linux/delay.h> 23#include <linux/delay.h>
24#include <linux/errno.h> 24#include <linux/errno.h>
25#include <linux/fs.h> 25#include <linux/fs.h>
26#include <linux/init.h>
27#include <linux/kernel.h> 26#include <linux/kernel.h>
28#include <linux/slab.h> 27#include <linux/slab.h>
29#include <linux/mm.h> 28#include <linux/mm.h>
@@ -442,7 +441,7 @@ static int ar_do_ioctl(struct inode *inode, struct file *file,
442 { 441 {
443 struct video_window *w = arg; 442 struct video_window *w = arg;
444 DEBUG(1, "VIDIOCGWIN:\n"); 443 DEBUG(1, "VIDIOCGWIN:\n");
445 memset(w, 0, sizeof(w)); 444 memset(w, 0, sizeof(*w));
446 w->width = ar->width; 445 w->width = ar->width;
447 w->height = ar->height; 446 w->height = ar->height;
448 return 0; 447 return 0;
diff --git a/drivers/media/video/bt8xx/Kconfig b/drivers/media/video/bt8xx/Kconfig
index 58eae887a629..2ca162b390a2 100644
--- a/drivers/media/video/bt8xx/Kconfig
+++ b/drivers/media/video/bt8xx/Kconfig
@@ -4,7 +4,7 @@ config VIDEO_BT848
4 select I2C_ALGOBIT 4 select I2C_ALGOBIT
5 select FW_LOADER 5 select FW_LOADER
6 select VIDEO_BTCX 6 select VIDEO_BTCX
7 select VIDEO_BUF 7 select VIDEOBUF_DMA_SG
8 select VIDEO_IR 8 select VIDEO_IR
9 select VIDEO_TUNER 9 select VIDEO_TUNER
10 select VIDEO_TVEEPROM 10 select VIDEO_TVEEPROM
diff --git a/drivers/media/video/bt8xx/bttv-cards.c b/drivers/media/video/bt8xx/bttv-cards.c
index f6715007d409..dd6a7d68b07f 100644
--- a/drivers/media/video/bt8xx/bttv-cards.c
+++ b/drivers/media/video/bt8xx/bttv-cards.c
@@ -27,7 +27,6 @@
27 27
28#include <linux/delay.h> 28#include <linux/delay.h>
29#include <linux/module.h> 29#include <linux/module.h>
30#include <linux/moduleparam.h>
31#include <linux/kmod.h> 30#include <linux/kmod.h>
32#include <linux/init.h> 31#include <linux/init.h>
33#include <linux/pci.h> 32#include <linux/pci.h>
@@ -2989,6 +2988,23 @@ struct tvcard bttv_tvcards[] = {
2989 .no_tda9875 = 1, 2988 .no_tda9875 = 1,
2990 .no_tda7432 = 1, 2989 .no_tda7432 = 1,
2991 }, 2990 },
2991 /* ---- card 0x95---------------------------------- */
2992 [BTTV_BOARD_TYPHOON_TVTUNERPCI] = {
2993 .name = "Typhoon TV-Tuner PCI (50684)",
2994 .video_inputs = 3,
2995 .audio_inputs = 1,
2996 .tuner = 0,
2997 .svhs = 2,
2998 .gpiomask = 0x3014f,
2999 .muxsel = { 2, 3, 1, 1 },
3000 .gpiomux = { 0x20001,0x10001, 0, 0 },
3001 .gpiomute = 10,
3002 .needs_tvaudio = 1,
3003 .pll = PLL_28,
3004 .tuner_type = TUNER_PHILIPS_PAL_I,
3005 .tuner_addr = ADDR_UNSET,
3006 .radio_addr = ADDR_UNSET,
3007 },
2992}; 3008};
2993 3009
2994static const unsigned int bttv_num_tvcards = ARRAY_SIZE(bttv_tvcards); 3010static const unsigned int bttv_num_tvcards = ARRAY_SIZE(bttv_tvcards);
@@ -3276,15 +3292,15 @@ static void eagle_muxsel(struct bttv *btv, unsigned int input)
3276 btaor((2)<<5, ~(3<<5), BT848_IFORM); 3292 btaor((2)<<5, ~(3<<5), BT848_IFORM);
3277 gpio_bits(3,bttv_tvcards[btv->c.type].muxsel[input&7]); 3293 gpio_bits(3,bttv_tvcards[btv->c.type].muxsel[input&7]);
3278 3294
3279 /* composite */ 3295 /* composite */
3280 /* set chroma ADC to sleep */ 3296 /* set chroma ADC to sleep */
3281 btor(BT848_ADC_C_SLEEP, BT848_ADC); 3297 btor(BT848_ADC_C_SLEEP, BT848_ADC);
3282 /* set to composite video */ 3298 /* set to composite video */
3283 btand(~BT848_CONTROL_COMP, BT848_E_CONTROL); 3299 btand(~BT848_CONTROL_COMP, BT848_E_CONTROL);
3284 btand(~BT848_CONTROL_COMP, BT848_O_CONTROL); 3300 btand(~BT848_CONTROL_COMP, BT848_O_CONTROL);
3285 3301
3286 /* switch sync drive off */ 3302 /* switch sync drive off */
3287 gpio_bits(LM1882_SYNC_DRIVE,LM1882_SYNC_DRIVE); 3303 gpio_bits(LM1882_SYNC_DRIVE,LM1882_SYNC_DRIVE);
3288} 3304}
3289 3305
3290static void gvc1100_muxsel(struct bttv *btv, unsigned int input) 3306static void gvc1100_muxsel(struct bttv *btv, unsigned int input)
@@ -3453,7 +3469,7 @@ void __devinit bttv_init_card2(struct bttv *btv)
3453 printk("bttv%d: radio detected by subsystem id (CPH05x)\n",btv->c.nr); 3469 printk("bttv%d: radio detected by subsystem id (CPH05x)\n",btv->c.nr);
3454 } 3470 }
3455 break; 3471 break;
3456 case BTTV_BOARD_STB2: 3472 case BTTV_BOARD_STB2:
3457 if (btv->cardid == 0x3060121a) { 3473 if (btv->cardid == 0x3060121a) {
3458 /* Fix up entry for 3DFX VoodooTV 100, 3474 /* Fix up entry for 3DFX VoodooTV 100,
3459 which is an OEM STB card variant. */ 3475 which is an OEM STB card variant. */
@@ -3784,7 +3800,7 @@ static void __devinit osprey_eeprom(struct bttv *btv, const u8 ee[256])
3784 for (i = 12; i < 21; i++) 3800 for (i = 12; i < 21; i++)
3785 serial *= 10, serial += ee[i] - '0'; 3801 serial *= 10, serial += ee[i] - '0';
3786 } 3802 }
3787 } else { 3803 } else {
3788 unsigned short type; 3804 unsigned short type;
3789 3805
3790 for (i = 4*16; i < 8*16; i += 16) { 3806 for (i = 4*16; i < 8*16; i += 16) {
diff --git a/drivers/media/video/bt8xx/bttv-driver.c b/drivers/media/video/bt8xx/bttv-driver.c
index cb555f2c40f9..7a332b3efe51 100644
--- a/drivers/media/video/bt8xx/bttv-driver.c
+++ b/drivers/media/video/bt8xx/bttv-driver.c
@@ -30,7 +30,6 @@
30 30
31#include <linux/init.h> 31#include <linux/init.h>
32#include <linux/module.h> 32#include <linux/module.h>
33#include <linux/moduleparam.h>
34#include <linux/delay.h> 33#include <linux/delay.h>
35#include <linux/errno.h> 34#include <linux/errno.h>
36#include <linux/fs.h> 35#include <linux/fs.h>
@@ -155,13 +154,14 @@ MODULE_LICENSE("GPL");
155/* ----------------------------------------------------------------------- */ 154/* ----------------------------------------------------------------------- */
156/* sysfs */ 155/* sysfs */
157 156
158static ssize_t show_card(struct class_device *cd, char *buf) 157static ssize_t show_card(struct device *cd,
158 struct device_attribute *attr, char *buf)
159{ 159{
160 struct video_device *vfd = to_video_device(cd); 160 struct video_device *vfd = to_video_device(cd);
161 struct bttv *btv = dev_get_drvdata(vfd->dev); 161 struct bttv *btv = dev_get_drvdata(vfd->dev);
162 return sprintf(buf, "%d\n", btv ? btv->c.type : UNSET); 162 return sprintf(buf, "%d\n", btv ? btv->c.type : UNSET);
163} 163}
164static CLASS_DEVICE_ATTR(card, S_IRUGO, show_card, NULL); 164static DEVICE_ATTR(card, S_IRUGO, show_card, NULL);
165 165
166/* ----------------------------------------------------------------------- */ 166/* ----------------------------------------------------------------------- */
167/* dvb auto-load setup */ 167/* dvb auto-load setup */
@@ -2583,7 +2583,7 @@ static int setup_window(struct bttv_fh *fh, struct bttv *btv,
2583 if (check_btres(fh, RESOURCE_OVERLAY)) { 2583 if (check_btres(fh, RESOURCE_OVERLAY)) {
2584 struct bttv_buffer *new; 2584 struct bttv_buffer *new;
2585 2585
2586 new = videobuf_alloc(sizeof(*new)); 2586 new = videobuf_pci_alloc(sizeof(*new));
2587 new->crop = btv->crop[!!fh->do_crop].rect; 2587 new->crop = btv->crop[!!fh->do_crop].rect;
2588 bttv_overlay_risc(btv, &fh->ov, fh->ovfmt, new); 2588 bttv_overlay_risc(btv, &fh->ov, fh->ovfmt, new);
2589 retval = bttv_switch_overlay(btv,fh,new); 2589 retval = bttv_switch_overlay(btv,fh,new);
@@ -3049,7 +3049,7 @@ static int bttv_do_ioctl(struct inode *inode, struct file *file,
3049 mutex_lock(&fh->cap.lock); 3049 mutex_lock(&fh->cap.lock);
3050 if (*on) { 3050 if (*on) {
3051 fh->ov.tvnorm = btv->tvnorm; 3051 fh->ov.tvnorm = btv->tvnorm;
3052 new = videobuf_alloc(sizeof(*new)); 3052 new = videobuf_pci_alloc(sizeof(*new));
3053 new->crop = btv->crop[!!fh->do_crop].rect; 3053 new->crop = btv->crop[!!fh->do_crop].rect;
3054 bttv_overlay_risc(btv, &fh->ov, fh->ovfmt, new); 3054 bttv_overlay_risc(btv, &fh->ov, fh->ovfmt, new);
3055 } else { 3055 } else {
@@ -3072,6 +3072,8 @@ static int bttv_do_ioctl(struct inode *inode, struct file *file,
3072 V4L2_MEMORY_MMAP); 3072 V4L2_MEMORY_MMAP);
3073 if (retval < 0) 3073 if (retval < 0)
3074 goto fh_unlock_and_return; 3074 goto fh_unlock_and_return;
3075
3076 gbuffers = retval;
3075 memset(mbuf,0,sizeof(*mbuf)); 3077 memset(mbuf,0,sizeof(*mbuf));
3076 mbuf->frames = gbuffers; 3078 mbuf->frames = gbuffers;
3077 mbuf->size = gbuffers * gbufsize; 3079 mbuf->size = gbuffers * gbufsize;
@@ -3142,9 +3144,12 @@ static int bttv_do_ioctl(struct inode *inode, struct file *file,
3142 retval = -EIO; 3144 retval = -EIO;
3143 /* fall through */ 3145 /* fall through */
3144 case STATE_DONE: 3146 case STATE_DONE:
3145 videobuf_dma_sync(&fh->cap,&buf->vb.dma); 3147 {
3148 struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb);
3149 videobuf_dma_sync(&fh->cap,dma);
3146 bttv_dma_free(&fh->cap,btv,buf); 3150 bttv_dma_free(&fh->cap,btv,buf);
3147 break; 3151 break;
3152 }
3148 default: 3153 default:
3149 retval = -EINVAL; 3154 retval = -EINVAL;
3150 break; 3155 break;
@@ -3338,7 +3343,7 @@ static int bttv_do_ioctl(struct inode *inode, struct file *file,
3338 if (check_btres(fh, RESOURCE_OVERLAY)) { 3343 if (check_btres(fh, RESOURCE_OVERLAY)) {
3339 struct bttv_buffer *new; 3344 struct bttv_buffer *new;
3340 3345
3341 new = videobuf_alloc(sizeof(*new)); 3346 new = videobuf_pci_alloc(sizeof(*new));
3342 new->crop = btv->crop[!!fh->do_crop].rect; 3347 new->crop = btv->crop[!!fh->do_crop].rect;
3343 bttv_overlay_risc(btv,&fh->ov,fh->ovfmt,new); 3348 bttv_overlay_risc(btv,&fh->ov,fh->ovfmt,new);
3344 retval = bttv_switch_overlay(btv,fh,new); 3349 retval = bttv_switch_overlay(btv,fh,new);
@@ -3697,7 +3702,7 @@ static unsigned int bttv_poll(struct file *file, poll_table *wait)
3697 mutex_unlock(&fh->cap.lock); 3702 mutex_unlock(&fh->cap.lock);
3698 return POLLERR; 3703 return POLLERR;
3699 } 3704 }
3700 fh->cap.read_buf = videobuf_alloc(fh->cap.msize); 3705 fh->cap.read_buf = videobuf_pci_alloc(fh->cap.msize);
3701 if (NULL == fh->cap.read_buf) { 3706 if (NULL == fh->cap.read_buf) {
3702 mutex_unlock(&fh->cap.lock); 3707 mutex_unlock(&fh->cap.lock);
3703 return POLLERR; 3708 return POLLERR;
@@ -3764,13 +3769,13 @@ static int bttv_open(struct inode *inode, struct file *file)
3764 fh->ov.setup_ok = 0; 3769 fh->ov.setup_ok = 0;
3765 v4l2_prio_open(&btv->prio,&fh->prio); 3770 v4l2_prio_open(&btv->prio,&fh->prio);
3766 3771
3767 videobuf_queue_init(&fh->cap, &bttv_video_qops, 3772 videobuf_queue_pci_init(&fh->cap, &bttv_video_qops,
3768 btv->c.pci, &btv->s_lock, 3773 btv->c.pci, &btv->s_lock,
3769 V4L2_BUF_TYPE_VIDEO_CAPTURE, 3774 V4L2_BUF_TYPE_VIDEO_CAPTURE,
3770 V4L2_FIELD_INTERLACED, 3775 V4L2_FIELD_INTERLACED,
3771 sizeof(struct bttv_buffer), 3776 sizeof(struct bttv_buffer),
3772 fh); 3777 fh);
3773 videobuf_queue_init(&fh->vbi, &bttv_vbi_qops, 3778 videobuf_queue_pci_init(&fh->vbi, &bttv_vbi_qops,
3774 btv->c.pci, &btv->s_lock, 3779 btv->c.pci, &btv->s_lock,
3775 V4L2_BUF_TYPE_VBI_CAPTURE, 3780 V4L2_BUF_TYPE_VBI_CAPTURE,
3776 V4L2_FIELD_SEQ_TB, 3781 V4L2_FIELD_SEQ_TB,
@@ -4613,9 +4618,9 @@ static int __devinit bttv_register_video(struct bttv *btv)
4613 goto err; 4618 goto err;
4614 printk(KERN_INFO "bttv%d: registered device video%d\n", 4619 printk(KERN_INFO "bttv%d: registered device video%d\n",
4615 btv->c.nr,btv->video_dev->minor & 0x1f); 4620 btv->c.nr,btv->video_dev->minor & 0x1f);
4616 if (class_device_create_file(&btv->video_dev->class_dev, 4621 if (device_create_file(&btv->video_dev->class_dev,
4617 &class_device_attr_card)<0) { 4622 &dev_attr_card)<0) {
4618 printk(KERN_ERR "bttv%d: class_device_create_file 'card' " 4623 printk(KERN_ERR "bttv%d: device_create_file 'card' "
4619 "failed\n", btv->c.nr); 4624 "failed\n", btv->c.nr);
4620 goto err; 4625 goto err;
4621 } 4626 }
diff --git a/drivers/media/video/bt8xx/bttv-gpio.c b/drivers/media/video/bt8xx/bttv-gpio.c
index 84154c26f9c5..dce6dae5740e 100644
--- a/drivers/media/video/bt8xx/bttv-gpio.c
+++ b/drivers/media/video/bt8xx/bttv-gpio.c
@@ -106,11 +106,9 @@ int bttv_sub_add_device(struct bttv_core *core, char *name)
106 106
107int bttv_sub_del_devices(struct bttv_core *core) 107int bttv_sub_del_devices(struct bttv_core *core)
108{ 108{
109 struct bttv_sub_device *sub; 109 struct bttv_sub_device *sub, *save;
110 struct list_head *item,*save;
111 110
112 list_for_each_safe(item,save,&core->subs) { 111 list_for_each_entry_safe(sub, save, &core->subs, list) {
113 sub = list_entry(item,struct bttv_sub_device,list);
114 list_del(&sub->list); 112 list_del(&sub->list);
115 device_unregister(&sub->dev); 113 device_unregister(&sub->dev);
116 } 114 }
diff --git a/drivers/media/video/bt8xx/bttv-i2c.c b/drivers/media/video/bt8xx/bttv-i2c.c
index 0dfa49b66418..844f1762c45a 100644
--- a/drivers/media/video/bt8xx/bttv-i2c.c
+++ b/drivers/media/video/bt8xx/bttv-i2c.c
@@ -28,7 +28,6 @@
28*/ 28*/
29 29
30#include <linux/module.h> 30#include <linux/module.h>
31#include <linux/moduleparam.h>
32#include <linux/init.h> 31#include <linux/init.h>
33#include <linux/delay.h> 32#include <linux/delay.h>
34 33
diff --git a/drivers/media/video/bt8xx/bttv-input.c b/drivers/media/video/bt8xx/bttv-input.c
index 4201552bc3c0..e7c521b8444a 100644
--- a/drivers/media/video/bt8xx/bttv-input.c
+++ b/drivers/media/video/bt8xx/bttv-input.c
@@ -19,7 +19,6 @@
19 */ 19 */
20 20
21#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/moduleparam.h>
23#include <linux/init.h> 22#include <linux/init.h>
24#include <linux/delay.h> 23#include <linux/delay.h>
25#include <linux/interrupt.h> 24#include <linux/interrupt.h>
diff --git a/drivers/media/video/bt8xx/bttv-risc.c b/drivers/media/video/bt8xx/bttv-risc.c
index e7104d9cb4bd..58986f1a5f1a 100644
--- a/drivers/media/video/bt8xx/bttv-risc.c
+++ b/drivers/media/video/bt8xx/bttv-risc.c
@@ -574,10 +574,12 @@ bttv_risc_hook(struct bttv *btv, int slot, struct btcx_riscmem *risc,
574void 574void
575bttv_dma_free(struct videobuf_queue *q,struct bttv *btv, struct bttv_buffer *buf) 575bttv_dma_free(struct videobuf_queue *q,struct bttv *btv, struct bttv_buffer *buf)
576{ 576{
577 struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb);
578
577 BUG_ON(in_interrupt()); 579 BUG_ON(in_interrupt());
578 videobuf_waiton(&buf->vb,0,0); 580 videobuf_waiton(&buf->vb,0,0);
579 videobuf_dma_unmap(q, &buf->vb.dma); 581 videobuf_dma_unmap(q, dma);
580 videobuf_dma_free(&buf->vb.dma); 582 videobuf_dma_free(dma);
581 btcx_riscmem_free(btv->c.pci,&buf->bottom); 583 btcx_riscmem_free(btv->c.pci,&buf->bottom);
582 btcx_riscmem_free(btv->c.pci,&buf->top); 584 btcx_riscmem_free(btv->c.pci,&buf->top);
583 buf->vb.state = STATE_NEEDS_INIT; 585 buf->vb.state = STATE_NEEDS_INIT;
@@ -699,6 +701,7 @@ int
699bttv_buffer_risc(struct bttv *btv, struct bttv_buffer *buf) 701bttv_buffer_risc(struct bttv *btv, struct bttv_buffer *buf)
700{ 702{
701 const struct bttv_tvnorm *tvnorm = bttv_tvnorms + buf->tvnorm; 703 const struct bttv_tvnorm *tvnorm = bttv_tvnorms + buf->tvnorm;
704 struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb);
702 705
703 dprintk(KERN_DEBUG 706 dprintk(KERN_DEBUG
704 "bttv%d: buffer field: %s format: %s size: %dx%d\n", 707 "bttv%d: buffer field: %s format: %s size: %dx%d\n",
@@ -716,25 +719,25 @@ bttv_buffer_risc(struct bttv *btv, struct bttv_buffer *buf)
716 719
717 switch (buf->vb.field) { 720 switch (buf->vb.field) {
718 case V4L2_FIELD_TOP: 721 case V4L2_FIELD_TOP:
719 bttv_risc_packed(btv,&buf->top,buf->vb.dma.sglist, 722 bttv_risc_packed(btv,&buf->top,dma->sglist,
720 /* offset */ 0,bpl, 723 /* offset */ 0,bpl,
721 /* padding */ 0,/* skip_lines */ 0, 724 /* padding */ 0,/* skip_lines */ 0,
722 buf->vb.height); 725 buf->vb.height);
723 break; 726 break;
724 case V4L2_FIELD_BOTTOM: 727 case V4L2_FIELD_BOTTOM:
725 bttv_risc_packed(btv,&buf->bottom,buf->vb.dma.sglist, 728 bttv_risc_packed(btv,&buf->bottom,dma->sglist,
726 0,bpl,0,0,buf->vb.height); 729 0,bpl,0,0,buf->vb.height);
727 break; 730 break;
728 case V4L2_FIELD_INTERLACED: 731 case V4L2_FIELD_INTERLACED:
729 bttv_risc_packed(btv,&buf->top,buf->vb.dma.sglist, 732 bttv_risc_packed(btv,&buf->top,dma->sglist,
730 0,bpl,bpl,0,buf->vb.height >> 1); 733 0,bpl,bpl,0,buf->vb.height >> 1);
731 bttv_risc_packed(btv,&buf->bottom,buf->vb.dma.sglist, 734 bttv_risc_packed(btv,&buf->bottom,dma->sglist,
732 bpl,bpl,bpl,0,buf->vb.height >> 1); 735 bpl,bpl,bpl,0,buf->vb.height >> 1);
733 break; 736 break;
734 case V4L2_FIELD_SEQ_TB: 737 case V4L2_FIELD_SEQ_TB:
735 bttv_risc_packed(btv,&buf->top,buf->vb.dma.sglist, 738 bttv_risc_packed(btv,&buf->top,dma->sglist,
736 0,bpl,0,0,buf->vb.height >> 1); 739 0,bpl,0,0,buf->vb.height >> 1);
737 bttv_risc_packed(btv,&buf->bottom,buf->vb.dma.sglist, 740 bttv_risc_packed(btv,&buf->bottom,dma->sglist,
738 bpf,bpl,0,0,buf->vb.height >> 1); 741 bpf,bpl,0,0,buf->vb.height >> 1);
739 break; 742 break;
740 default: 743 default:
@@ -767,7 +770,7 @@ bttv_buffer_risc(struct bttv *btv, struct bttv_buffer *buf)
767 bttv_calc_geo(btv,&buf->geo,buf->vb.width, 770 bttv_calc_geo(btv,&buf->geo,buf->vb.width,
768 buf->vb.height,/* both_fields */ 0, 771 buf->vb.height,/* both_fields */ 0,
769 tvnorm,&buf->crop); 772 tvnorm,&buf->crop);
770 bttv_risc_planar(btv, &buf->top, buf->vb.dma.sglist, 773 bttv_risc_planar(btv, &buf->top, dma->sglist,
771 0,buf->vb.width,0,buf->vb.height, 774 0,buf->vb.width,0,buf->vb.height,
772 uoffset,voffset,buf->fmt->hshift, 775 uoffset,voffset,buf->fmt->hshift,
773 buf->fmt->vshift,0); 776 buf->fmt->vshift,0);
@@ -776,7 +779,7 @@ bttv_buffer_risc(struct bttv *btv, struct bttv_buffer *buf)
776 bttv_calc_geo(btv,&buf->geo,buf->vb.width, 779 bttv_calc_geo(btv,&buf->geo,buf->vb.width,
777 buf->vb.height,0, 780 buf->vb.height,0,
778 tvnorm,&buf->crop); 781 tvnorm,&buf->crop);
779 bttv_risc_planar(btv, &buf->bottom, buf->vb.dma.sglist, 782 bttv_risc_planar(btv, &buf->bottom, dma->sglist,
780 0,buf->vb.width,0,buf->vb.height, 783 0,buf->vb.width,0,buf->vb.height,
781 uoffset,voffset,buf->fmt->hshift, 784 uoffset,voffset,buf->fmt->hshift,
782 buf->fmt->vshift,0); 785 buf->fmt->vshift,0);
@@ -789,14 +792,14 @@ bttv_buffer_risc(struct bttv *btv, struct bttv_buffer *buf)
789 ypadding = buf->vb.width; 792 ypadding = buf->vb.width;
790 cpadding = buf->vb.width >> buf->fmt->hshift; 793 cpadding = buf->vb.width >> buf->fmt->hshift;
791 bttv_risc_planar(btv,&buf->top, 794 bttv_risc_planar(btv,&buf->top,
792 buf->vb.dma.sglist, 795 dma->sglist,
793 0,buf->vb.width,ypadding,lines, 796 0,buf->vb.width,ypadding,lines,
794 uoffset,voffset, 797 uoffset,voffset,
795 buf->fmt->hshift, 798 buf->fmt->hshift,
796 buf->fmt->vshift, 799 buf->fmt->vshift,
797 cpadding); 800 cpadding);
798 bttv_risc_planar(btv,&buf->bottom, 801 bttv_risc_planar(btv,&buf->bottom,
799 buf->vb.dma.sglist, 802 dma->sglist,
800 ypadding,buf->vb.width,ypadding,lines, 803 ypadding,buf->vb.width,ypadding,lines,
801 uoffset+cpadding, 804 uoffset+cpadding,
802 voffset+cpadding, 805 voffset+cpadding,
@@ -812,7 +815,7 @@ bttv_buffer_risc(struct bttv *btv, struct bttv_buffer *buf)
812 ypadding = buf->vb.width; 815 ypadding = buf->vb.width;
813 cpadding = buf->vb.width >> buf->fmt->hshift; 816 cpadding = buf->vb.width >> buf->fmt->hshift;
814 bttv_risc_planar(btv,&buf->top, 817 bttv_risc_planar(btv,&buf->top,
815 buf->vb.dma.sglist, 818 dma->sglist,
816 0,buf->vb.width,0,lines, 819 0,buf->vb.width,0,lines,
817 uoffset >> 1, 820 uoffset >> 1,
818 voffset >> 1, 821 voffset >> 1,
@@ -820,7 +823,7 @@ bttv_buffer_risc(struct bttv *btv, struct bttv_buffer *buf)
820 buf->fmt->vshift, 823 buf->fmt->vshift,
821 0); 824 0);
822 bttv_risc_planar(btv,&buf->bottom, 825 bttv_risc_planar(btv,&buf->bottom,
823 buf->vb.dma.sglist, 826 dma->sglist,
824 lines * ypadding,buf->vb.width,0,lines, 827 lines * ypadding,buf->vb.width,0,lines,
825 lines * ypadding + (uoffset >> 1), 828 lines * ypadding + (uoffset >> 1),
826 lines * ypadding + (voffset >> 1), 829 lines * ypadding + (voffset >> 1),
@@ -839,10 +842,10 @@ bttv_buffer_risc(struct bttv *btv, struct bttv_buffer *buf)
839 buf->vb.field = V4L2_FIELD_SEQ_TB; 842 buf->vb.field = V4L2_FIELD_SEQ_TB;
840 bttv_calc_geo(btv,&buf->geo,tvnorm->swidth,tvnorm->sheight, 843 bttv_calc_geo(btv,&buf->geo,tvnorm->swidth,tvnorm->sheight,
841 1,tvnorm,&buf->crop); 844 1,tvnorm,&buf->crop);
842 bttv_risc_packed(btv, &buf->top, buf->vb.dma.sglist, 845 bttv_risc_packed(btv, &buf->top, dma->sglist,
843 /* offset */ 0, RAW_BPL, /* padding */ 0, 846 /* offset */ 0, RAW_BPL, /* padding */ 0,
844 /* skip_lines */ 0, RAW_LINES); 847 /* skip_lines */ 0, RAW_LINES);
845 bttv_risc_packed(btv, &buf->bottom, buf->vb.dma.sglist, 848 bttv_risc_packed(btv, &buf->bottom, dma->sglist,
846 buf->vb.size/2 , RAW_BPL, 0, 0, RAW_LINES); 849 buf->vb.size/2 , RAW_BPL, 0, 0, RAW_LINES);
847 } 850 }
848 851
diff --git a/drivers/media/video/bt8xx/bttv-vbi.c b/drivers/media/video/bt8xx/bttv-vbi.c
index 93e35de5a181..346ce019bdcb 100644
--- a/drivers/media/video/bt8xx/bttv-vbi.c
+++ b/drivers/media/video/bt8xx/bttv-vbi.c
@@ -24,7 +24,6 @@
24*/ 24*/
25 25
26#include <linux/module.h> 26#include <linux/module.h>
27#include <linux/moduleparam.h>
28#include <linux/errno.h> 27#include <linux/errno.h>
29#include <linux/fs.h> 28#include <linux/fs.h>
30#include <linux/kernel.h> 29#include <linux/kernel.h>
@@ -151,13 +150,14 @@ static int vbi_buffer_prepare(struct videobuf_queue *q,
151 150
152 if (redo_dma_risc) { 151 if (redo_dma_risc) {
153 unsigned int bpl, padding, offset; 152 unsigned int bpl, padding, offset;
153 struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb);
154 154
155 bpl = 2044; /* max. vbipack */ 155 bpl = 2044; /* max. vbipack */
156 padding = VBI_BPL - bpl; 156 padding = VBI_BPL - bpl;
157 157
158 if (fh->vbi_fmt.fmt.count[0] > 0) { 158 if (fh->vbi_fmt.fmt.count[0] > 0) {
159 rc = bttv_risc_packed(btv, &buf->top, 159 rc = bttv_risc_packed(btv, &buf->top,
160 buf->vb.dma.sglist, 160 dma->sglist,
161 /* offset */ 0, bpl, 161 /* offset */ 0, bpl,
162 padding, skip_lines0, 162 padding, skip_lines0,
163 fh->vbi_fmt.fmt.count[0]); 163 fh->vbi_fmt.fmt.count[0]);
@@ -169,7 +169,7 @@ static int vbi_buffer_prepare(struct videobuf_queue *q,
169 offset = fh->vbi_fmt.fmt.count[0] * VBI_BPL; 169 offset = fh->vbi_fmt.fmt.count[0] * VBI_BPL;
170 170
171 rc = bttv_risc_packed(btv, &buf->bottom, 171 rc = bttv_risc_packed(btv, &buf->bottom,
172 buf->vb.dma.sglist, 172 dma->sglist,
173 offset, bpl, 173 offset, bpl,
174 padding, skip_lines1, 174 padding, skip_lines1,
175 fh->vbi_fmt.fmt.count[1]); 175 fh->vbi_fmt.fmt.count[1]);
diff --git a/drivers/media/video/bt8xx/bttv.h b/drivers/media/video/bt8xx/bttv.h
index dcc847dc2486..19e75d50a107 100644
--- a/drivers/media/video/bt8xx/bttv.h
+++ b/drivers/media/video/bt8xx/bttv.h
@@ -172,6 +172,8 @@
172#define BTTV_BOARD_SSAI_ULTRASOUND 0x92 172#define BTTV_BOARD_SSAI_ULTRASOUND 0x92
173#define BTTV_BOARD_VOODOOTV_200 0x93 173#define BTTV_BOARD_VOODOOTV_200 0x93
174#define BTTV_BOARD_DVICO_FUSIONHDTV_2 0x94 174#define BTTV_BOARD_DVICO_FUSIONHDTV_2 0x94
175#define BTTV_BOARD_TYPHOON_TVTUNERPCI 0x95
176
175 177
176/* more card-specific defines */ 178/* more card-specific defines */
177#define PT2254_L_CHANNEL 0x10 179#define PT2254_L_CHANNEL 0x10
diff --git a/drivers/media/video/bt8xx/bttvp.h b/drivers/media/video/bt8xx/bttvp.h
index 5b25faca1504..0b92c35a8435 100644
--- a/drivers/media/video/bt8xx/bttvp.h
+++ b/drivers/media/video/bt8xx/bttvp.h
@@ -41,7 +41,7 @@
41#include <media/v4l2-common.h> 41#include <media/v4l2-common.h>
42 42
43#include <linux/device.h> 43#include <linux/device.h>
44#include <media/video-buf.h> 44#include <media/videobuf-dma-sg.h>
45#include <media/tuner.h> 45#include <media/tuner.h>
46#include <media/tveeprom.h> 46#include <media/tveeprom.h>
47#include <media/ir-common.h> 47#include <media/ir-common.h>
diff --git a/drivers/media/video/btcx-risc.c b/drivers/media/video/btcx-risc.c
index b4aca7249276..ce0840ccd594 100644
--- a/drivers/media/video/btcx-risc.c
+++ b/drivers/media/video/btcx-risc.c
@@ -23,7 +23,6 @@
23*/ 23*/
24 24
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/moduleparam.h>
27#include <linux/init.h> 26#include <linux/init.h>
28#include <linux/pci.h> 27#include <linux/pci.h>
29#include <linux/interrupt.h> 28#include <linux/interrupt.h>
diff --git a/drivers/media/video/bw-qcam.c b/drivers/media/video/bw-qcam.c
index 7d47cbe6ad25..7f7e3d3398d0 100644
--- a/drivers/media/video/bw-qcam.c
+++ b/drivers/media/video/bw-qcam.c
@@ -104,6 +104,17 @@ static inline void write_lpdata(struct qcam_device *q, int d)
104 104
105static inline void write_lpcontrol(struct qcam_device *q, int d) 105static inline void write_lpcontrol(struct qcam_device *q, int d)
106{ 106{
107 if (d & 0x20) {
108 /* Set bidirectional mode to reverse (data in) */
109 parport_data_reverse(q->pport);
110 } else {
111 /* Set bidirectional mode to forward (data out) */
112 parport_data_forward(q->pport);
113 }
114
115 /* Now issue the regular port command, but strip out the
116 * direction flag */
117 d &= ~0x20;
107 parport_write_control(q->pport, d); 118 parport_write_control(q->pport, d);
108} 119}
109 120
@@ -344,10 +355,13 @@ static int qc_detect(struct qcam_device *q)
344 /* Be (even more) liberal in what you accept... */ 355 /* Be (even more) liberal in what you accept... */
345 356
346/* if (count > 30 && count < 200) */ 357/* if (count > 30 && count < 200) */
347 if (count > 20 && count < 300) 358 if (count > 20 && count < 400) {
348 return 1; /* found */ 359 return 1; /* found */
349 else 360 } else {
361 printk(KERN_ERR "No Quickcam found on port %s\n",
362 q->pport->name);
350 return 0; /* not found */ 363 return 0; /* not found */
364 }
351} 365}
352 366
353 367
diff --git a/drivers/media/video/cafe_ccic.c b/drivers/media/video/cafe_ccic.c
index ef5361824f87..b63cab336920 100644
--- a/drivers/media/video/cafe_ccic.c
+++ b/drivers/media/video/cafe_ccic.c
@@ -14,7 +14,6 @@
14 14
15#include <linux/kernel.h> 15#include <linux/kernel.h>
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/moduleparam.h>
18#include <linux/init.h> 17#include <linux/init.h>
19#include <linux/fs.h> 18#include <linux/fs.h>
20#include <linux/pci.h> 19#include <linux/pci.h>
@@ -63,13 +62,13 @@ MODULE_SUPPORTED_DEVICE("Video");
63 */ 62 */
64 63
65#define MAX_DMA_BUFS 3 64#define MAX_DMA_BUFS 3
66static int alloc_bufs_at_load = 0; 65static int alloc_bufs_at_read = 0;
67module_param(alloc_bufs_at_load, bool, 0444); 66module_param(alloc_bufs_at_read, bool, 0444);
68MODULE_PARM_DESC(alloc_bufs_at_load, 67MODULE_PARM_DESC(alloc_bufs_at_read,
69 "Non-zero value causes DMA buffers to be allocated at module " 68 "Non-zero value causes DMA buffers to be allocated when the "
70 "load time. This increases the chances of successfully getting " 69 "video capture device is read, rather than at module load "
71 "those buffers, but at the cost of nailing down the memory from " 70 "time. This saves memory, but decreases the chances of "
72 "the outset."); 71 "successfully getting those buffers.");
73 72
74static int n_dma_bufs = 3; 73static int n_dma_bufs = 3;
75module_param(n_dma_bufs, uint, 0644); 74module_param(n_dma_bufs, uint, 0644);
@@ -1198,7 +1197,7 @@ static int cafe_setup_siobuf(struct cafe_camera *cam, int index)
1198 buf->v4lbuf.field = V4L2_FIELD_NONE; 1197 buf->v4lbuf.field = V4L2_FIELD_NONE;
1199 buf->v4lbuf.memory = V4L2_MEMORY_MMAP; 1198 buf->v4lbuf.memory = V4L2_MEMORY_MMAP;
1200 /* 1199 /*
1201 * Offset: must be 32-bit even on a 64-bit system. video-buf 1200 * Offset: must be 32-bit even on a 64-bit system. videobuf-dma-sg
1202 * just uses the length times the index, but the spec warns 1201 * just uses the length times the index, but the spec warns
1203 * against doing just that - vma merging problems. So we 1202 * against doing just that - vma merging problems. So we
1204 * leave a gap between each pair of buffers. 1203 * leave a gap between each pair of buffers.
@@ -1503,7 +1502,7 @@ static int cafe_v4l_release(struct inode *inode, struct file *filp)
1503 } 1502 }
1504 if (cam->users == 0) { 1503 if (cam->users == 0) {
1505 cafe_ctlr_power_down(cam); 1504 cafe_ctlr_power_down(cam);
1506 if (! alloc_bufs_at_load) 1505 if (alloc_bufs_at_read)
1507 cafe_free_dma_bufs(cam); 1506 cafe_free_dma_bufs(cam);
1508 } 1507 }
1509 mutex_unlock(&cam->s_mutex); 1508 mutex_unlock(&cam->s_mutex);
@@ -2162,7 +2161,7 @@ static int cafe_pci_probe(struct pci_dev *pdev,
2162 /* 2161 /*
2163 * If so requested, try to get our DMA buffers now. 2162 * If so requested, try to get our DMA buffers now.
2164 */ 2163 */
2165 if (alloc_bufs_at_load) { 2164 if (!alloc_bufs_at_read) {
2166 if (cafe_alloc_dma_bufs(cam, 1)) 2165 if (cafe_alloc_dma_bufs(cam, 1))
2167 cam_warn(cam, "Unable to alloc DMA buffers at load" 2166 cam_warn(cam, "Unable to alloc DMA buffers at load"
2168 " will try again later."); 2167 " will try again later.");
diff --git a/drivers/media/video/compat_ioctl32.c b/drivers/media/video/compat_ioctl32.c
index f065ad12cc61..cefd1381e8de 100644
--- a/drivers/media/video/compat_ioctl32.c
+++ b/drivers/media/video/compat_ioctl32.c
@@ -848,6 +848,8 @@ long v4l_compat_ioctl32(struct file *file, unsigned int cmd, unsigned long arg)
848 case VIDIOCSFREQ32: 848 case VIDIOCSFREQ32:
849 case VIDIOCGAUDIO: 849 case VIDIOCGAUDIO:
850 case VIDIOCSAUDIO: 850 case VIDIOCSAUDIO:
851 case VIDIOCGVBIFMT:
852 case VIDIOCSVBIFMT:
851#endif 853#endif
852 case VIDIOC_QUERYCAP: 854 case VIDIOC_QUERYCAP:
853 case VIDIOC_ENUM_FMT: 855 case VIDIOC_ENUM_FMT:
@@ -874,7 +876,10 @@ long v4l_compat_ioctl32(struct file *file, unsigned int cmd, unsigned long arg)
874 case VIDIOC_ENUMINPUT: 876 case VIDIOC_ENUMINPUT:
875 case VIDIOC_ENUMINPUT32: 877 case VIDIOC_ENUMINPUT32:
876 case VIDIOC_G_CTRL: 878 case VIDIOC_G_CTRL:
879 case VIDIOC_S_CTRL:
877 case VIDIOC_S_CTRL32: 880 case VIDIOC_S_CTRL32:
881 case VIDIOC_S_FREQUENCY:
882 case VIDIOC_G_FREQUENCY:
878 case VIDIOC_QUERYCTRL: 883 case VIDIOC_QUERYCTRL:
879 case VIDIOC_G_INPUT32: 884 case VIDIOC_G_INPUT32:
880 case VIDIOC_S_INPUT32: 885 case VIDIOC_S_INPUT32:
diff --git a/drivers/media/video/cpia.c b/drivers/media/video/cpia.c
index 78c9699eafbb..a1d02e5ce0fd 100644
--- a/drivers/media/video/cpia.c
+++ b/drivers/media/video/cpia.c
@@ -28,7 +28,6 @@
28 28
29 29
30#include <linux/module.h> 30#include <linux/module.h>
31#include <linux/moduleparam.h>
32#include <linux/init.h> 31#include <linux/init.h>
33#include <linux/fs.h> 32#include <linux/fs.h>
34#include <linux/vmalloc.h> 33#include <linux/vmalloc.h>
diff --git a/drivers/media/video/cpia2/cpia2_v4l.c b/drivers/media/video/cpia2/cpia2_v4l.c
index 92778cd1d735..e3aaba1e0e0a 100644
--- a/drivers/media/video/cpia2/cpia2_v4l.c
+++ b/drivers/media/video/cpia2/cpia2_v4l.c
@@ -37,7 +37,6 @@
37#include <linux/sched.h> 37#include <linux/sched.h>
38#include <linux/slab.h> 38#include <linux/slab.h>
39#include <linux/init.h> 39#include <linux/init.h>
40#include <linux/moduleparam.h>
41 40
42#include "cpia2.h" 41#include "cpia2.h"
43#include "cpia2dev.h" 42#include "cpia2dev.h"
diff --git a/drivers/media/video/cx2341x.c b/drivers/media/video/cx2341x.c
index d73c86aeeaac..62304255dcae 100644
--- a/drivers/media/video/cx2341x.c
+++ b/drivers/media/video/cx2341x.c
@@ -20,7 +20,6 @@
20 20
21 21
22#include <linux/module.h> 22#include <linux/module.h>
23#include <linux/moduleparam.h>
24#include <linux/errno.h> 23#include <linux/errno.h>
25#include <linux/kernel.h> 24#include <linux/kernel.h>
26#include <linux/init.h> 25#include <linux/init.h>
@@ -191,17 +190,21 @@ static int cx2341x_get_ctrl(struct cx2341x_mpeg_params *params,
191 190
192/* Map the control ID to the correct field in the cx2341x_mpeg_params 191/* Map the control ID to the correct field in the cx2341x_mpeg_params
193 struct. Return -EINVAL if the ID is unknown, else return 0. */ 192 struct. Return -EINVAL if the ID is unknown, else return 0. */
194static int cx2341x_set_ctrl(struct cx2341x_mpeg_params *params, 193static int cx2341x_set_ctrl(struct cx2341x_mpeg_params *params, int busy,
195 struct v4l2_ext_control *ctrl) 194 struct v4l2_ext_control *ctrl)
196{ 195{
197 switch (ctrl->id) { 196 switch (ctrl->id) {
198 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: 197 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
198 if (busy)
199 return -EBUSY;
199 params->audio_sampling_freq = ctrl->value; 200 params->audio_sampling_freq = ctrl->value;
200 break; 201 break;
201 case V4L2_CID_MPEG_AUDIO_ENCODING: 202 case V4L2_CID_MPEG_AUDIO_ENCODING:
202 params->audio_encoding = ctrl->value; 203 params->audio_encoding = ctrl->value;
203 break; 204 break;
204 case V4L2_CID_MPEG_AUDIO_L2_BITRATE: 205 case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
206 if (busy)
207 return -EBUSY;
205 params->audio_l2_bitrate = ctrl->value; 208 params->audio_l2_bitrate = ctrl->value;
206 break; 209 break;
207 case V4L2_CID_MPEG_AUDIO_MODE: 210 case V4L2_CID_MPEG_AUDIO_MODE:
@@ -246,6 +249,8 @@ static int cx2341x_set_ctrl(struct cx2341x_mpeg_params *params,
246 params->video_gop_closure = ctrl->value; 249 params->video_gop_closure = ctrl->value;
247 break; 250 break;
248 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: 251 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
252 if (busy)
253 return -EBUSY;
249 /* MPEG-1 only allows CBR */ 254 /* MPEG-1 only allows CBR */
250 if (params->video_encoding == V4L2_MPEG_VIDEO_ENCODING_MPEG_1 && 255 if (params->video_encoding == V4L2_MPEG_VIDEO_ENCODING_MPEG_1 &&
251 ctrl->value != V4L2_MPEG_VIDEO_BITRATE_MODE_CBR) 256 ctrl->value != V4L2_MPEG_VIDEO_BITRATE_MODE_CBR)
@@ -253,9 +258,13 @@ static int cx2341x_set_ctrl(struct cx2341x_mpeg_params *params,
253 params->video_bitrate_mode = ctrl->value; 258 params->video_bitrate_mode = ctrl->value;
254 break; 259 break;
255 case V4L2_CID_MPEG_VIDEO_BITRATE: 260 case V4L2_CID_MPEG_VIDEO_BITRATE:
261 if (busy)
262 return -EBUSY;
256 params->video_bitrate = ctrl->value; 263 params->video_bitrate = ctrl->value;
257 break; 264 break;
258 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK: 265 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK:
266 if (busy)
267 return -EBUSY;
259 params->video_bitrate_peak = ctrl->value; 268 params->video_bitrate_peak = ctrl->value;
260 break; 269 break;
261 case V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION: 270 case V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION:
@@ -268,6 +277,8 @@ static int cx2341x_set_ctrl(struct cx2341x_mpeg_params *params,
268 params->video_mute_yuv = ctrl->value; 277 params->video_mute_yuv = ctrl->value;
269 break; 278 break;
270 case V4L2_CID_MPEG_STREAM_TYPE: 279 case V4L2_CID_MPEG_STREAM_TYPE:
280 if (busy)
281 return -EBUSY;
271 params->stream_type = ctrl->value; 282 params->stream_type = ctrl->value;
272 params->video_encoding = 283 params->video_encoding =
273 (params->stream_type == V4L2_MPEG_STREAM_TYPE_MPEG1_SS || 284 (params->stream_type == V4L2_MPEG_STREAM_TYPE_MPEG1_SS ||
@@ -632,7 +643,7 @@ static void cx2341x_calc_audio_properties(struct cx2341x_mpeg_params *params)
632 (params->audio_crc << 14); 643 (params->audio_crc << 14);
633} 644}
634 645
635int cx2341x_ext_ctrls(struct cx2341x_mpeg_params *params, 646int cx2341x_ext_ctrls(struct cx2341x_mpeg_params *params, int busy,
636 struct v4l2_ext_controls *ctrls, unsigned int cmd) 647 struct v4l2_ext_controls *ctrls, unsigned int cmd)
637{ 648{
638 int err = 0; 649 int err = 0;
@@ -664,7 +675,7 @@ int cx2341x_ext_ctrls(struct cx2341x_mpeg_params *params,
664 err = v4l2_ctrl_check(ctrl, &qctrl, menu_items); 675 err = v4l2_ctrl_check(ctrl, &qctrl, menu_items);
665 if (err) 676 if (err)
666 break; 677 break;
667 err = cx2341x_set_ctrl(params, ctrl); 678 err = cx2341x_set_ctrl(params, busy, ctrl);
668 if (err) 679 if (err)
669 break; 680 break;
670 } 681 }
diff --git a/drivers/media/video/cx23885/Kconfig b/drivers/media/video/cx23885/Kconfig
new file mode 100644
index 000000000000..72004a07b2d5
--- /dev/null
+++ b/drivers/media/video/cx23885/Kconfig
@@ -0,0 +1,20 @@
1config VIDEO_CX23885
2 tristate "Conexant cx23885 (2388x successor) support"
3 depends on DVB_CORE && VIDEO_DEV && PCI && I2C
4 select I2C_ALGOBIT
5 select FW_LOADER
6 select VIDEO_BTCX
7 select VIDEO_TUNER
8 select VIDEO_TVEEPROM
9 select VIDEO_IR
10 select VIDEOBUF_DVB
11 select DVB_TUNER_MT2131 if !DVB_FE_CUSTOMISE
12 select DVB_S5H1409 if !DVB_FE_CUSTOMISE
13 select DVB_PLL if !DVB_FE_CUSTOMISE
14 ---help---
15 This is a video4linux driver for Conexant 23885 based
16 TV cards.
17
18 To compile this driver as a module, choose M here: the
19 module will be called cx23885
20
diff --git a/drivers/media/video/cx23885/Makefile b/drivers/media/video/cx23885/Makefile
new file mode 100644
index 000000000000..665067022d2a
--- /dev/null
+++ b/drivers/media/video/cx23885/Makefile
@@ -0,0 +1,9 @@
1cx23885-objs := cx23885-cards.o cx23885-core.o cx23885-i2c.o cx23885-dvb.o
2
3obj-$(CONFIG_VIDEO_CX23885) += cx23885.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/cx23885/cx23885-cards.c b/drivers/media/video/cx23885/cx23885-cards.c
new file mode 100644
index 000000000000..b9012acabb2f
--- /dev/null
+++ b/drivers/media/video/cx23885/cx23885-cards.c
@@ -0,0 +1,280 @@
1/*
2 * Driver for the Conexant CX23885 PCIe bridge
3 *
4 * Copyright (c) 2006 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/init.h>
23#include <linux/module.h>
24#include <linux/pci.h>
25#include <linux/delay.h>
26
27#include "cx23885.h"
28
29/* ------------------------------------------------------------------ */
30/* board config info */
31
32struct cx23885_board cx23885_boards[] = {
33 [CX23885_BOARD_UNKNOWN] = {
34 .name = "UNKNOWN/GENERIC",
35 .input = {{
36 .type = CX23885_VMUX_COMPOSITE1,
37 .vmux = 0,
38 },{
39 .type = CX23885_VMUX_COMPOSITE2,
40 .vmux = 1,
41 },{
42 .type = CX23885_VMUX_COMPOSITE3,
43 .vmux = 2,
44 },{
45 .type = CX23885_VMUX_COMPOSITE4,
46 .vmux = 3,
47 }},
48 },
49 [CX23885_BOARD_HAUPPAUGE_HVR1800lp] = {
50 .name = "Hauppauge WinTV-HVR1800lp",
51 .portc = CX23885_MPEG_DVB,
52 .input = {{
53 .type = CX23885_VMUX_TELEVISION,
54 .vmux = 0,
55 .gpio0 = 0xff00,
56 },{
57 .type = CX23885_VMUX_DEBUG,
58 .vmux = 0,
59 .gpio0 = 0xff01,
60 },{
61 .type = CX23885_VMUX_COMPOSITE1,
62 .vmux = 1,
63 .gpio0 = 0xff02,
64 },{
65 .type = CX23885_VMUX_SVIDEO,
66 .vmux = 2,
67 .gpio0 = 0xff02,
68 }},
69 },
70 [CX23885_BOARD_HAUPPAUGE_HVR1800] = {
71 .name = "Hauppauge WinTV-HVR1800",
72 .portc = CX23885_MPEG_DVB,
73 .input = {{
74 .type = CX23885_VMUX_TELEVISION,
75 .vmux = 0,
76 .gpio0 = 0xff00,
77 },{
78 .type = CX23885_VMUX_DEBUG,
79 .vmux = 0,
80 .gpio0 = 0xff01,
81 },{
82 .type = CX23885_VMUX_COMPOSITE1,
83 .vmux = 1,
84 .gpio0 = 0xff02,
85 },{
86 .type = CX23885_VMUX_SVIDEO,
87 .vmux = 2,
88 .gpio0 = 0xff02,
89 }},
90 },
91 [CX23885_BOARD_HAUPPAUGE_HVR1250] = {
92 .name = "Hauppauge WinTV-HVR1250",
93 .portc = CX23885_MPEG_DVB,
94 .input = {{
95 .type = CX23885_VMUX_TELEVISION,
96 .vmux = 0,
97 .gpio0 = 0xff00,
98 },{
99 .type = CX23885_VMUX_DEBUG,
100 .vmux = 0,
101 .gpio0 = 0xff01,
102 },{
103 .type = CX23885_VMUX_COMPOSITE1,
104 .vmux = 1,
105 .gpio0 = 0xff02,
106 },{
107 .type = CX23885_VMUX_SVIDEO,
108 .vmux = 2,
109 .gpio0 = 0xff02,
110 }},
111 },
112 [CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP] = {
113 .name = "DViCO FusionHDTV5 Express",
114 .portb = CX23885_MPEG_DVB,
115 },
116};
117const unsigned int cx23885_bcount = ARRAY_SIZE(cx23885_boards);
118
119/* ------------------------------------------------------------------ */
120/* PCI subsystem IDs */
121
122struct cx23885_subid cx23885_subids[] = {
123 {
124 .subvendor = 0x0070,
125 .subdevice = 0x3400,
126 .card = CX23885_BOARD_UNKNOWN,
127 },{
128 .subvendor = 0x0070,
129 .subdevice = 0x7600,
130 .card = CX23885_BOARD_HAUPPAUGE_HVR1800lp,
131 },{
132 .subvendor = 0x0070,
133 .subdevice = 0x7800,
134 .card = CX23885_BOARD_HAUPPAUGE_HVR1800,
135 },{
136 .subvendor = 0x0070,
137 .subdevice = 0x7801,
138 .card = CX23885_BOARD_HAUPPAUGE_HVR1800,
139 },{
140 .subvendor = 0x0070,
141 .subdevice = 0x7911,
142 .card = CX23885_BOARD_HAUPPAUGE_HVR1250,
143 },{
144 .subvendor = 0x18ac,
145 .subdevice = 0xd500,
146 .card = CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP,
147 },
148};
149const unsigned int cx23885_idcount = ARRAY_SIZE(cx23885_subids);
150
151void cx23885_card_list(struct cx23885_dev *dev)
152{
153 int i;
154
155 if (0 == dev->pci->subsystem_vendor &&
156 0 == dev->pci->subsystem_device) {
157 printk("%s: Your board has no valid PCIe Subsystem ID and thus can't\n"
158 "%s: be autodetected. Please pass card=<n> insmod option to\n"
159 "%s: workaround that. Redirect complaints to the vendor of\n"
160 "%s: the TV card. Best regards,\n"
161 "%s: -- tux\n",
162 dev->name, dev->name, dev->name, dev->name, dev->name);
163 } else {
164 printk("%s: Your board isn't known (yet) to the driver. You can\n"
165 "%s: try to pick one of the existing card configs via\n"
166 "%s: card=<n> insmod option. Updating to the latest\n"
167 "%s: version might help as well.\n",
168 dev->name, dev->name, dev->name, dev->name);
169 }
170 printk("%s: Here is a list of valid choices for the card=<n> insmod option:\n",
171 dev->name);
172 for (i = 0; i < cx23885_bcount; i++)
173 printk("%s: card=%d -> %s\n",
174 dev->name, i, cx23885_boards[i].name);
175}
176
177static void hauppauge_eeprom(struct cx23885_dev *dev, u8 *eeprom_data)
178{
179 struct tveeprom tv;
180
181 tveeprom_hauppauge_analog(&dev->i2c_bus[0].i2c_client, &tv, eeprom_data);
182
183 /* Make sure we support the board model */
184 switch (tv.model)
185 {
186 case 76601: /* WinTV-HVR1800lp (PCIe, Retail, No IR, Dual channel ATSC and MPEG2 HW Encoder */
187 case 77001: /* WinTV-HVR1500 (Express Card, Retail, No IR, ATSC and Basic analog */
188 case 78501: /* WinTV-HVR1800 (PCIe, Retail, IR, Dual channel ATSC and MPEG2 HW Encoder */
189 case 78521: /* WinTV-HVR1800 (PCIe, Retail, IR, Dual channel ATSC and MPEG2 HW Encoder */
190 break;
191 default:
192 printk("%s: warning: unknown hauppauge model #%d\n", dev->name, tv.model);
193 break;
194 }
195
196 printk(KERN_INFO "%s: hauppauge eeprom: model=%d\n",
197 dev->name, tv.model);
198}
199
200void cx23885_gpio_setup(struct cx23885_dev *dev)
201{
202 switch(dev->board) {
203 case CX23885_BOARD_HAUPPAUGE_HVR1250:
204 /* GPIO-0 cx24227 demodulator reset */
205 cx_set(GP0_IO, 0x00010001); /* Bring the part out of reset */
206 break;
207 case CX23885_BOARD_HAUPPAUGE_HVR1800:
208 /* GPIO-0 656_CLK */
209 /* GPIO-1 656_D0 */
210 /* GPIO-2 8295A Reset */
211 /* GPIO-3-10 cx23417 data0-7 */
212 /* GPIO-11-14 cx23417 addr0-3 */
213 /* GPIO-15-18 cx23417 READY, CS, RD, WR */
214 /* GPIO-19 IR_RX */
215 // FIXME: Analog requires the tuner is brought out of reset
216 break;
217 }
218}
219
220int cx23885_ir_init(struct cx23885_dev *dev)
221{
222 switch (dev->board) {
223 case CX23885_BOARD_HAUPPAUGE_HVR1250:
224 case CX23885_BOARD_HAUPPAUGE_HVR1800:
225 /* FIXME: Implement me */
226 break;
227 }
228
229 return 0;
230}
231
232void cx23885_card_setup(struct cx23885_dev *dev)
233{
234 struct cx23885_tsport *ts1 = &dev->ts1;
235 struct cx23885_tsport *ts2 = &dev->ts2;
236
237 static u8 eeprom[256];
238
239 if (dev->i2c_bus[0].i2c_rc == 0) {
240 dev->i2c_bus[0].i2c_client.addr = 0xa0 >> 1;
241 tveeprom_read(&dev->i2c_bus[0].i2c_client,
242 eeprom, sizeof(eeprom));
243 }
244
245 switch (dev->board) {
246 case CX23885_BOARD_HAUPPAUGE_HVR1250:
247 case CX23885_BOARD_HAUPPAUGE_HVR1800:
248 case CX23885_BOARD_HAUPPAUGE_HVR1800lp:
249 if (dev->i2c_bus[0].i2c_rc == 0)
250 hauppauge_eeprom(dev, eeprom+0x80);
251 break;
252 }
253
254 switch (dev->board) {
255 case CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP:
256 ts1->gen_ctrl_val = 0xc; /* Serial bus + punctured clock */
257 ts1->ts_clk_en_val = 0x1; /* Enable TS_CLK */
258 ts1->src_sel_val = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO;
259 break;
260 case CX23885_BOARD_HAUPPAUGE_HVR1250:
261 case CX23885_BOARD_HAUPPAUGE_HVR1800:
262 case CX23885_BOARD_HAUPPAUGE_HVR1800lp:
263 default:
264 ts2->gen_ctrl_val = 0xc; /* Serial bus + punctured clock */
265 ts2->ts_clk_en_val = 0x1; /* Enable TS_CLK */
266 ts2->src_sel_val = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO;
267 }
268
269}
270
271/* ------------------------------------------------------------------ */
272
273EXPORT_SYMBOL(cx23885_boards);
274
275/*
276 * Local variables:
277 * c-basic-offset: 8
278 * End:
279 * 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
280 */
diff --git a/drivers/media/video/cx23885/cx23885-core.c b/drivers/media/video/cx23885/cx23885-core.c
new file mode 100644
index 000000000000..af16505bd2e0
--- /dev/null
+++ b/drivers/media/video/cx23885/cx23885-core.c
@@ -0,0 +1,1530 @@
1/*
2 * Driver for the Conexant CX23885 PCIe bridge
3 *
4 * Copyright (c) 2006 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/init.h>
23#include <linux/list.h>
24#include <linux/module.h>
25#include <linux/moduleparam.h>
26#include <linux/kmod.h>
27#include <linux/kernel.h>
28#include <linux/slab.h>
29#include <linux/interrupt.h>
30#include <linux/delay.h>
31#include <asm/div64.h>
32
33#include "cx23885.h"
34
35MODULE_DESCRIPTION("Driver for cx23885 based TV cards");
36MODULE_AUTHOR("Steven Toth <stoth@hauppauge.com>");
37MODULE_LICENSE("GPL");
38
39static unsigned int debug = 0;
40module_param(debug,int,0644);
41MODULE_PARM_DESC(debug,"enable debug messages");
42
43static unsigned int card[] = {[0 ... (CX23885_MAXBOARDS - 1)] = UNSET };
44module_param_array(card, int, NULL, 0444);
45MODULE_PARM_DESC(card,"card type");
46
47#define dprintk(level,fmt, arg...) if (debug >= level) \
48 printk(KERN_DEBUG "%s/0: " fmt, dev->name , ## arg)
49
50static unsigned int cx23885_devcount;
51
52static DEFINE_MUTEX(devlist);
53static LIST_HEAD(cx23885_devlist);
54
55#define NO_SYNC_LINE (-1U)
56
57/*
58 * CX23885 Assumptions
59 * 1 line = 16 bytes of CDT
60 * cmds size = 80
61 * cdt size = 16 * linesize
62 * iqsize = 64
63 * maxlines = 6
64 *
65 * Address Space:
66 * 0x00000000 0x00008fff FIFO clusters
67 * 0x00010000 0x000104af Channel Management Data Structures
68 * 0x000104b0 0x000104ff Free
69 * 0x00010500 0x000108bf 15 channels * iqsize
70 * 0x000108c0 0x000108ff Free
71 * 0x00010900 0x00010e9f IQ's + Cluster Descriptor Tables
72 * 15 channels * (iqsize + (maxlines * linesize))
73 * 0x00010ea0 0x00010xxx Free
74 */
75
76struct sram_channel cx23885_sram_channels[] = {
77 [SRAM_CH01] = {
78 .name = "test ch1",
79 .cmds_start = 0x10000,
80 .ctrl_start = 0x10500,
81 .cdt = 0x10900,
82 .fifo_start = 0x3000,
83 .fifo_size = 0x1000,
84 .ptr1_reg = DMA1_PTR1,
85 .ptr2_reg = DMA1_PTR2,
86 .cnt1_reg = DMA1_CNT1,
87 .cnt2_reg = DMA1_CNT2,
88 .jumponly = 1,
89 },
90 [SRAM_CH02] = {
91 .name = "ch2",
92 .cmds_start = 0x0,
93 .ctrl_start = 0x0,
94 .cdt = 0x0,
95 .fifo_start = 0x0,
96 .fifo_size = 0x0,
97 .ptr1_reg = DMA2_PTR1,
98 .ptr2_reg = DMA2_PTR2,
99 .cnt1_reg = DMA2_CNT1,
100 .cnt2_reg = DMA2_CNT2,
101 },
102 [SRAM_CH03] = {
103 .name = "TS1 B",
104 .cmds_start = 0x100A0,
105 .ctrl_start = 0x10780,
106 .cdt = 0x10400,
107 .fifo_start = 0x5000,
108 .fifo_size = 0x1000,
109 .ptr1_reg = DMA3_PTR1,
110 .ptr2_reg = DMA3_PTR2,
111 .cnt1_reg = DMA3_CNT1,
112 .cnt2_reg = DMA3_CNT2,
113 },
114 [SRAM_CH04] = {
115 .name = "ch4",
116 .cmds_start = 0x0,
117 .ctrl_start = 0x0,
118 .cdt = 0x0,
119 .fifo_start = 0x0,
120 .fifo_size = 0x0,
121 .ptr1_reg = DMA4_PTR1,
122 .ptr2_reg = DMA4_PTR2,
123 .cnt1_reg = DMA4_CNT1,
124 .cnt2_reg = DMA4_CNT2,
125 },
126 [SRAM_CH05] = {
127 .name = "ch5",
128 .cmds_start = 0x0,
129 .ctrl_start = 0x0,
130 .cdt = 0x0,
131 .fifo_start = 0x0,
132 .fifo_size = 0x0,
133 .ptr1_reg = DMA5_PTR1,
134 .ptr2_reg = DMA5_PTR2,
135 .cnt1_reg = DMA5_CNT1,
136 .cnt2_reg = DMA5_CNT2,
137 },
138 [SRAM_CH06] = {
139 .name = "TS2 C",
140 .cmds_start = 0x10140,
141 .ctrl_start = 0x10680,
142 .cdt = 0x10480,
143 .fifo_start = 0x6000,
144 .fifo_size = 0x1000,
145 .ptr1_reg = DMA5_PTR1,
146 .ptr2_reg = DMA5_PTR2,
147 .cnt1_reg = DMA5_CNT1,
148 .cnt2_reg = DMA5_CNT2,
149 },
150 [SRAM_CH07] = {
151 .name = "ch7",
152 .cmds_start = 0x0,
153 .ctrl_start = 0x0,
154 .cdt = 0x0,
155 .fifo_start = 0x0,
156 .fifo_size = 0x0,
157 .ptr1_reg = DMA6_PTR1,
158 .ptr2_reg = DMA6_PTR2,
159 .cnt1_reg = DMA6_CNT1,
160 .cnt2_reg = DMA6_CNT2,
161 },
162 [SRAM_CH08] = {
163 .name = "ch8",
164 .cmds_start = 0x0,
165 .ctrl_start = 0x0,
166 .cdt = 0x0,
167 .fifo_start = 0x0,
168 .fifo_size = 0x0,
169 .ptr1_reg = DMA7_PTR1,
170 .ptr2_reg = DMA7_PTR2,
171 .cnt1_reg = DMA7_CNT1,
172 .cnt2_reg = DMA7_CNT2,
173 },
174 [SRAM_CH09] = {
175 .name = "ch9",
176 .cmds_start = 0x0,
177 .ctrl_start = 0x0,
178 .cdt = 0x0,
179 .fifo_start = 0x0,
180 .fifo_size = 0x0,
181 .ptr1_reg = DMA8_PTR1,
182 .ptr2_reg = DMA8_PTR2,
183 .cnt1_reg = DMA8_CNT1,
184 .cnt2_reg = DMA8_CNT2,
185 },
186};
187
188/* FIXME, these allocations will change when
189 * analog arrives. The be reviewed.
190 * CX23887 Assumptions
191 * 1 line = 16 bytes of CDT
192 * cmds size = 80
193 * cdt size = 16 * linesize
194 * iqsize = 64
195 * maxlines = 6
196 *
197 * Address Space:
198 * 0x00000000 0x00008fff FIFO clusters
199 * 0x00010000 0x000104af Channel Management Data Structures
200 * 0x000104b0 0x000104ff Free
201 * 0x00010500 0x000108bf 15 channels * iqsize
202 * 0x000108c0 0x000108ff Free
203 * 0x00010900 0x00010e9f IQ's + Cluster Descriptor Tables
204 * 15 channels * (iqsize + (maxlines * linesize))
205 * 0x00010ea0 0x00010xxx Free
206 */
207
208struct sram_channel cx23887_sram_channels[] = {
209 [SRAM_CH01] = {
210 .name = "test ch1",
211 .cmds_start = 0x0,
212 .ctrl_start = 0x0,
213 .cdt = 0x0,
214 .fifo_start = 0x0,
215 .fifo_size = 0x0,
216 .ptr1_reg = DMA1_PTR1,
217 .ptr2_reg = DMA1_PTR2,
218 .cnt1_reg = DMA1_CNT1,
219 .cnt2_reg = DMA1_CNT2,
220 },
221 [SRAM_CH02] = {
222 .name = "ch2",
223 .cmds_start = 0x0,
224 .ctrl_start = 0x0,
225 .cdt = 0x0,
226 .fifo_start = 0x0,
227 .fifo_size = 0x0,
228 .ptr1_reg = DMA2_PTR1,
229 .ptr2_reg = DMA2_PTR2,
230 .cnt1_reg = DMA2_CNT1,
231 .cnt2_reg = DMA2_CNT2,
232 },
233 [SRAM_CH03] = {
234 .name = "ch3",
235 .cmds_start = 0x0,
236 .ctrl_start = 0x0,
237 .cdt = 0x0,
238 .fifo_start = 0x0,
239 .fifo_size = 0x0,
240 .ptr1_reg = DMA3_PTR1,
241 .ptr2_reg = DMA3_PTR2,
242 .cnt1_reg = DMA3_CNT1,
243 .cnt2_reg = DMA3_CNT2,
244 },
245 [SRAM_CH04] = {
246 .name = "ch4",
247 .cmds_start = 0x0,
248 .ctrl_start = 0x0,
249 .cdt = 0x0,
250 .fifo_start = 0x0,
251 .fifo_size = 0x0,
252 .ptr1_reg = DMA4_PTR1,
253 .ptr2_reg = DMA4_PTR2,
254 .cnt1_reg = DMA4_CNT1,
255 .cnt2_reg = DMA4_CNT2,
256 },
257 [SRAM_CH05] = {
258 .name = "ch5",
259 .cmds_start = 0x0,
260 .ctrl_start = 0x0,
261 .cdt = 0x0,
262 .fifo_start = 0x0,
263 .fifo_size = 0x0,
264 .ptr1_reg = DMA5_PTR1,
265 .ptr2_reg = DMA5_PTR2,
266 .cnt1_reg = DMA5_CNT1,
267 .cnt2_reg = DMA5_CNT2,
268 },
269 [SRAM_CH06] = {
270 .name = "TS2 C",
271 .cmds_start = 0x10140,
272 .ctrl_start = 0x10680,
273 .cdt = 0x108d0,
274 .fifo_start = 0x6000,
275 .fifo_size = 0x1000,
276 .ptr1_reg = DMA5_PTR1,
277 .ptr2_reg = DMA5_PTR2,
278 .cnt1_reg = DMA5_CNT1,
279 .cnt2_reg = DMA5_CNT2,
280 },
281 [SRAM_CH07] = {
282 .name = "ch7",
283 .cmds_start = 0x0,
284 .ctrl_start = 0x0,
285 .cdt = 0x0,
286 .fifo_start = 0x0,
287 .fifo_size = 0x0,
288 .ptr1_reg = DMA6_PTR1,
289 .ptr2_reg = DMA6_PTR2,
290 .cnt1_reg = DMA6_CNT1,
291 .cnt2_reg = DMA6_CNT2,
292 },
293 [SRAM_CH08] = {
294 .name = "ch8",
295 .cmds_start = 0x0,
296 .ctrl_start = 0x0,
297 .cdt = 0x0,
298 .fifo_start = 0x0,
299 .fifo_size = 0x0,
300 .ptr1_reg = DMA7_PTR1,
301 .ptr2_reg = DMA7_PTR2,
302 .cnt1_reg = DMA7_CNT1,
303 .cnt2_reg = DMA7_CNT2,
304 },
305 [SRAM_CH09] = {
306 .name = "ch9",
307 .cmds_start = 0x0,
308 .ctrl_start = 0x0,
309 .cdt = 0x0,
310 .fifo_start = 0x0,
311 .fifo_size = 0x0,
312 .ptr1_reg = DMA8_PTR1,
313 .ptr2_reg = DMA8_PTR2,
314 .cnt1_reg = DMA8_CNT1,
315 .cnt2_reg = DMA8_CNT2,
316 },
317};
318
319static int cx23885_risc_decode(u32 risc)
320{
321 static char *instr[16] = {
322 [ RISC_SYNC >> 28 ] = "sync",
323 [ RISC_WRITE >> 28 ] = "write",
324 [ RISC_WRITEC >> 28 ] = "writec",
325 [ RISC_READ >> 28 ] = "read",
326 [ RISC_READC >> 28 ] = "readc",
327 [ RISC_JUMP >> 28 ] = "jump",
328 [ RISC_SKIP >> 28 ] = "skip",
329 [ RISC_WRITERM >> 28 ] = "writerm",
330 [ RISC_WRITECM >> 28 ] = "writecm",
331 [ RISC_WRITECR >> 28 ] = "writecr",
332 };
333 static int incr[16] = {
334 [ RISC_WRITE >> 28 ] = 3,
335 [ RISC_JUMP >> 28 ] = 3,
336 [ RISC_SKIP >> 28 ] = 1,
337 [ RISC_SYNC >> 28 ] = 1,
338 [ RISC_WRITERM >> 28 ] = 3,
339 [ RISC_WRITECM >> 28 ] = 3,
340 [ RISC_WRITECR >> 28 ] = 4,
341 };
342 static char *bits[] = {
343 "12", "13", "14", "resync",
344 "cnt0", "cnt1", "18", "19",
345 "20", "21", "22", "23",
346 "irq1", "irq2", "eol", "sol",
347 };
348 int i;
349
350 printk("0x%08x [ %s", risc,
351 instr[risc >> 28] ? instr[risc >> 28] : "INVALID");
352 for (i = ARRAY_SIZE(bits) - 1; i >= 0; i--)
353 if (risc & (1 << (i + 12)))
354 printk(" %s", bits[i]);
355 printk(" count=%d ]\n", risc & 0xfff);
356 return incr[risc >> 28] ? incr[risc >> 28] : 1;
357}
358
359void cx23885_wakeup(struct cx23885_tsport *port,
360 struct cx23885_dmaqueue *q, u32 count)
361{
362 struct cx23885_dev *dev = port->dev;
363 struct cx23885_buffer *buf;
364 int bc;
365
366 for (bc = 0;; bc++) {
367 if (list_empty(&q->active))
368 break;
369 buf = list_entry(q->active.next,
370 struct cx23885_buffer, vb.queue);
371
372 /* count comes from the hw and is is 16bit wide --
373 * this trick handles wrap-arounds correctly for
374 * up to 32767 buffers in flight... */
375 if ((s16) (count - buf->count) < 0)
376 break;
377
378 do_gettimeofday(&buf->vb.ts);
379 dprintk(2, "[%p/%d] wakeup reg=%d buf=%d\n", buf, buf->vb.i,
380 count, buf->count);
381 buf->vb.state = STATE_DONE;
382 list_del(&buf->vb.queue);
383 wake_up(&buf->vb.done);
384 }
385 if (list_empty(&q->active)) {
386 del_timer(&q->timeout);
387 } else {
388 mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
389 }
390 if (bc != 1)
391 printk("%s: %d buffers handled (should be 1)\n",
392 __FUNCTION__, bc);
393}
394void cx23885_sram_channel_dump(struct cx23885_dev *dev,
395 struct sram_channel *ch);
396
397int cx23885_sram_channel_setup(struct cx23885_dev *dev,
398 struct sram_channel *ch,
399 unsigned int bpl, u32 risc)
400{
401 unsigned int i, lines;
402 u32 cdt;
403
404 if (ch->cmds_start == 0)
405 {
406 dprintk(1, "%s() Erasing channel [%s]\n", __FUNCTION__,
407 ch->name);
408 cx_write(ch->ptr1_reg, 0);
409 cx_write(ch->ptr2_reg, 0);
410 cx_write(ch->cnt2_reg, 0);
411 cx_write(ch->cnt1_reg, 0);
412 return 0;
413 } else {
414 dprintk(1, "%s() Configuring channel [%s]\n", __FUNCTION__,
415 ch->name);
416 }
417
418 bpl = (bpl + 7) & ~7; /* alignment */
419 cdt = ch->cdt;
420 lines = ch->fifo_size / bpl;
421 if (lines > 6)
422 lines = 6;
423 BUG_ON(lines < 2);
424
425 cx_write(8 + 0, cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC) );
426 cx_write(8 + 4, cpu_to_le32(8) );
427 cx_write(8 + 8, cpu_to_le32(0) );
428
429 /* write CDT */
430 for (i = 0; i < lines; i++) {
431 dprintk(2, "%s() 0x%08x <- 0x%08x\n", __FUNCTION__, cdt + 16*i,
432 ch->fifo_start + bpl*i);
433 cx_write(cdt + 16*i, ch->fifo_start + bpl*i);
434 cx_write(cdt + 16*i + 4, 0);
435 cx_write(cdt + 16*i + 8, 0);
436 cx_write(cdt + 16*i + 12, 0);
437 }
438
439 /* write CMDS */
440 if (ch->jumponly)
441 cx_write(ch->cmds_start + 0, 8);
442 else
443 cx_write(ch->cmds_start + 0, risc);
444 cx_write(ch->cmds_start + 4, 0); /* 64 bits 63-32 */
445 cx_write(ch->cmds_start + 8, cdt);
446 cx_write(ch->cmds_start + 12, (lines*16) >> 3);
447 cx_write(ch->cmds_start + 16, ch->ctrl_start);
448 if (ch->jumponly)
449 cx_write(ch->cmds_start + 20, 0x80000000 | (64 >> 2) );
450 else
451 cx_write(ch->cmds_start + 20, 64 >> 2);
452 for (i = 24; i < 80; i += 4)
453 cx_write(ch->cmds_start + i, 0);
454
455 /* fill registers */
456 cx_write(ch->ptr1_reg, ch->fifo_start);
457 cx_write(ch->ptr2_reg, cdt);
458 cx_write(ch->cnt2_reg, (lines*16) >> 3);
459 cx_write(ch->cnt1_reg, (bpl >> 3) -1);
460
461 dprintk(2,"[bridge %d] sram setup %s: bpl=%d lines=%d\n",
462 dev->bridge,
463 ch->name,
464 bpl,
465 lines);
466
467 return 0;
468}
469
470void cx23885_sram_channel_dump(struct cx23885_dev *dev,
471 struct sram_channel *ch)
472{
473 static char *name[] = {
474 "init risc lo",
475 "init risc hi",
476 "cdt base",
477 "cdt size",
478 "iq base",
479 "iq size",
480 "risc pc lo",
481 "risc pc hi",
482 "iq wr ptr",
483 "iq rd ptr",
484 "cdt current",
485 "pci target lo",
486 "pci target hi",
487 "line / byte",
488 };
489 u32 risc;
490 unsigned int i, j, n;
491
492 printk("%s: %s - dma channel status dump\n",
493 dev->name, ch->name);
494 for (i = 0; i < ARRAY_SIZE(name); i++)
495 printk("%s: cmds: %-15s: 0x%08x\n",
496 dev->name, name[i],
497 cx_read(ch->cmds_start + 4*i));
498
499 for (i = 0; i < 4; i++) {
500 risc = cx_read(ch->cmds_start + 4 * (i + 14));
501 printk("%s: risc%d: ", dev->name, i);
502 cx23885_risc_decode(risc);
503 }
504 for (i = 0; i < (64 >> 2); i += n) {
505 risc = cx_read(ch->ctrl_start + 4 * i);
506 /* No consideration for bits 63-32 */
507
508 printk("%s: (0x%08x) iq %x: ", dev->name,
509 ch->ctrl_start + 4 * i, i);
510 n = cx23885_risc_decode(risc);
511 for (j = 1; j < n; j++) {
512 risc = cx_read(ch->ctrl_start + 4 * (i + j));
513 printk("%s: iq %x: 0x%08x [ arg #%d ]\n",
514 dev->name, i+j, risc, j);
515 }
516 }
517
518 printk("%s: fifo: 0x%08x -> 0x%x\n",
519 dev->name, ch->fifo_start, ch->fifo_start+ch->fifo_size);
520 printk("%s: ctrl: 0x%08x -> 0x%x\n",
521 dev->name, ch->ctrl_start, ch->ctrl_start + 6*16);
522 printk("%s: ptr1_reg: 0x%08x\n",
523 dev->name, cx_read(ch->ptr1_reg));
524 printk("%s: ptr2_reg: 0x%08x\n",
525 dev->name, cx_read(ch->ptr2_reg));
526 printk("%s: cnt1_reg: 0x%08x\n",
527 dev->name, cx_read(ch->cnt1_reg));
528 printk("%s: cnt2_reg: 0x%08x\n",
529 dev->name, cx_read(ch->cnt2_reg));
530}
531
532void cx23885_risc_disasm(struct cx23885_tsport *port,
533 struct btcx_riscmem *risc)
534{
535 struct cx23885_dev *dev = port->dev;
536 unsigned int i, j, n;
537
538 printk("%s: risc disasm: %p [dma=0x%08lx]\n",
539 dev->name, risc->cpu, (unsigned long)risc->dma);
540 for (i = 0; i < (risc->size >> 2); i += n) {
541 printk("%s: %04d: ", dev->name, i);
542 n = cx23885_risc_decode(risc->cpu[i]);
543 for (j = 1; j < n; j++)
544 printk("%s: %04d: 0x%08x [ arg #%d ]\n",
545 dev->name, i + j, risc->cpu[i + j], j);
546 if (risc->cpu[i] == RISC_JUMP)
547 break;
548 }
549}
550
551void cx23885_shutdown(struct cx23885_dev *dev)
552{
553 /* disable RISC controller */
554 cx_write(DEV_CNTRL2, 0);
555
556 /* Disable all IR activity */
557 cx_write(IR_CNTRL_REG, 0);
558
559 /* Disable Video A/B activity */
560 cx_write(VID_A_DMA_CTL, 0);
561 cx_write(VID_B_DMA_CTL, 0);
562 cx_write(VID_C_DMA_CTL, 0);
563
564 /* Disable Audio activity */
565 cx_write(AUD_INT_DMA_CTL, 0);
566 cx_write(AUD_EXT_DMA_CTL, 0);
567
568 /* Disable Serial port */
569 cx_write(UART_CTL, 0);
570
571 /* Disable Interrupts */
572 cx_write(PCI_INT_MSK, 0);
573 cx_write(VID_A_INT_MSK, 0);
574 cx_write(VID_B_INT_MSK, 0);
575 cx_write(VID_C_INT_MSK, 0);
576 cx_write(AUDIO_INT_INT_MSK, 0);
577 cx_write(AUDIO_EXT_INT_MSK, 0);
578
579}
580
581void cx23885_reset(struct cx23885_dev *dev)
582{
583 dprintk(1, "%s()\n", __FUNCTION__);
584
585 cx23885_shutdown(dev);
586
587 cx_write(PCI_INT_STAT, 0xffffffff);
588 cx_write(VID_A_INT_STAT, 0xffffffff);
589 cx_write(VID_B_INT_STAT, 0xffffffff);
590 cx_write(VID_C_INT_STAT, 0xffffffff);
591 cx_write(AUDIO_INT_INT_STAT, 0xffffffff);
592 cx_write(AUDIO_EXT_INT_STAT, 0xffffffff);
593 cx_write(CLK_DELAY, cx_read(CLK_DELAY) & 0x80000000);
594
595 mdelay(100);
596
597 cx23885_sram_channel_setup(dev, &dev->sram_channels[ SRAM_CH01 ], 188*4, 0);
598 cx23885_sram_channel_setup(dev, &dev->sram_channels[ SRAM_CH02 ], 128, 0);
599 cx23885_sram_channel_setup(dev, &dev->sram_channels[ SRAM_CH03 ], 188*4, 0);
600 cx23885_sram_channel_setup(dev, &dev->sram_channels[ SRAM_CH04 ], 128, 0);
601 cx23885_sram_channel_setup(dev, &dev->sram_channels[ SRAM_CH05 ], 128, 0);
602 cx23885_sram_channel_setup(dev, &dev->sram_channels[ SRAM_CH06 ], 188*4, 0);
603 cx23885_sram_channel_setup(dev, &dev->sram_channels[ SRAM_CH07 ], 128, 0);
604 cx23885_sram_channel_setup(dev, &dev->sram_channels[ SRAM_CH08 ], 128, 0);
605 cx23885_sram_channel_setup(dev, &dev->sram_channels[ SRAM_CH09 ], 128, 0);
606
607 cx23885_gpio_setup(dev);
608}
609
610
611static int cx23885_pci_quirks(struct cx23885_dev *dev)
612{
613 dprintk(1, "%s()\n", __FUNCTION__);
614
615 /* The cx23885 bridge has a weird bug which causes NMI to be asserted
616 * when DMA begins if RDR_TLCTL0 bit4 is not cleared. It does not
617 * occur on the cx23887 bridge.
618 */
619 if(dev->bridge == CX23885_BRIDGE_885)
620 cx_clear(RDR_TLCTL0, 1 << 4);
621
622 return 0;
623}
624
625static int get_resources(struct cx23885_dev *dev)
626{
627 if (request_mem_region(pci_resource_start(dev->pci,0),
628 pci_resource_len(dev->pci,0),
629 dev->name))
630 return 0;
631
632 printk(KERN_ERR "%s: can't get MMIO memory @ 0x%llx\n",
633 dev->name, (unsigned long long)pci_resource_start(dev->pci,0));
634
635 return -EBUSY;
636}
637
638static void cx23885_timeout(unsigned long data);
639int cx23885_risc_stopper(struct pci_dev *pci, struct btcx_riscmem *risc,
640 u32 reg, u32 mask, u32 value);
641
642static int cx23885_init_tsport(struct cx23885_dev *dev, struct cx23885_tsport *port, int portno)
643{
644 dprintk(1, "%s(portno=%d)\n", __FUNCTION__, portno);
645
646 /* Transport bus init dma queue - Common settings */
647 port->dma_ctl_val = 0x11; /* Enable RISC controller and Fifo */
648 port->ts_int_msk_val = 0x1111; /* TS port bits for RISC */
649
650 spin_lock_init(&port->slock);
651 port->dev = dev;
652 port->nr = portno;
653
654 INIT_LIST_HEAD(&port->mpegq.active);
655 INIT_LIST_HEAD(&port->mpegq.queued);
656 port->mpegq.timeout.function = cx23885_timeout;
657 port->mpegq.timeout.data = (unsigned long)port;
658 init_timer(&port->mpegq.timeout);
659
660 switch(portno) {
661 case 1:
662 port->reg_gpcnt = VID_B_GPCNT;
663 port->reg_gpcnt_ctl = VID_B_GPCNT_CTL;
664 port->reg_dma_ctl = VID_B_DMA_CTL;
665 port->reg_lngth = VID_B_LNGTH;
666 port->reg_hw_sop_ctrl = VID_B_HW_SOP_CTL;
667 port->reg_gen_ctrl = VID_B_GEN_CTL;
668 port->reg_bd_pkt_status = VID_B_BD_PKT_STATUS;
669 port->reg_sop_status = VID_B_SOP_STATUS;
670 port->reg_fifo_ovfl_stat = VID_B_FIFO_OVFL_STAT;
671 port->reg_vld_misc = VID_B_VLD_MISC;
672 port->reg_ts_clk_en = VID_B_TS_CLK_EN;
673 port->reg_src_sel = VID_B_SRC_SEL;
674 port->reg_ts_int_msk = VID_B_INT_MSK;
675 port->reg_ts_int_stat = VID_B_INT_STAT;
676 port->sram_chno = SRAM_CH03; /* VID_B */
677 port->pci_irqmask = 0x02; /* VID_B bit1 */
678 break;
679 case 2:
680 port->reg_gpcnt = VID_C_GPCNT;
681 port->reg_gpcnt_ctl = VID_C_GPCNT_CTL;
682 port->reg_dma_ctl = VID_C_DMA_CTL;
683 port->reg_lngth = VID_C_LNGTH;
684 port->reg_hw_sop_ctrl = VID_C_HW_SOP_CTL;
685 port->reg_gen_ctrl = VID_C_GEN_CTL;
686 port->reg_bd_pkt_status = VID_C_BD_PKT_STATUS;
687 port->reg_sop_status = VID_C_SOP_STATUS;
688 port->reg_fifo_ovfl_stat = VID_C_FIFO_OVFL_STAT;
689 port->reg_vld_misc = VID_C_VLD_MISC;
690 port->reg_ts_clk_en = VID_C_TS_CLK_EN;
691 port->reg_src_sel = 0;
692 port->reg_ts_int_msk = VID_C_INT_MSK;
693 port->reg_ts_int_stat = VID_C_INT_STAT;
694 port->sram_chno = SRAM_CH06; /* VID_C */
695 port->pci_irqmask = 0x04; /* VID_C bit2 */
696 break;
697 default:
698 BUG();
699 }
700
701 cx23885_risc_stopper(dev->pci, &port->mpegq.stopper,
702 port->reg_dma_ctl, port->dma_ctl_val, 0x00);
703
704 return 0;
705}
706
707static int cx23885_dev_setup(struct cx23885_dev *dev)
708{
709 int i;
710
711 mutex_init(&dev->lock);
712
713 atomic_inc(&dev->refcount);
714
715 dev->nr = cx23885_devcount++;
716 sprintf(dev->name, "cx23885[%d]", dev->nr);
717
718 mutex_lock(&devlist);
719 list_add_tail(&dev->devlist, &cx23885_devlist);
720 mutex_unlock(&devlist);
721
722 /* Configure the internal memory */
723 if(dev->pci->device == 0x8880) {
724 dev->bridge = CX23885_BRIDGE_887;
725 dev->sram_channels = cx23887_sram_channels;
726 } else
727 if(dev->pci->device == 0x8852) {
728 dev->bridge = CX23885_BRIDGE_885;
729 dev->sram_channels = cx23885_sram_channels;
730 } else
731 BUG();
732
733 dprintk(1, "%s() Memory configured for PCIe bridge type %d\n",
734 __FUNCTION__, dev->bridge);
735
736 /* board config */
737 dev->board = UNSET;
738 if (card[dev->nr] < cx23885_bcount)
739 dev->board = card[dev->nr];
740 for (i = 0; UNSET == dev->board && i < cx23885_idcount; i++)
741 if (dev->pci->subsystem_vendor == cx23885_subids[i].subvendor &&
742 dev->pci->subsystem_device == cx23885_subids[i].subdevice)
743 dev->board = cx23885_subids[i].card;
744 if (UNSET == dev->board) {
745 dev->board = CX23885_BOARD_UNKNOWN;
746 cx23885_card_list(dev);
747 }
748
749 dev->pci_bus = dev->pci->bus->number;
750 dev->pci_slot = PCI_SLOT(dev->pci->devfn);
751 dev->pci_irqmask = 0x001f00;
752
753 /* External Master 1 Bus */
754 dev->i2c_bus[0].nr = 0;
755 dev->i2c_bus[0].dev = dev;
756 dev->i2c_bus[0].reg_stat = I2C1_STAT;
757 dev->i2c_bus[0].reg_ctrl = I2C1_CTRL;
758 dev->i2c_bus[0].reg_addr = I2C1_ADDR;
759 dev->i2c_bus[0].reg_rdata = I2C1_RDATA;
760 dev->i2c_bus[0].reg_wdata = I2C1_WDATA;
761 dev->i2c_bus[0].i2c_period = (0x9d << 24); /* 100kHz */
762
763 /* External Master 2 Bus */
764 dev->i2c_bus[1].nr = 1;
765 dev->i2c_bus[1].dev = dev;
766 dev->i2c_bus[1].reg_stat = I2C2_STAT;
767 dev->i2c_bus[1].reg_ctrl = I2C2_CTRL;
768 dev->i2c_bus[1].reg_addr = I2C2_ADDR;
769 dev->i2c_bus[1].reg_rdata = I2C2_RDATA;
770 dev->i2c_bus[1].reg_wdata = I2C2_WDATA;
771 dev->i2c_bus[1].i2c_period = (0x9d << 24); /* 100kHz */
772
773 /* Internal Master 3 Bus */
774 dev->i2c_bus[2].nr = 2;
775 dev->i2c_bus[2].dev = dev;
776 dev->i2c_bus[2].reg_stat = I2C3_STAT;
777 dev->i2c_bus[2].reg_ctrl = I2C3_CTRL;
778 dev->i2c_bus[2].reg_addr = I2C3_ADDR;
779 dev->i2c_bus[2].reg_rdata = I2C3_RDATA;
780 dev->i2c_bus[2].reg_wdata = I2C3_WDATA;
781 dev->i2c_bus[2].i2c_period = (0x07 << 24); /* 1.95MHz */
782
783 if(cx23885_boards[dev->board].portb == CX23885_MPEG_DVB)
784 cx23885_init_tsport(dev, &dev->ts1, 1);
785
786 if(cx23885_boards[dev->board].portc == CX23885_MPEG_DVB)
787 cx23885_init_tsport(dev, &dev->ts2, 2);
788
789 if (get_resources(dev) < 0) {
790 printk(KERN_ERR "CORE %s No more PCIe resources for "
791 "subsystem: %04x:%04x\n",
792 dev->name, dev->pci->subsystem_vendor,
793 dev->pci->subsystem_device);
794
795 cx23885_devcount--;
796 goto fail_free;
797 }
798
799 /* PCIe stuff */
800 dev->lmmio = ioremap(pci_resource_start(dev->pci,0),
801 pci_resource_len(dev->pci,0));
802
803 dev->bmmio = (u8 __iomem *)dev->lmmio;
804
805 printk(KERN_INFO "CORE %s: subsystem: %04x:%04x, board: %s [card=%d,%s]\n",
806 dev->name, dev->pci->subsystem_vendor,
807 dev->pci->subsystem_device, cx23885_boards[dev->board].name,
808 dev->board, card[dev->nr] == dev->board ?
809 "insmod option" : "autodetected");
810
811 cx23885_pci_quirks(dev);
812
813 /* init hardware */
814 cx23885_reset(dev);
815
816 cx23885_i2c_register(&dev->i2c_bus[0]);
817 cx23885_i2c_register(&dev->i2c_bus[1]);
818 cx23885_i2c_register(&dev->i2c_bus[2]);
819 cx23885_call_i2c_clients (&dev->i2c_bus[0], TUNER_SET_STANDBY, NULL);
820 cx23885_card_setup(dev);
821 cx23885_ir_init(dev);
822
823 if(cx23885_boards[dev->board].portb == CX23885_MPEG_DVB) {
824 if (cx23885_dvb_register(&dev->ts1) < 0) {
825 printk(KERN_ERR "%s() Failed to register dvb adapters on VID_B\n",
826 __FUNCTION__);
827 }
828 }
829
830 if(cx23885_boards[dev->board].portc == CX23885_MPEG_DVB) {
831 if (cx23885_dvb_register(&dev->ts2) < 0) {
832 printk(KERN_ERR "%s() Failed to register dvb adapters on VID_C\n",
833 __FUNCTION__);
834 }
835 }
836
837 return 0;
838
839fail_free:
840 kfree(dev);
841 return -ENODEV;
842}
843
844void cx23885_dev_unregister(struct cx23885_dev *dev)
845{
846 release_mem_region(pci_resource_start(dev->pci,0),
847 pci_resource_len(dev->pci,0));
848
849 if (!atomic_dec_and_test(&dev->refcount))
850 return;
851
852 if(cx23885_boards[dev->board].portb == CX23885_MPEG_DVB)
853 cx23885_dvb_unregister(&dev->ts1);
854
855 if(cx23885_boards[dev->board].portc == CX23885_MPEG_DVB)
856 cx23885_dvb_unregister(&dev->ts2);
857
858 cx23885_i2c_unregister(&dev->i2c_bus[2]);
859 cx23885_i2c_unregister(&dev->i2c_bus[1]);
860 cx23885_i2c_unregister(&dev->i2c_bus[0]);
861
862 iounmap(dev->lmmio);
863}
864
865static u32* cx23885_risc_field(u32 *rp, struct scatterlist *sglist,
866 unsigned int offset, u32 sync_line,
867 unsigned int bpl, unsigned int padding,
868 unsigned int lines)
869{
870 struct scatterlist *sg;
871 unsigned int line, todo;
872
873 /* sync instruction */
874 if (sync_line != NO_SYNC_LINE)
875 *(rp++) = cpu_to_le32(RISC_RESYNC | sync_line);
876
877 /* scan lines */
878 sg = sglist;
879 for (line = 0; line < lines; line++) {
880 while (offset && offset >= sg_dma_len(sg)) {
881 offset -= sg_dma_len(sg);
882 sg++;
883 }
884 if (bpl <= sg_dma_len(sg)-offset) {
885 /* fits into current chunk */
886 *(rp++)=cpu_to_le32(RISC_WRITE|RISC_SOL|RISC_EOL|bpl);
887 *(rp++)=cpu_to_le32(sg_dma_address(sg)+offset);
888 *(rp++)=cpu_to_le32(0); /* bits 63-32 */
889 offset+=bpl;
890 } else {
891 /* scanline needs to be split */
892 todo = bpl;
893 *(rp++)=cpu_to_le32(RISC_WRITE|RISC_SOL|
894 (sg_dma_len(sg)-offset));
895 *(rp++)=cpu_to_le32(sg_dma_address(sg)+offset);
896 *(rp++)=cpu_to_le32(0); /* bits 63-32 */
897 todo -= (sg_dma_len(sg)-offset);
898 offset = 0;
899 sg++;
900 while (todo > sg_dma_len(sg)) {
901 *(rp++)=cpu_to_le32(RISC_WRITE|
902 sg_dma_len(sg));
903 *(rp++)=cpu_to_le32(sg_dma_address(sg));
904 *(rp++)=cpu_to_le32(0); /* bits 63-32 */
905 todo -= sg_dma_len(sg);
906 sg++;
907 }
908 *(rp++)=cpu_to_le32(RISC_WRITE|RISC_EOL|todo);
909 *(rp++)=cpu_to_le32(sg_dma_address(sg));
910 *(rp++)=cpu_to_le32(0); /* bits 63-32 */
911 offset += todo;
912 }
913 offset += padding;
914 }
915
916 return rp;
917}
918
919int cx23885_risc_buffer(struct pci_dev *pci, struct btcx_riscmem *risc,
920 struct scatterlist *sglist, unsigned int top_offset,
921 unsigned int bottom_offset, unsigned int bpl,
922 unsigned int padding, unsigned int lines)
923{
924 u32 instructions, fields;
925 u32 *rp;
926 int rc;
927
928 fields = 0;
929 if (UNSET != top_offset)
930 fields++;
931 if (UNSET != bottom_offset)
932 fields++;
933
934 /* estimate risc mem: worst case is one write per page border +
935 one write per scan line + syncs + jump (all 2 dwords). Padding
936 can cause next bpl to start close to a page border. First DMA
937 region may be smaller than PAGE_SIZE */
938 /* write and jump need and extra dword */
939 instructions = fields * (1 + ((bpl + padding) * lines) / PAGE_SIZE + lines);
940 instructions += 2;
941 if ((rc = btcx_riscmem_alloc(pci,risc,instructions*12)) < 0)
942 return rc;
943
944 /* write risc instructions */
945 rp = risc->cpu;
946 if (UNSET != top_offset)
947 rp = cx23885_risc_field(rp, sglist, top_offset, 0,
948 bpl, padding, lines);
949 if (UNSET != bottom_offset)
950 rp = cx23885_risc_field(rp, sglist, bottom_offset, 0x200,
951 bpl, padding, lines);
952
953 /* save pointer to jmp instruction address */
954 risc->jmp = rp;
955 BUG_ON((risc->jmp - risc->cpu + 2) * sizeof (*risc->cpu) > risc->size);
956 return 0;
957}
958
959int cx23885_risc_databuffer(struct pci_dev *pci, struct btcx_riscmem *risc,
960 struct scatterlist *sglist, unsigned int bpl,
961 unsigned int lines)
962{
963 u32 instructions;
964 u32 *rp;
965 int rc;
966
967 /* estimate risc mem: worst case is one write per page border +
968 one write per scan line + syncs + jump (all 2 dwords). Here
969 there is no padding and no sync. First DMA region may be smaller
970 than PAGE_SIZE */
971 /* Jump and write need an extra dword */
972 instructions = 1 + (bpl * lines) / PAGE_SIZE + lines;
973 instructions += 1;
974
975 if ((rc = btcx_riscmem_alloc(pci,risc,instructions*12)) < 0)
976 return rc;
977
978 /* write risc instructions */
979 rp = risc->cpu;
980 rp = cx23885_risc_field(rp, sglist, 0, NO_SYNC_LINE, bpl, 0, lines);
981
982 /* save pointer to jmp instruction address */
983 risc->jmp = rp;
984 BUG_ON((risc->jmp - risc->cpu + 2) * sizeof (*risc->cpu) > risc->size);
985 return 0;
986}
987
988int cx23885_risc_stopper(struct pci_dev *pci, struct btcx_riscmem *risc,
989 u32 reg, u32 mask, u32 value)
990{
991 u32 *rp;
992 int rc;
993
994 if ((rc = btcx_riscmem_alloc(pci, risc, 4*16)) < 0)
995 return rc;
996
997 /* write risc instructions */
998 rp = risc->cpu;
999 *(rp++) = cpu_to_le32(RISC_WRITECR | RISC_IRQ2);
1000 *(rp++) = cpu_to_le32(reg);
1001 *(rp++) = cpu_to_le32(value);
1002 *(rp++) = cpu_to_le32(mask);
1003 *(rp++) = cpu_to_le32(RISC_JUMP);
1004 *(rp++) = cpu_to_le32(risc->dma);
1005 *(rp++) = cpu_to_le32(0); /* bits 63-32 */
1006 return 0;
1007}
1008
1009void cx23885_free_buffer(struct videobuf_queue *q, struct cx23885_buffer *buf)
1010{
1011 struct videobuf_dmabuf *dma = videobuf_to_dma(&buf->vb);
1012
1013 BUG_ON(in_interrupt());
1014 videobuf_waiton(&buf->vb, 0, 0);
1015 videobuf_dma_unmap(q, dma);
1016 videobuf_dma_free(dma);
1017 btcx_riscmem_free((struct pci_dev *)q->dev, &buf->risc);
1018 buf->vb.state = STATE_NEEDS_INIT;
1019}
1020
1021static int cx23885_start_dma(struct cx23885_tsport *port,
1022 struct cx23885_dmaqueue *q,
1023 struct cx23885_buffer *buf)
1024{
1025 struct cx23885_dev *dev = port->dev;
1026
1027 dprintk(1, "%s() w: %d, h: %d, f: %d\n", __FUNCTION__,
1028 buf->vb.width, buf->vb.height, buf->vb.field);
1029
1030 /* setup fifo + format */
1031 cx23885_sram_channel_setup(dev,
1032 &dev->sram_channels[ port->sram_chno ],
1033 port->ts_packet_size, buf->risc.dma);
1034 if(debug > 5) {
1035 cx23885_sram_channel_dump(dev, &dev->sram_channels[ port->sram_chno ] );
1036 cx23885_risc_disasm(port, &buf->risc);
1037 }
1038
1039 /* write TS length to chip */
1040 cx_write(port->reg_lngth, buf->vb.width);
1041
1042 if ( (!(cx23885_boards[dev->board].portb & CX23885_MPEG_DVB)) &&
1043 (!(cx23885_boards[dev->board].portc & CX23885_MPEG_DVB)) ) {
1044 printk( "%s() Failed. Unsupported value in .portb/c (0x%08x)/(0x%08x)\n",
1045 __FUNCTION__,
1046 cx23885_boards[dev->board].portb,
1047 cx23885_boards[dev->board].portc );
1048 return -EINVAL;
1049 }
1050
1051 udelay(100);
1052
1053 /* If the port supports SRC SELECT, configure it */
1054 if(port->reg_src_sel)
1055 cx_write(port->reg_src_sel, port->src_sel_val);
1056
1057 cx_write(port->reg_hw_sop_ctrl, 0x47 << 16 | 188 << 4);
1058 cx_write(port->reg_ts_clk_en, port->ts_clk_en_val);
1059 cx_write(port->reg_vld_misc, 0x00);
1060 cx_write(port->reg_gen_ctrl, port->gen_ctrl_val);
1061 udelay(100);
1062
1063 // NOTE: this is 2 (reserved) for portb, does it matter?
1064 /* reset counter to zero */
1065 cx_write(port->reg_gpcnt_ctl, 3);
1066 q->count = 1;
1067
1068 switch(dev->bridge) {
1069 case CX23885_BRIDGE_885:
1070 case CX23885_BRIDGE_887:
1071 /* enable irqs */
1072 dprintk(1, "%s() enabling TS int's and DMA\n", __FUNCTION__ );
1073 cx_set(port->reg_ts_int_msk, port->ts_int_msk_val);
1074 cx_set(port->reg_dma_ctl, port->dma_ctl_val);
1075 cx_set(PCI_INT_MSK, dev->pci_irqmask | port->pci_irqmask);
1076 break;
1077 default:
1078 BUG();
1079 }
1080
1081 cx_set(DEV_CNTRL2, (1<<5)); /* Enable RISC controller */
1082
1083 return 0;
1084}
1085
1086static int cx23885_stop_dma(struct cx23885_tsport *port)
1087{
1088 struct cx23885_dev *dev = port->dev;
1089 dprintk(1, "%s()\n", __FUNCTION__);
1090
1091 /* Stop interrupts and DMA */
1092 cx_clear(port->reg_ts_int_msk, port->ts_int_msk_val);
1093 cx_clear(port->reg_dma_ctl, port->dma_ctl_val);
1094
1095 return 0;
1096}
1097
1098static int cx23885_restart_queue(struct cx23885_tsport *port,
1099 struct cx23885_dmaqueue *q)
1100{
1101 struct cx23885_dev *dev = port->dev;
1102 struct cx23885_buffer *buf;
1103
1104 dprintk(5, "%s()\n", __FUNCTION__);
1105 if (list_empty(&q->active))
1106 {
1107 struct cx23885_buffer *prev;
1108 prev = NULL;
1109
1110 dprintk(5, "%s() queue is empty\n", __FUNCTION__);
1111
1112 for (;;) {
1113 if (list_empty(&q->queued))
1114 return 0;
1115 buf = list_entry(q->queued.next, struct cx23885_buffer,
1116 vb.queue);
1117 if (NULL == prev) {
1118 list_del(&buf->vb.queue);
1119 list_add_tail(&buf->vb.queue, &q->active);
1120 cx23885_start_dma(port, q, buf);
1121 buf->vb.state = STATE_ACTIVE;
1122 buf->count = q->count++;
1123 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
1124 dprintk(5, "[%p/%d] restart_queue - first active\n",
1125 buf, buf->vb.i);
1126
1127 } else if (prev->vb.width == buf->vb.width &&
1128 prev->vb.height == buf->vb.height &&
1129 prev->fmt == buf->fmt) {
1130 list_del(&buf->vb.queue);
1131 list_add_tail(&buf->vb.queue, &q->active);
1132 buf->vb.state = STATE_ACTIVE;
1133 buf->count = q->count++;
1134 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
1135 prev->risc.jmp[2] = cpu_to_le32(0); /* 64 bit bits 63-32 */
1136 dprintk(5,"[%p/%d] restart_queue - move to active\n",
1137 buf, buf->vb.i);
1138 } else {
1139 return 0;
1140 }
1141 prev = buf;
1142 }
1143 return 0;
1144 }
1145
1146 buf = list_entry(q->active.next, struct cx23885_buffer, vb.queue);
1147 dprintk(2, "restart_queue [%p/%d]: restart dma\n",
1148 buf, buf->vb.i);
1149 cx23885_start_dma(port, q, buf);
1150 list_for_each_entry(buf, &q->active, vb.queue)
1151 buf->count = q->count++;
1152 mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
1153 return 0;
1154}
1155
1156/* ------------------------------------------------------------------ */
1157
1158int cx23885_buf_prepare(struct videobuf_queue *q, struct cx23885_tsport *port,
1159 struct cx23885_buffer *buf, enum v4l2_field field)
1160{
1161 struct cx23885_dev *dev = port->dev;
1162 int size = port->ts_packet_size * port->ts_packet_count;
1163 int rc;
1164
1165 dprintk(1, "%s: %p\n", __FUNCTION__, buf);
1166 if (0 != buf->vb.baddr && buf->vb.bsize < size)
1167 return -EINVAL;
1168
1169 if (STATE_NEEDS_INIT == buf->vb.state) {
1170 buf->vb.width = port->ts_packet_size;
1171 buf->vb.height = port->ts_packet_count;
1172 buf->vb.size = size;
1173 buf->vb.field = field /*V4L2_FIELD_TOP*/;
1174
1175 if (0 != (rc = videobuf_iolock(q, &buf->vb, NULL)))
1176 goto fail;
1177 cx23885_risc_databuffer(dev->pci, &buf->risc,
1178 videobuf_to_dma(&buf->vb)->sglist,
1179 buf->vb.width, buf->vb.height);
1180 }
1181 buf->vb.state = STATE_PREPARED;
1182 return 0;
1183
1184 fail:
1185 cx23885_free_buffer(q, buf);
1186 return rc;
1187}
1188
1189void cx23885_buf_queue(struct cx23885_tsport *port, struct cx23885_buffer *buf)
1190{
1191 struct cx23885_buffer *prev;
1192 struct cx23885_dev *dev = port->dev;
1193 struct cx23885_dmaqueue *cx88q = &port->mpegq;
1194
1195 /* add jump to stopper */
1196 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
1197 buf->risc.jmp[1] = cpu_to_le32(cx88q->stopper.dma);
1198 buf->risc.jmp[2] = cpu_to_le32(0); /* bits 63-32 */
1199
1200 if (list_empty(&cx88q->active)) {
1201 dprintk( 1, "queue is empty - first active\n" );
1202 list_add_tail(&buf->vb.queue, &cx88q->active);
1203 cx23885_start_dma(port, cx88q, buf);
1204 buf->vb.state = STATE_ACTIVE;
1205 buf->count = cx88q->count++;
1206 mod_timer(&cx88q->timeout, jiffies + BUFFER_TIMEOUT);
1207 dprintk(1, "[%p/%d] %s - first active\n",
1208 buf, buf->vb.i, __FUNCTION__);
1209 } else {
1210 dprintk( 1, "queue is not empty - append to active\n" );
1211 prev = list_entry(cx88q->active.prev, struct cx23885_buffer,
1212 vb.queue);
1213 list_add_tail(&buf->vb.queue, &cx88q->active);
1214 buf->vb.state = STATE_ACTIVE;
1215 buf->count = cx88q->count++;
1216 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
1217 prev->risc.jmp[2] = cpu_to_le32(0); /* 64 bit bits 63-32 */
1218 dprintk( 1, "[%p/%d] %s - append to active\n",
1219 buf, buf->vb.i, __FUNCTION__);
1220 }
1221}
1222
1223/* ----------------------------------------------------------- */
1224
1225static void do_cancel_buffers(struct cx23885_tsport *port, char *reason,
1226 int restart)
1227{
1228 struct cx23885_dev *dev = port->dev;
1229 struct cx23885_dmaqueue *q = &port->mpegq;
1230 struct cx23885_buffer *buf;
1231 unsigned long flags;
1232
1233 spin_lock_irqsave(&port->slock, flags);
1234 while (!list_empty(&q->active)) {
1235 buf = list_entry(q->active.next, struct cx23885_buffer,
1236 vb.queue);
1237 list_del(&buf->vb.queue);
1238 buf->vb.state = STATE_ERROR;
1239 wake_up(&buf->vb.done);
1240 dprintk(1, "[%p/%d] %s - dma=0x%08lx\n",
1241 buf, buf->vb.i, reason, (unsigned long)buf->risc.dma);
1242 }
1243 if (restart) {
1244 dprintk(1, "restarting queue\n" );
1245 cx23885_restart_queue(port, q);
1246 }
1247 spin_unlock_irqrestore(&port->slock, flags);
1248}
1249
1250void cx23885_cancel_buffers(struct cx23885_tsport *port)
1251{
1252 struct cx23885_dev *dev = port->dev;
1253 struct cx23885_dmaqueue *q = &port->mpegq;
1254
1255 dprintk(1, "%s()\n", __FUNCTION__);
1256 del_timer_sync(&q->timeout);
1257 cx23885_stop_dma(port);
1258 do_cancel_buffers(port, "cancel", 0);
1259}
1260
1261static void cx23885_timeout(unsigned long data)
1262{
1263 struct cx23885_tsport *port = (struct cx23885_tsport *)data;
1264 struct cx23885_dev *dev = port->dev;
1265
1266 dprintk(1, "%s()\n",__FUNCTION__);
1267
1268 if (debug > 5)
1269 cx23885_sram_channel_dump(dev, &dev->sram_channels[ port->sram_chno ]);
1270
1271 cx23885_stop_dma(port);
1272 do_cancel_buffers(port, "timeout", 1);
1273}
1274
1275static int cx23885_irq_ts(struct cx23885_tsport *port, u32 status)
1276{
1277 struct cx23885_dev *dev = port->dev;
1278 int handled = 0;
1279 u32 count;
1280
1281 if ( (status & VID_BC_MSK_OPC_ERR) ||
1282 (status & VID_BC_MSK_BAD_PKT) ||
1283 (status & VID_BC_MSK_SYNC) ||
1284 (status & VID_BC_MSK_OF))
1285 {
1286 if (status & VID_BC_MSK_OPC_ERR)
1287 dprintk(7, " (VID_BC_MSK_OPC_ERR 0x%08x)\n", VID_BC_MSK_OPC_ERR);
1288 if (status & VID_BC_MSK_BAD_PKT)
1289 dprintk(7, " (VID_BC_MSK_BAD_PKT 0x%08x)\n", VID_BC_MSK_BAD_PKT);
1290 if (status & VID_BC_MSK_SYNC)
1291 dprintk(7, " (VID_BC_MSK_SYNC 0x%08x)\n", VID_BC_MSK_SYNC);
1292 if (status & VID_BC_MSK_OF)
1293 dprintk(7, " (VID_BC_MSK_OF 0x%08x)\n", VID_BC_MSK_OF);
1294
1295 printk(KERN_ERR "%s: mpeg risc op code error\n", dev->name);
1296
1297 cx_clear(port->reg_dma_ctl, port->dma_ctl_val);
1298 cx23885_sram_channel_dump(dev, &dev->sram_channels[ port->sram_chno ]);
1299
1300 } else if (status & VID_BC_MSK_RISCI1) {
1301
1302 dprintk(7, " (RISCI1 0x%08x)\n", VID_BC_MSK_RISCI1);
1303
1304 spin_lock(&port->slock);
1305 count = cx_read(port->reg_gpcnt);
1306 cx23885_wakeup(port, &port->mpegq, count);
1307 spin_unlock(&port->slock);
1308
1309 } else if (status & VID_BC_MSK_RISCI2) {
1310
1311 dprintk(7, " (RISCI2 0x%08x)\n", VID_BC_MSK_RISCI2);
1312
1313 spin_lock(&port->slock);
1314 cx23885_restart_queue(port, &port->mpegq);
1315 spin_unlock(&port->slock);
1316
1317 }
1318 if (status) {
1319 cx_write(port->reg_ts_int_stat, status);
1320 handled = 1;
1321 }
1322
1323 return handled;
1324}
1325
1326static irqreturn_t cx23885_irq(int irq, void *dev_id)
1327{
1328 struct cx23885_dev *dev = dev_id;
1329 struct cx23885_tsport *ts1 = &dev->ts1;
1330 struct cx23885_tsport *ts2 = &dev->ts2;
1331 u32 pci_status, pci_mask;
1332 u32 ts1_status, ts1_mask;
1333 u32 ts2_status, ts2_mask;
1334 int ts1_count = 0, ts2_count = 0, handled = 0;
1335
1336 pci_status = cx_read(PCI_INT_STAT);
1337 pci_mask = cx_read(PCI_INT_MSK);
1338 ts1_status = cx_read(VID_B_INT_STAT);
1339 ts1_mask = cx_read(VID_B_INT_MSK);
1340 ts2_status = cx_read(VID_C_INT_STAT);
1341 ts2_mask = cx_read(VID_C_INT_MSK);
1342
1343 if ( (pci_status == 0) && (ts2_status == 0) && (ts1_status == 0) )
1344 goto out;
1345
1346 ts1_count = cx_read(ts1->reg_gpcnt);
1347 ts2_count = cx_read(ts2->reg_gpcnt);
1348 dprintk(7, "pci_status: 0x%08x pci_mask: 0x%08x\n", pci_status, pci_mask );
1349 dprintk(7, "ts1_status: 0x%08x ts1_mask: 0x%08x count: 0x%x\n", ts1_status, ts1_mask, ts1_count );
1350 dprintk(7, "ts2_status: 0x%08x ts2_mask: 0x%08x count: 0x%x\n", ts2_status, ts2_mask, ts2_count );
1351
1352 if ( (pci_status & PCI_MSK_RISC_RD) ||
1353 (pci_status & PCI_MSK_RISC_WR) ||
1354 (pci_status & PCI_MSK_AL_RD) ||
1355 (pci_status & PCI_MSK_AL_WR) ||
1356 (pci_status & PCI_MSK_APB_DMA) ||
1357 (pci_status & PCI_MSK_VID_C) ||
1358 (pci_status & PCI_MSK_VID_B) ||
1359 (pci_status & PCI_MSK_VID_A) ||
1360 (pci_status & PCI_MSK_AUD_INT) ||
1361 (pci_status & PCI_MSK_AUD_EXT) )
1362 {
1363
1364 if (pci_status & PCI_MSK_RISC_RD)
1365 dprintk(7, " (PCI_MSK_RISC_RD 0x%08x)\n", PCI_MSK_RISC_RD);
1366 if (pci_status & PCI_MSK_RISC_WR)
1367 dprintk(7, " (PCI_MSK_RISC_WR 0x%08x)\n", PCI_MSK_RISC_WR);
1368 if (pci_status & PCI_MSK_AL_RD)
1369 dprintk(7, " (PCI_MSK_AL_RD 0x%08x)\n", PCI_MSK_AL_RD);
1370 if (pci_status & PCI_MSK_AL_WR)
1371 dprintk(7, " (PCI_MSK_AL_WR 0x%08x)\n", PCI_MSK_AL_WR);
1372 if (pci_status & PCI_MSK_APB_DMA)
1373 dprintk(7, " (PCI_MSK_APB_DMA 0x%08x)\n", PCI_MSK_APB_DMA);
1374 if (pci_status & PCI_MSK_VID_C)
1375 dprintk(7, " (PCI_MSK_VID_C 0x%08x)\n", PCI_MSK_VID_C);
1376 if (pci_status & PCI_MSK_VID_B)
1377 dprintk(7, " (PCI_MSK_VID_B 0x%08x)\n", PCI_MSK_VID_B);
1378 if (pci_status & PCI_MSK_VID_A)
1379 dprintk(7, " (PCI_MSK_VID_A 0x%08x)\n", PCI_MSK_VID_A);
1380 if (pci_status & PCI_MSK_AUD_INT)
1381 dprintk(7, " (PCI_MSK_AUD_INT 0x%08x)\n", PCI_MSK_AUD_INT);
1382 if (pci_status & PCI_MSK_AUD_EXT)
1383 dprintk(7, " (PCI_MSK_AUD_EXT 0x%08x)\n", PCI_MSK_AUD_EXT);
1384
1385 }
1386
1387 if (ts1_status)
1388 handled += cx23885_irq_ts(ts1, ts1_status);
1389
1390 if (ts2_status)
1391 handled += cx23885_irq_ts(ts2, ts2_status);
1392
1393 if (handled)
1394 cx_write(PCI_INT_STAT, pci_status);
1395out:
1396 return IRQ_RETVAL(handled);
1397}
1398
1399static int __devinit cx23885_initdev(struct pci_dev *pci_dev,
1400 const struct pci_device_id *pci_id)
1401{
1402 struct cx23885_dev *dev;
1403 int err;
1404
1405 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
1406 if (NULL == dev)
1407 return -ENOMEM;
1408
1409 /* pci init */
1410 dev->pci = pci_dev;
1411 if (pci_enable_device(pci_dev)) {
1412 err = -EIO;
1413 goto fail_free;
1414 }
1415
1416 if (cx23885_dev_setup(dev) < 0) {
1417 err = -EINVAL;
1418 goto fail_free;
1419 }
1420
1421 /* print pci info */
1422 pci_read_config_byte(pci_dev, PCI_CLASS_REVISION, &dev->pci_rev);
1423 pci_read_config_byte(pci_dev, PCI_LATENCY_TIMER, &dev->pci_lat);
1424 printk(KERN_INFO "%s/0: found at %s, rev: %d, irq: %d, "
1425 "latency: %d, mmio: 0x%llx\n", dev->name,
1426 pci_name(pci_dev), dev->pci_rev, pci_dev->irq,
1427 dev->pci_lat, (unsigned long long)pci_resource_start(pci_dev,0));
1428
1429 pci_set_master(pci_dev);
1430 if (!pci_dma_supported(pci_dev, 0xffffffff)) {
1431 printk("%s/0: Oops: no 32bit PCI DMA ???\n", dev->name);
1432 err = -EIO;
1433 goto fail_irq;
1434 }
1435
1436 err = request_irq(pci_dev->irq, cx23885_irq,
1437 IRQF_SHARED | IRQF_DISABLED, dev->name, dev);
1438 if (err < 0) {
1439 printk(KERN_ERR "%s: can't get IRQ %d\n",
1440 dev->name, pci_dev->irq);
1441 goto fail_irq;
1442 }
1443
1444 pci_set_drvdata(pci_dev, dev);
1445 return 0;
1446
1447fail_irq:
1448 cx23885_dev_unregister(dev);
1449fail_free:
1450 kfree(dev);
1451 return err;
1452}
1453
1454static void __devexit cx23885_finidev(struct pci_dev *pci_dev)
1455{
1456 struct cx23885_dev *dev = pci_get_drvdata(pci_dev);
1457
1458 cx23885_shutdown(dev);
1459
1460 pci_disable_device(pci_dev);
1461
1462 /* unregister stuff */
1463 free_irq(pci_dev->irq, dev);
1464 pci_set_drvdata(pci_dev, NULL);
1465
1466 mutex_lock(&devlist);
1467 list_del(&dev->devlist);
1468 mutex_unlock(&devlist);
1469
1470 cx23885_dev_unregister(dev);
1471 kfree(dev);
1472}
1473
1474static struct pci_device_id cx23885_pci_tbl[] = {
1475 {
1476 /* CX23885 */
1477 .vendor = 0x14f1,
1478 .device = 0x8852,
1479 .subvendor = PCI_ANY_ID,
1480 .subdevice = PCI_ANY_ID,
1481 },{
1482 /* CX23887 Rev 2 */
1483 .vendor = 0x14f1,
1484 .device = 0x8880,
1485 .subvendor = PCI_ANY_ID,
1486 .subdevice = PCI_ANY_ID,
1487 },{
1488 /* --- end of list --- */
1489 }
1490};
1491MODULE_DEVICE_TABLE(pci, cx23885_pci_tbl);
1492
1493static struct pci_driver cx23885_pci_driver = {
1494 .name = "cx23885",
1495 .id_table = cx23885_pci_tbl,
1496 .probe = cx23885_initdev,
1497 .remove = __devexit_p(cx23885_finidev),
1498 /* TODO */
1499 .suspend = NULL,
1500 .resume = NULL,
1501};
1502
1503static int cx23885_init(void)
1504{
1505 printk(KERN_INFO "cx23885 driver version %d.%d.%d loaded\n",
1506 (CX23885_VERSION_CODE >> 16) & 0xff,
1507 (CX23885_VERSION_CODE >> 8) & 0xff,
1508 CX23885_VERSION_CODE & 0xff);
1509#ifdef SNAPSHOT
1510 printk(KERN_INFO "cx23885: snapshot date %04d-%02d-%02d\n",
1511 SNAPSHOT/10000, (SNAPSHOT/100)%100, SNAPSHOT%100);
1512#endif
1513 return pci_register_driver(&cx23885_pci_driver);
1514}
1515
1516static void cx23885_fini(void)
1517{
1518 pci_unregister_driver(&cx23885_pci_driver);
1519}
1520
1521module_init(cx23885_init);
1522module_exit(cx23885_fini);
1523
1524/* ----------------------------------------------------------- */
1525/*
1526 * Local variables:
1527 * c-basic-offset: 8
1528 * End:
1529 * 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
1530 */
diff --git a/drivers/media/video/cx23885/cx23885-dvb.c b/drivers/media/video/cx23885/cx23885-dvb.c
new file mode 100644
index 000000000000..eda8c05d0931
--- /dev/null
+++ b/drivers/media/video/cx23885/cx23885-dvb.c
@@ -0,0 +1,213 @@
1/*
2 * Driver for the Conexant CX23885 PCIe bridge
3 *
4 * Copyright (c) 2006 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/fs.h>
26#include <linux/kthread.h>
27#include <linux/file.h>
28#include <linux/suspend.h>
29
30#include "cx23885.h"
31#include <media/v4l2-common.h>
32
33#include "s5h1409.h"
34#include "mt2131.h"
35#include "lgdt330x.h"
36#include "dvb-pll.h"
37
38static unsigned int debug = 0;
39
40#define dprintk(level,fmt, arg...) if (debug >= level) \
41 printk(KERN_DEBUG "%s: " fmt, dev->name, ## arg)
42
43/* ------------------------------------------------------------------ */
44
45static int dvb_buf_setup(struct videobuf_queue *q,
46 unsigned int *count, unsigned int *size)
47{
48 struct cx23885_tsport *port = q->priv_data;
49
50 port->ts_packet_size = 188 * 4;
51 port->ts_packet_count = 32;
52
53 *size = port->ts_packet_size * port->ts_packet_count;
54 *count = 32;
55 return 0;
56}
57
58static int dvb_buf_prepare(struct videobuf_queue *q,
59 struct videobuf_buffer *vb, enum v4l2_field field)
60{
61 struct cx23885_tsport *port = q->priv_data;
62 return cx23885_buf_prepare(q, port, (struct cx23885_buffer*)vb, field);
63}
64
65static void dvb_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
66{
67 struct cx23885_tsport *port = q->priv_data;
68 cx23885_buf_queue(port, (struct cx23885_buffer*)vb);
69}
70
71static void dvb_buf_release(struct videobuf_queue *q,
72 struct videobuf_buffer *vb)
73{
74 cx23885_free_buffer(q, (struct cx23885_buffer*)vb);
75}
76
77static struct videobuf_queue_ops dvb_qops = {
78 .buf_setup = dvb_buf_setup,
79 .buf_prepare = dvb_buf_prepare,
80 .buf_queue = dvb_buf_queue,
81 .buf_release = dvb_buf_release,
82};
83
84static struct s5h1409_config hauppauge_generic_config = {
85 .demod_address = 0x32 >> 1,
86 .output_mode = S5H1409_SERIAL_OUTPUT,
87 .gpio = S5H1409_GPIO_ON,
88 .if_freq = 44000,
89 .inversion = S5H1409_INVERSION_OFF,
90 .status_mode = S5H1409_DEMODLOCKING
91};
92
93static struct s5h1409_config hauppauge_hvr1800lp_config = {
94 .demod_address = 0x32 >> 1,
95 .output_mode = S5H1409_SERIAL_OUTPUT,
96 .gpio = S5H1409_GPIO_OFF,
97 .if_freq = 44000,
98 .inversion = S5H1409_INVERSION_OFF,
99 .status_mode = S5H1409_DEMODLOCKING
100};
101
102static struct mt2131_config hauppauge_generic_tunerconfig = {
103 0x61
104};
105
106static struct lgdt330x_config fusionhdtv_5_express = {
107 .demod_address = 0x0e,
108 .demod_chip = LGDT3303,
109 .serial_mpeg = 0x40,
110};
111
112static int dvb_register(struct cx23885_tsport *port)
113{
114 struct cx23885_dev *dev = port->dev;
115 struct cx23885_i2c *i2c_bus = NULL;
116
117 /* init struct videobuf_dvb */
118 port->dvb.name = dev->name;
119
120 /* init frontend */
121 switch (dev->board) {
122 case CX23885_BOARD_HAUPPAUGE_HVR1250:
123 case CX23885_BOARD_HAUPPAUGE_HVR1800:
124 i2c_bus = &dev->i2c_bus[0];
125 port->dvb.frontend = dvb_attach(s5h1409_attach,
126 &hauppauge_generic_config,
127 &i2c_bus->i2c_adap);
128 if (port->dvb.frontend != NULL) {
129 dvb_attach(mt2131_attach, port->dvb.frontend,
130 &i2c_bus->i2c_adap,
131 &hauppauge_generic_tunerconfig, 0);
132 }
133 break;
134 case CX23885_BOARD_HAUPPAUGE_HVR1800lp:
135 i2c_bus = &dev->i2c_bus[0];
136 port->dvb.frontend = dvb_attach(s5h1409_attach,
137 &hauppauge_hvr1800lp_config,
138 &i2c_bus->i2c_adap);
139 if (port->dvb.frontend != NULL) {
140 dvb_attach(mt2131_attach, port->dvb.frontend,
141 &i2c_bus->i2c_adap,
142 &hauppauge_generic_tunerconfig, 0);
143 }
144 break;
145 case CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP:
146 i2c_bus = &dev->i2c_bus[0];
147 port->dvb.frontend = dvb_attach(lgdt330x_attach,
148 &fusionhdtv_5_express,
149 &i2c_bus->i2c_adap);
150 if (port->dvb.frontend != NULL) {
151 dvb_attach(dvb_pll_attach, port->dvb.frontend, 0x61,
152 &i2c_bus->i2c_adap, DVB_PLL_LG_TDVS_H06XF);
153 }
154 break;
155 default:
156 printk("%s: The frontend of your DVB/ATSC card isn't supported yet\n",
157 dev->name);
158 break;
159 }
160 if (NULL == port->dvb.frontend) {
161 printk("%s: frontend initialization failed\n", dev->name);
162 return -1;
163 }
164
165 /* Put the analog decoder in standby to keep it quiet */
166 cx23885_call_i2c_clients(i2c_bus, TUNER_SET_STANDBY, NULL);
167
168 /* register everything */
169 return videobuf_dvb_register(&port->dvb, THIS_MODULE, port,
170 &dev->pci->dev);
171}
172
173int cx23885_dvb_register(struct cx23885_tsport *port)
174{
175 struct cx23885_dev *dev = port->dev;
176 int err;
177
178 dprintk(1, "%s\n", __FUNCTION__);
179 dprintk(1, " ->being probed by Card=%d Name=%s, PCI %02x:%02x\n",
180 dev->board,
181 dev->name,
182 dev->pci_bus,
183 dev->pci_slot);
184
185 err = -ENODEV;
186
187 /* dvb stuff */
188 printk("%s: cx23885 based dvb card\n", dev->name);
189 videobuf_queue_pci_init(&port->dvb.dvbq, &dvb_qops, dev->pci, &port->slock,
190 V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_TOP,
191 sizeof(struct cx23885_buffer), port);
192 err = dvb_register(port);
193 if (err != 0)
194 printk("%s() dvb_register failed err = %d\n", __FUNCTION__, err);
195
196 return err;
197}
198
199int cx23885_dvb_unregister(struct cx23885_tsport *port)
200{
201 /* dvb */
202 if(port->dvb.frontend)
203 videobuf_dvb_unregister(&port->dvb);
204
205 return 0;
206}
207
208/*
209 * Local variables:
210 * c-basic-offset: 8
211 * End:
212 * 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
213*/
diff --git a/drivers/media/video/cx23885/cx23885-i2c.c b/drivers/media/video/cx23885/cx23885-i2c.c
new file mode 100644
index 000000000000..b517c8b5a566
--- /dev/null
+++ b/drivers/media/video/cx23885/cx23885-i2c.c
@@ -0,0 +1,382 @@
1/*
2 * Driver for the Conexant CX23885 PCIe bridge
3 *
4 * Copyright (c) 2006 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 <asm/io.h>
27
28#include "cx23885.h"
29
30#include <media/v4l2-common.h>
31
32static unsigned int i2c_debug = 0;
33module_param(i2c_debug, int, 0644);
34MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]");
35
36static unsigned int i2c_scan = 0;
37module_param(i2c_scan, int, 0444);
38MODULE_PARM_DESC(i2c_scan, "scan i2c bus at insmod time");
39
40#define dprintk(level,fmt, arg...) if (i2c_debug >= level) \
41 printk(KERN_DEBUG "%s: " fmt, dev->name , ## arg)
42
43#define I2C_WAIT_DELAY 32
44#define I2C_WAIT_RETRY 64
45
46#define I2C_EXTEND (1 << 3)
47#define I2C_NOSTOP (1 << 4)
48
49static inline int i2c_slave_did_ack(struct i2c_adapter *i2c_adap)
50{
51 struct cx23885_i2c *bus = i2c_adap->algo_data;
52 struct cx23885_dev *dev = bus->dev;
53 return cx_read(bus->reg_stat) & 0x01;
54}
55
56static inline int i2c_is_busy(struct i2c_adapter *i2c_adap)
57{
58 struct cx23885_i2c *bus = i2c_adap->algo_data;
59 struct cx23885_dev *dev = bus->dev;
60 return cx_read(bus->reg_stat) & 0x02 ? 1 : 0;
61}
62
63static int i2c_wait_done(struct i2c_adapter *i2c_adap)
64{
65 int count;
66
67 for (count = 0; count < I2C_WAIT_RETRY; count++) {
68 if (!i2c_is_busy(i2c_adap))
69 break;
70 udelay(I2C_WAIT_DELAY);
71 }
72
73 if (I2C_WAIT_RETRY == count)
74 return 0;
75
76 return 1;
77}
78
79static int i2c_sendbytes(struct i2c_adapter *i2c_adap,
80 const struct i2c_msg *msg, int last)
81{
82 struct cx23885_i2c *bus = i2c_adap->algo_data;
83 struct cx23885_dev *dev = bus->dev;
84 u32 wdata, addr, ctrl;
85 int retval, cnt;
86
87 dprintk(1, "%s()\n", __FUNCTION__);
88 /* Deal with i2c probe functions with zero payload */
89 if (msg->len == 0) {
90 cx_write(bus->reg_addr, msg->addr << 25);
91 cx_write(bus->reg_ctrl, bus->i2c_period | (1 << 2));
92 if (!i2c_wait_done(i2c_adap))
93 return -EIO;
94 if (!i2c_slave_did_ack(i2c_adap))
95 return -EIO;
96
97 dprintk(1, "%s() returns 0\n", __FUNCTION__);
98 return 0;
99 }
100
101
102 /* dev, reg + first byte */
103 addr = (msg->addr << 25) | msg->buf[0];
104 wdata = msg->buf[0];
105 ctrl = bus->i2c_period | (1 << 12) | (1 << 2);
106
107 if (msg->len > 1)
108 ctrl |= I2C_NOSTOP | I2C_EXTEND;
109
110 cx_write(bus->reg_addr, addr);
111 cx_write(bus->reg_wdata, wdata);
112 cx_write(bus->reg_ctrl, ctrl);
113
114 retval = i2c_wait_done(i2c_adap);
115 if (retval < 0)
116 goto err;
117 if (retval == 0)
118 goto eio;
119 if (i2c_debug) {
120 printk(" <W %02x %02x", msg->addr << 1, msg->buf[0]);
121 if (!(ctrl & I2C_NOSTOP))
122 printk(" >\n");
123 }
124
125 for (cnt = 1; cnt < msg->len; cnt++ ) {
126 /* following bytes */
127 wdata = msg->buf[cnt];
128 ctrl = bus->i2c_period | (1 << 12) | (1 << 2);
129
130 if (cnt < msg->len-1 || !last)
131 ctrl |= I2C_NOSTOP | I2C_EXTEND;
132
133 cx_write(bus->reg_addr, addr);
134 cx_write(bus->reg_wdata, wdata);
135 cx_write(bus->reg_ctrl, ctrl);
136
137 retval = i2c_wait_done(i2c_adap);
138 if (retval < 0)
139 goto err;
140 if (retval == 0)
141 goto eio;
142 if (i2c_debug) {
143 printk(" %02x", msg->buf[cnt]);
144 if (!(ctrl & I2C_NOSTOP))
145 printk(" >\n");
146 }
147 }
148 return msg->len;
149
150 eio:
151 retval = -EIO;
152 err:
153 printk(" ERR: %d\n", retval);
154 return retval;
155}
156
157static int i2c_readbytes(struct i2c_adapter *i2c_adap,
158 const struct i2c_msg *msg, int last)
159{
160 struct cx23885_i2c *bus = i2c_adap->algo_data;
161 struct cx23885_dev *dev = bus->dev;
162 u32 ctrl, cnt;
163 int retval;
164
165 dprintk(1, "%s()\n", __FUNCTION__);
166
167 /* Deal with i2c probe functions with zero payload */
168 if (msg->len == 0) {
169 cx_write(bus->reg_addr, msg->addr << 25);
170 cx_write(bus->reg_ctrl, bus->i2c_period | (1 << 2) | 1);
171 if (!i2c_wait_done(i2c_adap))
172 return -EIO;
173 if (!i2c_slave_did_ack(i2c_adap))
174 return -EIO;
175
176
177 dprintk(1, "%s() returns 0\n", __FUNCTION__);
178 return 0;
179 }
180
181 for(cnt = 0; cnt < msg->len; cnt++) {
182
183 ctrl = bus->i2c_period | (1 << 12) | (1 << 2) | 1;
184
185 if (cnt < msg->len-1 || !last)
186 ctrl |= I2C_NOSTOP | I2C_EXTEND;
187
188 cx_write(bus->reg_addr, msg->addr << 25);
189 cx_write(bus->reg_ctrl, ctrl);
190
191 retval = i2c_wait_done(i2c_adap);
192 if (retval < 0)
193 goto err;
194 if (retval == 0)
195 goto eio;
196 msg->buf[cnt] = cx_read(bus->reg_rdata) & 0xff;
197 if (i2c_debug) {
198 if (!(ctrl & I2C_NOSTOP))
199 printk(" <R %02x", (msg->addr << 1) +1);
200 printk(" =%02x", msg->buf[cnt]);
201 if (!(ctrl & I2C_NOSTOP))
202 printk(" >\n");
203 }
204 }
205 return msg->len;
206
207 eio:
208 retval = -EIO;
209 err:
210 printk(" ERR: %d\n", retval);
211 return retval;
212}
213
214static int i2c_xfer(struct i2c_adapter *i2c_adap,
215 struct i2c_msg *msgs, int num)
216{
217 struct cx23885_i2c *bus = i2c_adap->algo_data;
218 struct cx23885_dev *dev = bus->dev;
219 int i, retval = 0;
220
221 dprintk(1, "%s(num = %d)\n", __FUNCTION__, num);
222
223 for (i = 0 ; i < num; i++) {
224 dprintk(1, "%s(num = %d) addr = 0x%02x len = 0x%x\n",
225 __FUNCTION__, num, msgs[i].addr, msgs[i].len);
226 if (msgs[i].flags & I2C_M_RD) {
227 /* read */
228 retval = i2c_readbytes(i2c_adap, &msgs[i], i+1 == num);
229 if (retval < 0)
230 goto err;
231 } else {
232 /* write */
233 retval = i2c_sendbytes(i2c_adap, &msgs[i], i+1 == num);
234 if (retval < 0)
235 goto err;
236 }
237 }
238 return num;
239
240 err:
241 return retval;
242}
243
244static int attach_inform(struct i2c_client *client)
245{
246 struct cx23885_dev *dev = i2c_get_adapdata(client->adapter);
247
248 dprintk(1, "%s i2c attach [addr=0x%x,client=%s]\n",
249 client->driver->driver.name, client->addr, client->name);
250
251 if (!client->driver->command)
252 return 0;
253
254 return 0;
255}
256
257static int detach_inform(struct i2c_client *client)
258{
259 struct cx23885_dev *dev = i2c_get_adapdata(client->adapter);
260
261 dprintk(1, "i2c detach [client=%s]\n", client->name);
262
263 return 0;
264}
265
266void cx23885_call_i2c_clients(struct cx23885_i2c *bus,
267 unsigned int cmd, void *arg)
268{
269 if (bus->i2c_rc != 0)
270 return;
271
272 i2c_clients_command(&bus->i2c_adap, cmd, arg);
273}
274
275static int cx23885_algo_control(struct i2c_adapter *adap,
276 unsigned int cmd, unsigned long arg)
277{
278 return 0;
279}
280
281static u32 cx23885_functionality(struct i2c_adapter *adap)
282{
283 return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_I2C;
284}
285
286static struct i2c_algorithm cx23885_i2c_algo_template = {
287 .master_xfer = i2c_xfer,
288 .algo_control = cx23885_algo_control,
289 .functionality = cx23885_functionality,
290};
291
292/* ----------------------------------------------------------------------- */
293
294static struct i2c_adapter cx23885_i2c_adap_template = {
295 .name = "cx23885",
296 .owner = THIS_MODULE,
297 .id = I2C_HW_B_CX23885,
298 .algo = &cx23885_i2c_algo_template,
299 .client_register = attach_inform,
300 .client_unregister = detach_inform,
301};
302
303static struct i2c_client cx23885_i2c_client_template = {
304 .name = "cx23885 internal",
305};
306
307static char *i2c_devs[128] = {
308 [ 0x1c >> 1 ] = "lgdt3303",
309 [ 0x86 >> 1 ] = "tda9887",
310 [ 0x32 >> 1 ] = "cx24227",
311 [ 0x88 >> 1 ] = "cx25837",
312 [ 0x84 >> 1 ] = "tda8295",
313 [ 0xa0 >> 1 ] = "eeprom",
314 [ 0xc0 >> 1 ] = "tuner/mt2131/tda8275",
315 [ 0xc2 >> 1 ] = "tuner/mt2131/tda8275",
316};
317
318static void do_i2c_scan(char *name, struct i2c_client *c)
319{
320 unsigned char buf;
321 int i, rc;
322
323 for (i = 0; i < 128; i++) {
324 c->addr = i;
325 rc = i2c_master_recv(c, &buf, 0);
326 if (rc < 0)
327 continue;
328 printk("%s: i2c scan: found device @ 0x%x [%s]\n",
329 name, i << 1, i2c_devs[i] ? i2c_devs[i] : "???");
330 }
331}
332
333/* init + register i2c algo-bit adapter */
334int cx23885_i2c_register(struct cx23885_i2c *bus)
335{
336 struct cx23885_dev *dev = bus->dev;
337
338 dprintk(1, "%s(bus = %d)\n", __FUNCTION__, bus->nr);
339
340 memcpy(&bus->i2c_adap, &cx23885_i2c_adap_template,
341 sizeof(bus->i2c_adap));
342 memcpy(&bus->i2c_algo, &cx23885_i2c_algo_template,
343 sizeof(bus->i2c_algo));
344 memcpy(&bus->i2c_client, &cx23885_i2c_client_template,
345 sizeof(bus->i2c_client));
346
347 bus->i2c_adap.dev.parent = &dev->pci->dev;
348
349 strlcpy(bus->i2c_adap.name, bus->dev->name,
350 sizeof(bus->i2c_adap.name));
351
352 bus->i2c_algo.data = bus;
353 bus->i2c_adap.algo_data = bus;
354 i2c_add_adapter(&bus->i2c_adap);
355
356 bus->i2c_client.adapter = &bus->i2c_adap;
357
358 if (0 == bus->i2c_rc) {
359 printk("%s: i2c bus %d registered\n", dev->name, bus->nr);
360 if (i2c_scan)
361 do_i2c_scan(dev->name, &bus->i2c_client);
362 } else
363 printk("%s: i2c bus %d register FAILED\n", dev->name, bus->nr);
364
365 return bus->i2c_rc;
366}
367
368int cx23885_i2c_unregister(struct cx23885_i2c *bus)
369{
370 i2c_del_adapter(&bus->i2c_adap);
371 return 0;
372}
373
374/* ----------------------------------------------------------------------- */
375
376EXPORT_SYMBOL(cx23885_call_i2c_clients);
377
378/*
379 * Local variables:
380 * c-basic-offset: 8
381 * End:
382 */
diff --git a/drivers/media/video/cx23885/cx23885-reg.h b/drivers/media/video/cx23885/cx23885-reg.h
new file mode 100644
index 000000000000..162169f9091b
--- /dev/null
+++ b/drivers/media/video/cx23885/cx23885-reg.h
@@ -0,0 +1,431 @@
1/*
2 * Driver for the Conexant CX23885 PCIe bridge
3 *
4 * Copyright (c) 2006 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#ifndef _CX23885_REG_H_
23#define _CX23885_REG_H_
24
25/*
26Address Map
270x00000000 -> 0x00009000 TX SRAM (Fifos)
280x00010000 -> 0x00013c00 RX SRAM CMDS + CDT
29
30EACH CMDS struct is 0x80 bytes long
31
32DMAx_PTR1 = 0x03040 address of first cluster
33DMAx_PTR2 = 0x10600 address of the CDT
34DMAx_CNT1 = cluster size in (bytes >> 4) -1
35DMAx_CNT2 = total cdt size for all entries >> 3
36
37Cluster Descriptor entry = 4 DWORDS
38 DWORD 0 -> ptr to cluster
39 DWORD 1 Reserved
40 DWORD 2 Reserved
41 DWORD 3 Reserved
42
43Channel manager Data Structure entry = 20 DWORD
44 0 IntialProgramCounterLow
45 1 IntialProgramCounterHigh
46 2 ClusterDescriptorTableBase
47 3 ClusterDescriptorTableSize
48 4 InstructionQueueBase
49 5 InstructionQueueSize
50... Reserved
51 19 Reserved
52*/
53
54/* Risc Instructions */
55#define RISC_CNT_INC 0x00010000
56#define RISC_CNT_RESET 0x00030000
57#define RISC_IRQ1 0x01000000
58#define RISC_IRQ2 0x02000000
59#define RISC_EOL 0x04000000
60#define RISC_SOL 0x08000000
61#define RISC_WRITE 0x10000000
62#define RISC_SKIP 0x20000000
63#define RISC_JUMP 0x70000000
64#define RISC_SYNC 0x80000000
65#define RISC_RESYNC 0x80008000
66#define RISC_READ 0x90000000
67#define RISC_WRITERM 0xB0000000
68#define RISC_WRITECM 0xC0000000
69#define RISC_WRITECR 0xD0000000
70#define RISC_WRITEC 0x50000000
71#define RISC_READC 0xA0000000
72
73
74/* Audio and Video Core */
75#define HOST_REG1 0x00000000
76#define HOST_REG2 0x00000001
77#define HOST_REG3 0x00000002
78
79/* Chip Configuration Registers */
80#define CHIP_CTRL 0x00000100
81#define AFE_CTRL 0x00000104
82#define VID_PLL_INT_POST 0x00000108
83#define VID_PLL_FRAC 0x0000010C
84#define AUX_PLL_INT_POST 0x00000110
85#define AUX_PLL_FRAC 0x00000114
86#define SYS_PLL_INT_POST 0x00000118
87#define SYS_PLL_FRAC 0x0000011C
88#define PIN_CTRL 0x00000120
89#define AUD_IO_CTRL 0x00000124
90#define AUD_LOCK1 0x00000128
91#define AUD_LOCK2 0x0000012C
92#define POWER_CTRL 0x00000130
93#define AFE_DIAG_CTRL1 0x00000134
94#define AFE_DIAG_CTRL3 0x0000013C
95#define PLL_DIAG_CTRL 0x00000140
96#define AFE_CLK_OUT_CTRL 0x00000144
97#define DLL1_DIAG_CTRL 0x0000015C
98
99/* GPIO[23:19] Output Enable */
100#define GPIO2_OUT_EN_REG 0x00000160
101/* GPIO[23:19] Data Registers */
102#define GPIO2 0x00000164
103
104#define IFADC_CTRL 0x00000180
105
106/* Infrared Remote Registers */
107#define IR_CNTRL_REG 0x00000200
108#define IR_TXCLK_REG 0x00000204
109#define IR_RXCLK_REG 0x00000208
110#define IR_CDUTY_REG 0x0000020C
111#define IR_STAT_REG 0x00000210
112#define IR_IRQEN_REG 0x00000214
113#define IR_FILTR_REG 0x00000218
114#define IR_FIFO_REG 0x0000023C
115
116/* Video Decoder Registers */
117#define MODE_CTRL 0x00000400
118#define OUT_CTRL1 0x00000404
119#define OUT_CTRL2 0x00000408
120#define GEN_STAT 0x0000040C
121#define INT_STAT_MASK 0x00000410
122#define LUMA_CTRL 0x00000414
123#define HSCALE_CTRL 0x00000418
124#define VSCALE_CTRL 0x0000041C
125#define CHROMA_CTRL 0x00000420
126#define VBI_LINE_CTRL1 0x00000424
127#define VBI_LINE_CTRL2 0x00000428
128#define VBI_LINE_CTRL3 0x0000042C
129#define VBI_LINE_CTRL4 0x00000430
130#define VBI_LINE_CTRL5 0x00000434
131#define VBI_FC_CFG 0x00000438
132#define VBI_MISC_CFG1 0x0000043C
133#define VBI_MISC_CFG2 0x00000440
134#define VBI_PAY1 0x00000444
135#define VBI_PAY2 0x00000448
136#define VBI_CUST1_CFG1 0x0000044C
137#define VBI_CUST1_CFG2 0x00000450
138#define VBI_CUST1_CFG3 0x00000454
139#define VBI_CUST2_CFG1 0x00000458
140#define VBI_CUST2_CFG2 0x0000045C
141#define VBI_CUST2_CFG3 0x00000460
142#define VBI_CUST3_CFG1 0x00000464
143#define VBI_CUST3_CFG2 0x00000468
144#define VBI_CUST3_CFG3 0x0000046C
145#define HORIZ_TIM_CTRL 0x00000470
146#define VERT_TIM_CTRL 0x00000474
147#define SRC_COMB_CFG 0x00000478
148#define CHROMA_VBIOFF_CFG 0x0000047C
149#define FIELD_COUNT 0x00000480
150#define MISC_TIM_CTRL 0x00000484
151#define DFE_CTRL1 0x00000488
152#define DFE_CTRL2 0x0000048C
153#define DFE_CTRL3 0x00000490
154#define PLL_CTRL 0x00000494
155#define HTL_CTRL 0x00000498
156#define COMB_CTRL 0x0000049C
157#define CRUSH_CTRL 0x000004A0
158#define SOFT_RST_CTRL 0x000004A4
159#define CX885_VERSION 0x000004B4
160#define VBI_PASS_CTRL 0x000004BC
161
162/* Audio Decoder Registers */
163/* 8051 Configuration */
164#define DL_CTL 0x00000800
165#define STD_DET_STATUS 0x00000804
166#define STD_DET_CTL 0x00000808
167#define DW8051_INT 0x0000080C
168#define GENERAL_CTL 0x00000810
169#define AAGC_CTL 0x00000814
170#define DEMATRIX_CTL 0x000008CC
171#define PATH1_CTL1 0x000008D0
172#define PATH1_VOL_CTL 0x000008D4
173#define PATH1_EQ_CTL 0x000008D8
174#define PATH1_SC_CTL 0x000008DC
175#define PATH2_CTL1 0x000008E0
176#define PATH2_VOL_CTL 0x000008E4
177#define PATH2_EQ_CTL 0x000008E8
178#define PATH2_SC_CTL 0x000008EC
179
180/* Sample Rate Converter */
181#define SRC_CTL 0x000008F0
182#define SRC_LF_COEF 0x000008F4
183#define SRC1_CTL 0x000008F8
184#define SRC2_CTL 0x000008FC
185#define SRC3_CTL 0x00000900
186#define SRC4_CTL 0x00000904
187#define SRC5_CTL 0x00000908
188#define SRC6_CTL 0x0000090C
189#define BAND_OUT_SEL 0x00000910
190#define I2S_N_CTL 0x00000914
191#define I2S_OUT_CTL 0x00000918
192#define AUTOCONFIG_REG 0x000009C4
193
194/* Audio ADC Registers */
195#define DSM_CTRL1 0x00000000
196#define DSM_CTRL2 0x00000001
197#define CHP_EN_CTRL 0x00000002
198#define CHP_CLK_CTRL1 0x00000004
199#define CHP_CLK_CTRL2 0x00000005
200#define BG_REF_CTRL 0x00000006
201#define SD2_SW_CTRL1 0x00000008
202#define SD2_SW_CTRL2 0x00000009
203#define SD2_BIAS_CTRL 0x0000000A
204#define AMP_BIAS_CTRL 0x0000000C
205#define CH_PWR_CTRL1 0x0000000E
206#define CH_PWR_CTRL2 0x0000000F
207#define DSM_STATUS1 0x00000010
208#define DSM_STATUS2 0x00000011
209#define DIG_CTL1 0x00000012
210#define DIG_CTL2 0x00000013
211#define I2S_TX_CFG 0x0000001A
212
213#define DEV_CNTRL2 0x00040000
214
215#define PCI_MSK_APB_DMA (1 << 12)
216#define PCI_MSK_AL_WR (1 << 11)
217#define PCI_MSK_AL_RD (1 << 10)
218#define PCI_MSK_RISC_WR (1 << 9)
219#define PCI_MSK_RISC_RD (1 << 8)
220#define PCI_MSK_AUD_EXT (1 << 4)
221#define PCI_MSK_AUD_INT (1 << 3)
222#define PCI_MSK_VID_C (1 << 2)
223#define PCI_MSK_VID_B (1 << 1)
224#define PCI_MSK_VID_A 1
225#define PCI_INT_MSK 0x00040010
226
227#define PCI_INT_STAT 0x00040014
228#define PCI_INT_MSTAT 0x00040018
229
230#define VID_A_INT_MSK 0x00040020
231#define VID_A_INT_STAT 0x00040024
232#define VID_A_INT_MSTAT 0x00040028
233#define VID_A_INT_SSTAT 0x0004002C
234
235#define VID_B_INT_MSK 0x00040030
236#define VID_B_INT_STAT 0x00040034
237#define VID_B_INT_MSTAT 0x00040038
238#define VID_B_INT_SSTAT 0x0004003C
239
240#define VID_B_MSK_BAD_PKT (1 << 20)
241#define VID_B_MSK_OPC_ERR (1 << 16)
242#define VID_B_MSK_SYNC (1 << 12)
243#define VID_B_MSK_OF (1 << 8)
244#define VID_B_MSK_RISCI2 (1 << 4)
245#define VID_B_MSK_RISCI1 1
246
247#define VID_C_MSK_BAD_PKT (1 << 20)
248#define VID_C_MSK_OPC_ERR (1 << 16)
249#define VID_C_MSK_SYNC (1 << 12)
250#define VID_C_MSK_OF (1 << 8)
251#define VID_C_MSK_RISCI2 (1 << 4)
252#define VID_C_MSK_RISCI1 1
253
254/* A superset for testing purposes */
255#define VID_BC_MSK_BAD_PKT (1 << 20)
256#define VID_BC_MSK_OPC_ERR (1 << 16)
257#define VID_BC_MSK_SYNC (1 << 12)
258#define VID_BC_MSK_OF (1 << 8)
259#define VID_BC_MSK_RISCI2 (1 << 4)
260#define VID_BC_MSK_RISCI1 1
261
262#define VID_C_INT_MSK 0x00040040
263#define VID_C_INT_STAT 0x00040044
264#define VID_C_INT_MSTAT 0x00040048
265#define VID_C_INT_SSTAT 0x0004004C
266
267#define AUDIO_INT_INT_MSK 0x00040050
268#define AUDIO_INT_INT_STAT 0x00040054
269#define AUDIO_INT_INT_MSTAT 0x00040058
270#define AUDIO_INT_INT_SSTAT 0x0004005C
271
272#define AUDIO_EXT_INT_MSK 0x00040060
273#define AUDIO_EXT_INT_STAT 0x00040064
274#define AUDIO_EXT_INT_MSTAT 0x00040068
275#define AUDIO_EXT_INT_SSTAT 0x0004006C
276
277#define RDR_CFG0 0x00050000
278#define RDR_CFG1 0x00050004
279#define RDR_TLCTL0 0x00050318
280
281/* APB DMAC Current Buffer Pointer */
282#define DMA1_PTR1 0x00100000
283#define DMA2_PTR1 0x00100004
284#define DMA3_PTR1 0x00100008
285#define DMA4_PTR1 0x0010000C
286#define DMA5_PTR1 0x00100010
287#define DMA6_PTR1 0x00100014
288#define DMA7_PTR1 0x00100018
289#define DMA8_PTR1 0x0010001C
290
291/* APB DMAC Current Table Pointer */
292#define DMA1_PTR2 0x00100040
293#define DMA2_PTR2 0x00100044
294#define DMA3_PTR2 0x00100048
295#define DMA4_PTR2 0x0010004C
296#define DMA5_PTR2 0x00100050
297#define DMA6_PTR2 0x00100054
298#define DMA7_PTR2 0x00100058
299#define DMA8_PTR2 0x0010005C
300
301/* APB DMAC Buffer Limit */
302#define DMA1_CNT1 0x00100080
303#define DMA2_CNT1 0x00100084
304#define DMA3_CNT1 0x00100088
305#define DMA4_CNT1 0x0010008C
306#define DMA5_CNT1 0x00100090
307#define DMA6_CNT1 0x00100094
308#define DMA7_CNT1 0x00100098
309#define DMA8_CNT1 0x0010009C
310
311/* APB DMAC Table Size */
312#define DMA1_CNT2 0x001000C0
313#define DMA2_CNT2 0x001000C4
314#define DMA3_CNT2 0x001000C8
315#define DMA4_CNT2 0x001000CC
316#define DMA5_CNT2 0x001000D0
317#define DMA6_CNT2 0x001000D4
318#define DMA7_CNT2 0x001000D8
319#define DMA8_CNT2 0x001000DC
320
321/* Timer Counters */
322#define TM_CNT_LDW 0x00110000
323#define TM_CNT_UW 0x00110004
324#define TM_LMT_LDW 0x00110008
325#define TM_LMT_UW 0x0011000C
326
327/* GPIO */
328#define GP0_IO 0x00110010
329#define GPIO_ISM 0x00110014
330#define SOFT_RESET 0x0011001C
331
332/* GPIO (417 Microsoftcontroller) RW Data */
333#define MC417_RWD 0x00110020
334
335/* GPIO (417 Microsoftcontroller) Output Enable, Low Active */
336#define MC417_OEN 0x00110024
337#define MC417_CTL 0x00110028
338#define CLK_DELAY 0x00110048
339#define PAD_CTRL 0x0011004C
340
341/* Video A Interface */
342#define VID_A_GPCNT 0x00130020
343#define VBI_A_GPCNT 0x00130024
344#define VID_A_GPCNT_CTL 0x00130030
345#define VBI_A_GPCNT_CTL 0x00130034
346#define VID_A_DMA_CTL 0x00130040
347#define VID_A_VIP_CTRL 0x00130080
348#define VID_A_PIXEL_FRMT 0x00130084
349#define VID_A_VBI_CTRL 0x00130088
350
351/* Video B Interface */
352#define VID_B_DMA 0x00130100
353#define VBI_B_DMA 0x00130108
354#define VID_B_GPCNT 0x00130120
355#define VBI_B_GPCNT 0x00130124
356#define VID_B_GPCNT_CTL 0x00130134
357#define VBI_B_GPCNT_CTL 0x00130138
358#define VID_B_DMA_CTL 0x00130140
359#define VID_B_SRC_SEL 0x00130144
360#define VID_B_LNGTH 0x00130150
361#define VID_B_HW_SOP_CTL 0x00130154
362#define VID_B_GEN_CTL 0x00130158
363#define VID_B_BD_PKT_STATUS 0x0013015C
364#define VID_B_SOP_STATUS 0x00130160
365#define VID_B_FIFO_OVFL_STAT 0x00130164
366#define VID_B_VLD_MISC 0x00130168
367#define VID_B_TS_CLK_EN 0x0013016C
368#define VID_B_VIP_CTRL 0x00130180
369#define VID_B_PIXEL_FRMT 0x00130184
370
371/* Video C Interface */
372#define VID_C_GPCNT 0x00130220
373#define VID_C_GPCNT_CTL 0x00130230
374#define VBI_C_GPCNT_CTL 0x00130234
375#define VID_C_DMA_CTL 0x00130240
376#define VID_C_LNGTH 0x00130250
377#define VID_C_HW_SOP_CTL 0x00130254
378#define VID_C_GEN_CTL 0x00130258
379#define VID_C_BD_PKT_STATUS 0x0013025C
380#define VID_C_SOP_STATUS 0x00130260
381#define VID_C_FIFO_OVFL_STAT 0x00130264
382#define VID_C_VLD_MISC 0x00130268
383#define VID_C_TS_CLK_EN 0x0013026C
384
385/* Internal Audio Interface */
386#define AUD_INT_A_GPCNT 0x00140020
387#define AUD_INT_B_GPCNT 0x00140024
388#define AUD_INT_A_GPCNT_CTL 0x00140030
389#define AUD_INT_B_GPCNT_CTL 0x00140034
390#define AUD_INT_DMA_CTL 0x00140040
391#define AUD_INT_A_LNGTH 0x00140050
392#define AUD_INT_B_LNGTH 0x00140054
393#define AUD_INT_A_MODE 0x00140058
394#define AUD_INT_B_MODE 0x0014005C
395
396/* External Audio Interface */
397#define AUD_EXT_DMA 0x00140100
398#define AUD_EXT_GPCNT 0x00140120
399#define AUD_EXT_GPCNT_CTL 0x00140130
400#define AUD_EXT_DMA_CTL 0x00140140
401#define AUD_EXT_LNGTH 0x00140150
402#define AUD_EXT_A_MODE 0x00140158
403
404/* I2C Bus 1 */
405#define I2C1_ADDR 0x00180000
406#define I2C1_WDATA 0x00180004
407#define I2C1_CTRL 0x00180008
408#define I2C1_RDATA 0x0018000C
409#define I2C1_STAT 0x00180010
410
411/* I2C Bus 2 */
412#define I2C2_ADDR 0x00190000
413#define I2C2_WDATA 0x00190004
414#define I2C2_CTRL 0x00190008
415#define I2C2_RDATA 0x0019000C
416#define I2C2_STAT 0x00190010
417
418/* I2C Bus 3 */
419#define I2C3_ADDR 0x001A0000
420#define I2C3_WDATA 0x001A0004
421#define I2C3_CTRL 0x001A0008
422#define I2C3_RDATA 0x001A000C
423#define I2C3_STAT 0x001A0010
424
425/* UART */
426#define UART_CTL 0x001B0000
427#define UART_BRD 0x001B0004
428#define UART_ISR 0x001B000C
429#define UART_CNT 0x001B0010
430
431#endif /* _CX23885_REG_H_ */
diff --git a/drivers/media/video/cx23885/cx23885.h b/drivers/media/video/cx23885/cx23885.h
new file mode 100644
index 000000000000..dec4dc2fcbb4
--- /dev/null
+++ b/drivers/media/video/cx23885/cx23885.h
@@ -0,0 +1,301 @@
1/*
2 * Driver for the Conexant CX23885 PCIe bridge
3 *
4 * Copyright (c) 2006 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/pci.h>
23#include <linux/i2c.h>
24#include <linux/i2c-algo-bit.h>
25#include <linux/kdev_t.h>
26
27#include <media/v4l2-common.h>
28#include <media/tuner.h>
29#include <media/tveeprom.h>
30#include <media/videobuf-dma-sg.h>
31#include <media/videobuf-dvb.h>
32
33#include "btcx-risc.h"
34#include "cx23885-reg.h"
35
36#include <linux/version.h>
37#include <linux/mutex.h>
38
39#define CX23885_VERSION_CODE KERNEL_VERSION(0,0,1)
40
41#define UNSET (-1U)
42
43#define CX23885_MAXBOARDS 8
44
45/* Max number of inputs by card */
46#define MAX_CX23885_INPUT 8
47
48#define BUFFER_TIMEOUT (HZ) /* 0.5 seconds */
49
50#define CX23885_BOARD_NOAUTO UNSET
51#define CX23885_BOARD_UNKNOWN 0
52#define CX23885_BOARD_HAUPPAUGE_HVR1800lp 1
53#define CX23885_BOARD_HAUPPAUGE_HVR1800 2
54#define CX23885_BOARD_HAUPPAUGE_HVR1250 3
55#define CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP 4
56
57enum cx23885_itype {
58 CX23885_VMUX_COMPOSITE1 = 1,
59 CX23885_VMUX_COMPOSITE2,
60 CX23885_VMUX_COMPOSITE3,
61 CX23885_VMUX_COMPOSITE4,
62 CX23885_VMUX_SVIDEO,
63 CX23885_VMUX_TELEVISION,
64 CX23885_VMUX_CABLE,
65 CX23885_VMUX_DVB,
66 CX23885_VMUX_DEBUG,
67 CX23885_RADIO,
68};
69
70enum cx23885_src_sel_type {
71 CX23885_SRC_SEL_EXT_656_VIDEO = 0,
72 CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO
73};
74
75/* buffer for one video frame */
76struct cx23885_buffer {
77 /* common v4l buffer stuff -- must be first */
78 struct videobuf_buffer vb;
79
80 /* cx23885 specific */
81 unsigned int bpl;
82 struct btcx_riscmem risc;
83 struct cx23885_fmt *fmt;
84 u32 count;
85};
86
87struct cx23885_input {
88 enum cx23885_itype type;
89 unsigned int vmux;
90 u32 gpio0, gpio1, gpio2, gpio3;
91};
92
93typedef enum {
94 CX23885_MPEG_UNDEFINED = 0,
95 CX23885_MPEG_DVB
96} port_t;
97
98struct cx23885_board {
99 char *name;
100 port_t portb, portc;
101 struct cx23885_input input[MAX_CX23885_INPUT];
102};
103
104struct cx23885_subid {
105 u16 subvendor;
106 u16 subdevice;
107 u32 card;
108};
109
110struct cx23885_i2c {
111 struct cx23885_dev *dev;
112
113 int nr;
114
115 /* i2c i/o */
116 struct i2c_adapter i2c_adap;
117 struct i2c_algo_bit_data i2c_algo;
118 struct i2c_client i2c_client;
119 u32 i2c_rc;
120
121 /* 885 registers used for raw addess */
122 u32 i2c_period;
123 u32 reg_ctrl;
124 u32 reg_stat;
125 u32 reg_addr;
126 u32 reg_rdata;
127 u32 reg_wdata;
128};
129
130struct cx23885_dmaqueue {
131 struct list_head active;
132 struct list_head queued;
133 struct timer_list timeout;
134 struct btcx_riscmem stopper;
135 u32 count;
136};
137
138struct cx23885_tsport {
139 struct cx23885_dev *dev;
140
141 int nr;
142 int sram_chno;
143
144 struct videobuf_dvb dvb;
145
146 /* dma queues */
147 struct cx23885_dmaqueue mpegq;
148 u32 ts_packet_size;
149 u32 ts_packet_count;
150
151 int width;
152 int height;
153
154 spinlock_t slock;
155
156 /* registers */
157 u32 reg_gpcnt;
158 u32 reg_gpcnt_ctl;
159 u32 reg_dma_ctl;
160 u32 reg_lngth;
161 u32 reg_hw_sop_ctrl;
162 u32 reg_gen_ctrl;
163 u32 reg_bd_pkt_status;
164 u32 reg_sop_status;
165 u32 reg_fifo_ovfl_stat;
166 u32 reg_vld_misc;
167 u32 reg_ts_clk_en;
168 u32 reg_ts_int_msk;
169 u32 reg_ts_int_stat;
170 u32 reg_src_sel;
171
172 /* Default register vals */
173 int pci_irqmask;
174 u32 dma_ctl_val;
175 u32 ts_int_msk_val;
176 u32 gen_ctrl_val;
177 u32 ts_clk_en_val;
178 u32 src_sel_val;
179};
180
181struct cx23885_dev {
182 struct list_head devlist;
183 atomic_t refcount;
184
185 /* pci stuff */
186 struct pci_dev *pci;
187 unsigned char pci_rev, pci_lat;
188 int pci_bus, pci_slot;
189 u32 __iomem *lmmio;
190 u8 __iomem *bmmio;
191 int pci_irqmask;
192
193 /* I2C adapters: Master 1 & 2 (External) & Master 3 (Internal only) */
194 struct cx23885_i2c i2c_bus[3];
195
196 int nr;
197 struct mutex lock;
198
199 /* board details */
200 unsigned int board;
201 char name[32];
202
203 struct cx23885_tsport ts1, ts2;
204
205 /* sram configuration */
206 struct sram_channel *sram_channels;
207
208 enum {
209 CX23885_BRIDGE_UNDEFINED = 0,
210 CX23885_BRIDGE_885 = 885,
211 CX23885_BRIDGE_887 = 887,
212 } bridge;
213};
214
215#define SRAM_CH01 0 /* Video A */
216#define SRAM_CH02 1 /* VBI A */
217#define SRAM_CH03 2 /* Video B */
218#define SRAM_CH04 3 /* Transport via B */
219#define SRAM_CH05 4 /* VBI B */
220#define SRAM_CH06 5 /* Video C */
221#define SRAM_CH07 6 /* Transport via C */
222#define SRAM_CH08 7 /* Audio Internal A */
223#define SRAM_CH09 8 /* Audio Internal B */
224#define SRAM_CH10 9 /* Audio External */
225#define SRAM_CH11 10 /* COMB_3D_N */
226#define SRAM_CH12 11 /* Comb 3D N1 */
227#define SRAM_CH13 12 /* Comb 3D N2 */
228#define SRAM_CH14 13 /* MOE Vid */
229#define SRAM_CH15 14 /* MOE RSLT */
230
231struct sram_channel {
232 char *name;
233 u32 cmds_start;
234 u32 ctrl_start;
235 u32 cdt;
236 u32 fifo_start;;
237 u32 fifo_size;
238 u32 ptr1_reg;
239 u32 ptr2_reg;
240 u32 cnt1_reg;
241 u32 cnt2_reg;
242 u32 jumponly;
243};
244
245/* ----------------------------------------------------------- */
246
247#define cx_read(reg) readl(dev->lmmio + ((reg)>>2))
248#define cx_write(reg,value) writel((value), dev->lmmio + ((reg)>>2))
249
250#define cx_andor(reg,mask,value) \
251 writel((readl(dev->lmmio+((reg)>>2)) & ~(mask)) |\
252 ((value) & (mask)), dev->lmmio+((reg)>>2))
253
254#define cx_set(reg,bit) cx_andor((reg),(bit),(bit))
255#define cx_clear(reg,bit) cx_andor((reg),(bit),0)
256
257extern int cx23885_sram_channel_setup(struct cx23885_dev *dev,
258 struct sram_channel *ch,
259 unsigned int bpl, u32 risc);
260
261/* ----------------------------------------------------------- */
262/* cx23885-cards.c */
263
264extern struct cx23885_board cx23885_boards[];
265extern const unsigned int cx23885_bcount;
266
267extern struct cx23885_subid cx23885_subids[];
268extern const unsigned int cx23885_idcount;
269
270extern void cx23885_card_list(struct cx23885_dev *dev);
271extern int cx23885_ir_init(struct cx23885_dev *dev);
272extern void cx23885_gpio_setup(struct cx23885_dev *dev);
273extern void cx23885_card_setup(struct cx23885_dev *dev);
274extern void cx23885_card_setup_pre_i2c(struct cx23885_dev *dev);
275
276extern int cx23885_dvb_register(struct cx23885_tsport *port);
277extern int cx23885_dvb_unregister(struct cx23885_tsport *port);
278
279extern int cx23885_buf_prepare(struct videobuf_queue *q,
280 struct cx23885_tsport *port,
281 struct cx23885_buffer *buf,
282 enum v4l2_field field);
283
284extern void cx23885_buf_queue(struct cx23885_tsport *port,
285 struct cx23885_buffer *buf);
286extern void cx23885_free_buffer(struct videobuf_queue *q,
287 struct cx23885_buffer *buf);
288
289/* ----------------------------------------------------------- */
290/* cx23885-i2c.c */
291extern int cx23885_i2c_register(struct cx23885_i2c *bus);
292extern int cx23885_i2c_unregister(struct cx23885_i2c *bus);
293extern void cx23885_call_i2c_clients(struct cx23885_i2c *bus, unsigned int cmd,
294 void *arg);
295
296/*
297 * Local variables:
298 * c-basic-offset: 8
299 * End:
300 * 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
301 */
diff --git a/drivers/media/video/cx25840/cx25840-audio.c b/drivers/media/video/cx25840/cx25840-audio.c
index f897c1ebd5f3..3d46a776df36 100644
--- a/drivers/media/video/cx25840/cx25840-audio.c
+++ b/drivers/media/video/cx25840/cx25840-audio.c
@@ -157,13 +157,12 @@ void cx25840_audio_set_path(struct i2c_client *client)
157{ 157{
158 struct cx25840_state *state = i2c_get_clientdata(client); 158 struct cx25840_state *state = i2c_get_clientdata(client);
159 159
160 /* assert soft reset */
161 cx25840_and_or(client, 0x810, ~0x1, 0x01);
162
160 /* stop microcontroller */ 163 /* stop microcontroller */
161 cx25840_and_or(client, 0x803, ~0x10, 0); 164 cx25840_and_or(client, 0x803, ~0x10, 0);
162 165
163 /* assert soft reset */
164 if (!state->is_cx25836)
165 cx25840_and_or(client, 0x810, ~0x1, 0x01);
166
167 /* Mute everything to prevent the PFFT! */ 166 /* Mute everything to prevent the PFFT! */
168 cx25840_write(client, 0x8d3, 0x1f); 167 cx25840_write(client, 0x8d3, 0x1f);
169 168
@@ -181,32 +180,46 @@ void cx25840_audio_set_path(struct i2c_client *client)
181 180
182 set_audclk_freq(client, state->audclk_freq); 181 set_audclk_freq(client, state->audclk_freq);
183 182
184 /* deassert soft reset */
185 if (!state->is_cx25836)
186 cx25840_and_or(client, 0x810, ~0x1, 0x00);
187
188 if (state->aud_input != CX25840_AUDIO_SERIAL) { 183 if (state->aud_input != CX25840_AUDIO_SERIAL) {
189 /* When the microcontroller detects the 184 /* When the microcontroller detects the
190 * audio format, it will unmute the lines */ 185 * audio format, it will unmute the lines */
191 cx25840_and_or(client, 0x803, ~0x10, 0x10); 186 cx25840_and_or(client, 0x803, ~0x10, 0x10);
192 } 187 }
188
189 /* deassert soft reset */
190 cx25840_and_or(client, 0x810, ~0x1, 0x00);
193} 191}
194 192
195static int get_volume(struct i2c_client *client) 193static int get_volume(struct i2c_client *client)
196{ 194{
195 struct cx25840_state *state = i2c_get_clientdata(client);
196 int vol;
197
198 if (state->unmute_volume >= 0)
199 return state->unmute_volume;
200
197 /* Volume runs +18dB to -96dB in 1/2dB steps 201 /* Volume runs +18dB to -96dB in 1/2dB steps
198 * change to fit the msp3400 -114dB to +12dB range */ 202 * change to fit the msp3400 -114dB to +12dB range */
199 203
200 /* check PATH1_VOLUME */ 204 /* check PATH1_VOLUME */
201 int vol = 228 - cx25840_read(client, 0x8d4); 205 vol = 228 - cx25840_read(client, 0x8d4);
202 vol = (vol / 2) + 23; 206 vol = (vol / 2) + 23;
203 return vol << 9; 207 return vol << 9;
204} 208}
205 209
206static void set_volume(struct i2c_client *client, int volume) 210static void set_volume(struct i2c_client *client, int volume)
207{ 211{
208 /* First convert the volume to msp3400 values (0-127) */ 212 struct cx25840_state *state = i2c_get_clientdata(client);
209 int vol = volume >> 9; 213 int vol;
214
215 if (state->unmute_volume >= 0) {
216 state->unmute_volume = volume;
217 return;
218 }
219
220 /* Convert the volume to msp3400 values (0-127) */
221 vol = volume >> 9;
222
210 /* now scale it up to cx25840 values 223 /* now scale it up to cx25840 values
211 * -114dB to -96dB maps to 0 224 * -114dB to -96dB maps to 0
212 * this should be 19, but in my testing that was 4dB too loud */ 225 * this should be 19, but in my testing that was 4dB too loud */
@@ -284,30 +297,26 @@ static void set_balance(struct i2c_client *client, int balance)
284 297
285static int get_mute(struct i2c_client *client) 298static int get_mute(struct i2c_client *client)
286{ 299{
287 /* check SRC1_MUTE_EN */ 300 struct cx25840_state *state = i2c_get_clientdata(client);
288 return cx25840_read(client, 0x8d3) & 0x2 ? 1 : 0; 301
302 return state->unmute_volume >= 0;
289} 303}
290 304
291static void set_mute(struct i2c_client *client, int mute) 305static void set_mute(struct i2c_client *client, int mute)
292{ 306{
293 struct cx25840_state *state = i2c_get_clientdata(client); 307 struct cx25840_state *state = i2c_get_clientdata(client);
294 308
295 if (state->aud_input != CX25840_AUDIO_SERIAL) { 309 if (mute && state->unmute_volume == -1) {
296 /* Must turn off microcontroller in order to mute sound. 310 int vol = get_volume(client);
297 * Not sure if this is the best method, but it does work. 311
298 * If the microcontroller is running, then it will undo any 312 set_volume(client, 0);
299 * changes to the mute register. */ 313 state->unmute_volume = vol;
300 if (mute) { 314 }
301 /* disable microcontroller */ 315 else if (!mute && state->unmute_volume != -1) {
302 cx25840_and_or(client, 0x803, ~0x10, 0x00); 316 int vol = state->unmute_volume;
303 cx25840_write(client, 0x8d3, 0x1f); 317
304 } else { 318 state->unmute_volume = -1;
305 /* enable microcontroller */ 319 set_volume(client, vol);
306 cx25840_and_or(client, 0x803, ~0x10, 0x10);
307 }
308 } else {
309 /* SRC1_MUTE_EN */
310 cx25840_and_or(client, 0x8d3, ~0x2, mute ? 0x02 : 0x00);
311 } 320 }
312} 321}
313 322
@@ -319,18 +328,18 @@ int cx25840_audio(struct i2c_client *client, unsigned int cmd, void *arg)
319 328
320 switch (cmd) { 329 switch (cmd) {
321 case VIDIOC_INT_AUDIO_CLOCK_FREQ: 330 case VIDIOC_INT_AUDIO_CLOCK_FREQ:
331 if (!state->is_cx25836)
332 cx25840_and_or(client, 0x810, ~0x1, 1);
322 if (state->aud_input != CX25840_AUDIO_SERIAL) { 333 if (state->aud_input != CX25840_AUDIO_SERIAL) {
323 cx25840_and_or(client, 0x803, ~0x10, 0); 334 cx25840_and_or(client, 0x803, ~0x10, 0);
324 cx25840_write(client, 0x8d3, 0x1f); 335 cx25840_write(client, 0x8d3, 0x1f);
325 } 336 }
326 if (!state->is_cx25836)
327 cx25840_and_or(client, 0x810, ~0x1, 1);
328 retval = set_audclk_freq(client, *(u32 *)arg); 337 retval = set_audclk_freq(client, *(u32 *)arg);
329 if (!state->is_cx25836)
330 cx25840_and_or(client, 0x810, ~0x1, 0);
331 if (state->aud_input != CX25840_AUDIO_SERIAL) { 338 if (state->aud_input != CX25840_AUDIO_SERIAL) {
332 cx25840_and_or(client, 0x803, ~0x10, 0x10); 339 cx25840_and_or(client, 0x803, ~0x10, 0x10);
333 } 340 }
341 if (!state->is_cx25836)
342 cx25840_and_or(client, 0x810, ~0x1, 0);
334 return retval; 343 return retval;
335 344
336 case VIDIOC_G_CTRL: 345 case VIDIOC_G_CTRL:
diff --git a/drivers/media/video/cx25840/cx25840-core.c b/drivers/media/video/cx25840/cx25840-core.c
index 67bda9f9a44b..15f191e170d2 100644
--- a/drivers/media/video/cx25840/cx25840-core.c
+++ b/drivers/media/video/cx25840/cx25840-core.c
@@ -34,6 +34,7 @@
34#include <linux/slab.h> 34#include <linux/slab.h>
35#include <linux/videodev2.h> 35#include <linux/videodev2.h>
36#include <linux/i2c.h> 36#include <linux/i2c.h>
37#include <linux/delay.h>
37#include <media/v4l2-common.h> 38#include <media/v4l2-common.h>
38#include <media/v4l2-chip-ident.h> 39#include <media/v4l2-chip-ident.h>
39#include <media/cx25840.h> 40#include <media/cx25840.h>
@@ -133,7 +134,9 @@ static void init_dll1(struct i2c_client *client)
133 cx25840_write(client, 0x159, 0x23); 134 cx25840_write(client, 0x159, 0x23);
134 cx25840_write(client, 0x15a, 0x87); 135 cx25840_write(client, 0x15a, 0x87);
135 cx25840_write(client, 0x15b, 0x06); 136 cx25840_write(client, 0x15b, 0x06);
137 udelay(10);
136 cx25840_write(client, 0x159, 0xe1); 138 cx25840_write(client, 0x159, 0xe1);
139 udelay(10);
137 cx25840_write(client, 0x15a, 0x86); 140 cx25840_write(client, 0x15a, 0x86);
138 cx25840_write(client, 0x159, 0xe0); 141 cx25840_write(client, 0x159, 0xe0);
139 cx25840_write(client, 0x159, 0xe1); 142 cx25840_write(client, 0x159, 0xe1);
@@ -147,6 +150,7 @@ static void init_dll2(struct i2c_client *client)
147 cx25840_write(client, 0x15d, 0xe3); 150 cx25840_write(client, 0x15d, 0xe3);
148 cx25840_write(client, 0x15e, 0x86); 151 cx25840_write(client, 0x15e, 0x86);
149 cx25840_write(client, 0x15f, 0x06); 152 cx25840_write(client, 0x15f, 0x06);
153 udelay(10);
150 cx25840_write(client, 0x15d, 0xe1); 154 cx25840_write(client, 0x15d, 0xe1);
151 cx25840_write(client, 0x15d, 0xe0); 155 cx25840_write(client, 0x15d, 0xe0);
152 cx25840_write(client, 0x15d, 0xe1); 156 cx25840_write(client, 0x15d, 0xe1);
@@ -165,9 +169,7 @@ static void cx25836_initialize(struct i2c_client *client)
165 /* 3c. */ 169 /* 3c. */
166 cx25840_and_or(client, 0x159, ~0x02, 0x02); 170 cx25840_and_or(client, 0x159, ~0x02, 0x02);
167 /* 3d. */ 171 /* 3d. */
168 /* There should be a 10-us delay here, but since the 172 udelay(10);
169 i2c bus already has a 10-us delay we don't need to do
170 anything */
171 /* 3e. */ 173 /* 3e. */
172 cx25840_and_or(client, 0x159, ~0x02, 0x00); 174 cx25840_and_or(client, 0x159, ~0x02, 0x00);
173 /* 3f. */ 175 /* 3f. */
@@ -179,9 +181,18 @@ static void cx25836_initialize(struct i2c_client *client)
179 cx25840_and_or(client, 0x15b, ~0x1e, 0x10); 181 cx25840_and_or(client, 0x15b, ~0x1e, 0x10);
180} 182}
181 183
182static void cx25840_initialize(struct i2c_client *client, int loadfw) 184static void cx25840_work_handler(struct work_struct *work)
183{ 185{
186 struct cx25840_state *state = container_of(work, struct cx25840_state, fw_work);
187 cx25840_loadfw(state->c);
188 wake_up(&state->fw_wait);
189}
190
191static void cx25840_initialize(struct i2c_client *client)
192{
193 DEFINE_WAIT(wait);
184 struct cx25840_state *state = i2c_get_clientdata(client); 194 struct cx25840_state *state = i2c_get_clientdata(client);
195 struct workqueue_struct *q;
185 196
186 /* datasheet startup in numbered steps, refer to page 3-77 */ 197 /* datasheet startup in numbered steps, refer to page 3-77 */
187 /* 2. */ 198 /* 2. */
@@ -197,8 +208,19 @@ static void cx25840_initialize(struct i2c_client *client, int loadfw)
197 cx25840_write(client, 0x13c, 0x01); 208 cx25840_write(client, 0x13c, 0x01);
198 cx25840_write(client, 0x13c, 0x00); 209 cx25840_write(client, 0x13c, 0x00);
199 /* 5. */ 210 /* 5. */
200 if (loadfw) 211 /* Do the firmware load in a work handler to prevent.
201 cx25840_loadfw(client); 212 Otherwise the kernel is blocked waiting for the
213 bit-banging i2c interface to finish uploading the
214 firmware. */
215 INIT_WORK(&state->fw_work, cx25840_work_handler);
216 init_waitqueue_head(&state->fw_wait);
217 q = create_singlethread_workqueue("cx25840_fw");
218 prepare_to_wait(&state->fw_wait, &wait, TASK_UNINTERRUPTIBLE);
219 queue_work(q, &state->fw_work);
220 schedule();
221 finish_wait(&state->fw_wait, &wait);
222 destroy_workqueue(q);
223
202 /* 6. */ 224 /* 6. */
203 cx25840_write(client, 0x115, 0x8c); 225 cx25840_write(client, 0x115, 0x8c);
204 cx25840_write(client, 0x116, 0x07); 226 cx25840_write(client, 0x116, 0x07);
@@ -251,8 +273,13 @@ static void input_change(struct i2c_client *client)
251 } 273 }
252 cx25840_and_or(client, 0x401, ~0x60, 0); 274 cx25840_and_or(client, 0x401, ~0x60, 0);
253 cx25840_and_or(client, 0x401, ~0x60, 0x60); 275 cx25840_and_or(client, 0x401, ~0x60, 0x60);
276 cx25840_and_or(client, 0x810, ~0x01, 1);
254 277
255 if (std & V4L2_STD_525_60) { 278 if (state->radio) {
279 cx25840_write(client, 0x808, 0xf9);
280 cx25840_write(client, 0x80b, 0x00);
281 }
282 else if (std & V4L2_STD_525_60) {
256 /* Certain Hauppauge PVR150 models have a hardware bug 283 /* Certain Hauppauge PVR150 models have a hardware bug
257 that causes audio to drop out. For these models the 284 that causes audio to drop out. For these models the
258 audio standard must be set explicitly. 285 audio standard must be set explicitly.
@@ -281,11 +308,7 @@ static void input_change(struct i2c_client *client)
281 cx25840_write(client, 0x80b, 0x10); 308 cx25840_write(client, 0x80b, 0x10);
282 } 309 }
283 310
284 if (cx25840_read(client, 0x803) & 0x10) { 311 cx25840_and_or(client, 0x810, ~0x01, 0);
285 /* restart audio decoder microcontroller */
286 cx25840_and_or(client, 0x803, ~0x10, 0x00);
287 cx25840_and_or(client, 0x803, ~0x10, 0x10);
288 }
289} 312}
290 313
291static int set_input(struct i2c_client *client, enum cx25840_video_input vid_input, 314static int set_input(struct i2c_client *client, enum cx25840_video_input vid_input,
@@ -625,6 +648,22 @@ static int cx25840_command(struct i2c_client *client, unsigned int cmd,
625 struct v4l2_tuner *vt = arg; 648 struct v4l2_tuner *vt = arg;
626 struct v4l2_routing *route = arg; 649 struct v4l2_routing *route = arg;
627 650
651 /* ignore these commands */
652 switch (cmd) {
653 case TUNER_SET_TYPE_ADDR:
654 return 0;
655 }
656
657 if (!state->is_initialized) {
658 v4l_dbg(1, cx25840_debug, client, "cmd %08x triggered fw load\n", cmd);
659 /* initialize on first use */
660 state->is_initialized = 1;
661 if (state->is_cx25836)
662 cx25836_initialize(client);
663 else
664 cx25840_initialize(client);
665 }
666
628 switch (cmd) { 667 switch (cmd) {
629#ifdef CONFIG_VIDEO_ADV_DEBUG 668#ifdef CONFIG_VIDEO_ADV_DEBUG
630 /* ioctls to allow direct access to the 669 /* ioctls to allow direct access to the
@@ -825,7 +864,7 @@ static int cx25840_command(struct i2c_client *client, unsigned int cmd,
825 if (state->is_cx25836) 864 if (state->is_cx25836)
826 cx25836_initialize(client); 865 cx25836_initialize(client);
827 else 866 else
828 cx25840_initialize(client, 0); 867 cx25840_initialize(client);
829 break; 868 break;
830 869
831 case VIDIOC_G_CHIP_IDENT: 870 case VIDIOC_G_CHIP_IDENT:
@@ -856,17 +895,16 @@ static int cx25840_detect_client(struct i2c_adapter *adapter, int address,
856 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) 895 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C))
857 return 0; 896 return 0;
858 897
859 state = kzalloc(sizeof(struct cx25840_state), GFP_KERNEL); 898 client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
860 if (state == 0) 899 if (client == 0)
861 return -ENOMEM; 900 return -ENOMEM;
862 901
863 client = &state->c;
864 client->addr = address; 902 client->addr = address;
865 client->adapter = adapter; 903 client->adapter = adapter;
866 client->driver = &i2c_driver_cx25840; 904 client->driver = &i2c_driver_cx25840;
867 snprintf(client->name, sizeof(client->name) - 1, "cx25840"); 905 snprintf(client->name, sizeof(client->name) - 1, "cx25840");
868 906
869 v4l_dbg(1, cx25840_debug, client, "detecting cx25840 client on address 0x%x\n", address << 1); 907 v4l_dbg(1, cx25840_debug, client, "detecting cx25840 client on address 0x%x\n", client->addr << 1);
870 908
871 device_id = cx25840_read(client, 0x101) << 8; 909 device_id = cx25840_read(client, 0x101) << 8;
872 device_id |= cx25840_read(client, 0x100); 910 device_id |= cx25840_read(client, 0x100);
@@ -875,42 +913,44 @@ static int cx25840_detect_client(struct i2c_adapter *adapter, int address,
875 * 0x83 for the cx2583x and 0x84 for the cx2584x */ 913 * 0x83 for the cx2583x and 0x84 for the cx2584x */
876 if ((device_id & 0xff00) == 0x8300) { 914 if ((device_id & 0xff00) == 0x8300) {
877 id = V4L2_IDENT_CX25836 + ((device_id >> 4) & 0xf) - 6; 915 id = V4L2_IDENT_CX25836 + ((device_id >> 4) & 0xf) - 6;
878 state->is_cx25836 = 1;
879 } 916 }
880 else if ((device_id & 0xff00) == 0x8400) { 917 else if ((device_id & 0xff00) == 0x8400) {
881 id = V4L2_IDENT_CX25840 + ((device_id >> 4) & 0xf); 918 id = V4L2_IDENT_CX25840 + ((device_id >> 4) & 0xf);
882 state->is_cx25836 = 0;
883 } 919 }
884 else { 920 else {
885 v4l_dbg(1, cx25840_debug, client, "cx25840 not found\n"); 921 v4l_dbg(1, cx25840_debug, client, "cx25840 not found\n");
886 kfree(state); 922 kfree(client);
887 return 0; 923 return 0;
888 } 924 }
889 925
926 state = kzalloc(sizeof(struct cx25840_state), GFP_KERNEL);
927 if (state == NULL) {
928 kfree(client);
929 return -ENOMEM;
930 }
931
890 /* Note: revision '(device_id & 0x0f) == 2' was never built. The 932 /* Note: revision '(device_id & 0x0f) == 2' was never built. The
891 marking skips from 0x1 == 22 to 0x3 == 23. */ 933 marking skips from 0x1 == 22 to 0x3 == 23. */
892 v4l_info(client, "cx25%3x-2%x found @ 0x%x (%s)\n", 934 v4l_info(client, "cx25%3x-2%x found @ 0x%x (%s)\n",
893 (device_id & 0xfff0) >> 4, 935 (device_id & 0xfff0) >> 4,
894 (device_id & 0x0f) < 3 ? (device_id & 0x0f) + 1 : (device_id & 0x0f), 936 (device_id & 0x0f) < 3 ? (device_id & 0x0f) + 1 : (device_id & 0x0f),
895 address << 1, adapter->name); 937 client->addr << 1, client->adapter->name);
896 938
897 i2c_set_clientdata(client, state); 939 i2c_set_clientdata(client, state);
940 state->c = client;
941 state->is_cx25836 = ((device_id & 0xff00) == 0x8300);
898 state->vid_input = CX25840_COMPOSITE7; 942 state->vid_input = CX25840_COMPOSITE7;
899 state->aud_input = CX25840_AUDIO8; 943 state->aud_input = CX25840_AUDIO8;
900 state->audclk_freq = 48000; 944 state->audclk_freq = 48000;
901 state->pvr150_workaround = 0; 945 state->pvr150_workaround = 0;
902 state->audmode = V4L2_TUNER_MODE_LANG1; 946 state->audmode = V4L2_TUNER_MODE_LANG1;
947 state->unmute_volume = -1;
903 state->vbi_line_offset = 8; 948 state->vbi_line_offset = 8;
904 state->id = id; 949 state->id = id;
905 state->rev = device_id; 950 state->rev = device_id;
906 951
907 i2c_attach_client(client); 952 i2c_attach_client(client);
908 953
909 if (state->is_cx25836)
910 cx25836_initialize(client);
911 else
912 cx25840_initialize(client, 1);
913
914 return 0; 954 return 0;
915} 955}
916 956
@@ -932,6 +972,7 @@ static int cx25840_detach_client(struct i2c_client *client)
932 } 972 }
933 973
934 kfree(state); 974 kfree(state);
975 kfree(client);
935 976
936 return 0; 977 return 0;
937} 978}
@@ -1056,9 +1097,10 @@ static void log_audio_status(struct i2c_client *client)
1056 } 1097 }
1057 v4l_info(client, "Detected audio standard: %s\n", p); 1098 v4l_info(client, "Detected audio standard: %s\n", p);
1058 v4l_info(client, "Audio muted: %s\n", 1099 v4l_info(client, "Audio muted: %s\n",
1059 (mute_ctl & 0x2) ? "yes" : "no"); 1100 (state->unmute_volume >= 0) ? "yes" : "no");
1060 v4l_info(client, "Audio microcontroller: %s\n", 1101 v4l_info(client, "Audio microcontroller: %s\n",
1061 (download_ctl & 0x10) ? "running" : "stopped"); 1102 (download_ctl & 0x10) ?
1103 ((mute_ctl & 0x2) ? "detecting" : "running") : "stopped");
1062 1104
1063 switch (audio_config >> 4) { 1105 switch (audio_config >> 4) {
1064 case 0x00: p = "undefined"; break; 1106 case 0x00: p = "undefined"; break;
diff --git a/drivers/media/video/cx25840/cx25840-core.h b/drivers/media/video/cx25840/cx25840-core.h
index f4b56d2fd6b6..ea669b1f084d 100644
--- a/drivers/media/video/cx25840/cx25840-core.h
+++ b/drivers/media/video/cx25840/cx25840-core.h
@@ -35,17 +35,21 @@ extern int cx25840_debug;
35#define CX25840_CID_ENABLE_PVR150_WORKAROUND (V4L2_CID_PRIVATE_BASE+0) 35#define CX25840_CID_ENABLE_PVR150_WORKAROUND (V4L2_CID_PRIVATE_BASE+0)
36 36
37struct cx25840_state { 37struct 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 enum cx25840_video_input vid_input; 41 enum cx25840_video_input vid_input;
42 enum cx25840_audio_input aud_input; 42 enum cx25840_audio_input aud_input;
43 u32 audclk_freq; 43 u32 audclk_freq;
44 int audmode; 44 int audmode;
45 int unmute_volume; /* -1 if not muted */
45 int vbi_line_offset; 46 int vbi_line_offset;
46 u32 id; 47 u32 id;
47 u32 rev; 48 u32 rev;
48 int is_cx25836; 49 int is_cx25836;
50 int is_initialized;
51 wait_queue_head_t fw_wait; /* wake up when the fw load is finished */
52 struct work_struct fw_work; /* work entry for fw load */
49}; 53};
50 54
51/* ----------------------------------------------------------------------- */ 55/* ----------------------------------------------------------------------- */
diff --git a/drivers/media/video/cx88/Kconfig b/drivers/media/video/cx88/Kconfig
index f750a543c961..eeb5224ca101 100644
--- a/drivers/media/video/cx88/Kconfig
+++ b/drivers/media/video/cx88/Kconfig
@@ -4,7 +4,7 @@ config VIDEO_CX88
4 select I2C_ALGOBIT 4 select I2C_ALGOBIT
5 select FW_LOADER 5 select FW_LOADER
6 select VIDEO_BTCX 6 select VIDEO_BTCX
7 select VIDEO_BUF 7 select VIDEOBUF_DMA_SG
8 select VIDEO_TUNER 8 select VIDEO_TUNER
9 select VIDEO_TVEEPROM 9 select VIDEO_TVEEPROM
10 select VIDEO_IR 10 select VIDEO_IR
@@ -46,7 +46,7 @@ config VIDEO_CX88_BLACKBIRD
46config VIDEO_CX88_DVB 46config VIDEO_CX88_DVB
47 tristate "DVB/ATSC Support for cx2388x based TV cards" 47 tristate "DVB/ATSC Support for cx2388x based TV cards"
48 depends on VIDEO_CX88 && DVB_CORE 48 depends on VIDEO_CX88 && DVB_CORE
49 select VIDEO_BUF_DVB 49 select VIDEOBUF_DVB
50 select DVB_PLL if !DVB_FE_CUSTOMISE 50 select DVB_PLL if !DVB_FE_CUSTOMISE
51 select DVB_MT352 if !DVB_FE_CUSTOMISE 51 select DVB_MT352 if !DVB_FE_CUSTOMISE
52 select DVB_ZL10353 if !DVB_FE_CUSTOMISE 52 select DVB_ZL10353 if !DVB_FE_CUSTOMISE
diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
index 2d666b56020c..90c36c5705c3 100644
--- a/drivers/media/video/cx88/cx88-alsa.c
+++ b/drivers/media/video/cx88/cx88-alsa.c
@@ -3,6 +3,7 @@
3 * Support for audio capture 3 * Support for audio capture
4 * PCI function #1 of the cx2388x. 4 * PCI function #1 of the cx2388x.
5 * 5 *
6 * (c) 2007 Trent Piepho <xyzzy@speakeasy.org>
6 * (c) 2005,2006 Ricardo Cerqueira <v4l@cerqueira.org> 7 * (c) 2005,2006 Ricardo Cerqueira <v4l@cerqueira.org>
7 * (c) 2005 Mauro Carvalho Chehab <mchehab@infradead.org> 8 * (c) 2005 Mauro Carvalho Chehab <mchehab@infradead.org>
8 * Based on a dummy cx88 module by Gerd Knorr <kraxel@bytesex.org> 9 * Based on a dummy cx88 module by Gerd Knorr <kraxel@bytesex.org>
@@ -27,7 +28,9 @@
27#include <linux/init.h> 28#include <linux/init.h>
28#include <linux/device.h> 29#include <linux/device.h>
29#include <linux/interrupt.h> 30#include <linux/interrupt.h>
31#include <linux/vmalloc.h>
30#include <linux/dma-mapping.h> 32#include <linux/dma-mapping.h>
33#include <linux/pci.h>
31 34
32#include <asm/delay.h> 35#include <asm/delay.h>
33#include <sound/driver.h> 36#include <sound/driver.h>
@@ -46,21 +49,16 @@
46#define dprintk_core(level,fmt, arg...) if (debug >= level) \ 49#define dprintk_core(level,fmt, arg...) if (debug >= level) \
47 printk(KERN_DEBUG "%s/1: " fmt, chip->core->name , ## arg) 50 printk(KERN_DEBUG "%s/1: " fmt, chip->core->name , ## arg)
48 51
49
50/**************************************************************************** 52/****************************************************************************
51 Data type declarations - Can be moded to a header file later 53 Data type declarations - Can be moded to a header file later
52 ****************************************************************************/ 54 ****************************************************************************/
53 55
54/* These can be replaced after done */
55#define MIXER_ADDR_LAST MAX_CX88_INPUT
56
57struct cx88_audio_dev { 56struct cx88_audio_dev {
58 struct cx88_core *core; 57 struct cx88_core *core;
59 struct cx88_dmaqueue q; 58 struct cx88_dmaqueue q;
60 59
61 /* pci i/o */ 60 /* pci i/o */
62 struct pci_dev *pci; 61 struct pci_dev *pci;
63 unsigned char pci_rev,pci_lat;
64 62
65 /* audio controls */ 63 /* audio controls */
66 int irq; 64 int irq;
@@ -68,24 +66,17 @@ struct cx88_audio_dev {
68 struct snd_card *card; 66 struct snd_card *card;
69 67
70 spinlock_t reg_lock; 68 spinlock_t reg_lock;
69 atomic_t count;
71 70
72 unsigned int dma_size; 71 unsigned int dma_size;
73 unsigned int period_size; 72 unsigned int period_size;
74 unsigned int num_periods; 73 unsigned int num_periods;
75 74
76 struct videobuf_dmabuf dma_risc; 75 struct videobuf_dmabuf *dma_risc;
77
78 int mixer_volume[MIXER_ADDR_LAST+1][2];
79 int capture_source[MIXER_ADDR_LAST+1][2];
80
81 long int read_count;
82 long int read_offset;
83
84 struct cx88_buffer *buf;
85 76
86 long opened; 77 struct cx88_buffer *buf;
87 struct snd_pcm_substream *substream;
88 78
79 struct snd_pcm_substream *substream;
89}; 80};
90typedef struct cx88_audio_dev snd_cx88_card_t; 81typedef struct cx88_audio_dev snd_cx88_card_t;
91 82
@@ -98,7 +89,6 @@ typedef struct cx88_audio_dev snd_cx88_card_t;
98static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ 89static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
99static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 90static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
100static int enable[SNDRV_CARDS] = {1, [1 ... (SNDRV_CARDS - 1)] = 1}; 91static int enable[SNDRV_CARDS] = {1, [1 ... (SNDRV_CARDS - 1)] = 1};
101static struct snd_card *snd_cx88_cards[SNDRV_CARDS];
102 92
103module_param_array(enable, bool, NULL, 0444); 93module_param_array(enable, bool, NULL, 0444);
104MODULE_PARM_DESC(enable, "Enable cx88x soundcard. default enabled."); 94MODULE_PARM_DESC(enable, "Enable cx88x soundcard. default enabled.");
@@ -136,38 +126,39 @@ static int _cx88_start_audio_dma(snd_cx88_card_t *chip)
136 struct cx88_core *core=chip->core; 126 struct cx88_core *core=chip->core;
137 struct sram_channel *audio_ch = &cx88_sram_channels[SRAM_CH25]; 127 struct sram_channel *audio_ch = &cx88_sram_channels[SRAM_CH25];
138 128
139 129 /* Make sure RISC/FIFO are off before changing FIFO/RISC settings */
140 dprintk(1, "Starting audio DMA for %i bytes/line and %i (%i) lines at address %08x\n",buf->bpl, chip->num_periods, audio_ch->fifo_size / buf->bpl, audio_ch->fifo_start); 130 cx_clear(MO_AUD_DMACNTRL, 0x11);
141 131
142 /* setup fifo + format - out channel */ 132 /* setup fifo + format - out channel */
143 cx88_sram_channel_setup(chip->core, &cx88_sram_channels[SRAM_CH25], 133 cx88_sram_channel_setup(chip->core, audio_ch, buf->bpl, buf->risc.dma);
144 buf->bpl, buf->risc.dma);
145 134
146 /* sets bpl size */ 135 /* sets bpl size */
147 cx_write(MO_AUDD_LNGTH, buf->bpl); 136 cx_write(MO_AUDD_LNGTH, buf->bpl);
148 137
149 /* reset counter */ 138 /* reset counter */
150 cx_write(MO_AUDD_GPCNTRL,GP_COUNT_CONTROL_RESET); 139 cx_write(MO_AUDD_GPCNTRL, GP_COUNT_CONTROL_RESET);
151 140 atomic_set(&chip->count, 0);
152 dprintk(1,"Enabling IRQ, setting mask from 0x%x to 0x%x\n",chip->core->pci_irqmask,(chip->core->pci_irqmask | 0x02));
153 /* enable irqs */
154 cx_set(MO_PCI_INTMSK, chip->core->pci_irqmask | 0x02);
155 141
142 dprintk(1, "Start audio DMA, %d B/line, %d lines/FIFO, %d periods, %d "
143 "byte buffer\n", buf->bpl, cx_read(audio_ch->cmds_start + 8)>>1,
144 chip->num_periods, buf->bpl * chip->num_periods);
156 145
157 /* Enables corresponding bits at AUD_INT_STAT */ 146 /* Enables corresponding bits at AUD_INT_STAT */
158 cx_write(MO_AUD_INTMSK, 147 cx_write(MO_AUD_INTMSK, AUD_INT_OPC_ERR | AUD_INT_DN_SYNC |
159 (1<<16)| 148 AUD_INT_DN_RISCI2 | AUD_INT_DN_RISCI1);
160 (1<<12)| 149
161 (1<<4)| 150 /* Clean any pending interrupt bits already set */
162 (1<<0) 151 cx_write(MO_AUD_INTSTAT, ~0);
163 ); 152
153 /* enable audio irqs */
154 cx_set(MO_PCI_INTMSK, chip->core->pci_irqmask | PCI_INT_AUDINT);
164 155
165 /* start dma */ 156 /* start dma */
166 cx_set(MO_DEV_CNTRL2, (1<<5)); /* Enables Risc Processor */ 157 cx_set(MO_DEV_CNTRL2, (1<<5)); /* Enables Risc Processor */
167 cx_set(MO_AUD_DMACNTRL, 0x11); /* audio downstream FIFO and RISC enable */ 158 cx_set(MO_AUD_DMACNTRL, 0x11); /* audio downstream FIFO and RISC enable */
168 159
169 if (debug) 160 if (debug)
170 cx88_sram_channel_dump(chip->core, &cx88_sram_channels[SRAM_CH25]); 161 cx88_sram_channel_dump(chip->core, audio_ch);
171 162
172 return 0; 163 return 0;
173} 164}
@@ -184,13 +175,9 @@ static int _cx88_stop_audio_dma(snd_cx88_card_t *chip)
184 cx_clear(MO_AUD_DMACNTRL, 0x11); 175 cx_clear(MO_AUD_DMACNTRL, 0x11);
185 176
186 /* disable irqs */ 177 /* disable irqs */
187 cx_clear(MO_PCI_INTMSK, 0x02); 178 cx_clear(MO_PCI_INTMSK, PCI_INT_AUDINT);
188 cx_clear(MO_AUD_INTMSK, 179 cx_clear(MO_AUD_INTMSK, AUD_INT_OPC_ERR | AUD_INT_DN_SYNC |
189 (1<<16)| 180 AUD_INT_DN_RISCI2 | AUD_INT_DN_RISCI1);
190 (1<<12)|
191 (1<<4)|
192 (1<<0)
193 );
194 181
195 if (debug) 182 if (debug)
196 cx88_sram_channel_dump(chip->core, &cx88_sram_channels[SRAM_CH25]); 183 cx88_sram_channel_dump(chip->core, &cx88_sram_channels[SRAM_CH25]);
@@ -198,7 +185,7 @@ static int _cx88_stop_audio_dma(snd_cx88_card_t *chip)
198 return 0; 185 return 0;
199} 186}
200 187
201#define MAX_IRQ_LOOP 10 188#define MAX_IRQ_LOOP 50
202 189
203/* 190/*
204 * BOARD Specific: IRQ dma bits 191 * BOARD Specific: IRQ dma bits
@@ -223,42 +210,32 @@ static void cx8801_aud_irq(snd_cx88_card_t *chip)
223{ 210{
224 struct cx88_core *core = chip->core; 211 struct cx88_core *core = chip->core;
225 u32 status, mask; 212 u32 status, mask;
226 u32 count;
227 213
228 status = cx_read(MO_AUD_INTSTAT); 214 status = cx_read(MO_AUD_INTSTAT);
229 mask = cx_read(MO_AUD_INTMSK); 215 mask = cx_read(MO_AUD_INTMSK);
230 if (0 == (status & mask)) { 216 if (0 == (status & mask))
231 spin_unlock(&chip->reg_lock);
232 return; 217 return;
233 }
234 cx_write(MO_AUD_INTSTAT, status); 218 cx_write(MO_AUD_INTSTAT, status);
235 if (debug > 1 || (status & mask & ~0xff)) 219 if (debug > 1 || (status & mask & ~0xff))
236 cx88_print_irqbits(core->name, "irq aud", 220 cx88_print_irqbits(core->name, "irq aud",
237 cx88_aud_irqs, ARRAY_SIZE(cx88_aud_irqs), 221 cx88_aud_irqs, ARRAY_SIZE(cx88_aud_irqs),
238 status, mask); 222 status, mask);
239 /* risc op code error */ 223 /* risc op code error */
240 if (status & (1 << 16)) { 224 if (status & AUD_INT_OPC_ERR) {
241 printk(KERN_WARNING "%s/0: audio risc op code error\n",core->name); 225 printk(KERN_WARNING "%s/1: Audio risc op code error\n",core->name);
242 cx_clear(MO_AUD_DMACNTRL, 0x11); 226 cx_clear(MO_AUD_DMACNTRL, 0x11);
243 cx88_sram_channel_dump(core, &cx88_sram_channels[SRAM_CH25]); 227 cx88_sram_channel_dump(core, &cx88_sram_channels[SRAM_CH25]);
244 } 228 }
245 229 if (status & AUD_INT_DN_SYNC) {
246 /* risc1 downstream */ 230 dprintk(1, "Downstream sync error\n");
247 if (status & 0x01) { 231 cx_write(MO_AUDD_GPCNTRL, GP_COUNT_CONTROL_RESET);
248 spin_lock(&chip->reg_lock); 232 return;
249 count = cx_read(MO_AUDD_GPCNT);
250 spin_unlock(&chip->reg_lock);
251 if (chip->read_count == 0)
252 chip->read_count += chip->dma_size;
253 } 233 }
254 234 /* risc1 downstream */
255 if (chip->read_count >= chip->period_size) { 235 if (status & AUD_INT_DN_RISCI1) {
256 dprintk(2, "Elapsing period\n"); 236 atomic_set(&chip->count, cx_read(MO_AUDD_GPCNT));
257 snd_pcm_period_elapsed(chip->substream); 237 snd_pcm_period_elapsed(chip->substream);
258 } 238 }
259
260 dprintk(3,"Leaving audio IRQ handler...\n");
261
262 /* FIXME: Any other status should deserve a special handling? */ 239 /* FIXME: Any other status should deserve a special handling? */
263} 240}
264 241
@@ -273,27 +250,26 @@ static irqreturn_t cx8801_irq(int irq, void *dev_id)
273 int loop, handled = 0; 250 int loop, handled = 0;
274 251
275 for (loop = 0; loop < MAX_IRQ_LOOP; loop++) { 252 for (loop = 0; loop < MAX_IRQ_LOOP; loop++) {
276 status = cx_read(MO_PCI_INTSTAT) & (core->pci_irqmask | 0x02); 253 status = cx_read(MO_PCI_INTSTAT) &
254 (core->pci_irqmask | PCI_INT_AUDINT);
277 if (0 == status) 255 if (0 == status)
278 goto out; 256 goto out;
279 dprintk( 3, "cx8801_irq\n" ); 257 dprintk(3, "cx8801_irq loop %d/%d, status %x\n",
280 dprintk( 3, " loop: %d/%d\n", loop, MAX_IRQ_LOOP ); 258 loop, MAX_IRQ_LOOP, status);
281 dprintk( 3, " status: %d\n", status );
282 handled = 1; 259 handled = 1;
283 cx_write(MO_PCI_INTSTAT, status); 260 cx_write(MO_PCI_INTSTAT, status);
284 261
285 if (status & 0x02) 262 if (status & core->pci_irqmask)
286 { 263 cx88_core_irq(core, status);
287 dprintk( 2, " ALSA IRQ handling\n" ); 264 if (status & PCI_INT_AUDINT)
288 cx8801_aud_irq(chip); 265 cx8801_aud_irq(chip);
289 } 266 }
290 };
291 267
292 if (MAX_IRQ_LOOP == loop) { 268 if (MAX_IRQ_LOOP == loop) {
293 dprintk( 0, "clearing mask\n" ); 269 printk(KERN_ERR
294 dprintk(1,"%s/0: irq loop -- clearing mask\n", 270 "%s/1: IRQ loop detected, disabling interrupts\n",
295 core->name); 271 core->name);
296 cx_clear(MO_PCI_INTMSK,0x02); 272 cx_clear(MO_PCI_INTMSK, PCI_INT_AUDINT);
297 } 273 }
298 274
299 out: 275 out:
@@ -306,14 +282,15 @@ static int dsp_buffer_free(snd_cx88_card_t *chip)
306 BUG_ON(!chip->dma_size); 282 BUG_ON(!chip->dma_size);
307 283
308 dprintk(2,"Freeing buffer\n"); 284 dprintk(2,"Freeing buffer\n");
309 videobuf_pci_dma_unmap(chip->pci, &chip->dma_risc); 285 videobuf_pci_dma_unmap(chip->pci, chip->dma_risc);
310 videobuf_dma_free(&chip->dma_risc); 286 videobuf_dma_free(chip->dma_risc);
311 btcx_riscmem_free(chip->pci,&chip->buf->risc); 287 btcx_riscmem_free(chip->pci,&chip->buf->risc);
312 kfree(chip->buf); 288 kfree(chip->buf);
313 289
290 chip->dma_risc = NULL;
314 chip->dma_size = 0; 291 chip->dma_size = 0;
315 292
316 return 0; 293 return 0;
317} 294}
318 295
319/**************************************************************************** 296/****************************************************************************
@@ -323,6 +300,7 @@ static int dsp_buffer_free(snd_cx88_card_t *chip)
323/* 300/*
324 * Digital hardware definition 301 * Digital hardware definition
325 */ 302 */
303#define DEFAULT_FIFO_SIZE 4096
326static struct snd_pcm_hardware snd_cx88_digital_hw = { 304static struct snd_pcm_hardware snd_cx88_digital_hw = {
327 .info = SNDRV_PCM_INFO_MMAP | 305 .info = SNDRV_PCM_INFO_MMAP |
328 SNDRV_PCM_INFO_INTERLEAVED | 306 SNDRV_PCM_INFO_INTERLEAVED |
@@ -333,22 +311,18 @@ static struct snd_pcm_hardware snd_cx88_digital_hw = {
333 .rates = SNDRV_PCM_RATE_48000, 311 .rates = SNDRV_PCM_RATE_48000,
334 .rate_min = 48000, 312 .rate_min = 48000,
335 .rate_max = 48000, 313 .rate_max = 48000,
336 .channels_min = 1, 314 .channels_min = 2,
337 .channels_max = 2, 315 .channels_max = 2,
338 .buffer_bytes_max = (2*2048), 316 /* Analog audio output will be full of clicks and pops if there
339 .period_bytes_min = 2048, 317 are not exactly four lines in the SRAM FIFO buffer. */
340 .period_bytes_max = 2048, 318 .period_bytes_min = DEFAULT_FIFO_SIZE/4,
341 .periods_min = 2, 319 .period_bytes_max = DEFAULT_FIFO_SIZE/4,
342 .periods_max = 2, 320 .periods_min = 1,
321 .periods_max = 1024,
322 .buffer_bytes_max = (1024*1024),
343}; 323};
344 324
345/* 325/*
346 * audio pcm capture runtime free
347 */
348static void snd_card_cx88_runtime_free(struct snd_pcm_runtime *runtime)
349{
350}
351/*
352 * audio pcm capture open callback 326 * audio pcm capture open callback
353 */ 327 */
354static int snd_cx88_pcm_open(struct snd_pcm_substream *substream) 328static int snd_cx88_pcm_open(struct snd_pcm_substream *substream)
@@ -357,26 +331,24 @@ static int snd_cx88_pcm_open(struct snd_pcm_substream *substream)
357 struct snd_pcm_runtime *runtime = substream->runtime; 331 struct snd_pcm_runtime *runtime = substream->runtime;
358 int err; 332 int err;
359 333
360 if (test_and_set_bit(0, &chip->opened)) 334 err = snd_pcm_hw_constraint_pow2(runtime, 0, SNDRV_PCM_HW_PARAM_PERIODS);
361 return -EBUSY;
362
363 err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
364 if (err < 0) 335 if (err < 0)
365 goto _error; 336 goto _error;
366 337
367 chip->substream = substream; 338 chip->substream = substream;
368 339
369 chip->read_count = 0;
370 chip->read_offset = 0;
371
372 runtime->private_free = snd_card_cx88_runtime_free;
373 runtime->hw = snd_cx88_digital_hw; 340 runtime->hw = snd_cx88_digital_hw;
374 341
342 if (cx88_sram_channels[SRAM_CH25].fifo_size != DEFAULT_FIFO_SIZE) {
343 unsigned int bpl = cx88_sram_channels[SRAM_CH25].fifo_size / 4;
344 bpl &= ~7; /* must be multiple of 8 */
345 runtime->hw.period_bytes_min = bpl;
346 runtime->hw.period_bytes_max = bpl;
347 }
348
375 return 0; 349 return 0;
376_error: 350_error:
377 dprintk(1,"Error opening PCM!\n"); 351 dprintk(1,"Error opening PCM!\n");
378 clear_bit(0, &chip->opened);
379 smp_mb__after_clear_bit();
380 return err; 352 return err;
381} 353}
382 354
@@ -385,11 +357,6 @@ _error:
385 */ 357 */
386static int snd_cx88_close(struct snd_pcm_substream *substream) 358static int snd_cx88_close(struct snd_pcm_substream *substream)
387{ 359{
388 snd_cx88_card_t *chip = snd_pcm_substream_chip(substream);
389
390 clear_bit(0, &chip->opened);
391 smp_mb__after_clear_bit();
392
393 return 0; 360 return 0;
394} 361}
395 362
@@ -400,55 +367,67 @@ static int snd_cx88_hw_params(struct snd_pcm_substream * substream,
400 struct snd_pcm_hw_params * hw_params) 367 struct snd_pcm_hw_params * hw_params)
401{ 368{
402 snd_cx88_card_t *chip = snd_pcm_substream_chip(substream); 369 snd_cx88_card_t *chip = snd_pcm_substream_chip(substream);
370 struct videobuf_dmabuf *dma;
371
403 struct cx88_buffer *buf; 372 struct cx88_buffer *buf;
373 int ret;
404 374
405 if (substream->runtime->dma_area) { 375 if (substream->runtime->dma_area) {
406 dsp_buffer_free(chip); 376 dsp_buffer_free(chip);
407 substream->runtime->dma_area = NULL; 377 substream->runtime->dma_area = NULL;
408 } 378 }
409 379
410
411 chip->period_size = params_period_bytes(hw_params); 380 chip->period_size = params_period_bytes(hw_params);
412 chip->num_periods = params_periods(hw_params); 381 chip->num_periods = params_periods(hw_params);
413 chip->dma_size = chip->period_size * params_periods(hw_params); 382 chip->dma_size = chip->period_size * params_periods(hw_params);
414 383
415 BUG_ON(!chip->dma_size); 384 BUG_ON(!chip->dma_size);
385 BUG_ON(chip->num_periods & (chip->num_periods-1));
416 386
417 dprintk(1,"Setting buffer\n"); 387 buf = videobuf_pci_alloc(sizeof(*buf));
418
419 buf = kzalloc(sizeof(*buf),GFP_KERNEL);
420 if (NULL == buf) 388 if (NULL == buf)
421 return -ENOMEM; 389 return -ENOMEM;
422 390
423 buf->vb.memory = V4L2_MEMORY_MMAP; 391 buf->vb.memory = V4L2_MEMORY_MMAP;
392 buf->vb.field = V4L2_FIELD_NONE;
424 buf->vb.width = chip->period_size; 393 buf->vb.width = chip->period_size;
394 buf->bpl = chip->period_size;
425 buf->vb.height = chip->num_periods; 395 buf->vb.height = chip->num_periods;
426 buf->vb.size = chip->dma_size; 396 buf->vb.size = chip->dma_size;
427 buf->vb.field = V4L2_FIELD_NONE;
428 397
429 videobuf_dma_init(&buf->vb.dma); 398 dma=videobuf_to_dma(&buf->vb);
430 videobuf_dma_init_kernel(&buf->vb.dma,PCI_DMA_FROMDEVICE, 399 videobuf_dma_init(dma);
400 ret = videobuf_dma_init_kernel(dma, PCI_DMA_FROMDEVICE,
431 (PAGE_ALIGN(buf->vb.size) >> PAGE_SHIFT)); 401 (PAGE_ALIGN(buf->vb.size) >> PAGE_SHIFT));
402 if (ret < 0)
403 goto error;
432 404
433 videobuf_pci_dma_map(chip->pci,&buf->vb.dma); 405 ret = videobuf_pci_dma_map(chip->pci,dma);
406 if (ret < 0)
407 goto error;
434 408
409 ret = cx88_risc_databuffer(chip->pci, &buf->risc, dma->sglist,
410 buf->vb.width, buf->vb.height, 1);
411 if (ret < 0)
412 goto error;
435 413
436 cx88_risc_databuffer(chip->pci, &buf->risc, 414 /* Loop back to start of program */
437 buf->vb.dma.sglist, 415 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP|RISC_IRQ1|RISC_CNT_INC);
438 buf->vb.width, buf->vb.height);
439
440 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC);
441 buf->risc.jmp[1] = cpu_to_le32(buf->risc.dma); 416 buf->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
442 417
443 buf->vb.state = STATE_PREPARED; 418 buf->vb.state = STATE_PREPARED;
444 419
445 buf->bpl = chip->period_size;
446 chip->buf = buf; 420 chip->buf = buf;
447 chip->dma_risc = buf->vb.dma; 421 chip->dma_risc = dma;
448 422
449 dprintk(1,"Buffer ready at %u\n",chip->dma_risc.nr_pages); 423 substream->runtime->dma_area = chip->dma_risc->vmalloc;
450 substream->runtime->dma_area = chip->dma_risc.vmalloc; 424 substream->runtime->dma_bytes = chip->dma_size;
425 substream->runtime->dma_addr = 0;
451 return 0; 426 return 0;
427
428error:
429 kfree(buf);
430 return ret;
452} 431}
453 432
454/* 433/*
@@ -475,7 +454,6 @@ static int snd_cx88_prepare(struct snd_pcm_substream *substream)
475 return 0; 454 return 0;
476} 455}
477 456
478
479/* 457/*
480 * trigger callback 458 * trigger callback
481 */ 459 */
@@ -484,6 +462,7 @@ static int snd_cx88_card_trigger(struct snd_pcm_substream *substream, int cmd)
484 snd_cx88_card_t *chip = snd_pcm_substream_chip(substream); 462 snd_cx88_card_t *chip = snd_pcm_substream_chip(substream);
485 int err; 463 int err;
486 464
465 /* Local interrupts are already disabled by ALSA */
487 spin_lock(&chip->reg_lock); 466 spin_lock(&chip->reg_lock);
488 467
489 switch (cmd) { 468 switch (cmd) {
@@ -510,17 +489,24 @@ static snd_pcm_uframes_t snd_cx88_pointer(struct snd_pcm_substream *substream)
510{ 489{
511 snd_cx88_card_t *chip = snd_pcm_substream_chip(substream); 490 snd_cx88_card_t *chip = snd_pcm_substream_chip(substream);
512 struct snd_pcm_runtime *runtime = substream->runtime; 491 struct snd_pcm_runtime *runtime = substream->runtime;
492 u16 count;
513 493
514 if (chip->read_count) { 494 count = atomic_read(&chip->count);
515 chip->read_count -= snd_pcm_lib_period_bytes(substream);
516 chip->read_offset += snd_pcm_lib_period_bytes(substream);
517 if (chip->read_offset == chip->dma_size)
518 chip->read_offset = 0;
519 }
520 495
521 dprintk(2, "Pointer time, will return %li, read %li\n",chip->read_offset,chip->read_count); 496// dprintk(2, "%s - count %d (+%u), period %d, frame %lu\n", __FUNCTION__,
522 return bytes_to_frames(runtime, chip->read_offset); 497// count, new, count & (runtime->periods-1),
498// runtime->period_size * (count & (runtime->periods-1)));
499 return runtime->period_size * (count & (runtime->periods-1));
500}
523 501
502/*
503 * page callback (needed for mmap)
504 */
505static struct page *snd_cx88_page(struct snd_pcm_substream *substream,
506 unsigned long offset)
507{
508 void *pageptr = substream->runtime->dma_area + offset;
509 return vmalloc_to_page(pageptr);
524} 510}
525 511
526/* 512/*
@@ -535,6 +521,7 @@ static struct snd_pcm_ops snd_cx88_pcm_ops = {
535 .prepare = snd_cx88_prepare, 521 .prepare = snd_cx88_prepare,
536 .trigger = snd_cx88_card_trigger, 522 .trigger = snd_cx88_card_trigger,
537 .pointer = snd_cx88_pointer, 523 .pointer = snd_cx88_pointer,
524 .page = snd_cx88_page,
538}; 525};
539 526
540/* 527/*
@@ -562,7 +549,7 @@ static int snd_cx88_capture_volume_info(struct snd_kcontrol *kcontrol,
562 struct snd_ctl_elem_info *info) 549 struct snd_ctl_elem_info *info)
563{ 550{
564 info->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 551 info->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
565 info->count = 1; 552 info->count = 2;
566 info->value.integer.min = 0; 553 info->value.integer.min = 0;
567 info->value.integer.max = 0x3f; 554 info->value.integer.max = 0x3f;
568 555
@@ -575,8 +562,12 @@ static int snd_cx88_capture_volume_get(struct snd_kcontrol *kcontrol,
575{ 562{
576 snd_cx88_card_t *chip = snd_kcontrol_chip(kcontrol); 563 snd_cx88_card_t *chip = snd_kcontrol_chip(kcontrol);
577 struct cx88_core *core=chip->core; 564 struct cx88_core *core=chip->core;
565 int vol = 0x3f - (cx_read(AUD_VOL_CTL) & 0x3f),
566 bal = cx_read(AUD_BAL_CTL);
578 567
579 value->value.integer.value[0] = 0x3f - (cx_read(AUD_VOL_CTL) & 0x3f); 568 value->value.integer.value[(bal & 0x40) ? 0 : 1] = vol;
569 vol -= (bal & 0x3f);
570 value->value.integer.value[(bal & 0x40) ? 1 : 0] = vol < 0 ? 0 : vol;
580 571
581 return 0; 572 return 0;
582} 573}
@@ -587,16 +578,31 @@ static int snd_cx88_capture_volume_put(struct snd_kcontrol *kcontrol,
587{ 578{
588 snd_cx88_card_t *chip = snd_kcontrol_chip(kcontrol); 579 snd_cx88_card_t *chip = snd_kcontrol_chip(kcontrol);
589 struct cx88_core *core=chip->core; 580 struct cx88_core *core=chip->core;
590 int v; 581 int v, b;
591 u32 old_control; 582 int changed = 0;
592 583 u32 old;
584
585 b = value->value.integer.value[1] - value->value.integer.value[0];
586 if (b < 0) {
587 v = 0x3f - value->value.integer.value[0];
588 b = (-b) | 0x40;
589 } else {
590 v = 0x3f - value->value.integer.value[1];
591 }
592 /* Do we really know this will always be called with IRQs on? */
593 spin_lock_irq(&chip->reg_lock); 593 spin_lock_irq(&chip->reg_lock);
594 old_control = 0x3f - (cx_read(AUD_VOL_CTL) & 0x3f); 594 old = cx_read(AUD_VOL_CTL);
595 v = 0x3f - (value->value.integer.value[0] & 0x3f); 595 if (v != (old & 0x3f)) {
596 cx_andor(AUD_VOL_CTL, 0x3f, v); 596 cx_write(AUD_VOL_CTL, (old & ~0x3f) | v);
597 changed = 1;
598 }
599 if (cx_read(AUD_BAL_CTL) != b) {
600 cx_write(AUD_BAL_CTL, b);
601 changed = 1;
602 }
597 spin_unlock_irq(&chip->reg_lock); 603 spin_unlock_irq(&chip->reg_lock);
598 604
599 return v != old_control; 605 return changed;
600} 606}
601 607
602static struct snd_kcontrol_new snd_cx88_capture_volume = { 608static struct snd_kcontrol_new snd_cx88_capture_volume = {
@@ -665,6 +671,7 @@ static int __devinit snd_cx88_create(struct snd_card *card,
665 snd_cx88_card_t *chip; 671 snd_cx88_card_t *chip;
666 struct cx88_core *core; 672 struct cx88_core *core;
667 int err; 673 int err;
674 unsigned char pci_lat;
668 675
669 *rchip = NULL; 676 *rchip = NULL;
670 677
@@ -709,13 +716,12 @@ static int __devinit snd_cx88_create(struct snd_card *card,
709 } 716 }
710 717
711 /* print pci info */ 718 /* print pci info */
712 pci_read_config_byte(pci, PCI_CLASS_REVISION, &chip->pci_rev); 719 pci_read_config_byte(pci, PCI_LATENCY_TIMER, &pci_lat);
713 pci_read_config_byte(pci, PCI_LATENCY_TIMER, &chip->pci_lat);
714 720
715 dprintk(1,"ALSA %s/%i: found at %s, rev: %d, irq: %d, " 721 dprintk(1,"ALSA %s/%i: found at %s, rev: %d, irq: %d, "
716 "latency: %d, mmio: 0x%llx\n", core->name, devno, 722 "latency: %d, mmio: 0x%llx\n", core->name, devno,
717 pci_name(pci), chip->pci_rev, pci->irq, 723 pci_name(pci), pci->revision, pci->irq,
718 chip->pci_lat,(unsigned long long)pci_resource_start(pci,0)); 724 pci_lat, (unsigned long long)pci_resource_start(pci,0));
719 725
720 chip->irq = pci->irq; 726 chip->irq = pci->irq;
721 synchronize_irq(chip->irq); 727 synchronize_irq(chip->irq);
@@ -753,17 +759,12 @@ static int __devinit cx88_audio_initdev(struct pci_dev *pci,
753 return (err); 759 return (err);
754 760
755 err = snd_cx88_pcm(chip, 0, "CX88 Digital"); 761 err = snd_cx88_pcm(chip, 0, "CX88 Digital");
756 762 if (err < 0)
757 if (err < 0) { 763 goto error;
758 snd_card_free(card);
759 return (err);
760 }
761 764
762 err = snd_ctl_add(card, snd_ctl_new1(&snd_cx88_capture_volume, chip)); 765 err = snd_ctl_add(card, snd_ctl_new1(&snd_cx88_capture_volume, chip));
763 if (err < 0) { 766 if (err < 0)
764 snd_card_free(card); 767 goto error;
765 return (err);
766 }
767 768
768 strcpy (card->driver, "CX88x"); 769 strcpy (card->driver, "CX88x");
769 sprintf(card->shortname, "Conexant CX%x", pci->device); 770 sprintf(card->shortname, "Conexant CX%x", pci->device);
@@ -775,16 +776,16 @@ static int __devinit cx88_audio_initdev(struct pci_dev *pci,
775 card->driver,devno); 776 card->driver,devno);
776 777
777 err = snd_card_register(card); 778 err = snd_card_register(card);
778 if (err < 0) { 779 if (err < 0)
779 snd_card_free(card); 780 goto error;
780 return (err);
781 }
782 snd_cx88_cards[devno] = card;
783
784 pci_set_drvdata(pci,card); 781 pci_set_drvdata(pci,card);
785 782
786 devno++; 783 devno++;
787 return 0; 784 return 0;
785
786error:
787 snd_card_free(card);
788 return err;
788} 789}
789/* 790/*
790 * ALSA destructor 791 * ALSA destructor
diff --git a/drivers/media/video/cx88/cx88-blackbird.c b/drivers/media/video/cx88/cx88-blackbird.c
index f2fcdb92ecce..6d6f5048d762 100644
--- a/drivers/media/video/cx88/cx88-blackbird.c
+++ b/drivers/media/video/cx88/cx88-blackbird.c
@@ -27,7 +27,6 @@
27 */ 27 */
28 28
29#include <linux/module.h> 29#include <linux/module.h>
30#include <linux/moduleparam.h>
31#include <linux/init.h> 30#include <linux/init.h>
32#include <linux/fs.h> 31#include <linux/fs.h>
33#include <linux/delay.h> 32#include <linux/delay.h>
@@ -734,14 +733,14 @@ static int vidioc_querycap (struct file *file, void *priv,
734 struct cx88_core *core = dev->core; 733 struct cx88_core *core = dev->core;
735 734
736 strcpy(cap->driver, "cx88_blackbird"); 735 strcpy(cap->driver, "cx88_blackbird");
737 strlcpy(cap->card, cx88_boards[core->board].name,sizeof(cap->card)); 736 strlcpy(cap->card, core->board.name, sizeof(cap->card));
738 sprintf(cap->bus_info,"PCI:%s",pci_name(dev->pci)); 737 sprintf(cap->bus_info,"PCI:%s",pci_name(dev->pci));
739 cap->version = CX88_VERSION_CODE; 738 cap->version = CX88_VERSION_CODE;
740 cap->capabilities = 739 cap->capabilities =
741 V4L2_CAP_VIDEO_CAPTURE | 740 V4L2_CAP_VIDEO_CAPTURE |
742 V4L2_CAP_READWRITE | 741 V4L2_CAP_READWRITE |
743 V4L2_CAP_STREAMING; 742 V4L2_CAP_STREAMING;
744 if (UNSET != core->tuner_type) 743 if (UNSET != core->board.tuner_type)
745 cap->capabilities |= V4L2_CAP_TUNER; 744 cap->capabilities |= V4L2_CAP_TUNER;
746 return 0; 745 return 0;
747} 746}
@@ -877,7 +876,7 @@ static int vidioc_g_ext_ctrls (struct file *file, void *priv,
877 876
878 if (f->ctrl_class != V4L2_CTRL_CLASS_MPEG) 877 if (f->ctrl_class != V4L2_CTRL_CLASS_MPEG)
879 return -EINVAL; 878 return -EINVAL;
880 return cx2341x_ext_ctrls(&dev->params, f, VIDIOC_G_EXT_CTRLS); 879 return cx2341x_ext_ctrls(&dev->params, 0, f, VIDIOC_G_EXT_CTRLS);
881} 880}
882 881
883static int vidioc_s_ext_ctrls (struct file *file, void *priv, 882static int vidioc_s_ext_ctrls (struct file *file, void *priv,
@@ -890,7 +889,7 @@ static int vidioc_s_ext_ctrls (struct file *file, void *priv,
890 if (f->ctrl_class != V4L2_CTRL_CLASS_MPEG) 889 if (f->ctrl_class != V4L2_CTRL_CLASS_MPEG)
891 return -EINVAL; 890 return -EINVAL;
892 p = dev->params; 891 p = dev->params;
893 err = cx2341x_ext_ctrls(&p, f, VIDIOC_S_EXT_CTRLS); 892 err = cx2341x_ext_ctrls(&p, 0, f, VIDIOC_S_EXT_CTRLS);
894 if (!err) { 893 if (!err) {
895 err = cx2341x_update(dev, blackbird_mbox_func, &dev->params, &p); 894 err = cx2341x_update(dev, blackbird_mbox_func, &dev->params, &p);
896 dev->params = p; 895 dev->params = p;
@@ -908,7 +907,7 @@ static int vidioc_try_ext_ctrls (struct file *file, void *priv,
908 if (f->ctrl_class != V4L2_CTRL_CLASS_MPEG) 907 if (f->ctrl_class != V4L2_CTRL_CLASS_MPEG)
909 return -EINVAL; 908 return -EINVAL;
910 p = dev->params; 909 p = dev->params;
911 err = cx2341x_ext_ctrls(&p, f, VIDIOC_TRY_EXT_CTRLS); 910 err = cx2341x_ext_ctrls(&p, 0, f, VIDIOC_TRY_EXT_CTRLS);
912 911
913 return err; 912 return err;
914} 913}
@@ -990,7 +989,7 @@ static int vidioc_g_frequency (struct file *file, void *priv,
990 struct cx8802_fh *fh = priv; 989 struct cx8802_fh *fh = priv;
991 struct cx88_core *core = fh->dev->core; 990 struct cx88_core *core = fh->dev->core;
992 991
993 if (unlikely(UNSET == core->tuner_type)) 992 if (unlikely(UNSET == core->board.tuner_type))
994 return -EINVAL; 993 return -EINVAL;
995 994
996 f->type = V4L2_TUNER_ANALOG_TV; 995 f->type = V4L2_TUNER_ANALOG_TV;
@@ -1028,7 +1027,7 @@ static int vidioc_g_tuner (struct file *file, void *priv,
1028 struct cx88_core *core = ((struct cx8802_fh *)priv)->dev->core; 1027 struct cx88_core *core = ((struct cx8802_fh *)priv)->dev->core;
1029 u32 reg; 1028 u32 reg;
1030 1029
1031 if (unlikely(UNSET == core->tuner_type)) 1030 if (unlikely(UNSET == core->board.tuner_type))
1032 return -EINVAL; 1031 return -EINVAL;
1033 if (0 != t->index) 1032 if (0 != t->index)
1034 return -EINVAL; 1033 return -EINVAL;
@@ -1049,7 +1048,7 @@ static int vidioc_s_tuner (struct file *file, void *priv,
1049{ 1048{
1050 struct cx88_core *core = ((struct cx8802_fh *)priv)->dev->core; 1049 struct cx88_core *core = ((struct cx8802_fh *)priv)->dev->core;
1051 1050
1052 if (UNSET == core->tuner_type) 1051 if (UNSET == core->board.tuner_type)
1053 return -EINVAL; 1052 return -EINVAL;
1054 if (0 != t->index) 1053 if (0 != t->index)
1055 return -EINVAL; 1054 return -EINVAL;
@@ -1078,7 +1077,7 @@ static int mpeg_open(struct inode *inode, struct file *file)
1078 struct cx8802_driver *drv = NULL; 1077 struct cx8802_driver *drv = NULL;
1079 int err; 1078 int err;
1080 1079
1081 dev = cx8802_get_device(inode); 1080 dev = cx8802_get_device(inode);
1082 1081
1083 dprintk( 1, "%s\n", __FUNCTION__); 1082 dprintk( 1, "%s\n", __FUNCTION__);
1084 1083
@@ -1112,7 +1111,7 @@ static int mpeg_open(struct inode *inode, struct file *file)
1112 file->private_data = fh; 1111 file->private_data = fh;
1113 fh->dev = dev; 1112 fh->dev = dev;
1114 1113
1115 videobuf_queue_init(&fh->mpegq, &blackbird_qops, 1114 videobuf_queue_pci_init(&fh->mpegq, &blackbird_qops,
1116 dev->pci, &dev->slock, 1115 dev->pci, &dev->slock,
1117 V4L2_BUF_TYPE_VIDEO_CAPTURE, 1116 V4L2_BUF_TYPE_VIDEO_CAPTURE,
1118 V4L2_FIELD_INTERLACED, 1117 V4L2_FIELD_INTERLACED,
@@ -1235,7 +1234,7 @@ static struct video_device cx8802_mpeg_template =
1235 .vidioc_s_tuner = vidioc_s_tuner, 1234 .vidioc_s_tuner = vidioc_s_tuner,
1236 .vidioc_s_std = vidioc_s_std, 1235 .vidioc_s_std = vidioc_s_std,
1237 .tvnorms = CX88_NORMS, 1236 .tvnorms = CX88_NORMS,
1238 .current_norm = V4L2_STD_NTSC_M, 1237 .current_norm = V4L2_STD_NTSC_M,
1239}; 1238};
1240 1239
1241/* ------------------------------------------------------------------ */ 1240/* ------------------------------------------------------------------ */
@@ -1246,7 +1245,7 @@ static int cx8802_blackbird_advise_acquire(struct cx8802_driver *drv)
1246 struct cx88_core *core = drv->core; 1245 struct cx88_core *core = drv->core;
1247 int err = 0; 1246 int err = 0;
1248 1247
1249 switch (core->board) { 1248 switch (core->boardnr) {
1250 case CX88_BOARD_HAUPPAUGE_HVR1300: 1249 case CX88_BOARD_HAUPPAUGE_HVR1300:
1251 /* By default, core setup will leave the cx22702 out of reset, on the bus. 1250 /* By default, core setup will leave the cx22702 out of reset, on the bus.
1252 * We left the hardware on power up with the cx22702 active. 1251 * We left the hardware on power up with the cx22702 active.
@@ -1268,7 +1267,7 @@ static int cx8802_blackbird_advise_release(struct cx8802_driver *drv)
1268 struct cx88_core *core = drv->core; 1267 struct cx88_core *core = drv->core;
1269 int err = 0; 1268 int err = 0;
1270 1269
1271 switch (core->board) { 1270 switch (core->boardnr) {
1272 case CX88_BOARD_HAUPPAUGE_HVR1300: 1271 case CX88_BOARD_HAUPPAUGE_HVR1300:
1273 /* Exit leaving the cx23416 on the bus */ 1272 /* Exit leaving the cx23416 on the bus */
1274 break; 1273 break;
@@ -1316,13 +1315,13 @@ static int cx8802_blackbird_probe(struct cx8802_driver *drv)
1316 1315
1317 dprintk( 1, "%s\n", __FUNCTION__); 1316 dprintk( 1, "%s\n", __FUNCTION__);
1318 dprintk( 1, " ->being probed by Card=%d Name=%s, PCI %02x:%02x\n", 1317 dprintk( 1, " ->being probed by Card=%d Name=%s, PCI %02x:%02x\n",
1319 core->board, 1318 core->boardnr,
1320 core->name, 1319 core->name,
1321 core->pci_bus, 1320 core->pci_bus,
1322 core->pci_slot); 1321 core->pci_slot);
1323 1322
1324 err = -ENODEV; 1323 err = -ENODEV;
1325 if (!(cx88_boards[core->board].mpeg & CX88_MPEG_BLACKBIRD)) 1324 if (!(core->board.mpeg & CX88_MPEG_BLACKBIRD))
1326 goto fail_core; 1325 goto fail_core;
1327 1326
1328 dev->width = 720; 1327 dev->width = 720;
diff --git a/drivers/media/video/cx88/cx88-cards.c b/drivers/media/video/cx88/cx88-cards.c
index 6a136ddbccf8..a4eb6a87a761 100644
--- a/drivers/media/video/cx88/cx88-cards.c
+++ b/drivers/media/video/cx88/cx88-cards.c
@@ -27,10 +27,26 @@
27 27
28#include "cx88.h" 28#include "cx88.h"
29 29
30static unsigned int tuner[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
31static unsigned int radio[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
32static unsigned int card[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
33
34module_param_array(tuner, int, NULL, 0444);
35module_param_array(radio, int, NULL, 0444);
36module_param_array(card, int, NULL, 0444);
37
38MODULE_PARM_DESC(tuner,"tuner type");
39MODULE_PARM_DESC(radio,"radio tuner type");
40MODULE_PARM_DESC(card,"card type");
41
42static unsigned int latency = UNSET;
43module_param(latency,int,0444);
44MODULE_PARM_DESC(latency,"pci latency timer");
45
30/* ------------------------------------------------------------------ */ 46/* ------------------------------------------------------------------ */
31/* board config info */ 47/* board config info */
32 48
33struct cx88_board cx88_boards[] = { 49static const struct cx88_board cx88_boards[] = {
34 [CX88_BOARD_UNKNOWN] = { 50 [CX88_BOARD_UNKNOWN] = {
35 .name = "UNKNOWN/GENERIC", 51 .name = "UNKNOWN/GENERIC",
36 .tuner_type = UNSET, 52 .tuner_type = UNSET,
@@ -575,35 +591,34 @@ struct cx88_board cx88_boards[] = {
575 .tuner_addr = ADDR_UNSET, 591 .tuner_addr = ADDR_UNSET,
576 .radio_addr = ADDR_UNSET, 592 .radio_addr = ADDR_UNSET,
577 .tda9887_conf = TDA9887_PRESENT, 593 .tda9887_conf = TDA9887_PRESENT,
594 /* GPIO[2] = audio source for analog audio out connector
595 * 0 = analog audio input connector
596 * 1 = CX88 audio DACs
597 *
598 * GPIO[7] = input to CX88's audio/chroma ADC
599 * 0 = FM 10.7 MHz IF
600 * 1 = Sound 4.5 MHz IF
601 *
602 * GPIO[1,5,6] = Oren 51132 pins 27,35,28 respectively
603 *
604 * GPIO[16] = Remote control input
605 */
578 .input = {{ 606 .input = {{
579 .type = CX88_VMUX_TELEVISION, 607 .type = CX88_VMUX_TELEVISION,
580 .vmux = 0, 608 .vmux = 0,
581 .gpio0 = 0x00008484, 609 .gpio0 = 0x00008484,
582 .gpio1 = 0x00000000,
583 .gpio2 = 0x00000000,
584 .gpio3 = 0x00000000,
585 },{ 610 },{
586 .type = CX88_VMUX_COMPOSITE1, 611 .type = CX88_VMUX_COMPOSITE1,
587 .vmux = 1, 612 .vmux = 1,
588 .gpio0 = 0x00008400, 613 .gpio0 = 0x00008400,
589 .gpio1 = 0x00000000,
590 .gpio2 = 0x00000000,
591 .gpio3 = 0x00000000,
592 },{ 614 },{
593 .type = CX88_VMUX_SVIDEO, 615 .type = CX88_VMUX_SVIDEO,
594 .vmux = 2, 616 .vmux = 2,
595 .gpio0 = 0x00008400, 617 .gpio0 = 0x00008400,
596 .gpio1 = 0x00000000,
597 .gpio2 = 0x00000000,
598 .gpio3 = 0x00000000,
599 }}, 618 }},
600 .radio = { 619 .radio = {
601 .type = CX88_RADIO, 620 .type = CX88_RADIO,
602 .vmux = 2, 621 .gpio0 = 0x00008404,
603 .gpio0 = 0x00008400,
604 .gpio1 = 0x00000000,
605 .gpio2 = 0x00000000,
606 .gpio3 = 0x00000000,
607 }, 622 },
608 .mpeg = CX88_MPEG_DVB, 623 .mpeg = CX88_MPEG_DVB,
609 }, 624 },
@@ -1356,12 +1371,11 @@ struct cx88_board cx88_boards[] = {
1356 }}, 1371 }},
1357 }, 1372 },
1358}; 1373};
1359const unsigned int cx88_bcount = ARRAY_SIZE(cx88_boards);
1360 1374
1361/* ------------------------------------------------------------------ */ 1375/* ------------------------------------------------------------------ */
1362/* PCI subsystem IDs */ 1376/* PCI subsystem IDs */
1363 1377
1364struct cx88_subid cx88_subids[] = { 1378static const struct cx88_subid cx88_subids[] = {
1365 { 1379 {
1366 .subvendor = 0x0070, 1380 .subvendor = 0x0070,
1367 .subdevice = 0x3400, 1381 .subdevice = 0x3400,
@@ -1667,7 +1681,6 @@ struct cx88_subid cx88_subids[] = {
1667 .card = CX88_BOARD_ADSTECH_PTV_390, 1681 .card = CX88_BOARD_ADSTECH_PTV_390,
1668 }, 1682 },
1669}; 1683};
1670const unsigned int cx88_idcount = ARRAY_SIZE(cx88_subids);
1671 1684
1672/* ----------------------------------------------------------------------- */ 1685/* ----------------------------------------------------------------------- */
1673/* some leadtek specific stuff */ 1686/* some leadtek specific stuff */
@@ -1688,12 +1701,12 @@ static void leadtek_eeprom(struct cx88_core *core, u8 *eeprom_data)
1688 return; 1701 return;
1689 } 1702 }
1690 1703
1691 core->has_radio = 1; 1704 core->board.tuner_type = (eeprom_data[6] == 0x13) ?
1692 core->tuner_type = (eeprom_data[6] == 0x13) ? 43 : 38; 1705 TUNER_PHILIPS_FM1236_MK3 : TUNER_PHILIPS_FM1216ME_MK3;
1693 1706
1694 printk(KERN_INFO "%s: Leadtek Winfast 2000XP Expert config: " 1707 printk(KERN_INFO "%s: Leadtek Winfast 2000XP Expert config: "
1695 "tuner=%d, eeprom[0]=0x%02x\n", 1708 "tuner=%d, eeprom[0]=0x%02x\n",
1696 core->name, core->tuner_type, eeprom_data[0]); 1709 core->name, core->board.tuner_type, eeprom_data[0]);
1697} 1710}
1698 1711
1699static void hauppauge_eeprom(struct cx88_core *core, u8 *eeprom_data) 1712static void hauppauge_eeprom(struct cx88_core *core, u8 *eeprom_data)
@@ -1701,9 +1714,9 @@ static void hauppauge_eeprom(struct cx88_core *core, u8 *eeprom_data)
1701 struct tveeprom tv; 1714 struct tveeprom tv;
1702 1715
1703 tveeprom_hauppauge_analog(&core->i2c_client, &tv, eeprom_data); 1716 tveeprom_hauppauge_analog(&core->i2c_client, &tv, eeprom_data);
1704 core->tuner_type = tv.tuner_type; 1717 core->board.tuner_type = tv.tuner_type;
1705 core->tuner_formats = tv.tuner_formats; 1718 core->tuner_formats = tv.tuner_formats;
1706 core->has_radio = tv.has_radio; 1719 core->board.radio.type = tv.has_radio ? CX88_RADIO : 0;
1707 1720
1708 /* Make sure we support the board model */ 1721 /* Make sure we support the board model */
1709 switch (tv.model) 1722 switch (tv.model)
@@ -1793,8 +1806,9 @@ static void gdi_eeprom(struct cx88_core *core, u8 *eeprom_data)
1793 name ? name : "unknown"); 1806 name ? name : "unknown");
1794 if (NULL == name) 1807 if (NULL == name)
1795 return; 1808 return;
1796 core->tuner_type = gdi_tuner[eeprom_data[0x0d]].id; 1809 core->board.tuner_type = gdi_tuner[eeprom_data[0x0d]].id;
1797 core->has_radio = gdi_tuner[eeprom_data[0x0d]].fm; 1810 core->board.radio.type = gdi_tuner[eeprom_data[0x0d]].fm ?
1811 CX88_RADIO : 0;
1798} 1812}
1799 1813
1800/* ----------------------------------------------------------------------- */ 1814/* ----------------------------------------------------------------------- */
@@ -1833,7 +1847,7 @@ static void dvico_fusionhdtv_hybrid_init(struct cx88_core *core)
1833 1847
1834/* ----------------------------------------------------------------------- */ 1848/* ----------------------------------------------------------------------- */
1835 1849
1836void cx88_card_list(struct cx88_core *core, struct pci_dev *pci) 1850static void cx88_card_list(struct cx88_core *core, struct pci_dev *pci)
1837{ 1851{
1838 int i; 1852 int i;
1839 1853
@@ -1854,14 +1868,14 @@ void cx88_card_list(struct cx88_core *core, struct pci_dev *pci)
1854 } 1868 }
1855 printk("%s: Here is a list of valid choices for the card=<n> insmod option:\n", 1869 printk("%s: Here is a list of valid choices for the card=<n> insmod option:\n",
1856 core->name); 1870 core->name);
1857 for (i = 0; i < cx88_bcount; i++) 1871 for (i = 0; i < ARRAY_SIZE(cx88_boards); i++)
1858 printk("%s: card=%d -> %s\n", 1872 printk("%s: card=%d -> %s\n",
1859 core->name, i, cx88_boards[i].name); 1873 core->name, i, cx88_boards[i].name);
1860} 1874}
1861 1875
1862void cx88_card_setup_pre_i2c(struct cx88_core *core) 1876static void cx88_card_setup_pre_i2c(struct cx88_core *core)
1863{ 1877{
1864 switch (core->board) { 1878 switch (core->boardnr) {
1865 case CX88_BOARD_HAUPPAUGE_HVR1300: 1879 case CX88_BOARD_HAUPPAUGE_HVR1300:
1866 /* Bring the 702 demod up before i2c scanning/attach or devices are hidden */ 1880 /* Bring the 702 demod up before i2c scanning/attach or devices are hidden */
1867 /* We leave here with the 702 on the bus */ 1881 /* We leave here with the 702 on the bus */
@@ -1875,7 +1889,7 @@ void cx88_card_setup_pre_i2c(struct cx88_core *core)
1875 } 1889 }
1876} 1890}
1877 1891
1878void cx88_card_setup(struct cx88_core *core) 1892static void cx88_card_setup(struct cx88_core *core)
1879{ 1893{
1880 static u8 eeprom[256]; 1894 static u8 eeprom[256];
1881 1895
@@ -1884,7 +1898,7 @@ void cx88_card_setup(struct cx88_core *core)
1884 tveeprom_read(&core->i2c_client,eeprom,sizeof(eeprom)); 1898 tveeprom_read(&core->i2c_client,eeprom,sizeof(eeprom));
1885 } 1899 }
1886 1900
1887 switch (core->board) { 1901 switch (core->boardnr) {
1888 case CX88_BOARD_HAUPPAUGE: 1902 case CX88_BOARD_HAUPPAUGE:
1889 case CX88_BOARD_HAUPPAUGE_ROSLYN: 1903 case CX88_BOARD_HAUPPAUGE_ROSLYN:
1890 if (0 == core->i2c_rc) 1904 if (0 == core->i2c_rc)
@@ -1928,7 +1942,7 @@ void cx88_card_setup(struct cx88_core *core)
1928 msleep(1); 1942 msleep(1);
1929 cx_set(MO_GP0_IO, 0x00000101); 1943 cx_set(MO_GP0_IO, 0x00000101);
1930 if (0 == core->i2c_rc && 1944 if (0 == core->i2c_rc &&
1931 core->board == CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_HYBRID) 1945 core->boardnr == CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_HYBRID)
1932 dvico_fusionhdtv_hybrid_init(core); 1946 dvico_fusionhdtv_hybrid_init(core);
1933 break; 1947 break;
1934 case CX88_BOARD_KWORLD_DVB_T: 1948 case CX88_BOARD_KWORLD_DVB_T:
@@ -1966,13 +1980,148 @@ void cx88_card_setup(struct cx88_core *core)
1966 } 1980 }
1967 break; 1981 break;
1968 } 1982 }
1969 if (cx88_boards[core->board].radio.type == CX88_RADIO)
1970 core->has_radio = 1;
1971} 1983}
1972 1984
1973/* ------------------------------------------------------------------ */ 1985/* ------------------------------------------------------------------ */
1974 1986
1975EXPORT_SYMBOL(cx88_boards); 1987static int cx88_pci_quirks(const char *name, struct pci_dev *pci)
1988{
1989 unsigned int lat = UNSET;
1990 u8 ctrl = 0;
1991 u8 value;
1992
1993 /* check pci quirks */
1994 if (pci_pci_problems & PCIPCI_TRITON) {
1995 printk(KERN_INFO "%s: quirk: PCIPCI_TRITON -- set TBFX\n",
1996 name);
1997 ctrl |= CX88X_EN_TBFX;
1998 }
1999 if (pci_pci_problems & PCIPCI_NATOMA) {
2000 printk(KERN_INFO "%s: quirk: PCIPCI_NATOMA -- set TBFX\n",
2001 name);
2002 ctrl |= CX88X_EN_TBFX;
2003 }
2004 if (pci_pci_problems & PCIPCI_VIAETBF) {
2005 printk(KERN_INFO "%s: quirk: PCIPCI_VIAETBF -- set TBFX\n",
2006 name);
2007 ctrl |= CX88X_EN_TBFX;
2008 }
2009 if (pci_pci_problems & PCIPCI_VSFX) {
2010 printk(KERN_INFO "%s: quirk: PCIPCI_VSFX -- set VSFX\n",
2011 name);
2012 ctrl |= CX88X_EN_VSFX;
2013 }
2014#ifdef PCIPCI_ALIMAGIK
2015 if (pci_pci_problems & PCIPCI_ALIMAGIK) {
2016 printk(KERN_INFO "%s: quirk: PCIPCI_ALIMAGIK -- latency fixup\n",
2017 name);
2018 lat = 0x0A;
2019 }
2020#endif
2021
2022 /* check insmod options */
2023 if (UNSET != latency)
2024 lat = latency;
2025
2026 /* apply stuff */
2027 if (ctrl) {
2028 pci_read_config_byte(pci, CX88X_DEVCTRL, &value);
2029 value |= ctrl;
2030 pci_write_config_byte(pci, CX88X_DEVCTRL, value);
2031 }
2032 if (UNSET != lat) {
2033 printk(KERN_INFO "%s: setting pci latency timer to %d\n",
2034 name, latency);
2035 pci_write_config_byte(pci, PCI_LATENCY_TIMER, latency);
2036 }
2037 return 0;
2038}
2039
2040int cx88_get_resources(const struct cx88_core *core, struct pci_dev *pci)
2041{
2042 if (request_mem_region(pci_resource_start(pci,0),
2043 pci_resource_len(pci,0),
2044 core->name))
2045 return 0;
2046 printk(KERN_ERR
2047 "%s/%d: Can't get MMIO memory @ 0x%llx, subsystem: %04x:%04x\n",
2048 core->name, PCI_FUNC(pci->devfn),
2049 (unsigned long long)pci_resource_start(pci, 0),
2050 pci->subsystem_vendor, pci->subsystem_device);
2051 return -EBUSY;
2052}
2053
2054/* Allocate and initialize the cx88 core struct. One should hold the
2055 * devlist mutex before calling this. */
2056struct cx88_core *cx88_core_create(struct pci_dev *pci, int nr)
2057{
2058 struct cx88_core *core;
2059 int i;
2060
2061 core = kzalloc(sizeof(*core), GFP_KERNEL);
2062
2063 atomic_inc(&core->refcount);
2064 core->pci_bus = pci->bus->number;
2065 core->pci_slot = PCI_SLOT(pci->devfn);
2066 core->pci_irqmask = PCI_INT_RISC_RD_BERRINT | PCI_INT_RISC_WR_BERRINT |
2067 PCI_INT_BRDG_BERRINT | PCI_INT_SRC_DMA_BERRINT |
2068 PCI_INT_DST_DMA_BERRINT | PCI_INT_IPB_DMA_BERRINT;
2069 mutex_init(&core->lock);
2070
2071 core->nr = nr;
2072 sprintf(core->name, "cx88[%d]", core->nr);
2073 if (0 != cx88_get_resources(core, pci)) {
2074 kfree(core);
2075 return NULL;
2076 }
2077
2078 /* PCI stuff */
2079 cx88_pci_quirks(core->name, pci);
2080 core->lmmio = ioremap(pci_resource_start(pci, 0),
2081 pci_resource_len(pci, 0));
2082 core->bmmio = (u8 __iomem *)core->lmmio;
2083
2084 /* board config */
2085 core->boardnr = UNSET;
2086 if (card[core->nr] < ARRAY_SIZE(cx88_boards))
2087 core->boardnr = card[core->nr];
2088 for (i = 0; UNSET == core->boardnr && i < ARRAY_SIZE(cx88_subids); i++)
2089 if (pci->subsystem_vendor == cx88_subids[i].subvendor &&
2090 pci->subsystem_device == cx88_subids[i].subdevice)
2091 core->boardnr = cx88_subids[i].card;
2092 if (UNSET == core->boardnr) {
2093 core->boardnr = CX88_BOARD_UNKNOWN;
2094 cx88_card_list(core, pci);
2095 }
2096
2097 memcpy(&core->board, &cx88_boards[core->boardnr], sizeof(core->board));
2098
2099 printk(KERN_INFO "%s: subsystem: %04x:%04x, board: %s [card=%d,%s]\n",
2100 core->name,pci->subsystem_vendor,
2101 pci->subsystem_device, core->board.name,
2102 core->boardnr, card[core->nr] == core->boardnr ?
2103 "insmod option" : "autodetected");
2104
2105 if (tuner[core->nr] != UNSET)
2106 core->board.tuner_type = tuner[core->nr];
2107 if (radio[core->nr] != UNSET)
2108 core->board.radio_type = radio[core->nr];
2109
2110 printk(KERN_INFO "%s: TV tuner type %d, Radio tuner type %d\n",
2111 core->name, core->board.tuner_type, core->board.radio_type);
2112
2113 /* init hardware */
2114 cx88_reset(core);
2115 cx88_card_setup_pre_i2c(core);
2116 cx88_i2c_init(core, pci);
2117 cx88_call_i2c_clients (core, TUNER_SET_STANDBY, NULL);
2118 cx88_card_setup(core);
2119 cx88_ir_init(core, pci);
2120
2121 return core;
2122}
2123
2124/* ------------------------------------------------------------------ */
1976 2125
1977/* 2126/*
1978 * Local variables: 2127 * Local variables:
diff --git a/drivers/media/video/cx88/cx88-core.c b/drivers/media/video/cx88/cx88-core.c
index f31ec96924b9..62e8dd24c5f5 100644
--- a/drivers/media/video/cx88/cx88-core.c
+++ b/drivers/media/video/cx88/cx88-core.c
@@ -28,7 +28,6 @@
28#include <linux/init.h> 28#include <linux/init.h>
29#include <linux/list.h> 29#include <linux/list.h>
30#include <linux/module.h> 30#include <linux/module.h>
31#include <linux/moduleparam.h>
32#include <linux/kernel.h> 31#include <linux/kernel.h>
33#include <linux/slab.h> 32#include <linux/slab.h>
34#include <linux/kmod.h> 33#include <linux/kmod.h>
@@ -52,22 +51,6 @@ static unsigned int core_debug = 0;
52module_param(core_debug,int,0644); 51module_param(core_debug,int,0644);
53MODULE_PARM_DESC(core_debug,"enable debug messages [core]"); 52MODULE_PARM_DESC(core_debug,"enable debug messages [core]");
54 53
55static unsigned int latency = UNSET;
56module_param(latency,int,0444);
57MODULE_PARM_DESC(latency,"pci latency timer");
58
59static unsigned int tuner[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
60static unsigned int radio[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
61static unsigned int card[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
62
63module_param_array(tuner, int, NULL, 0444);
64module_param_array(radio, int, NULL, 0444);
65module_param_array(card, int, NULL, 0444);
66
67MODULE_PARM_DESC(tuner,"tuner type");
68MODULE_PARM_DESC(radio,"radio tuner type");
69MODULE_PARM_DESC(card,"card type");
70
71static unsigned int nicam = 0; 54static unsigned int nicam = 0;
72module_param(nicam,int,0644); 55module_param(nicam,int,0644);
73MODULE_PARM_DESC(nicam,"tv audio is nicam"); 56MODULE_PARM_DESC(nicam,"tv audio is nicam");
@@ -85,13 +68,15 @@ static DEFINE_MUTEX(devlist);
85 68
86#define NO_SYNC_LINE (-1U) 69#define NO_SYNC_LINE (-1U)
87 70
71/* @lpi: lines per IRQ, or 0 to not generate irqs. Note: IRQ to be
72 generated _after_ lpi lines are transferred. */
88static u32* cx88_risc_field(u32 *rp, struct scatterlist *sglist, 73static u32* cx88_risc_field(u32 *rp, struct scatterlist *sglist,
89 unsigned int offset, u32 sync_line, 74 unsigned int offset, u32 sync_line,
90 unsigned int bpl, unsigned int padding, 75 unsigned int bpl, unsigned int padding,
91 unsigned int lines) 76 unsigned int lines, unsigned int lpi)
92{ 77{
93 struct scatterlist *sg; 78 struct scatterlist *sg;
94 unsigned int line,todo; 79 unsigned int line,todo,sol;
95 80
96 /* sync instruction */ 81 /* sync instruction */
97 if (sync_line != NO_SYNC_LINE) 82 if (sync_line != NO_SYNC_LINE)
@@ -104,15 +89,19 @@ static u32* cx88_risc_field(u32 *rp, struct scatterlist *sglist,
104 offset -= sg_dma_len(sg); 89 offset -= sg_dma_len(sg);
105 sg++; 90 sg++;
106 } 91 }
92 if (lpi && line>0 && !(line % lpi))
93 sol = RISC_SOL | RISC_IRQ1 | RISC_CNT_INC;
94 else
95 sol = RISC_SOL;
107 if (bpl <= sg_dma_len(sg)-offset) { 96 if (bpl <= sg_dma_len(sg)-offset) {
108 /* fits into current chunk */ 97 /* fits into current chunk */
109 *(rp++)=cpu_to_le32(RISC_WRITE|RISC_SOL|RISC_EOL|bpl); 98 *(rp++)=cpu_to_le32(RISC_WRITE|sol|RISC_EOL|bpl);
110 *(rp++)=cpu_to_le32(sg_dma_address(sg)+offset); 99 *(rp++)=cpu_to_le32(sg_dma_address(sg)+offset);
111 offset+=bpl; 100 offset+=bpl;
112 } else { 101 } else {
113 /* scanline needs to be split */ 102 /* scanline needs to be split */
114 todo = bpl; 103 todo = bpl;
115 *(rp++)=cpu_to_le32(RISC_WRITE|RISC_SOL| 104 *(rp++)=cpu_to_le32(RISC_WRITE|sol|
116 (sg_dma_len(sg)-offset)); 105 (sg_dma_len(sg)-offset));
117 *(rp++)=cpu_to_le32(sg_dma_address(sg)+offset); 106 *(rp++)=cpu_to_le32(sg_dma_address(sg)+offset);
118 todo -= (sg_dma_len(sg)-offset); 107 todo -= (sg_dma_len(sg)-offset);
@@ -163,10 +152,10 @@ int cx88_risc_buffer(struct pci_dev *pci, struct btcx_riscmem *risc,
163 rp = risc->cpu; 152 rp = risc->cpu;
164 if (UNSET != top_offset) 153 if (UNSET != top_offset)
165 rp = cx88_risc_field(rp, sglist, top_offset, 0, 154 rp = cx88_risc_field(rp, sglist, top_offset, 0,
166 bpl, padding, lines); 155 bpl, padding, lines, 0);
167 if (UNSET != bottom_offset) 156 if (UNSET != bottom_offset)
168 rp = cx88_risc_field(rp, sglist, bottom_offset, 0x200, 157 rp = cx88_risc_field(rp, sglist, bottom_offset, 0x200,
169 bpl, padding, lines); 158 bpl, padding, lines, 0);
170 159
171 /* save pointer to jmp instruction address */ 160 /* save pointer to jmp instruction address */
172 risc->jmp = rp; 161 risc->jmp = rp;
@@ -176,7 +165,7 @@ int cx88_risc_buffer(struct pci_dev *pci, struct btcx_riscmem *risc,
176 165
177int cx88_risc_databuffer(struct pci_dev *pci, struct btcx_riscmem *risc, 166int cx88_risc_databuffer(struct pci_dev *pci, struct btcx_riscmem *risc,
178 struct scatterlist *sglist, unsigned int bpl, 167 struct scatterlist *sglist, unsigned int bpl,
179 unsigned int lines) 168 unsigned int lines, unsigned int lpi)
180{ 169{
181 u32 instructions; 170 u32 instructions;
182 u32 *rp; 171 u32 *rp;
@@ -193,7 +182,7 @@ int cx88_risc_databuffer(struct pci_dev *pci, struct btcx_riscmem *risc,
193 182
194 /* write risc instructions */ 183 /* write risc instructions */
195 rp = risc->cpu; 184 rp = risc->cpu;
196 rp = cx88_risc_field(rp, sglist, 0, NO_SYNC_LINE, bpl, 0, lines); 185 rp = cx88_risc_field(rp, sglist, 0, NO_SYNC_LINE, bpl, 0, lines, lpi);
197 186
198 /* save pointer to jmp instruction address */ 187 /* save pointer to jmp instruction address */
199 risc->jmp = rp; 188 risc->jmp = rp;
@@ -224,10 +213,12 @@ int cx88_risc_stopper(struct pci_dev *pci, struct btcx_riscmem *risc,
224void 213void
225cx88_free_buffer(struct videobuf_queue *q, struct cx88_buffer *buf) 214cx88_free_buffer(struct videobuf_queue *q, struct cx88_buffer *buf)
226{ 215{
216 struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb);
217
227 BUG_ON(in_interrupt()); 218 BUG_ON(in_interrupt());
228 videobuf_waiton(&buf->vb,0,0); 219 videobuf_waiton(&buf->vb,0,0);
229 videobuf_dma_unmap(q, &buf->vb.dma); 220 videobuf_dma_unmap(q, dma);
230 videobuf_dma_free(&buf->vb.dma); 221 videobuf_dma_free(dma);
231 btcx_riscmem_free((struct pci_dev *)q->dev, &buf->risc); 222 btcx_riscmem_free((struct pci_dev *)q->dev, &buf->risc);
232 buf->vb.state = STATE_NEEDS_INIT; 223 buf->vb.state = STATE_NEEDS_INIT;
233} 224}
@@ -451,10 +442,13 @@ void cx88_sram_channel_dump(struct cx88_core *core,
451 printk("%s: cmds: %-12s: 0x%08x\n", 442 printk("%s: cmds: %-12s: 0x%08x\n",
452 core->name,name[i], 443 core->name,name[i],
453 cx_read(ch->cmds_start + 4*i)); 444 cx_read(ch->cmds_start + 4*i));
454 for (i = 0; i < 4; i++) { 445 for (n = 1, i = 0; i < 4; i++) {
455 risc = cx_read(ch->cmds_start + 4 * (i+11)); 446 risc = cx_read(ch->cmds_start + 4 * (i+11));
456 printk("%s: risc%d: ", core->name, i); 447 printk("%s: risc%d: ", core->name, i);
457 cx88_risc_decode(risc); 448 if (--n)
449 printk("0x%08x [ arg #%d ]\n", risc, n);
450 else
451 n = cx88_risc_decode(risc);
458 } 452 }
459 for (i = 0; i < 16; i += n) { 453 for (i = 0; i < 16; i += n) {
460 risc = cx_read(ch->ctrl_start + 4 * i); 454 risc = cx_read(ch->ctrl_start + 4 * i);
@@ -514,7 +508,7 @@ int cx88_core_irq(struct cx88_core *core, u32 status)
514{ 508{
515 int handled = 0; 509 int handled = 0;
516 510
517 if (status & (1<<18)) { 511 if (status & PCI_INT_IR_SMPINT) {
518 cx88_ir_irq(core); 512 cx88_ir_irq(core);
519 handled++; 513 handled++;
520 } 514 }
@@ -738,7 +732,7 @@ int cx88_set_scale(struct cx88_core *core, unsigned int width, unsigned int heig
738 value |= (1 << 15); 732 value |= (1 << 15);
739 value |= (1 << 16); 733 value |= (1 << 16);
740 } 734 }
741 if (INPUT(core->input)->type == CX88_VMUX_SVIDEO) 735 if (INPUT(core->input).type == CX88_VMUX_SVIDEO)
742 value |= (1 << 13) | (1 << 5); 736 value |= (1 << 13) | (1 << 5);
743 if (V4L2_FIELD_INTERLACED == field) 737 if (V4L2_FIELD_INTERLACED == field)
744 value |= (1 << 3); // VINT (interlaced vertical scaling) 738 value |= (1 << 3); // VINT (interlaced vertical scaling)
@@ -833,7 +827,7 @@ static int set_tvaudio(struct cx88_core *core)
833{ 827{
834 v4l2_std_id norm = core->tvnorm; 828 v4l2_std_id norm = core->tvnorm;
835 829
836 if (CX88_VMUX_TELEVISION != INPUT(core->input)->type) 830 if (CX88_VMUX_TELEVISION != INPUT(core->input).type)
837 return 0; 831 return 0;
838 832
839 if (V4L2_STD_PAL_BG & norm) { 833 if (V4L2_STD_PAL_BG & norm) {
@@ -997,61 +991,6 @@ int cx88_set_tvnorm(struct cx88_core *core, v4l2_std_id norm)
997 991
998/* ------------------------------------------------------------------ */ 992/* ------------------------------------------------------------------ */
999 993
1000static int cx88_pci_quirks(char *name, struct pci_dev *pci)
1001{
1002 unsigned int lat = UNSET;
1003 u8 ctrl = 0;
1004 u8 value;
1005
1006 /* check pci quirks */
1007 if (pci_pci_problems & PCIPCI_TRITON) {
1008 printk(KERN_INFO "%s: quirk: PCIPCI_TRITON -- set TBFX\n",
1009 name);
1010 ctrl |= CX88X_EN_TBFX;
1011 }
1012 if (pci_pci_problems & PCIPCI_NATOMA) {
1013 printk(KERN_INFO "%s: quirk: PCIPCI_NATOMA -- set TBFX\n",
1014 name);
1015 ctrl |= CX88X_EN_TBFX;
1016 }
1017 if (pci_pci_problems & PCIPCI_VIAETBF) {
1018 printk(KERN_INFO "%s: quirk: PCIPCI_VIAETBF -- set TBFX\n",
1019 name);
1020 ctrl |= CX88X_EN_TBFX;
1021 }
1022 if (pci_pci_problems & PCIPCI_VSFX) {
1023 printk(KERN_INFO "%s: quirk: PCIPCI_VSFX -- set VSFX\n",
1024 name);
1025 ctrl |= CX88X_EN_VSFX;
1026 }
1027#ifdef PCIPCI_ALIMAGIK
1028 if (pci_pci_problems & PCIPCI_ALIMAGIK) {
1029 printk(KERN_INFO "%s: quirk: PCIPCI_ALIMAGIK -- latency fixup\n",
1030 name);
1031 lat = 0x0A;
1032 }
1033#endif
1034
1035 /* check insmod options */
1036 if (UNSET != latency)
1037 lat = latency;
1038
1039 /* apply stuff */
1040 if (ctrl) {
1041 pci_read_config_byte(pci, CX88X_DEVCTRL, &value);
1042 value |= ctrl;
1043 pci_write_config_byte(pci, CX88X_DEVCTRL, value);
1044 }
1045 if (UNSET != lat) {
1046 printk(KERN_INFO "%s: setting pci latency timer to %d\n",
1047 name, latency);
1048 pci_write_config_byte(pci, PCI_LATENCY_TIMER, latency);
1049 }
1050 return 0;
1051}
1052
1053/* ------------------------------------------------------------------ */
1054
1055struct video_device *cx88_vdev_init(struct cx88_core *core, 994struct video_device *cx88_vdev_init(struct cx88_core *core,
1056 struct pci_dev *pci, 995 struct pci_dev *pci,
1057 struct video_device *template, 996 struct video_device *template,
@@ -1067,122 +1006,38 @@ struct video_device *cx88_vdev_init(struct cx88_core *core,
1067 vfd->dev = &pci->dev; 1006 vfd->dev = &pci->dev;
1068 vfd->release = video_device_release; 1007 vfd->release = video_device_release;
1069 snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)", 1008 snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)",
1070 core->name, type, cx88_boards[core->board].name); 1009 core->name, type, core->board.name);
1071 return vfd; 1010 return vfd;
1072} 1011}
1073 1012
1074static int get_ressources(struct cx88_core *core, struct pci_dev *pci)
1075{
1076 if (request_mem_region(pci_resource_start(pci,0),
1077 pci_resource_len(pci,0),
1078 core->name))
1079 return 0;
1080 printk(KERN_ERR "%s: can't get MMIO memory @ 0x%llx\n",
1081 core->name,(unsigned long long)pci_resource_start(pci,0));
1082 return -EBUSY;
1083}
1084
1085struct cx88_core* cx88_core_get(struct pci_dev *pci) 1013struct cx88_core* cx88_core_get(struct pci_dev *pci)
1086{ 1014{
1087 struct cx88_core *core; 1015 struct cx88_core *core;
1088 struct list_head *item;
1089 int i;
1090 1016
1091 mutex_lock(&devlist); 1017 mutex_lock(&devlist);
1092 list_for_each(item,&cx88_devlist) { 1018 list_for_each_entry(core, &cx88_devlist, devlist) {
1093 core = list_entry(item, struct cx88_core, devlist);
1094 if (pci->bus->number != core->pci_bus) 1019 if (pci->bus->number != core->pci_bus)
1095 continue; 1020 continue;
1096 if (PCI_SLOT(pci->devfn) != core->pci_slot) 1021 if (PCI_SLOT(pci->devfn) != core->pci_slot)
1097 continue; 1022 continue;
1098 1023
1099 if (0 != get_ressources(core,pci)) 1024 if (0 != cx88_get_resources(core, pci)) {
1100 goto fail_unlock; 1025 mutex_unlock(&devlist);
1026 return NULL;
1027 }
1101 atomic_inc(&core->refcount); 1028 atomic_inc(&core->refcount);
1102 mutex_unlock(&devlist); 1029 mutex_unlock(&devlist);
1103 return core; 1030 return core;
1104 } 1031 }
1105 core = kzalloc(sizeof(*core),GFP_KERNEL); 1032
1106 if (NULL == core) 1033 core = cx88_core_create(pci, cx88_devcount);
1107 goto fail_unlock; 1034 if (NULL != core) {
1108 1035 cx88_devcount++;
1109 atomic_inc(&core->refcount); 1036 list_add_tail(&core->devlist, &cx88_devlist);
1110 core->pci_bus = pci->bus->number;
1111 core->pci_slot = PCI_SLOT(pci->devfn);
1112 core->pci_irqmask = 0x00fc00;
1113 mutex_init(&core->lock);
1114
1115 core->nr = cx88_devcount++;
1116 sprintf(core->name,"cx88[%d]",core->nr);
1117 if (0 != get_ressources(core,pci)) {
1118 printk(KERN_ERR "CORE %s No more PCI ressources for "
1119 "subsystem: %04x:%04x, board: %s\n",
1120 core->name,pci->subsystem_vendor,
1121 pci->subsystem_device,
1122 cx88_boards[core->board].name);
1123
1124 cx88_devcount--;
1125 goto fail_free;
1126 }
1127 list_add_tail(&core->devlist,&cx88_devlist);
1128
1129 /* PCI stuff */
1130 cx88_pci_quirks(core->name, pci);
1131 core->lmmio = ioremap(pci_resource_start(pci,0),
1132 pci_resource_len(pci,0));
1133 core->bmmio = (u8 __iomem *)core->lmmio;
1134
1135 /* board config */
1136 core->board = UNSET;
1137 if (card[core->nr] < cx88_bcount)
1138 core->board = card[core->nr];
1139 for (i = 0; UNSET == core->board && i < cx88_idcount; i++)
1140 if (pci->subsystem_vendor == cx88_subids[i].subvendor &&
1141 pci->subsystem_device == cx88_subids[i].subdevice)
1142 core->board = cx88_subids[i].card;
1143 if (UNSET == core->board) {
1144 core->board = CX88_BOARD_UNKNOWN;
1145 cx88_card_list(core,pci);
1146 } 1037 }
1147 printk(KERN_INFO "CORE %s: subsystem: %04x:%04x, board: %s [card=%d,%s]\n",
1148 core->name,pci->subsystem_vendor,
1149 pci->subsystem_device,cx88_boards[core->board].name,
1150 core->board, card[core->nr] == core->board ?
1151 "insmod option" : "autodetected");
1152
1153 core->tuner_type = tuner[core->nr];
1154 core->radio_type = radio[core->nr];
1155 if (UNSET == core->tuner_type)
1156 core->tuner_type = cx88_boards[core->board].tuner_type;
1157 if (UNSET == core->radio_type)
1158 core->radio_type = cx88_boards[core->board].radio_type;
1159 if (!core->tuner_addr)
1160 core->tuner_addr = cx88_boards[core->board].tuner_addr;
1161 if (!core->radio_addr)
1162 core->radio_addr = cx88_boards[core->board].radio_addr;
1163
1164 printk(KERN_INFO "TV tuner %d at 0x%02x, Radio tuner %d at 0x%02x\n",
1165 core->tuner_type, core->tuner_addr<<1,
1166 core->radio_type, core->radio_addr<<1);
1167
1168 core->tda9887_conf = cx88_boards[core->board].tda9887_conf;
1169
1170 /* init hardware */
1171 cx88_reset(core);
1172 cx88_card_setup_pre_i2c(core);
1173 cx88_i2c_init(core,pci);
1174 cx88_call_i2c_clients (core, TUNER_SET_STANDBY, NULL);
1175 cx88_card_setup(core);
1176 cx88_ir_init(core,pci);
1177 1038
1178 mutex_unlock(&devlist); 1039 mutex_unlock(&devlist);
1179 return core; 1040 return core;
1180
1181fail_free:
1182 kfree(core);
1183fail_unlock:
1184 mutex_unlock(&devlist);
1185 return NULL;
1186} 1041}
1187 1042
1188void cx88_core_put(struct cx88_core *core, struct pci_dev *pci) 1043void cx88_core_put(struct cx88_core *core, struct pci_dev *pci)
@@ -1229,6 +1084,9 @@ EXPORT_SYMBOL(cx88_vdev_init);
1229EXPORT_SYMBOL(cx88_core_get); 1084EXPORT_SYMBOL(cx88_core_get);
1230EXPORT_SYMBOL(cx88_core_put); 1085EXPORT_SYMBOL(cx88_core_put);
1231 1086
1087EXPORT_SYMBOL(cx88_ir_start);
1088EXPORT_SYMBOL(cx88_ir_stop);
1089
1232/* 1090/*
1233 * Local variables: 1091 * Local variables:
1234 * c-basic-offset: 8 1092 * c-basic-offset: 8
diff --git a/drivers/media/video/cx88/cx88-dvb.c b/drivers/media/video/cx88/cx88-dvb.c
index 1773b40467dc..d16e5c6d21c0 100644
--- a/drivers/media/video/cx88/cx88-dvb.c
+++ b/drivers/media/video/cx88/cx88-dvb.c
@@ -378,7 +378,7 @@ static int dvb_register(struct cx8802_dev *dev)
378 dev->ts_gen_cntrl = 0x0c; 378 dev->ts_gen_cntrl = 0x0c;
379 379
380 /* init frontend */ 380 /* init frontend */
381 switch (dev->core->board) { 381 switch (dev->core->boardnr) {
382 case CX88_BOARD_HAUPPAUGE_DVB_T1: 382 case CX88_BOARD_HAUPPAUGE_DVB_T1:
383 dev->dvb.frontend = dvb_attach(cx22702_attach, 383 dev->dvb.frontend = dvb_attach(cx22702_attach,
384 &connexant_refboard_config, 384 &connexant_refboard_config,
@@ -482,7 +482,7 @@ static int dvb_register(struct cx8802_dev *dev)
482 &dev->core->i2c_adap, DVB_PLL_FMD1216ME); 482 &dev->core->i2c_adap, DVB_PLL_FMD1216ME);
483 } 483 }
484#else 484#else
485 printk("%s: built without vp3054 support\n", dev->core->name); 485 printk(KERN_ERR "%s/2: built without vp3054 support\n", dev->core->name);
486#endif 486#endif
487 break; 487 break;
488 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_HYBRID: 488 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_HYBRID:
@@ -625,12 +625,12 @@ static int dvb_register(struct cx8802_dev *dev)
625 } 625 }
626 break; 626 break;
627 default: 627 default:
628 printk("%s: The frontend of your DVB/ATSC card isn't supported yet\n", 628 printk(KERN_ERR "%s/2: The frontend of your DVB/ATSC card isn't supported yet\n",
629 dev->core->name); 629 dev->core->name);
630 break; 630 break;
631 } 631 }
632 if (NULL == dev->dvb.frontend) { 632 if (NULL == dev->dvb.frontend) {
633 printk("%s: frontend initialization failed\n",dev->core->name); 633 printk(KERN_ERR "%s/2: frontend initialization failed\n", dev->core->name);
634 return -1; 634 return -1;
635 } 635 }
636 636
@@ -653,7 +653,7 @@ static int cx8802_dvb_advise_acquire(struct cx8802_driver *drv)
653 int err = 0; 653 int err = 0;
654 dprintk( 1, "%s\n", __FUNCTION__); 654 dprintk( 1, "%s\n", __FUNCTION__);
655 655
656 switch (core->board) { 656 switch (core->boardnr) {
657 case CX88_BOARD_HAUPPAUGE_HVR1300: 657 case CX88_BOARD_HAUPPAUGE_HVR1300:
658 /* We arrive here with either the cx23416 or the cx22702 658 /* We arrive here with either the cx23416 or the cx22702
659 * on the bus. Take the bus from the cx23416 and enable the 659 * on the bus. Take the bus from the cx23416 and enable the
@@ -676,7 +676,7 @@ static int cx8802_dvb_advise_release(struct cx8802_driver *drv)
676 int err = 0; 676 int err = 0;
677 dprintk( 1, "%s\n", __FUNCTION__); 677 dprintk( 1, "%s\n", __FUNCTION__);
678 678
679 switch (core->board) { 679 switch (core->boardnr) {
680 case CX88_BOARD_HAUPPAUGE_HVR1300: 680 case CX88_BOARD_HAUPPAUGE_HVR1300:
681 /* Do Nothing, leave the cx22702 on the bus. */ 681 /* Do Nothing, leave the cx22702 on the bus. */
682 break; 682 break;
@@ -694,13 +694,13 @@ static int cx8802_dvb_probe(struct cx8802_driver *drv)
694 694
695 dprintk( 1, "%s\n", __FUNCTION__); 695 dprintk( 1, "%s\n", __FUNCTION__);
696 dprintk( 1, " ->being probed by Card=%d Name=%s, PCI %02x:%02x\n", 696 dprintk( 1, " ->being probed by Card=%d Name=%s, PCI %02x:%02x\n",
697 core->board, 697 core->boardnr,
698 core->name, 698 core->name,
699 core->pci_bus, 699 core->pci_bus,
700 core->pci_slot); 700 core->pci_slot);
701 701
702 err = -ENODEV; 702 err = -ENODEV;
703 if (!(cx88_boards[core->board].mpeg & CX88_MPEG_DVB)) 703 if (!(core->board.mpeg & CX88_MPEG_DVB))
704 goto fail_core; 704 goto fail_core;
705 705
706 /* If vp3054 isn't enabled, a stub will just return 0 */ 706 /* If vp3054 isn't enabled, a stub will just return 0 */
@@ -709,8 +709,8 @@ static int cx8802_dvb_probe(struct cx8802_driver *drv)
709 goto fail_core; 709 goto fail_core;
710 710
711 /* dvb stuff */ 711 /* dvb stuff */
712 printk("%s/2: cx2388x based dvb card\n", core->name); 712 printk(KERN_INFO "%s/2: cx2388x based DVB/ATSC card\n", core->name);
713 videobuf_queue_init(&dev->dvb.dvbq, &dvb_qops, 713 videobuf_queue_pci_init(&dev->dvb.dvbq, &dvb_qops,
714 dev->pci, &dev->slock, 714 dev->pci, &dev->slock,
715 V4L2_BUF_TYPE_VIDEO_CAPTURE, 715 V4L2_BUF_TYPE_VIDEO_CAPTURE,
716 V4L2_FIELD_TOP, 716 V4L2_FIELD_TOP,
@@ -718,7 +718,8 @@ static int cx8802_dvb_probe(struct cx8802_driver *drv)
718 dev); 718 dev);
719 err = dvb_register(dev); 719 err = dvb_register(dev);
720 if (err != 0) 720 if (err != 0)
721 printk("%s dvb_register failed err = %d\n", __FUNCTION__, err); 721 printk(KERN_ERR "%s/2: dvb_register failed (err = %d)\n",
722 core->name, err);
722 723
723 fail_core: 724 fail_core:
724 return err; 725 return err;
@@ -747,7 +748,7 @@ static struct cx8802_driver cx8802_dvb_driver = {
747 748
748static int dvb_init(void) 749static int dvb_init(void)
749{ 750{
750 printk(KERN_INFO "cx2388x dvb driver version %d.%d.%d loaded\n", 751 printk(KERN_INFO "cx88/2: cx2388x dvb driver version %d.%d.%d loaded\n",
751 (CX88_VERSION_CODE >> 16) & 0xff, 752 (CX88_VERSION_CODE >> 16) & 0xff,
752 (CX88_VERSION_CODE >> 8) & 0xff, 753 (CX88_VERSION_CODE >> 8) & 0xff,
753 CX88_VERSION_CODE & 0xff); 754 CX88_VERSION_CODE & 0xff);
diff --git a/drivers/media/video/cx88/cx88-i2c.c b/drivers/media/video/cx88/cx88-i2c.c
index 78bbcfab9670..c8b1c50625f4 100644
--- a/drivers/media/video/cx88/cx88-i2c.c
+++ b/drivers/media/video/cx88/cx88-i2c.c
@@ -28,7 +28,6 @@
28*/ 28*/
29 29
30#include <linux/module.h> 30#include <linux/module.h>
31#include <linux/moduleparam.h>
32#include <linux/init.h> 31#include <linux/init.h>
33 32
34#include <asm/io.h> 33#include <asm/io.h>
@@ -108,28 +107,28 @@ static int attach_inform(struct i2c_client *client)
108 if (!client->driver->command) 107 if (!client->driver->command)
109 return 0; 108 return 0;
110 109
111 if (core->radio_type != UNSET) { 110 if (core->board.radio_type != UNSET) {
112 if ((core->radio_addr==ADDR_UNSET)||(core->radio_addr==client->addr)) { 111 if ((core->board.radio_addr==ADDR_UNSET)||(core->board.radio_addr==client->addr)) {
113 tun_setup.mode_mask = T_RADIO; 112 tun_setup.mode_mask = T_RADIO;
114 tun_setup.type = core->radio_type; 113 tun_setup.type = core->board.radio_type;
115 tun_setup.addr = core->radio_addr; 114 tun_setup.addr = core->board.radio_addr;
116 115
117 client->driver->command (client, TUNER_SET_TYPE_ADDR, &tun_setup); 116 client->driver->command (client, TUNER_SET_TYPE_ADDR, &tun_setup);
118 } 117 }
119 } 118 }
120 if (core->tuner_type != UNSET) { 119 if (core->board.tuner_type != UNSET) {
121 if ((core->tuner_addr==ADDR_UNSET)||(core->tuner_addr==client->addr)) { 120 if ((core->board.tuner_addr==ADDR_UNSET)||(core->board.tuner_addr==client->addr)) {
122 121
123 tun_setup.mode_mask = T_ANALOG_TV; 122 tun_setup.mode_mask = T_ANALOG_TV;
124 tun_setup.type = core->tuner_type; 123 tun_setup.type = core->board.tuner_type;
125 tun_setup.addr = core->tuner_addr; 124 tun_setup.addr = core->board.tuner_addr;
126 125
127 client->driver->command (client,TUNER_SET_TYPE_ADDR, &tun_setup); 126 client->driver->command (client,TUNER_SET_TYPE_ADDR, &tun_setup);
128 } 127 }
129 } 128 }
130 129
131 if (core->tda9887_conf) 130 if (core->board.tda9887_conf)
132 client->driver->command(client, TDA9887_SET_CONFIG, &core->tda9887_conf); 131 client->driver->command(client, TDA9887_SET_CONFIG, &core->board.tda9887_conf);
133 return 0; 132 return 0;
134} 133}
135 134
@@ -146,7 +145,7 @@ void cx88_call_i2c_clients(struct cx88_core *core, unsigned int cmd, void *arg)
146 if (0 != core->i2c_rc) 145 if (0 != core->i2c_rc)
147 return; 146 return;
148 147
149#if defined(CONFIG_VIDEO_BUF_DVB) || defined(CONFIG_VIDEO_BUF_DVB_MODULE) 148#if defined(CONFIG_VIDEO_CX88_DVB) || defined(CONFIG_VIDEO_CX88_DVB_MODULE)
150 if ( (core->dvbdev) && (core->dvbdev->dvb.frontend) ) { 149 if ( (core->dvbdev) && (core->dvbdev->dvb.frontend) ) {
151 if (core->dvbdev->dvb.frontend->ops.i2c_gate_ctrl) 150 if (core->dvbdev->dvb.frontend->ops.i2c_gate_ctrl)
152 core->dvbdev->dvb.frontend->ops.i2c_gate_ctrl(core->dvbdev->dvb.frontend, 1); 151 core->dvbdev->dvb.frontend->ops.i2c_gate_ctrl(core->dvbdev->dvb.frontend, 1);
@@ -204,9 +203,9 @@ int cx88_i2c_init(struct cx88_core *core, struct pci_dev *pci)
204 memcpy(&core->i2c_algo, &cx8800_i2c_algo_template, 203 memcpy(&core->i2c_algo, &cx8800_i2c_algo_template,
205 sizeof(core->i2c_algo)); 204 sizeof(core->i2c_algo));
206 205
207 if (core->tuner_type != TUNER_ABSENT) 206 if (core->board.tuner_type != TUNER_ABSENT)
208 core->i2c_adap.class |= I2C_CLASS_TV_ANALOG; 207 core->i2c_adap.class |= I2C_CLASS_TV_ANALOG;
209 if (cx88_boards[core->board].mpeg & CX88_MPEG_DVB) 208 if (core->board.mpeg & CX88_MPEG_DVB)
210 core->i2c_adap.class |= I2C_CLASS_TV_DIGITAL; 209 core->i2c_adap.class |= I2C_CLASS_TV_DIGITAL;
211 210
212 core->i2c_adap.dev.parent = &pci->dev; 211 core->i2c_adap.dev.parent = &pci->dev;
diff --git a/drivers/media/video/cx88/cx88-input.c b/drivers/media/video/cx88/cx88-input.c
index f5d4a565346e..e52de3968c63 100644
--- a/drivers/media/video/cx88/cx88-input.c
+++ b/drivers/media/video/cx88/cx88-input.c
@@ -27,7 +27,6 @@
27#include <linux/input.h> 27#include <linux/input.h>
28#include <linux/pci.h> 28#include <linux/pci.h>
29#include <linux/module.h> 29#include <linux/module.h>
30#include <linux/moduleparam.h>
31 30
32#include "cx88.h" 31#include "cx88.h"
33#include <media/ir-common.h> 32#include <media/ir-common.h>
@@ -74,7 +73,7 @@ static void cx88_ir_handle_key(struct cx88_IR *ir)
74 73
75 /* read gpio value */ 74 /* read gpio value */
76 gpio = cx_read(ir->gpio_addr); 75 gpio = cx_read(ir->gpio_addr);
77 switch (core->board) { 76 switch (core->boardnr) {
78 case CX88_BOARD_NPGTECH_REALTV_TOP10FM: 77 case CX88_BOARD_NPGTECH_REALTV_TOP10FM:
79 /* This board apparently uses a combination of 2 GPIO 78 /* This board apparently uses a combination of 2 GPIO
80 to represent the keys. Additionally, the second GPIO 79 to represent the keys. Additionally, the second GPIO
@@ -113,7 +112,7 @@ static void cx88_ir_handle_key(struct cx88_IR *ir)
113 (gpio & ir->mask_keydown) ? " down" : "", 112 (gpio & ir->mask_keydown) ? " down" : "",
114 (gpio & ir->mask_keyup) ? " up" : ""); 113 (gpio & ir->mask_keyup) ? " up" : "");
115 114
116 if (ir->core->board == CX88_BOARD_NORWOOD_MICRO) { 115 if (ir->core->boardnr == CX88_BOARD_NORWOOD_MICRO) {
117 u32 gpio_key = cx_read(MO_GP0_IO); 116 u32 gpio_key = cx_read(MO_GP0_IO);
118 117
119 data = (data << 4) | ((gpio_key & 0xf0) >> 4); 118 data = (data << 4) | ((gpio_key & 0xf0) >> 4);
@@ -159,7 +158,7 @@ static void cx88_ir_work(struct work_struct *work)
159 mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling)); 158 mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling));
160} 159}
161 160
162static void cx88_ir_start(struct cx88_core *core, struct cx88_IR *ir) 161void cx88_ir_start(struct cx88_core *core, struct cx88_IR *ir)
163{ 162{
164 if (ir->polling) { 163 if (ir->polling) {
165 setup_timer(&ir->timer, ir_timer, (unsigned long)ir); 164 setup_timer(&ir->timer, ir_timer, (unsigned long)ir);
@@ -167,17 +166,17 @@ static void cx88_ir_start(struct cx88_core *core, struct cx88_IR *ir)
167 schedule_work(&ir->work); 166 schedule_work(&ir->work);
168 } 167 }
169 if (ir->sampling) { 168 if (ir->sampling) {
170 core->pci_irqmask |= (1 << 18); /* IR_SMP_INT */ 169 core->pci_irqmask |= PCI_INT_IR_SMPINT;
171 cx_write(MO_DDS_IO, 0xa80a80); /* 4 kHz sample rate */ 170 cx_write(MO_DDS_IO, 0xa80a80); /* 4 kHz sample rate */
172 cx_write(MO_DDSCFG_IO, 0x5); /* enable */ 171 cx_write(MO_DDSCFG_IO, 0x5); /* enable */
173 } 172 }
174} 173}
175 174
176static void cx88_ir_stop(struct cx88_core *core, struct cx88_IR *ir) 175void cx88_ir_stop(struct cx88_core *core, struct cx88_IR *ir)
177{ 176{
178 if (ir->sampling) { 177 if (ir->sampling) {
179 cx_write(MO_DDSCFG_IO, 0x0); 178 cx_write(MO_DDSCFG_IO, 0x0);
180 core->pci_irqmask &= ~(1 << 18); 179 core->pci_irqmask &= ~PCI_INT_IR_SMPINT;
181 } 180 }
182 181
183 if (ir->polling) { 182 if (ir->polling) {
@@ -204,7 +203,7 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
204 ir->input = input_dev; 203 ir->input = input_dev;
205 204
206 /* detect & configure */ 205 /* detect & configure */
207 switch (core->board) { 206 switch (core->boardnr) {
208 case CX88_BOARD_DNTV_LIVE_DVB_T: 207 case CX88_BOARD_DNTV_LIVE_DVB_T:
209 case CX88_BOARD_KWORLD_DVB_T: 208 case CX88_BOARD_KWORLD_DVB_T:
210 case CX88_BOARD_KWORLD_DVB_T_CX22702: 209 case CX88_BOARD_KWORLD_DVB_T_CX22702:
@@ -314,8 +313,7 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
314 } 313 }
315 314
316 /* init input device */ 315 /* init input device */
317 snprintf(ir->name, sizeof(ir->name), "cx88 IR (%s)", 316 snprintf(ir->name, sizeof(ir->name), "cx88 IR (%s)", core->board.name);
318 cx88_boards[core->board].name);
319 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0", pci_name(pci)); 317 snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0", pci_name(pci));
320 318
321 ir_input_init(input_dev, &ir->ir, ir_type, ir_codes); 319 ir_input_init(input_dev, &ir->ir, ir_type, ir_codes);
@@ -406,7 +404,7 @@ void cx88_ir_irq(struct cx88_core *core)
406 ir_dump_samples(ir->samples, ir->scount); 404 ir_dump_samples(ir->samples, ir->scount);
407 405
408 /* decode it */ 406 /* decode it */
409 switch (core->board) { 407 switch (core->boardnr) {
410 case CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1: 408 case CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1:
411 case CX88_BOARD_DNTV_LIVE_DVB_T_PRO: 409 case CX88_BOARD_DNTV_LIVE_DVB_T_PRO:
412 ircode = ir_decode_pulsedistance(ir->samples, ir->scount, 1, 4); 410 ircode = ir_decode_pulsedistance(ir->samples, ir->scount, 1, 4);
diff --git a/drivers/media/video/cx88/cx88-mpeg.c b/drivers/media/video/cx88/cx88-mpeg.c
index da7a6b591a67..a652f294d23d 100644
--- a/drivers/media/video/cx88/cx88-mpeg.c
+++ b/drivers/media/video/cx88/cx88-mpeg.c
@@ -23,12 +23,10 @@
23 */ 23 */
24 24
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/moduleparam.h>
27#include <linux/init.h> 26#include <linux/init.h>
28#include <linux/device.h> 27#include <linux/device.h>
29#include <linux/dma-mapping.h> 28#include <linux/dma-mapping.h>
30#include <linux/interrupt.h> 29#include <linux/interrupt.h>
31#include <linux/dma-mapping.h>
32#include <asm/delay.h> 30#include <asm/delay.h>
33 31
34#include "cx88.h" 32#include "cx88.h"
@@ -56,9 +54,9 @@ static void request_module_async(struct work_struct *work)
56{ 54{
57 struct cx8802_dev *dev=container_of(work, struct cx8802_dev, request_module_wk); 55 struct cx8802_dev *dev=container_of(work, struct cx8802_dev, request_module_wk);
58 56
59 if (cx88_boards[dev->core->board].mpeg & CX88_MPEG_DVB) 57 if (dev->core->board.mpeg & CX88_MPEG_DVB)
60 request_module("cx88-dvb"); 58 request_module("cx88-dvb");
61 if (cx88_boards[dev->core->board].mpeg & CX88_MPEG_BLACKBIRD) 59 if (dev->core->board.mpeg & CX88_MPEG_BLACKBIRD)
62 request_module("cx88-blackbird"); 60 request_module("cx88-blackbird");
63} 61}
64 62
@@ -96,7 +94,7 @@ static int cx8802_start_dma(struct cx8802_dev *dev,
96 dprintk( 1, "core->active_type_id = 0x%08x\n", core->active_type_id); 94 dprintk( 1, "core->active_type_id = 0x%08x\n", core->active_type_id);
97 95
98 if ( (core->active_type_id == CX88_MPEG_DVB) && 96 if ( (core->active_type_id == CX88_MPEG_DVB) &&
99 (cx88_boards[core->board].mpeg & CX88_MPEG_DVB) ) { 97 (core->board.mpeg & CX88_MPEG_DVB) ) {
100 98
101 dprintk( 1, "cx8802_start_dma doing .dvb\n"); 99 dprintk( 1, "cx8802_start_dma doing .dvb\n");
102 /* negedge driven & software reset */ 100 /* negedge driven & software reset */
@@ -104,7 +102,7 @@ static int cx8802_start_dma(struct cx8802_dev *dev,
104 udelay(100); 102 udelay(100);
105 cx_write(MO_PINMUX_IO, 0x00); 103 cx_write(MO_PINMUX_IO, 0x00);
106 cx_write(TS_HW_SOP_CNTRL,0x47<<16|188<<4|0x01); 104 cx_write(TS_HW_SOP_CNTRL,0x47<<16|188<<4|0x01);
107 switch (core->board) { 105 switch (core->boardnr) {
108 case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_Q: 106 case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_Q:
109 case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_T: 107 case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_T:
110 case CX88_BOARD_DVICO_FUSIONHDTV_5_GOLD: 108 case CX88_BOARD_DVICO_FUSIONHDTV_5_GOLD:
@@ -125,7 +123,7 @@ static int cx8802_start_dma(struct cx8802_dev *dev,
125 cx_write(TS_GEN_CNTRL, dev->ts_gen_cntrl); 123 cx_write(TS_GEN_CNTRL, dev->ts_gen_cntrl);
126 udelay(100); 124 udelay(100);
127 } else if ( (core->active_type_id == CX88_MPEG_BLACKBIRD) && 125 } else if ( (core->active_type_id == CX88_MPEG_BLACKBIRD) &&
128 (cx88_boards[core->board].mpeg & CX88_MPEG_BLACKBIRD) ) { 126 (core->board.mpeg & CX88_MPEG_BLACKBIRD) ) {
129 dprintk( 1, "cx8802_start_dma doing .blackbird\n"); 127 dprintk( 1, "cx8802_start_dma doing .blackbird\n");
130 cx_write(MO_PINMUX_IO, 0x88); /* enable MPEG parallel IO */ 128 cx_write(MO_PINMUX_IO, 0x88); /* enable MPEG parallel IO */
131 129
@@ -139,7 +137,7 @@ static int cx8802_start_dma(struct cx8802_dev *dev,
139 udelay(100); 137 udelay(100);
140 } else { 138 } else {
141 printk( "%s() Failed. Unsupported value in .mpeg (0x%08x)\n", __FUNCTION__, 139 printk( "%s() Failed. Unsupported value in .mpeg (0x%08x)\n", __FUNCTION__,
142 cx88_boards[core->board].mpeg ); 140 core->board.mpeg );
143 return -EINVAL; 141 return -EINVAL;
144 } 142 }
145 143
@@ -149,7 +147,7 @@ static int cx8802_start_dma(struct cx8802_dev *dev,
149 147
150 /* enable irqs */ 148 /* enable irqs */
151 dprintk( 1, "setting the interrupt mask\n" ); 149 dprintk( 1, "setting the interrupt mask\n" );
152 cx_set(MO_PCI_INTMSK, core->pci_irqmask | 0x04); 150 cx_set(MO_PCI_INTMSK, core->pci_irqmask | PCI_INT_TSINT);
153 cx_set(MO_TS_INTMSK, 0x1f0011); 151 cx_set(MO_TS_INTMSK, 0x1f0011);
154 152
155 /* start dma */ 153 /* start dma */
@@ -167,7 +165,7 @@ static int cx8802_stop_dma(struct cx8802_dev *dev)
167 cx_clear(MO_TS_DMACNTRL, 0x11); 165 cx_clear(MO_TS_DMACNTRL, 0x11);
168 166
169 /* disable irqs */ 167 /* disable irqs */
170 cx_clear(MO_PCI_INTMSK, 0x000004); 168 cx_clear(MO_PCI_INTMSK, PCI_INT_TSINT);
171 cx_clear(MO_TS_INTMSK, 0x1f0011); 169 cx_clear(MO_TS_INTMSK, 0x1f0011);
172 170
173 /* Reset the controller */ 171 /* Reset the controller */
@@ -181,43 +179,43 @@ static int cx8802_restart_queue(struct cx8802_dev *dev,
181 struct cx88_buffer *buf; 179 struct cx88_buffer *buf;
182 struct list_head *item; 180 struct list_head *item;
183 181
184 dprintk( 1, "cx8802_restart_queue\n" ); 182 dprintk( 1, "cx8802_restart_queue\n" );
185 if (list_empty(&q->active)) 183 if (list_empty(&q->active))
186 { 184 {
187 struct cx88_buffer *prev; 185 struct cx88_buffer *prev;
188 prev = NULL; 186 prev = NULL;
189 187
190 dprintk(1, "cx8802_restart_queue: queue is empty\n" ); 188 dprintk(1, "cx8802_restart_queue: queue is empty\n" );
191 189
192 for (;;) { 190 for (;;) {
193 if (list_empty(&q->queued)) 191 if (list_empty(&q->queued))
194 return 0; 192 return 0;
195 buf = list_entry(q->queued.next, struct cx88_buffer, vb.queue); 193 buf = list_entry(q->queued.next, struct cx88_buffer, vb.queue);
196 if (NULL == prev) { 194 if (NULL == prev) {
197 list_del(&buf->vb.queue); 195 list_del(&buf->vb.queue);
198 list_add_tail(&buf->vb.queue,&q->active); 196 list_add_tail(&buf->vb.queue,&q->active);
199 cx8802_start_dma(dev, q, buf); 197 cx8802_start_dma(dev, q, buf);
200 buf->vb.state = STATE_ACTIVE; 198 buf->vb.state = STATE_ACTIVE;
201 buf->count = q->count++; 199 buf->count = q->count++;
202 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT); 200 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
203 dprintk(1,"[%p/%d] restart_queue - first active\n", 201 dprintk(1,"[%p/%d] restart_queue - first active\n",
204 buf,buf->vb.i); 202 buf,buf->vb.i);
205 203
206 } else if (prev->vb.width == buf->vb.width && 204 } else if (prev->vb.width == buf->vb.width &&
207 prev->vb.height == buf->vb.height && 205 prev->vb.height == buf->vb.height &&
208 prev->fmt == buf->fmt) { 206 prev->fmt == buf->fmt) {
209 list_del(&buf->vb.queue); 207 list_del(&buf->vb.queue);
210 list_add_tail(&buf->vb.queue,&q->active); 208 list_add_tail(&buf->vb.queue,&q->active);
211 buf->vb.state = STATE_ACTIVE; 209 buf->vb.state = STATE_ACTIVE;
212 buf->count = q->count++; 210 buf->count = q->count++;
213 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma); 211 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
214 dprintk(1,"[%p/%d] restart_queue - move to active\n", 212 dprintk(1,"[%p/%d] restart_queue - move to active\n",
215 buf,buf->vb.i); 213 buf,buf->vb.i);
216 } else { 214 } else {
217 return 0; 215 return 0;
218 } 216 }
219 prev = buf; 217 prev = buf;
220 } 218 }
221 return 0; 219 return 0;
222 } 220 }
223 221
@@ -239,6 +237,7 @@ int cx8802_buf_prepare(struct videobuf_queue *q, struct cx8802_dev *dev,
239 struct cx88_buffer *buf, enum v4l2_field field) 237 struct cx88_buffer *buf, enum v4l2_field field)
240{ 238{
241 int size = dev->ts_packet_size * dev->ts_packet_count; 239 int size = dev->ts_packet_size * dev->ts_packet_count;
240 struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb);
242 int rc; 241 int rc;
243 242
244 dprintk(1, "%s: %p\n", __FUNCTION__, buf); 243 dprintk(1, "%s: %p\n", __FUNCTION__, buf);
@@ -254,8 +253,8 @@ int cx8802_buf_prepare(struct videobuf_queue *q, struct cx8802_dev *dev,
254 if (0 != (rc = videobuf_iolock(q,&buf->vb,NULL))) 253 if (0 != (rc = videobuf_iolock(q,&buf->vb,NULL)))
255 goto fail; 254 goto fail;
256 cx88_risc_databuffer(dev->pci, &buf->risc, 255 cx88_risc_databuffer(dev->pci, &buf->risc,
257 buf->vb.dma.sglist, 256 dma->sglist,
258 buf->vb.width, buf->vb.height); 257 buf->vb.width, buf->vb.height, 0);
259 } 258 }
260 buf->vb.state = STATE_PREPARED; 259 buf->vb.state = STATE_PREPARED;
261 return 0; 260 return 0;
@@ -414,7 +413,8 @@ static irqreturn_t cx8802_irq(int irq, void *dev_id)
414 int loop, handled = 0; 413 int loop, handled = 0;
415 414
416 for (loop = 0; loop < MAX_IRQ_LOOP; loop++) { 415 for (loop = 0; loop < MAX_IRQ_LOOP; loop++) {
417 status = cx_read(MO_PCI_INTSTAT) & (core->pci_irqmask | 0x04); 416 status = cx_read(MO_PCI_INTSTAT) &
417 (core->pci_irqmask | PCI_INT_TSINT);
418 if (0 == status) 418 if (0 == status)
419 goto out; 419 goto out;
420 dprintk( 1, "cx8802_irq\n" ); 420 dprintk( 1, "cx8802_irq\n" );
@@ -425,7 +425,7 @@ static irqreturn_t cx8802_irq(int irq, void *dev_id)
425 425
426 if (status & core->pci_irqmask) 426 if (status & core->pci_irqmask)
427 cx88_core_irq(core,status); 427 cx88_core_irq(core,status);
428 if (status & 0x04) 428 if (status & PCI_INT_TSINT)
429 cx8802_mpeg_irq(dev); 429 cx8802_mpeg_irq(dev);
430 }; 430 };
431 if (MAX_IRQ_LOOP == loop) { 431 if (MAX_IRQ_LOOP == loop) {
@@ -676,22 +676,24 @@ int cx8802_register_driver(struct cx8802_driver *drv)
676 struct list_head *list; 676 struct list_head *list;
677 int err = 0, i = 0; 677 int err = 0, i = 0;
678 678
679 printk(KERN_INFO "%s() ->registering driver type=%s access=%s\n", __FUNCTION__ , 679 printk(KERN_INFO
680 drv->type_id == CX88_MPEG_DVB ? "dvb" : "blackbird", 680 "cx88/2: registering cx8802 driver, type: %s access: %s\n",
681 drv->hw_access == CX8802_DRVCTL_SHARED ? "shared" : "exclusive"); 681 drv->type_id == CX88_MPEG_DVB ? "dvb" : "blackbird",
682 drv->hw_access == CX8802_DRVCTL_SHARED ? "shared" : "exclusive");
682 683
683 if ((err = cx8802_check_driver(drv)) != 0) { 684 if ((err = cx8802_check_driver(drv)) != 0) {
684 printk(KERN_INFO "%s() cx8802_driver is invalid\n", __FUNCTION__ ); 685 printk(KERN_ERR "cx88/2: cx8802_driver is invalid\n");
685 return err; 686 return err;
686 } 687 }
687 688
688 list_for_each(list,&cx8802_devlist) { 689 list_for_each(list,&cx8802_devlist) {
689 h = list_entry(list, struct cx8802_dev, devlist); 690 h = list_entry(list, struct cx8802_dev, devlist);
690 691
691 printk(KERN_INFO "CORE %s: subsystem: %04x:%04x, board: %s [card=%d]\n", 692 printk(KERN_INFO
692 h->core->name,h->pci->subsystem_vendor, 693 "%s/2: subsystem: %04x:%04x, board: %s [card=%d]\n",
693 h->pci->subsystem_device,cx88_boards[h->core->board].name, 694 h->core->name, h->pci->subsystem_vendor,
694 h->core->board); 695 h->pci->subsystem_device, h->core->board.name,
696 h->core->boardnr);
695 697
696 /* Bring up a new struct for each driver instance */ 698 /* Bring up a new struct for each driver instance */
697 driver = kzalloc(sizeof(*drv),GFP_KERNEL); 699 driver = kzalloc(sizeof(*drv),GFP_KERNEL);
@@ -713,7 +715,9 @@ int cx8802_register_driver(struct cx8802_driver *drv)
713 list_add_tail(&driver->devlist,&h->drvlist.devlist); 715 list_add_tail(&driver->devlist,&h->drvlist.devlist);
714 mutex_unlock(&drv->core->lock); 716 mutex_unlock(&drv->core->lock);
715 } else { 717 } else {
716 printk(KERN_ERR "%s() ->probe failed err = %d\n", __FUNCTION__, err); 718 printk(KERN_ERR
719 "%s/2: cx8802 probe failed, err = %d\n",
720 h->core->name, err);
717 } 721 }
718 722
719 } 723 }
@@ -733,17 +737,20 @@ int cx8802_unregister_driver(struct cx8802_driver *drv)
733 struct list_head *list2, *q; 737 struct list_head *list2, *q;
734 int err = 0, i = 0; 738 int err = 0, i = 0;
735 739
736 printk(KERN_INFO "%s() ->unregistering driver type=%s\n", __FUNCTION__ , 740 printk(KERN_INFO
737 drv->type_id == CX88_MPEG_DVB ? "dvb" : "blackbird"); 741 "cx88/2: unregistering cx8802 driver, type: %s access: %s\n",
742 drv->type_id == CX88_MPEG_DVB ? "dvb" : "blackbird",
743 drv->hw_access == CX8802_DRVCTL_SHARED ? "shared" : "exclusive");
738 744
739 list_for_each(list,&cx8802_devlist) { 745 list_for_each(list,&cx8802_devlist) {
740 i++; 746 i++;
741 h = list_entry(list, struct cx8802_dev, devlist); 747 h = list_entry(list, struct cx8802_dev, devlist);
742 748
743 printk(KERN_INFO "CORE %s: subsystem: %04x:%04x, board: %s [card=%d]\n", 749 printk(KERN_INFO
744 h->core->name,h->pci->subsystem_vendor, 750 "%s/2: subsystem: %04x:%04x, board: %s [card=%d]\n",
745 h->pci->subsystem_device,cx88_boards[h->core->board].name, 751 h->core->name, h->pci->subsystem_vendor,
746 h->core->board); 752 h->pci->subsystem_device, h->core->board.name,
753 h->core->boardnr);
747 754
748 list_for_each_safe(list2, q, &h->drvlist.devlist) { 755 list_for_each_safe(list2, q, &h->drvlist.devlist) {
749 d = list_entry(list2, struct cx8802_driver, devlist); 756 d = list_entry(list2, struct cx8802_driver, devlist);
@@ -758,7 +765,8 @@ int cx8802_unregister_driver(struct cx8802_driver *drv)
758 list_del(list2); 765 list_del(list2);
759 mutex_unlock(&drv->core->lock); 766 mutex_unlock(&drv->core->lock);
760 } else 767 } else
761 printk(KERN_ERR "%s() ->remove failed err = %d\n", __FUNCTION__, err); 768 printk(KERN_ERR "%s/2: cx8802 driver remove "
769 "failed (%d)\n", h->core->name, err);
762 770
763 } 771 }
764 772
@@ -783,7 +791,7 @@ static int __devinit cx8802_probe(struct pci_dev *pci_dev,
783 printk("%s/2: cx2388x 8802 Driver Manager\n", core->name); 791 printk("%s/2: cx2388x 8802 Driver Manager\n", core->name);
784 792
785 err = -ENODEV; 793 err = -ENODEV;
786 if (!cx88_boards[core->board].mpeg) 794 if (!core->board.mpeg)
787 goto fail_core; 795 goto fail_core;
788 796
789 err = -ENOMEM; 797 err = -ENOMEM;
@@ -866,7 +874,7 @@ static struct pci_driver cx8802_pci_driver = {
866 874
867static int cx8802_init(void) 875static int cx8802_init(void)
868{ 876{
869 printk(KERN_INFO "cx2388x cx88-mpeg Driver Manager version %d.%d.%d loaded\n", 877 printk(KERN_INFO "cx88/2: cx2388x MPEG-TS Driver Manager version %d.%d.%d loaded\n",
870 (CX88_VERSION_CODE >> 16) & 0xff, 878 (CX88_VERSION_CODE >> 16) & 0xff,
871 (CX88_VERSION_CODE >> 8) & 0xff, 879 (CX88_VERSION_CODE >> 8) & 0xff,
872 CX88_VERSION_CODE & 0xff); 880 CX88_VERSION_CODE & 0xff);
diff --git a/drivers/media/video/cx88/cx88-reg.h b/drivers/media/video/cx88/cx88-reg.h
index d3bf5b17b1d4..2ec52d1cdea0 100644
--- a/drivers/media/video/cx88/cx88-reg.h
+++ b/drivers/media/video/cx88/cx88-reg.h
@@ -582,6 +582,28 @@
582/* ---------------------------------------------------------------------- */ 582/* ---------------------------------------------------------------------- */
583/* various constants */ 583/* various constants */
584 584
585// DMA
586/* Interrupt mask/status */
587#define PCI_INT_VIDINT (1 << 0)
588#define PCI_INT_AUDINT (1 << 1)
589#define PCI_INT_TSINT (1 << 2)
590#define PCI_INT_VIPINT (1 << 3)
591#define PCI_INT_HSTINT (1 << 4)
592#define PCI_INT_TM1INT (1 << 5)
593#define PCI_INT_SRCDMAINT (1 << 6)
594#define PCI_INT_DSTDMAINT (1 << 7)
595#define PCI_INT_RISC_RD_BERRINT (1 << 10)
596#define PCI_INT_RISC_WR_BERRINT (1 << 11)
597#define PCI_INT_BRDG_BERRINT (1 << 12)
598#define PCI_INT_SRC_DMA_BERRINT (1 << 13)
599#define PCI_INT_DST_DMA_BERRINT (1 << 14)
600#define PCI_INT_IPB_DMA_BERRINT (1 << 15)
601#define PCI_INT_I2CDONE (1 << 16)
602#define PCI_INT_I2CRACK (1 << 17)
603#define PCI_INT_IR_SMPINT (1 << 18)
604#define PCI_INT_GPIO_INT0 (1 << 19)
605#define PCI_INT_GPIO_INT1 (1 << 20)
606
585#define SEL_BTSC 0x01 607#define SEL_BTSC 0x01
586#define SEL_EIAJ 0x02 608#define SEL_EIAJ 0x02
587#define SEL_A2 0x04 609#define SEL_A2 0x04
@@ -590,6 +612,19 @@
590#define SEL_FMRADIO 0x20 612#define SEL_FMRADIO 0x20
591 613
592// AUD_CTL 614// AUD_CTL
615#define AUD_INT_DN_RISCI1 (1 << 0)
616#define AUD_INT_UP_RISCI1 (1 << 1)
617#define AUD_INT_RDS_DN_RISCI1 (1 << 2)
618#define AUD_INT_DN_RISCI2 (1 << 4) /* yes, 3 is skipped */
619#define AUD_INT_UP_RISCI2 (1 << 5)
620#define AUD_INT_RDS_DN_RISCI2 (1 << 6)
621#define AUD_INT_DN_SYNC (1 << 12)
622#define AUD_INT_UP_SYNC (1 << 13)
623#define AUD_INT_RDS_DN_SYNC (1 << 14)
624#define AUD_INT_OPC_ERR (1 << 16)
625#define AUD_INT_BER_IRQ (1 << 20)
626#define AUD_INT_MCHG_IRQ (1 << 21)
627
593#define EN_BTSC_FORCE_MONO 0 628#define EN_BTSC_FORCE_MONO 0
594#define EN_BTSC_FORCE_STEREO 1 629#define EN_BTSC_FORCE_STEREO 1
595#define EN_BTSC_FORCE_SAP 2 630#define EN_BTSC_FORCE_SAP 2
diff --git a/drivers/media/video/cx88/cx88-tvaudio.c b/drivers/media/video/cx88/cx88-tvaudio.c
index 1cc2d286a1cb..76e5c78d8ae4 100644
--- a/drivers/media/video/cx88/cx88-tvaudio.c
+++ b/drivers/media/video/cx88/cx88-tvaudio.c
@@ -36,7 +36,6 @@
36*/ 36*/
37 37
38#include <linux/module.h> 38#include <linux/module.h>
39#include <linux/moduleparam.h>
40#include <linux/errno.h> 39#include <linux/errno.h>
41#include <linux/freezer.h> 40#include <linux/freezer.h>
42#include <linux/kernel.h> 41#include <linux/kernel.h>
@@ -62,6 +61,10 @@ static unsigned int always_analog = 0;
62module_param(always_analog,int,0644); 61module_param(always_analog,int,0644);
63MODULE_PARM_DESC(always_analog,"force analog audio out"); 62MODULE_PARM_DESC(always_analog,"force analog audio out");
64 63
64static unsigned int radio_deemphasis = 0;
65module_param(radio_deemphasis,int,0644);
66MODULE_PARM_DESC(radio_deemphasis, "Radio deemphasis time constant, "
67 "0=None, 1=50us (elsewhere), 2=75us (USA)");
65 68
66#define dprintk(fmt, arg...) if (audio_debug) \ 69#define dprintk(fmt, arg...) if (audio_debug) \
67 printk(KERN_DEBUG "%s/0: " fmt, core->name , ## arg) 70 printk(KERN_DEBUG "%s/0: " fmt, core->name , ## arg)
@@ -140,7 +143,7 @@ static void set_audio_finish(struct cx88_core *core, u32 ctl)
140 cx_write(AUD_RATE_THRES_DMD, 0x000000C0); 143 cx_write(AUD_RATE_THRES_DMD, 0x000000C0);
141 cx88_start_audio_dma(core); 144 cx88_start_audio_dma(core);
142 145
143 if (cx88_boards[core->board].mpeg & CX88_MPEG_BLACKBIRD) { 146 if (core->board.mpeg & CX88_MPEG_BLACKBIRD) {
144 cx_write(AUD_I2SINPUTCNTL, 4); 147 cx_write(AUD_I2SINPUTCNTL, 4);
145 cx_write(AUD_BAUDRATE, 1); 148 cx_write(AUD_BAUDRATE, 1);
146 /* 'pass-thru mode': this enables the i2s output to the mpeg encoder */ 149 /* 'pass-thru mode': this enables the i2s output to the mpeg encoder */
@@ -149,7 +152,7 @@ static void set_audio_finish(struct cx88_core *core, u32 ctl)
149 cx_write(AUD_I2SCNTL, 0); 152 cx_write(AUD_I2SCNTL, 0);
150 /* cx_write(AUD_APB_IN_RATE_ADJ, 0); */ 153 /* cx_write(AUD_APB_IN_RATE_ADJ, 0); */
151 } 154 }
152 if ((always_analog) || (!(cx88_boards[core->board].mpeg & CX88_MPEG_BLACKBIRD))) { 155 if ((always_analog) || (!(core->board.mpeg & CX88_MPEG_BLACKBIRD))) {
153 ctl |= EN_DAC_ENABLE; 156 ctl |= EN_DAC_ENABLE;
154 cx_write(AUD_CTL, ctl); 157 cx_write(AUD_CTL, ctl);
155 } 158 }
@@ -678,6 +681,10 @@ static void set_audio_standard_FM(struct cx88_core *core,
678 }; 681 };
679 682
680 /* It is enough to leave default values? */ 683 /* It is enough to leave default values? */
684 /* No, it's not! The deemphasis registers are reset to the 75us
685 * values by default. Analyzing the spectrum of the decoded audio
686 * reveals that "no deemphasis" is the same as 75 us, while the 50 us
687 * setting results in less deemphasis. */
681 static const struct rlist fm_no_deemph[] = { 688 static const struct rlist fm_no_deemph[] = {
682 689
683 {AUD_POLYPH80SCALEFAC, 0x0003}, 690 {AUD_POLYPH80SCALEFAC, 0x0003},
@@ -688,6 +695,7 @@ static void set_audio_standard_FM(struct cx88_core *core,
688 set_audio_start(core, SEL_FMRADIO); 695 set_audio_start(core, SEL_FMRADIO);
689 696
690 switch (deemph) { 697 switch (deemph) {
698 default:
691 case FM_NO_DEEMPH: 699 case FM_NO_DEEMPH:
692 set_audio_registers(core, fm_no_deemph); 700 set_audio_registers(core, fm_no_deemph);
693 break; 701 break;
@@ -757,7 +765,7 @@ void cx88_set_tvaudio(struct cx88_core *core)
757 set_audio_standard_EIAJ(core); 765 set_audio_standard_EIAJ(core);
758 break; 766 break;
759 case WW_FM: 767 case WW_FM:
760 set_audio_standard_FM(core, FM_NO_DEEMPH); 768 set_audio_standard_FM(core, radio_deemphasis);
761 break; 769 break;
762 case WW_NONE: 770 case WW_NONE:
763 default: 771 default:
@@ -790,9 +798,9 @@ void cx88_get_stereo(struct cx88_core *core, struct v4l2_tuner *t)
790 core->astat = reg; 798 core->astat = reg;
791 799
792/* TODO 800/* TODO
793 Reading from AUD_STATUS is not enough 801 Reading from AUD_STATUS is not enough
794 for auto-detecting sap/dual-fm/nicam. 802 for auto-detecting sap/dual-fm/nicam.
795 Add some code here later. 803 Add some code here later.
796*/ 804*/
797 805
798 return; 806 return;
diff --git a/drivers/media/video/cx88/cx88-vbi.c b/drivers/media/video/cx88/cx88-vbi.c
index 86c1cf8334bc..babb08556406 100644
--- a/drivers/media/video/cx88/cx88-vbi.c
+++ b/drivers/media/video/cx88/cx88-vbi.c
@@ -2,7 +2,6 @@
2 */ 2 */
3#include <linux/kernel.h> 3#include <linux/kernel.h>
4#include <linux/module.h> 4#include <linux/module.h>
5#include <linux/moduleparam.h>
6#include <linux/init.h> 5#include <linux/init.h>
7#include <linux/slab.h> 6#include <linux/slab.h>
8 7
@@ -67,7 +66,7 @@ static int cx8800_start_vbi_dma(struct cx8800_dev *dev,
67 q->count = 1; 66 q->count = 1;
68 67
69 /* enable irqs */ 68 /* enable irqs */
70 cx_set(MO_PCI_INTMSK, core->pci_irqmask | 0x01); 69 cx_set(MO_PCI_INTMSK, core->pci_irqmask | PCI_INT_VIDINT);
71 cx_set(MO_VID_INTMSK, 0x0f0088); 70 cx_set(MO_VID_INTMSK, 0x0f0088);
72 71
73 /* enable capture */ 72 /* enable capture */
@@ -91,7 +90,7 @@ int cx8800_stop_vbi_dma(struct cx8800_dev *dev)
91 cx_clear(VID_CAPTURE_CONTROL,0x18); 90 cx_clear(VID_CAPTURE_CONTROL,0x18);
92 91
93 /* disable irqs */ 92 /* disable irqs */
94 cx_clear(MO_PCI_INTMSK, 0x000001); 93 cx_clear(MO_PCI_INTMSK, PCI_INT_VIDINT);
95 cx_clear(MO_VID_INTMSK, 0x0f0088); 94 cx_clear(MO_VID_INTMSK, 0x0f0088);
96 return 0; 95 return 0;
97} 96}
@@ -100,7 +99,6 @@ int cx8800_restart_vbi_queue(struct cx8800_dev *dev,
100 struct cx88_dmaqueue *q) 99 struct cx88_dmaqueue *q)
101{ 100{
102 struct cx88_buffer *buf; 101 struct cx88_buffer *buf;
103 struct list_head *item;
104 102
105 if (list_empty(&q->active)) 103 if (list_empty(&q->active))
106 return 0; 104 return 0;
@@ -109,10 +107,8 @@ int cx8800_restart_vbi_queue(struct cx8800_dev *dev,
109 dprintk(2,"restart_queue [%p/%d]: restart dma\n", 107 dprintk(2,"restart_queue [%p/%d]: restart dma\n",
110 buf, buf->vb.i); 108 buf, buf->vb.i);
111 cx8800_start_vbi_dma(dev, q, buf); 109 cx8800_start_vbi_dma(dev, q, buf);
112 list_for_each(item,&q->active) { 110 list_for_each_entry(buf, &q->active, vb.queue)
113 buf = list_entry(item, struct cx88_buffer, vb.queue);
114 buf->count = q->count++; 111 buf->count = q->count++;
115 }
116 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT); 112 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
117 return 0; 113 return 0;
118} 114}
@@ -173,6 +169,7 @@ vbi_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
173 return -EINVAL; 169 return -EINVAL;
174 170
175 if (STATE_NEEDS_INIT == buf->vb.state) { 171 if (STATE_NEEDS_INIT == buf->vb.state) {
172 struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb);
176 buf->vb.width = VBI_LINE_LENGTH; 173 buf->vb.width = VBI_LINE_LENGTH;
177 buf->vb.height = VBI_LINE_COUNT; 174 buf->vb.height = VBI_LINE_COUNT;
178 buf->vb.size = size; 175 buf->vb.size = size;
@@ -181,7 +178,7 @@ vbi_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
181 if (0 != (rc = videobuf_iolock(q,&buf->vb,NULL))) 178 if (0 != (rc = videobuf_iolock(q,&buf->vb,NULL)))
182 goto fail; 179 goto fail;
183 cx88_risc_buffer(dev->pci, &buf->risc, 180 cx88_risc_buffer(dev->pci, &buf->risc,
184 buf->vb.dma.sglist, 181 dma->sglist,
185 0, buf->vb.width * buf->vb.height, 182 0, buf->vb.width * buf->vb.height,
186 buf->vb.width, 0, 183 buf->vb.width, 0,
187 buf->vb.height); 184 buf->vb.height);
diff --git a/drivers/media/video/cx88/cx88-video.c b/drivers/media/video/cx88/cx88-video.c
index 06b233a7b20b..231ae6c4dd22 100644
--- a/drivers/media/video/cx88/cx88-video.c
+++ b/drivers/media/video/cx88/cx88-video.c
@@ -28,7 +28,6 @@
28#include <linux/init.h> 28#include <linux/init.h>
29#include <linux/list.h> 29#include <linux/list.h>
30#include <linux/module.h> 30#include <linux/module.h>
31#include <linux/moduleparam.h>
32#include <linux/kmod.h> 31#include <linux/kmod.h>
33#include <linux/kernel.h> 32#include <linux/kernel.h>
34#include <linux/slab.h> 33#include <linux/slab.h>
@@ -36,7 +35,6 @@
36#include <linux/dma-mapping.h> 35#include <linux/dma-mapping.h>
37#include <linux/delay.h> 36#include <linux/delay.h>
38#include <linux/kthread.h> 37#include <linux/kthread.h>
39#include <linux/dma-mapping.h>
40#include <asm/div64.h> 38#include <asm/div64.h>
41 39
42#include "cx88.h" 40#include "cx88.h"
@@ -369,17 +367,17 @@ int cx88_video_mux(struct cx88_core *core, unsigned int input)
369 /* struct cx88_core *core = dev->core; */ 367 /* struct cx88_core *core = dev->core; */
370 368
371 dprintk(1,"video_mux: %d [vmux=%d,gpio=0x%x,0x%x,0x%x,0x%x]\n", 369 dprintk(1,"video_mux: %d [vmux=%d,gpio=0x%x,0x%x,0x%x,0x%x]\n",
372 input, INPUT(input)->vmux, 370 input, INPUT(input).vmux,
373 INPUT(input)->gpio0,INPUT(input)->gpio1, 371 INPUT(input).gpio0,INPUT(input).gpio1,
374 INPUT(input)->gpio2,INPUT(input)->gpio3); 372 INPUT(input).gpio2,INPUT(input).gpio3);
375 core->input = input; 373 core->input = input;
376 cx_andor(MO_INPUT_FORMAT, 0x03 << 14, INPUT(input)->vmux << 14); 374 cx_andor(MO_INPUT_FORMAT, 0x03 << 14, INPUT(input).vmux << 14);
377 cx_write(MO_GP3_IO, INPUT(input)->gpio3); 375 cx_write(MO_GP3_IO, INPUT(input).gpio3);
378 cx_write(MO_GP0_IO, INPUT(input)->gpio0); 376 cx_write(MO_GP0_IO, INPUT(input).gpio0);
379 cx_write(MO_GP1_IO, INPUT(input)->gpio1); 377 cx_write(MO_GP1_IO, INPUT(input).gpio1);
380 cx_write(MO_GP2_IO, INPUT(input)->gpio2); 378 cx_write(MO_GP2_IO, INPUT(input).gpio2);
381 379
382 switch (INPUT(input)->type) { 380 switch (INPUT(input).type) {
383 case CX88_VMUX_SVIDEO: 381 case CX88_VMUX_SVIDEO:
384 cx_set(MO_AFECFG_IO, 0x00000001); 382 cx_set(MO_AFECFG_IO, 0x00000001);
385 cx_set(MO_INPUT_FORMAT, 0x00010010); 383 cx_set(MO_INPUT_FORMAT, 0x00010010);
@@ -394,9 +392,9 @@ int cx88_video_mux(struct cx88_core *core, unsigned int input)
394 break; 392 break;
395 } 393 }
396 394
397 if (cx88_boards[core->board].mpeg & CX88_MPEG_BLACKBIRD) { 395 if (core->board.mpeg & CX88_MPEG_BLACKBIRD) {
398 /* sets sound input from external adc */ 396 /* sets sound input from external adc */
399 if (INPUT(input)->extadc) 397 if (INPUT(input).extadc)
400 cx_set(AUD_CTL, EN_I2SIN_ENABLE); 398 cx_set(AUD_CTL, EN_I2SIN_ENABLE);
401 else 399 else
402 cx_clear(AUD_CTL, EN_I2SIN_ENABLE); 400 cx_clear(AUD_CTL, EN_I2SIN_ENABLE);
@@ -424,7 +422,7 @@ static int start_video_dma(struct cx8800_dev *dev,
424 q->count = 1; 422 q->count = 1;
425 423
426 /* enable irqs */ 424 /* enable irqs */
427 cx_set(MO_PCI_INTMSK, core->pci_irqmask | 0x01); 425 cx_set(MO_PCI_INTMSK, core->pci_irqmask | PCI_INT_VIDINT);
428 426
429 /* Enables corresponding bits at PCI_INT_STAT: 427 /* Enables corresponding bits at PCI_INT_STAT:
430 bits 0 to 4: video, audio, transport stream, VIP, Host 428 bits 0 to 4: video, audio, transport stream, VIP, Host
@@ -457,7 +455,7 @@ static int stop_video_dma(struct cx8800_dev *dev)
457 cx_clear(VID_CAPTURE_CONTROL,0x06); 455 cx_clear(VID_CAPTURE_CONTROL,0x06);
458 456
459 /* disable irqs */ 457 /* disable irqs */
460 cx_clear(MO_PCI_INTMSK, 0x000001); 458 cx_clear(MO_PCI_INTMSK, PCI_INT_VIDINT);
461 cx_clear(MO_VID_INTMSK, 0x0f0011); 459 cx_clear(MO_VID_INTMSK, 0x0f0011);
462 return 0; 460 return 0;
463} 461}
@@ -468,17 +466,14 @@ static int restart_video_queue(struct cx8800_dev *dev,
468{ 466{
469 struct cx88_core *core = dev->core; 467 struct cx88_core *core = dev->core;
470 struct cx88_buffer *buf, *prev; 468 struct cx88_buffer *buf, *prev;
471 struct list_head *item;
472 469
473 if (!list_empty(&q->active)) { 470 if (!list_empty(&q->active)) {
474 buf = list_entry(q->active.next, struct cx88_buffer, vb.queue); 471 buf = list_entry(q->active.next, struct cx88_buffer, vb.queue);
475 dprintk(2,"restart_queue [%p/%d]: restart dma\n", 472 dprintk(2,"restart_queue [%p/%d]: restart dma\n",
476 buf, buf->vb.i); 473 buf, buf->vb.i);
477 start_video_dma(dev, q, buf); 474 start_video_dma(dev, q, buf);
478 list_for_each(item,&q->active) { 475 list_for_each_entry(buf, &q->active, vb.queue)
479 buf = list_entry(item, struct cx88_buffer, vb.queue); 476 buf->count = q->count++;
480 buf->count = q->count++;
481 }
482 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT); 477 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
483 return 0; 478 return 0;
484 } 479 }
@@ -536,6 +531,7 @@ buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
536 struct cx8800_dev *dev = fh->dev; 531 struct cx8800_dev *dev = fh->dev;
537 struct cx88_core *core = dev->core; 532 struct cx88_core *core = dev->core;
538 struct cx88_buffer *buf = container_of(vb,struct cx88_buffer,vb); 533 struct cx88_buffer *buf = container_of(vb,struct cx88_buffer,vb);
534 struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb);
539 int rc, init_buffer = 0; 535 int rc, init_buffer = 0;
540 536
541 BUG_ON(NULL == fh->fmt); 537 BUG_ON(NULL == fh->fmt);
@@ -568,30 +564,30 @@ buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
568 switch (buf->vb.field) { 564 switch (buf->vb.field) {
569 case V4L2_FIELD_TOP: 565 case V4L2_FIELD_TOP:
570 cx88_risc_buffer(dev->pci, &buf->risc, 566 cx88_risc_buffer(dev->pci, &buf->risc,
571 buf->vb.dma.sglist, 0, UNSET, 567 dma->sglist, 0, UNSET,
572 buf->bpl, 0, buf->vb.height); 568 buf->bpl, 0, buf->vb.height);
573 break; 569 break;
574 case V4L2_FIELD_BOTTOM: 570 case V4L2_FIELD_BOTTOM:
575 cx88_risc_buffer(dev->pci, &buf->risc, 571 cx88_risc_buffer(dev->pci, &buf->risc,
576 buf->vb.dma.sglist, UNSET, 0, 572 dma->sglist, UNSET, 0,
577 buf->bpl, 0, buf->vb.height); 573 buf->bpl, 0, buf->vb.height);
578 break; 574 break;
579 case V4L2_FIELD_INTERLACED: 575 case V4L2_FIELD_INTERLACED:
580 cx88_risc_buffer(dev->pci, &buf->risc, 576 cx88_risc_buffer(dev->pci, &buf->risc,
581 buf->vb.dma.sglist, 0, buf->bpl, 577 dma->sglist, 0, buf->bpl,
582 buf->bpl, buf->bpl, 578 buf->bpl, buf->bpl,
583 buf->vb.height >> 1); 579 buf->vb.height >> 1);
584 break; 580 break;
585 case V4L2_FIELD_SEQ_TB: 581 case V4L2_FIELD_SEQ_TB:
586 cx88_risc_buffer(dev->pci, &buf->risc, 582 cx88_risc_buffer(dev->pci, &buf->risc,
587 buf->vb.dma.sglist, 583 dma->sglist,
588 0, buf->bpl * (buf->vb.height >> 1), 584 0, buf->bpl * (buf->vb.height >> 1),
589 buf->bpl, 0, 585 buf->bpl, 0,
590 buf->vb.height >> 1); 586 buf->vb.height >> 1);
591 break; 587 break;
592 case V4L2_FIELD_SEQ_BT: 588 case V4L2_FIELD_SEQ_BT:
593 cx88_risc_buffer(dev->pci, &buf->risc, 589 cx88_risc_buffer(dev->pci, &buf->risc,
594 buf->vb.dma.sglist, 590 dma->sglist,
595 buf->bpl * (buf->vb.height >> 1), 0, 591 buf->bpl * (buf->vb.height >> 1), 0,
596 buf->bpl, 0, 592 buf->bpl, 0,
597 buf->vb.height >> 1); 593 buf->vb.height >> 1);
@@ -714,12 +710,10 @@ static int video_open(struct inode *inode, struct file *file)
714 struct cx8800_dev *h,*dev = NULL; 710 struct cx8800_dev *h,*dev = NULL;
715 struct cx88_core *core; 711 struct cx88_core *core;
716 struct cx8800_fh *fh; 712 struct cx8800_fh *fh;
717 struct list_head *list;
718 enum v4l2_buf_type type = 0; 713 enum v4l2_buf_type type = 0;
719 int radio = 0; 714 int radio = 0;
720 715
721 list_for_each(list,&cx8800_devlist) { 716 list_for_each_entry(h, &cx8800_devlist, devlist) {
722 h = list_entry(list, struct cx8800_dev, devlist);
723 if (h->video_dev->minor == minor) { 717 if (h->video_dev->minor == minor) {
724 dev = h; 718 dev = h;
725 type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 719 type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
@@ -754,13 +748,13 @@ static int video_open(struct inode *inode, struct file *file)
754 fh->height = 240; 748 fh->height = 240;
755 fh->fmt = format_by_fourcc(V4L2_PIX_FMT_BGR24); 749 fh->fmt = format_by_fourcc(V4L2_PIX_FMT_BGR24);
756 750
757 videobuf_queue_init(&fh->vidq, &cx8800_video_qops, 751 videobuf_queue_pci_init(&fh->vidq, &cx8800_video_qops,
758 dev->pci, &dev->slock, 752 dev->pci, &dev->slock,
759 V4L2_BUF_TYPE_VIDEO_CAPTURE, 753 V4L2_BUF_TYPE_VIDEO_CAPTURE,
760 V4L2_FIELD_INTERLACED, 754 V4L2_FIELD_INTERLACED,
761 sizeof(struct cx88_buffer), 755 sizeof(struct cx88_buffer),
762 fh); 756 fh);
763 videobuf_queue_init(&fh->vbiq, &cx8800_vbi_qops, 757 videobuf_queue_pci_init(&fh->vbiq, &cx8800_vbi_qops,
764 dev->pci, &dev->slock, 758 dev->pci, &dev->slock,
765 V4L2_BUF_TYPE_VBI_CAPTURE, 759 V4L2_BUF_TYPE_VBI_CAPTURE,
766 V4L2_FIELD_SEQ_TB, 760 V4L2_FIELD_SEQ_TB,
@@ -768,12 +762,11 @@ static int video_open(struct inode *inode, struct file *file)
768 fh); 762 fh);
769 763
770 if (fh->radio) { 764 if (fh->radio) {
771 int board = core->board;
772 dprintk(1,"video_open: setting radio device\n"); 765 dprintk(1,"video_open: setting radio device\n");
773 cx_write(MO_GP3_IO, cx88_boards[board].radio.gpio3); 766 cx_write(MO_GP3_IO, core->board.radio.gpio3);
774 cx_write(MO_GP0_IO, cx88_boards[board].radio.gpio0); 767 cx_write(MO_GP0_IO, core->board.radio.gpio0);
775 cx_write(MO_GP1_IO, cx88_boards[board].radio.gpio1); 768 cx_write(MO_GP1_IO, core->board.radio.gpio1);
776 cx_write(MO_GP2_IO, cx88_boards[board].radio.gpio2); 769 cx_write(MO_GP2_IO, core->board.radio.gpio2);
777 core->tvaudio = WW_FM; 770 core->tvaudio = WW_FM;
778 cx88_set_tvaudio(core); 771 cx88_set_tvaudio(core);
779 cx88_set_stereo(core,V4L2_TUNER_MODE_STEREO,1); 772 cx88_set_stereo(core,V4L2_TUNER_MODE_STEREO,1);
@@ -1079,8 +1072,7 @@ static int vidioc_querycap (struct file *file, void *priv,
1079 struct cx88_core *core = dev->core; 1072 struct cx88_core *core = dev->core;
1080 1073
1081 strcpy(cap->driver, "cx8800"); 1074 strcpy(cap->driver, "cx8800");
1082 strlcpy(cap->card, cx88_boards[core->board].name, 1075 strlcpy(cap->card, core->board.name, sizeof(cap->card));
1083 sizeof(cap->card));
1084 sprintf(cap->bus_info,"PCI:%s",pci_name(dev->pci)); 1076 sprintf(cap->bus_info,"PCI:%s",pci_name(dev->pci));
1085 cap->version = CX88_VERSION_CODE; 1077 cap->version = CX88_VERSION_CODE;
1086 cap->capabilities = 1078 cap->capabilities =
@@ -1088,7 +1080,7 @@ static int vidioc_querycap (struct file *file, void *priv,
1088 V4L2_CAP_READWRITE | 1080 V4L2_CAP_READWRITE |
1089 V4L2_CAP_STREAMING | 1081 V4L2_CAP_STREAMING |
1090 V4L2_CAP_VBI_CAPTURE; 1082 V4L2_CAP_VBI_CAPTURE;
1091 if (UNSET != core->tuner_type) 1083 if (UNSET != core->board.tuner_type)
1092 cap->capabilities |= V4L2_CAP_TUNER; 1084 cap->capabilities |= V4L2_CAP_TUNER;
1093 return 0; 1085 return 0;
1094} 1086}
@@ -1108,28 +1100,9 @@ static int vidioc_enum_fmt_cap (struct file *file, void *priv,
1108#ifdef CONFIG_VIDEO_V4L1_COMPAT 1100#ifdef CONFIG_VIDEO_V4L1_COMPAT
1109static int vidiocgmbuf (struct file *file, void *priv, struct video_mbuf *mbuf) 1101static int vidiocgmbuf (struct file *file, void *priv, struct video_mbuf *mbuf)
1110{ 1102{
1111 struct cx8800_fh *fh = priv; 1103 struct cx8800_fh *fh = priv;
1112 struct videobuf_queue *q;
1113 struct v4l2_requestbuffers req;
1114 unsigned int i;
1115 int err;
1116 1104
1117 q = get_queue(fh); 1105 return videobuf_cgmbuf (get_queue(fh), mbuf, 8);
1118 memset(&req,0,sizeof(req));
1119 req.type = q->type;
1120 req.count = 8;
1121 req.memory = V4L2_MEMORY_MMAP;
1122 err = videobuf_reqbufs(q,&req);
1123 if (err < 0)
1124 return err;
1125
1126 mbuf->frames = req.count;
1127 mbuf->size = 0;
1128 for (i = 0; i < mbuf->frames; i++) {
1129 mbuf->offsets[i] = q->bufs[i]->boff;
1130 mbuf->size += q->bufs[i]->bsize;
1131 }
1132 return 0;
1133} 1106}
1134#endif 1107#endif
1135 1108
@@ -1222,14 +1195,14 @@ int cx88_enum_input (struct cx88_core *core,struct v4l2_input *i)
1222 n = i->index; 1195 n = i->index;
1223 if (n >= 4) 1196 if (n >= 4)
1224 return -EINVAL; 1197 return -EINVAL;
1225 if (0 == INPUT(n)->type) 1198 if (0 == INPUT(n).type)
1226 return -EINVAL; 1199 return -EINVAL;
1227 memset(i,0,sizeof(*i)); 1200 memset(i,0,sizeof(*i));
1228 i->index = n; 1201 i->index = n;
1229 i->type = V4L2_INPUT_TYPE_CAMERA; 1202 i->type = V4L2_INPUT_TYPE_CAMERA;
1230 strcpy(i->name,iname[INPUT(n)->type]); 1203 strcpy(i->name,iname[INPUT(n).type]);
1231 if ((CX88_VMUX_TELEVISION == INPUT(n)->type) || 1204 if ((CX88_VMUX_TELEVISION == INPUT(n).type) ||
1232 (CX88_VMUX_CABLE == INPUT(n)->type)) 1205 (CX88_VMUX_CABLE == INPUT(n).type))
1233 i->type = V4L2_INPUT_TYPE_TUNER; 1206 i->type = V4L2_INPUT_TYPE_TUNER;
1234 i->std = CX88_NORMS; 1207 i->std = CX88_NORMS;
1235 return 0; 1208 return 0;
@@ -1298,7 +1271,7 @@ static int vidioc_g_tuner (struct file *file, void *priv,
1298 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core; 1271 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1299 u32 reg; 1272 u32 reg;
1300 1273
1301 if (unlikely(UNSET == core->tuner_type)) 1274 if (unlikely(UNSET == core->board.tuner_type))
1302 return -EINVAL; 1275 return -EINVAL;
1303 if (0 != t->index) 1276 if (0 != t->index)
1304 return -EINVAL; 1277 return -EINVAL;
@@ -1319,7 +1292,7 @@ static int vidioc_s_tuner (struct file *file, void *priv,
1319{ 1292{
1320 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core; 1293 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1321 1294
1322 if (UNSET == core->tuner_type) 1295 if (UNSET == core->board.tuner_type)
1323 return -EINVAL; 1296 return -EINVAL;
1324 if (0 != t->index) 1297 if (0 != t->index)
1325 return -EINVAL; 1298 return -EINVAL;
@@ -1334,7 +1307,7 @@ static int vidioc_g_frequency (struct file *file, void *priv,
1334 struct cx8800_fh *fh = priv; 1307 struct cx8800_fh *fh = priv;
1335 struct cx88_core *core = fh->dev->core; 1308 struct cx88_core *core = fh->dev->core;
1336 1309
1337 if (unlikely(UNSET == core->tuner_type)) 1310 if (unlikely(UNSET == core->board.tuner_type))
1338 return -EINVAL; 1311 return -EINVAL;
1339 1312
1340 /* f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; */ 1313 /* f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; */
@@ -1349,7 +1322,7 @@ static int vidioc_g_frequency (struct file *file, void *priv,
1349int cx88_set_freq (struct cx88_core *core, 1322int cx88_set_freq (struct cx88_core *core,
1350 struct v4l2_frequency *f) 1323 struct v4l2_frequency *f)
1351{ 1324{
1352 if (unlikely(UNSET == core->tuner_type)) 1325 if (unlikely(UNSET == core->board.tuner_type))
1353 return -EINVAL; 1326 return -EINVAL;
1354 if (unlikely(f->tuner != 0)) 1327 if (unlikely(f->tuner != 0))
1355 return -EINVAL; 1328 return -EINVAL;
@@ -1420,8 +1393,7 @@ static int radio_querycap (struct file *file, void *priv,
1420 struct cx88_core *core = dev->core; 1393 struct cx88_core *core = dev->core;
1421 1394
1422 strcpy(cap->driver, "cx8800"); 1395 strcpy(cap->driver, "cx8800");
1423 strlcpy(cap->card, cx88_boards[core->board].name, 1396 strlcpy(cap->card, core->board.name, sizeof(cap->card));
1424 sizeof(cap->card));
1425 sprintf(cap->bus_info,"PCI:%s", pci_name(dev->pci)); 1397 sprintf(cap->bus_info,"PCI:%s", pci_name(dev->pci));
1426 cap->version = CX88_VERSION_CODE; 1398 cap->version = CX88_VERSION_CODE;
1427 cap->capabilities = V4L2_CAP_TUNER; 1399 cap->capabilities = V4L2_CAP_TUNER;
@@ -1608,7 +1580,8 @@ static irqreturn_t cx8800_irq(int irq, void *dev_id)
1608 int loop, handled = 0; 1580 int loop, handled = 0;
1609 1581
1610 for (loop = 0; loop < 10; loop++) { 1582 for (loop = 0; loop < 10; loop++) {
1611 status = cx_read(MO_PCI_INTSTAT) & (core->pci_irqmask | 0x01); 1583 status = cx_read(MO_PCI_INTSTAT) &
1584 (core->pci_irqmask | PCI_INT_VIDINT);
1612 if (0 == status) 1585 if (0 == status)
1613 goto out; 1586 goto out;
1614 cx_write(MO_PCI_INTSTAT, status); 1587 cx_write(MO_PCI_INTSTAT, status);
@@ -1616,7 +1589,7 @@ static irqreturn_t cx8800_irq(int irq, void *dev_id)
1616 1589
1617 if (status & core->pci_irqmask) 1590 if (status & core->pci_irqmask)
1618 cx88_core_irq(core,status); 1591 cx88_core_irq(core,status);
1619 if (status & 0x01) 1592 if (status & PCI_INT_VIDINT)
1620 cx8800_vid_irq(dev); 1593 cx8800_vid_irq(dev);
1621 }; 1594 };
1622 if (10 == loop) { 1595 if (10 == loop) {
@@ -1717,6 +1690,10 @@ static struct video_device cx8800_radio_template =
1717 .vidioc_s_ctrl = vidioc_s_ctrl, 1690 .vidioc_s_ctrl = vidioc_s_ctrl,
1718 .vidioc_g_frequency = vidioc_g_frequency, 1691 .vidioc_g_frequency = vidioc_g_frequency,
1719 .vidioc_s_frequency = vidioc_s_frequency, 1692 .vidioc_s_frequency = vidioc_s_frequency,
1693#ifdef CONFIG_VIDEO_ADV_DEBUG
1694 .vidioc_g_register = vidioc_g_register,
1695 .vidioc_s_register = vidioc_s_register,
1696#endif
1720}; 1697};
1721 1698
1722/* ----------------------------------------------------------- */ 1699/* ----------------------------------------------------------- */
@@ -1818,26 +1795,32 @@ static int __devinit cx8800_initdev(struct pci_dev *pci_dev,
1818 err = request_irq(pci_dev->irq, cx8800_irq, 1795 err = request_irq(pci_dev->irq, cx8800_irq,
1819 IRQF_SHARED | IRQF_DISABLED, core->name, dev); 1796 IRQF_SHARED | IRQF_DISABLED, core->name, dev);
1820 if (err < 0) { 1797 if (err < 0) {
1821 printk(KERN_ERR "%s: can't get IRQ %d\n", 1798 printk(KERN_ERR "%s/0: can't get IRQ %d\n",
1822 core->name,pci_dev->irq); 1799 core->name,pci_dev->irq);
1823 goto fail_core; 1800 goto fail_core;
1824 } 1801 }
1825 cx_set(MO_PCI_INTMSK, core->pci_irqmask); 1802 cx_set(MO_PCI_INTMSK, core->pci_irqmask);
1826 1803
1827 /* load and configure helper modules */ 1804 /* load and configure helper modules */
1828 if (TUNER_ABSENT != core->tuner_type) 1805 if (TUNER_ABSENT != core->board.tuner_type)
1829 request_module("tuner"); 1806 request_module("tuner");
1830 1807
1831 if (cx88_boards[ core->board ].audio_chip == AUDIO_CHIP_WM8775) 1808 if (core->board.audio_chip == AUDIO_CHIP_WM8775)
1832 request_module("wm8775"); 1809 request_module("wm8775");
1833 1810
1811 switch (core->boardnr) {
1812 case CX88_BOARD_DVICO_FUSIONHDTV_5_GOLD:
1813 request_module("ir-kbd-i2c");
1814 request_module("rtc-isl1208");
1815 }
1816
1834 /* register v4l devices */ 1817 /* register v4l devices */
1835 dev->video_dev = cx88_vdev_init(core,dev->pci, 1818 dev->video_dev = cx88_vdev_init(core,dev->pci,
1836 &cx8800_video_template,"video"); 1819 &cx8800_video_template,"video");
1837 err = video_register_device(dev->video_dev,VFL_TYPE_GRABBER, 1820 err = video_register_device(dev->video_dev,VFL_TYPE_GRABBER,
1838 video_nr[core->nr]); 1821 video_nr[core->nr]);
1839 if (err < 0) { 1822 if (err < 0) {
1840 printk(KERN_INFO "%s: can't register video device\n", 1823 printk(KERN_ERR "%s/0: can't register video device\n",
1841 core->name); 1824 core->name);
1842 goto fail_unreg; 1825 goto fail_unreg;
1843 } 1826 }
@@ -1848,20 +1831,20 @@ static int __devinit cx8800_initdev(struct pci_dev *pci_dev,
1848 err = video_register_device(dev->vbi_dev,VFL_TYPE_VBI, 1831 err = video_register_device(dev->vbi_dev,VFL_TYPE_VBI,
1849 vbi_nr[core->nr]); 1832 vbi_nr[core->nr]);
1850 if (err < 0) { 1833 if (err < 0) {
1851 printk(KERN_INFO "%s/0: can't register vbi device\n", 1834 printk(KERN_ERR "%s/0: can't register vbi device\n",
1852 core->name); 1835 core->name);
1853 goto fail_unreg; 1836 goto fail_unreg;
1854 } 1837 }
1855 printk(KERN_INFO "%s/0: registered device vbi%d\n", 1838 printk(KERN_INFO "%s/0: registered device vbi%d\n",
1856 core->name,dev->vbi_dev->minor & 0x1f); 1839 core->name,dev->vbi_dev->minor & 0x1f);
1857 1840
1858 if (core->has_radio) { 1841 if (core->board.radio.type == CX88_RADIO) {
1859 dev->radio_dev = cx88_vdev_init(core,dev->pci, 1842 dev->radio_dev = cx88_vdev_init(core,dev->pci,
1860 &cx8800_radio_template,"radio"); 1843 &cx8800_radio_template,"radio");
1861 err = video_register_device(dev->radio_dev,VFL_TYPE_RADIO, 1844 err = video_register_device(dev->radio_dev,VFL_TYPE_RADIO,
1862 radio_nr[core->nr]); 1845 radio_nr[core->nr]);
1863 if (err < 0) { 1846 if (err < 0) {
1864 printk(KERN_INFO "%s/0: can't register radio device\n", 1847 printk(KERN_ERR "%s/0: can't register radio device\n",
1865 core->name); 1848 core->name);
1866 goto fail_unreg; 1849 goto fail_unreg;
1867 } 1850 }
@@ -1881,12 +1864,12 @@ static int __devinit cx8800_initdev(struct pci_dev *pci_dev,
1881 mutex_unlock(&core->lock); 1864 mutex_unlock(&core->lock);
1882 1865
1883 /* start tvaudio thread */ 1866 /* start tvaudio thread */
1884 if (core->tuner_type != TUNER_ABSENT) { 1867 if (core->board.tuner_type != TUNER_ABSENT) {
1885 core->kthread = kthread_run(cx88_audio_thread, core, "cx88 tvaudio"); 1868 core->kthread = kthread_run(cx88_audio_thread, core, "cx88 tvaudio");
1886 if (IS_ERR(core->kthread)) { 1869 if (IS_ERR(core->kthread)) {
1887 err = PTR_ERR(core->kthread); 1870 err = PTR_ERR(core->kthread);
1888 printk(KERN_ERR "Failed to create cx88 audio thread, err=%d\n", 1871 printk(KERN_ERR "%s/0: failed to create cx88 audio thread, err=%d\n",
1889 err); 1872 core->name, err);
1890 } 1873 }
1891 } 1874 }
1892 return 0; 1875 return 0;
@@ -1937,17 +1920,19 @@ static int cx8800_suspend(struct pci_dev *pci_dev, pm_message_t state)
1937 /* stop video+vbi capture */ 1920 /* stop video+vbi capture */
1938 spin_lock(&dev->slock); 1921 spin_lock(&dev->slock);
1939 if (!list_empty(&dev->vidq.active)) { 1922 if (!list_empty(&dev->vidq.active)) {
1940 printk("%s: suspend video\n", core->name); 1923 printk("%s/0: suspend video\n", core->name);
1941 stop_video_dma(dev); 1924 stop_video_dma(dev);
1942 del_timer(&dev->vidq.timeout); 1925 del_timer(&dev->vidq.timeout);
1943 } 1926 }
1944 if (!list_empty(&dev->vbiq.active)) { 1927 if (!list_empty(&dev->vbiq.active)) {
1945 printk("%s: suspend vbi\n", core->name); 1928 printk("%s/0: suspend vbi\n", core->name);
1946 cx8800_stop_vbi_dma(dev); 1929 cx8800_stop_vbi_dma(dev);
1947 del_timer(&dev->vbiq.timeout); 1930 del_timer(&dev->vbiq.timeout);
1948 } 1931 }
1949 spin_unlock(&dev->slock); 1932 spin_unlock(&dev->slock);
1950 1933
1934 if (core->ir)
1935 cx88_ir_stop(core, core->ir);
1951 /* FIXME -- shutdown device */ 1936 /* FIXME -- shutdown device */
1952 cx88_shutdown(core); 1937 cx88_shutdown(core);
1953 1938
@@ -1968,8 +1953,8 @@ static int cx8800_resume(struct pci_dev *pci_dev)
1968 if (dev->state.disabled) { 1953 if (dev->state.disabled) {
1969 err=pci_enable_device(pci_dev); 1954 err=pci_enable_device(pci_dev);
1970 if (err) { 1955 if (err) {
1971 printk(KERN_ERR "%s: can't enable device\n", 1956 printk(KERN_ERR "%s/0: can't enable device\n",
1972 core->name); 1957 core->name);
1973 return err; 1958 return err;
1974 } 1959 }
1975 1960
@@ -1977,9 +1962,7 @@ static int cx8800_resume(struct pci_dev *pci_dev)
1977 } 1962 }
1978 err= pci_set_power_state(pci_dev, PCI_D0); 1963 err= pci_set_power_state(pci_dev, PCI_D0);
1979 if (err) { 1964 if (err) {
1980 printk(KERN_ERR "%s: can't enable device\n", 1965 printk(KERN_ERR "%s/0: can't set power state\n", core->name);
1981 core->name);
1982
1983 pci_disable_device(pci_dev); 1966 pci_disable_device(pci_dev);
1984 dev->state.disabled = 1; 1967 dev->state.disabled = 1;
1985 1968
@@ -1989,15 +1972,19 @@ static int cx8800_resume(struct pci_dev *pci_dev)
1989 1972
1990 /* FIXME: re-initialize hardware */ 1973 /* FIXME: re-initialize hardware */
1991 cx88_reset(core); 1974 cx88_reset(core);
1975 if (core->ir)
1976 cx88_ir_start(core, core->ir);
1977
1978 cx_set(MO_PCI_INTMSK, core->pci_irqmask);
1992 1979
1993 /* restart video+vbi capture */ 1980 /* restart video+vbi capture */
1994 spin_lock(&dev->slock); 1981 spin_lock(&dev->slock);
1995 if (!list_empty(&dev->vidq.active)) { 1982 if (!list_empty(&dev->vidq.active)) {
1996 printk("%s: resume video\n", core->name); 1983 printk("%s/0: resume video\n", core->name);
1997 restart_video_queue(dev,&dev->vidq); 1984 restart_video_queue(dev,&dev->vidq);
1998 } 1985 }
1999 if (!list_empty(&dev->vbiq.active)) { 1986 if (!list_empty(&dev->vbiq.active)) {
2000 printk("%s: resume vbi\n", core->name); 1987 printk("%s/0: resume vbi\n", core->name);
2001 cx8800_restart_vbi_queue(dev,&dev->vbiq); 1988 cx8800_restart_vbi_queue(dev,&dev->vbiq);
2002 } 1989 }
2003 spin_unlock(&dev->slock); 1990 spin_unlock(&dev->slock);
@@ -2033,7 +2020,7 @@ static struct pci_driver cx8800_pci_driver = {
2033 2020
2034static int cx8800_init(void) 2021static int cx8800_init(void)
2035{ 2022{
2036 printk(KERN_INFO "cx2388x v4l2 driver version %d.%d.%d loaded\n", 2023 printk(KERN_INFO "cx88/0: cx2388x v4l2 driver version %d.%d.%d loaded\n",
2037 (CX88_VERSION_CODE >> 16) & 0xff, 2024 (CX88_VERSION_CODE >> 16) & 0xff,
2038 (CX88_VERSION_CODE >> 8) & 0xff, 2025 (CX88_VERSION_CODE >> 8) & 0xff,
2039 CX88_VERSION_CODE & 0xff); 2026 CX88_VERSION_CODE & 0xff);
diff --git a/drivers/media/video/cx88/cx88-vp3054-i2c.c b/drivers/media/video/cx88/cx88-vp3054-i2c.c
index cd0877636a32..77c37889232b 100644
--- a/drivers/media/video/cx88/cx88-vp3054-i2c.c
+++ b/drivers/media/video/cx88/cx88-vp3054-i2c.c
@@ -23,7 +23,6 @@
23*/ 23*/
24 24
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/moduleparam.h>
27#include <linux/init.h> 26#include <linux/init.h>
28 27
29#include <asm/io.h> 28#include <asm/io.h>
@@ -111,7 +110,7 @@ int vp3054_i2c_probe(struct cx8802_dev *dev)
111 struct vp3054_i2c_state *vp3054_i2c; 110 struct vp3054_i2c_state *vp3054_i2c;
112 int rc; 111 int rc;
113 112
114 if (core->board != CX88_BOARD_DNTV_LIVE_DVB_T_PRO) 113 if (core->boardnr != CX88_BOARD_DNTV_LIVE_DVB_T_PRO)
115 return 0; 114 return 0;
116 115
117 dev->card_priv = kzalloc(sizeof(*vp3054_i2c), GFP_KERNEL); 116 dev->card_priv = kzalloc(sizeof(*vp3054_i2c), GFP_KERNEL);
@@ -152,7 +151,7 @@ void vp3054_i2c_remove(struct cx8802_dev *dev)
152 struct vp3054_i2c_state *vp3054_i2c = dev->card_priv; 151 struct vp3054_i2c_state *vp3054_i2c = dev->card_priv;
153 152
154 if (vp3054_i2c == NULL || 153 if (vp3054_i2c == NULL ||
155 dev->core->board != CX88_BOARD_DNTV_LIVE_DVB_T_PRO) 154 dev->core->boardnr != CX88_BOARD_DNTV_LIVE_DVB_T_PRO)
156 return; 155 return;
157 156
158 i2c_del_adapter(&vp3054_i2c->adap); 157 i2c_del_adapter(&vp3054_i2c->adap);
diff --git a/drivers/media/video/cx88/cx88.h b/drivers/media/video/cx88/cx88.h
index 809126866a3e..42e0a9b8c550 100644
--- a/drivers/media/video/cx88/cx88.h
+++ b/drivers/media/video/cx88/cx88.h
@@ -28,11 +28,11 @@
28#include <media/v4l2-common.h> 28#include <media/v4l2-common.h>
29#include <media/tuner.h> 29#include <media/tuner.h>
30#include <media/tveeprom.h> 30#include <media/tveeprom.h>
31#include <media/video-buf.h> 31#include <media/videobuf-dma-sg.h>
32#include <media/cx2341x.h> 32#include <media/cx2341x.h>
33#include <media/audiochip.h> 33#include <media/audiochip.h>
34#if defined(CONFIG_VIDEO_BUF_DVB) || defined(CONFIG_VIDEO_BUF_DVB_MODULE) 34#if defined(CONFIG_VIDEO_CX88_DVB) || defined(CONFIG_VIDEO_CX88_DVB_MODULE)
35#include <media/video-buf-dvb.h> 35#include <media/videobuf-dvb.h>
36#endif 36#endif
37 37
38#include "btcx-risc.h" 38#include "btcx-risc.h"
@@ -226,8 +226,8 @@ enum cx88_itype {
226 226
227struct cx88_input { 227struct cx88_input {
228 enum cx88_itype type; 228 enum cx88_itype type;
229 unsigned int vmux;
230 u32 gpio0, gpio1, gpio2, gpio3; 229 u32 gpio0, gpio1, gpio2, gpio3;
230 unsigned int vmux:2;
231 unsigned int extadc:1; 231 unsigned int extadc:1;
232}; 232};
233 233
@@ -250,7 +250,7 @@ struct cx88_subid {
250 u32 card; 250 u32 card;
251}; 251};
252 252
253#define INPUT(nr) (&cx88_boards[core->board].input[nr]) 253#define INPUT(nr) (core->board.input[nr])
254 254
255/* ----------------------------------------------------------- */ 255/* ----------------------------------------------------------- */
256/* device / file handle status */ 256/* device / file handle status */
@@ -304,19 +304,14 @@ struct cx88_core {
304 u32 i2c_state, i2c_rc; 304 u32 i2c_state, i2c_rc;
305 305
306 /* config info -- analog */ 306 /* config info -- analog */
307 unsigned int board; 307 unsigned int boardnr;
308 unsigned int tuner_type; 308 struct cx88_board board;
309 unsigned int radio_type;
310 unsigned char tuner_addr;
311 unsigned char radio_addr;
312 unsigned int tda9887_conf;
313 unsigned int has_radio;
314 309
315 /* Supported V4L _STD_ tuner formats */ 310 /* Supported V4L _STD_ tuner formats */
316 unsigned int tuner_formats; 311 unsigned int tuner_formats;
317 312
318 /* config info -- dvb */ 313 /* config info -- dvb */
319#if defined(CONFIG_VIDEO_BUF_DVB) || defined(CONFIG_VIDEO_BUF_DVB_MODULE) 314#if defined(CONFIG_VIDEO_CX88_DVB) || defined(CONFIG_VIDEO_CX88_DVB_MODULE)
320 int (*prev_set_voltage)(struct dvb_frontend* fe, fe_sec_voltage_t voltage); 315 int (*prev_set_voltage)(struct dvb_frontend* fe, fe_sec_voltage_t voltage);
321#endif 316#endif
322 317
@@ -463,7 +458,7 @@ struct cx8802_dev {
463 int width; 458 int width;
464 int height; 459 int height;
465 460
466#if defined(CONFIG_VIDEO_BUF_DVB) || defined(CONFIG_VIDEO_BUF_DVB_MODULE) 461#if defined(CONFIG_VIDEO_CX88_DVB) || defined(CONFIG_VIDEO_CX88_DVB_MODULE)
467 /* for dvb only */ 462 /* for dvb only */
468 struct videobuf_dvb dvb; 463 struct videobuf_dvb dvb;
469 464
@@ -524,7 +519,7 @@ cx88_risc_buffer(struct pci_dev *pci, struct btcx_riscmem *risc,
524extern int 519extern int
525cx88_risc_databuffer(struct pci_dev *pci, struct btcx_riscmem *risc, 520cx88_risc_databuffer(struct pci_dev *pci, struct btcx_riscmem *risc,
526 struct scatterlist *sglist, unsigned int bpl, 521 struct scatterlist *sglist, unsigned int bpl,
527 unsigned int lines); 522 unsigned int lines, unsigned int lpi);
528extern int 523extern int
529cx88_risc_stopper(struct pci_dev *pci, struct btcx_riscmem *risc, 524cx88_risc_stopper(struct pci_dev *pci, struct btcx_riscmem *risc,
530 u32 reg, u32 mask, u32 value); 525 u32 reg, u32 mask, u32 value);
@@ -585,15 +580,9 @@ extern void cx88_call_i2c_clients(struct cx88_core *core,
585/* ----------------------------------------------------------- */ 580/* ----------------------------------------------------------- */
586/* cx88-cards.c */ 581/* cx88-cards.c */
587 582
588extern struct cx88_board cx88_boards[]; 583extern int cx88_get_resources(const struct cx88_core *core,
589extern const unsigned int cx88_bcount; 584 struct pci_dev *pci);
590 585extern struct cx88_core *cx88_core_create(struct pci_dev *pci, int nr);
591extern struct cx88_subid cx88_subids[];
592extern const unsigned int cx88_idcount;
593
594extern void cx88_card_list(struct cx88_core *core, struct pci_dev *pci);
595extern void cx88_card_setup(struct cx88_core *core);
596extern void cx88_card_setup_pre_i2c(struct cx88_core *core);
597 586
598/* ----------------------------------------------------------- */ 587/* ----------------------------------------------------------- */
599/* cx88-tvaudio.c */ 588/* cx88-tvaudio.c */
@@ -625,6 +614,8 @@ struct cx8802_driver * cx8802_get_driver(struct cx8802_dev *dev, enum cx88_board
625int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci); 614int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci);
626int cx88_ir_fini(struct cx88_core *core); 615int cx88_ir_fini(struct cx88_core *core);
627void cx88_ir_irq(struct cx88_core *core); 616void cx88_ir_irq(struct cx88_core *core);
617void cx88_ir_start(struct cx88_core *core, struct cx88_IR *ir);
618void cx88_ir_stop(struct cx88_core *core, struct cx88_IR *ir);
628 619
629/* ----------------------------------------------------------- */ 620/* ----------------------------------------------------------- */
630/* cx88-mpeg.c */ 621/* cx88-mpeg.c */
diff --git a/drivers/media/video/dpc7146.c b/drivers/media/video/dpc7146.c
index 0fcc935828f8..255dae303708 100644
--- a/drivers/media/video/dpc7146.c
+++ b/drivers/media/video/dpc7146.c
@@ -92,7 +92,6 @@ static int dpc_probe(struct saa7146_dev* dev)
92{ 92{
93 struct dpc* dpc = NULL; 93 struct dpc* dpc = NULL;
94 struct i2c_client *client; 94 struct i2c_client *client;
95 struct list_head *item;
96 95
97 dpc = kzalloc(sizeof(struct dpc), GFP_KERNEL); 96 dpc = kzalloc(sizeof(struct dpc), GFP_KERNEL);
98 if( NULL == dpc ) { 97 if( NULL == dpc ) {
@@ -116,11 +115,9 @@ static int dpc_probe(struct saa7146_dev* dev)
116 } 115 }
117 116
118 /* loop through all i2c-devices on the bus and look who is there */ 117 /* loop through all i2c-devices on the bus and look who is there */
119 list_for_each(item,&dpc->i2c_adapter.clients) { 118 list_for_each_entry(client, &dpc->i2c_adapter.clients, list)
120 client = list_entry(item, struct i2c_client, list);
121 if( I2C_SAA7111A == client->addr ) 119 if( I2C_SAA7111A == client->addr )
122 dpc->saa7111a = client; 120 dpc->saa7111a = client;
123 }
124 121
125 /* check if all devices are present */ 122 /* check if all devices are present */
126 if( 0 == dpc->saa7111a ) { 123 if( 0 == dpc->saa7111a ) {
diff --git a/drivers/media/video/em28xx/em28xx-core.c b/drivers/media/video/em28xx/em28xx-core.c
index 255a47dfb84f..d3282ec62c5b 100644
--- a/drivers/media/video/em28xx/em28xx-core.c
+++ b/drivers/media/video/em28xx/em28xx-core.c
@@ -24,7 +24,6 @@
24#include <linux/init.h> 24#include <linux/init.h>
25#include <linux/list.h> 25#include <linux/list.h>
26#include <linux/module.h> 26#include <linux/module.h>
27#include <linux/moduleparam.h>
28#include <linux/usb.h> 27#include <linux/usb.h>
29#include <linux/vmalloc.h> 28#include <linux/vmalloc.h>
30 29
diff --git a/drivers/media/video/em28xx/em28xx-input.c b/drivers/media/video/em28xx/em28xx-input.c
index 55d45b0032cf..e3894b68c4ee 100644
--- a/drivers/media/video/em28xx/em28xx-input.c
+++ b/drivers/media/video/em28xx/em28xx-input.c
@@ -22,7 +22,6 @@
22 */ 22 */
23 23
24#include <linux/module.h> 24#include <linux/module.h>
25#include <linux/moduleparam.h>
26#include <linux/init.h> 25#include <linux/init.h>
27#include <linux/delay.h> 26#include <linux/delay.h>
28#include <linux/interrupt.h> 27#include <linux/interrupt.h>
diff --git a/drivers/media/video/em28xx/em28xx-video.c b/drivers/media/video/em28xx/em28xx-video.c
index 40307f3f6fe3..b8d5327c438d 100644
--- a/drivers/media/video/em28xx/em28xx-video.c
+++ b/drivers/media/video/em28xx/em28xx-video.c
@@ -252,10 +252,8 @@ static int em28xx_v4l2_open(struct inode *inode, struct file *filp)
252 int minor = iminor(inode); 252 int minor = iminor(inode);
253 int errCode = 0; 253 int errCode = 0;
254 struct em28xx *h,*dev = NULL; 254 struct em28xx *h,*dev = NULL;
255 struct list_head *list;
256 255
257 list_for_each(list,&em28xx_devlist) { 256 list_for_each_entry(h, &em28xx_devlist, devlist) {
258 h = list_entry(list, struct em28xx, devlist);
259 if (h->vdev->minor == minor) { 257 if (h->vdev->minor == minor) {
260 dev = h; 258 dev = h;
261 dev->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 259 dev->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
@@ -268,8 +266,6 @@ static int em28xx_v4l2_open(struct inode *inode, struct file *filp)
268 if (NULL == dev) 266 if (NULL == dev)
269 return -ENODEV; 267 return -ENODEV;
270 268
271 filp->private_data=dev;
272
273 em28xx_videodbg("open minor=%d type=%s users=%d\n", 269 em28xx_videodbg("open minor=%d type=%s users=%d\n",
274 minor,v4l2_type_names[dev->type],dev->users); 270 minor,v4l2_type_names[dev->type],dev->users);
275 271
diff --git a/drivers/media/video/et61x251/et61x251_core.c b/drivers/media/video/et61x251/et61x251_core.c
index 585bd1fe0765..d5fef4c01c87 100644
--- a/drivers/media/video/et61x251/et61x251_core.c
+++ b/drivers/media/video/et61x251/et61x251_core.c
@@ -22,7 +22,6 @@
22#include <linux/init.h> 22#include <linux/init.h>
23#include <linux/kernel.h> 23#include <linux/kernel.h>
24#include <linux/param.h> 24#include <linux/param.h>
25#include <linux/moduleparam.h>
26#include <linux/errno.h> 25#include <linux/errno.h>
27#include <linux/slab.h> 26#include <linux/slab.h>
28#include <linux/device.h> 27#include <linux/device.h>
@@ -707,7 +706,8 @@ static u8 et61x251_strtou8(const char* buff, size_t len, ssize_t* count)
707 NOTE 2: buffers are PAGE_SIZE long 706 NOTE 2: buffers are PAGE_SIZE long
708*/ 707*/
709 708
710static ssize_t et61x251_show_reg(struct class_device* cd, char* buf) 709static ssize_t et61x251_show_reg(struct device* cd,
710 struct device_attribute *attr, char* buf)
711{ 711{
712 struct et61x251_device* cam; 712 struct et61x251_device* cam;
713 ssize_t count; 713 ssize_t count;
@@ -730,7 +730,8 @@ static ssize_t et61x251_show_reg(struct class_device* cd, char* buf)
730 730
731 731
732static ssize_t 732static ssize_t
733et61x251_store_reg(struct class_device* cd, const char* buf, size_t len) 733et61x251_store_reg(struct device* cd,
734 struct device_attribute *attr, const char* buf, size_t len)
734{ 735{
735 struct et61x251_device* cam; 736 struct et61x251_device* cam;
736 u8 index; 737 u8 index;
@@ -762,7 +763,8 @@ et61x251_store_reg(struct class_device* cd, const char* buf, size_t len)
762} 763}
763 764
764 765
765static ssize_t et61x251_show_val(struct class_device* cd, char* buf) 766static ssize_t et61x251_show_val(struct device* cd,
767 struct device_attribute *attr, char* buf)
766{ 768{
767 struct et61x251_device* cam; 769 struct et61x251_device* cam;
768 ssize_t count; 770 ssize_t count;
@@ -793,7 +795,8 @@ static ssize_t et61x251_show_val(struct class_device* cd, char* buf)
793 795
794 796
795static ssize_t 797static ssize_t
796et61x251_store_val(struct class_device* cd, const char* buf, size_t len) 798et61x251_store_val(struct device* cd, struct device_attribute *attr,
799 const char* buf, size_t len)
797{ 800{
798 struct et61x251_device* cam; 801 struct et61x251_device* cam;
799 u8 value; 802 u8 value;
@@ -831,7 +834,8 @@ et61x251_store_val(struct class_device* cd, const char* buf, size_t len)
831} 834}
832 835
833 836
834static ssize_t et61x251_show_i2c_reg(struct class_device* cd, char* buf) 837static ssize_t et61x251_show_i2c_reg(struct device* cd,
838 struct device_attribute *attr, char* buf)
835{ 839{
836 struct et61x251_device* cam; 840 struct et61x251_device* cam;
837 ssize_t count; 841 ssize_t count;
@@ -856,7 +860,8 @@ static ssize_t et61x251_show_i2c_reg(struct class_device* cd, char* buf)
856 860
857 861
858static ssize_t 862static ssize_t
859et61x251_store_i2c_reg(struct class_device* cd, const char* buf, size_t len) 863et61x251_store_i2c_reg(struct device* cd, struct device_attribute *attr,
864 const char* buf, size_t len)
860{ 865{
861 struct et61x251_device* cam; 866 struct et61x251_device* cam;
862 u8 index; 867 u8 index;
@@ -888,7 +893,8 @@ et61x251_store_i2c_reg(struct class_device* cd, const char* buf, size_t len)
888} 893}
889 894
890 895
891static ssize_t et61x251_show_i2c_val(struct class_device* cd, char* buf) 896static ssize_t et61x251_show_i2c_val(struct device* cd,
897 struct device_attribute *attr, char* buf)
892{ 898{
893 struct et61x251_device* cam; 899 struct et61x251_device* cam;
894 ssize_t count; 900 ssize_t count;
@@ -924,7 +930,8 @@ static ssize_t et61x251_show_i2c_val(struct class_device* cd, char* buf)
924 930
925 931
926static ssize_t 932static ssize_t
927et61x251_store_i2c_val(struct class_device* cd, const char* buf, size_t len) 933et61x251_store_i2c_val(struct device* cd, struct device_attribute *attr,
934 const char* buf, size_t len)
928{ 935{
929 struct et61x251_device* cam; 936 struct et61x251_device* cam;
930 u8 value; 937 u8 value;
@@ -967,42 +974,40 @@ et61x251_store_i2c_val(struct class_device* cd, const char* buf, size_t len)
967} 974}
968 975
969 976
970static CLASS_DEVICE_ATTR(reg, S_IRUGO | S_IWUSR, 977static DEVICE_ATTR(reg, S_IRUGO | S_IWUSR,
971 et61x251_show_reg, et61x251_store_reg); 978 et61x251_show_reg, et61x251_store_reg);
972static CLASS_DEVICE_ATTR(val, S_IRUGO | S_IWUSR, 979static DEVICE_ATTR(val, S_IRUGO | S_IWUSR,
973 et61x251_show_val, et61x251_store_val); 980 et61x251_show_val, et61x251_store_val);
974static CLASS_DEVICE_ATTR(i2c_reg, S_IRUGO | S_IWUSR, 981static DEVICE_ATTR(i2c_reg, S_IRUGO | S_IWUSR,
975 et61x251_show_i2c_reg, et61x251_store_i2c_reg); 982 et61x251_show_i2c_reg, et61x251_store_i2c_reg);
976static CLASS_DEVICE_ATTR(i2c_val, S_IRUGO | S_IWUSR, 983static DEVICE_ATTR(i2c_val, S_IRUGO | S_IWUSR,
977 et61x251_show_i2c_val, et61x251_store_i2c_val); 984 et61x251_show_i2c_val, et61x251_store_i2c_val);
978 985
979 986
980static int et61x251_create_sysfs(struct et61x251_device* cam) 987static int et61x251_create_sysfs(struct et61x251_device* cam)
981{ 988{
982 struct class_device *classdev = &(cam->v4ldev->class_dev); 989 struct device *classdev = &(cam->v4ldev->class_dev);
983 int err = 0; 990 int err = 0;
984 991
985 if ((err = class_device_create_file(classdev, &class_device_attr_reg))) 992 if ((err = device_create_file(classdev, &dev_attr_reg)))
986 goto err_out; 993 goto err_out;
987 if ((err = class_device_create_file(classdev, &class_device_attr_val))) 994 if ((err = device_create_file(classdev, &dev_attr_val)))
988 goto err_reg; 995 goto err_reg;
989 996
990 if (cam->sensor.sysfs_ops) { 997 if (cam->sensor.sysfs_ops) {
991 if ((err = class_device_create_file(classdev, 998 if ((err = device_create_file(classdev, &dev_attr_i2c_reg)))
992 &class_device_attr_i2c_reg)))
993 goto err_val; 999 goto err_val;
994 if ((err = class_device_create_file(classdev, 1000 if ((err = device_create_file(classdev, &dev_attr_i2c_val)))
995 &class_device_attr_i2c_val)))
996 goto err_i2c_reg; 1001 goto err_i2c_reg;
997 } 1002 }
998 1003
999err_i2c_reg: 1004err_i2c_reg:
1000 if (cam->sensor.sysfs_ops) 1005 if (cam->sensor.sysfs_ops)
1001 class_device_remove_file(classdev, &class_device_attr_i2c_reg); 1006 device_remove_file(classdev, &dev_attr_i2c_reg);
1002err_val: 1007err_val:
1003 class_device_remove_file(classdev, &class_device_attr_val); 1008 device_remove_file(classdev, &dev_attr_val);
1004err_reg: 1009err_reg:
1005 class_device_remove_file(classdev, &class_device_attr_reg); 1010 device_remove_file(classdev, &dev_attr_reg);
1006err_out: 1011err_out:
1007 return err; 1012 return err;
1008} 1013}
diff --git a/drivers/media/video/ir-kbd-i2c.c b/drivers/media/video/ir-kbd-i2c.c
index 2d709e064679..d98dd0d1e373 100644
--- a/drivers/media/video/ir-kbd-i2c.c
+++ b/drivers/media/video/ir-kbd-i2c.c
@@ -10,6 +10,8 @@
10 * Ulrich Mueller <ulrich.mueller42@web.de> 10 * Ulrich Mueller <ulrich.mueller42@web.de>
11 * modified for em2820 based USB TV tuners by 11 * modified for em2820 based USB TV tuners by
12 * Markus Rechberger <mrechberger@gmail.com> 12 * Markus Rechberger <mrechberger@gmail.com>
13 * modified for DViCO Fusion HDTV 5 RT GOLD by
14 * Chaogui Zhang <czhang1974@gmail.com>
13 * 15 *
14 * This program is free software; you can redistribute it and/or modify 16 * 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 17 * it under the terms of the GNU General Public License as published by
@@ -28,7 +30,6 @@
28 */ 30 */
29 31
30#include <linux/module.h> 32#include <linux/module.h>
31#include <linux/moduleparam.h>
32#include <linux/init.h> 33#include <linux/init.h>
33#include <linux/kernel.h> 34#include <linux/kernel.h>
34#include <linux/string.h> 35#include <linux/string.h>
@@ -142,6 +143,30 @@ static int get_key_pv951(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
142 return 1; 143 return 1;
143} 144}
144 145
146static int get_key_fusionhdtv(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
147{
148 unsigned char buf[4];
149
150 /* poll IR chip */
151 if (4 != i2c_master_recv(&ir->c,buf,4)) {
152 dprintk(1,"read error\n");
153 return -EIO;
154 }
155
156 if(buf[0] !=0 || buf[1] !=0 || buf[2] !=0 || buf[3] != 0)
157 dprintk(2, "%s: 0x%2x 0x%2x 0x%2x 0x%2x\n", __FUNCTION__,
158 buf[0], buf[1], buf[2], buf[3]);
159
160 /* no key pressed or signal from other ir remote */
161 if(buf[0] != 0x1 || buf[1] != 0xfe)
162 return 0;
163
164 *ir_key = buf[2];
165 *ir_raw = (buf[2] << 8) | buf[3];
166
167 return 1;
168}
169
145static int get_key_knc1(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) 170static int get_key_knc1(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
146{ 171{
147 unsigned char b; 172 unsigned char b;
@@ -364,6 +389,12 @@ static int ir_attach(struct i2c_adapter *adap, int addr,
364 ir_type = IR_TYPE_OTHER; 389 ir_type = IR_TYPE_OTHER;
365 ir_codes = ir_codes_empty; 390 ir_codes = ir_codes_empty;
366 break; 391 break;
392 case 0x6b:
393 name = "FusionHDTV";
394 ir->get_key = get_key_fusionhdtv;
395 ir_type = IR_TYPE_RC5;
396 ir_codes = ir_codes_fusionhdtv_mce;
397 break;
367 case 0x7a: 398 case 0x7a:
368 case 0x47: 399 case 0x47:
369 case 0x71: 400 case 0x71:
@@ -475,7 +506,8 @@ static int ir_probe(struct i2c_adapter *adap)
475 static const int probe_bttv[] = { 0x1a, 0x18, 0x4b, 0x64, 0x30, -1}; 506 static const int probe_bttv[] = { 0x1a, 0x18, 0x4b, 0x64, 0x30, -1};
476 static const int probe_saa7134[] = { 0x7a, 0x47, 0x71, -1 }; 507 static const int probe_saa7134[] = { 0x7a, 0x47, 0x71, -1 };
477 static const int probe_em28XX[] = { 0x30, 0x47, -1 }; 508 static const int probe_em28XX[] = { 0x30, 0x47, -1 };
478 static const int probe_cx88[] = { 0x18, 0x71, -1 }; 509 static const int probe_cx88[] = { 0x18, 0x6b, 0x71, -1 };
510 static const int probe_cx23885[] = { 0x6b, -1 };
479 const int *probe = NULL; 511 const int *probe = NULL;
480 struct i2c_client c; 512 struct i2c_client c;
481 unsigned char buf; 513 unsigned char buf;
@@ -496,6 +528,8 @@ static int ir_probe(struct i2c_adapter *adap)
496 break; 528 break;
497 case I2C_HW_B_CX2388x: 529 case I2C_HW_B_CX2388x:
498 probe = probe_cx88; 530 probe = probe_cx88;
531 case I2C_HW_B_CX23885:
532 probe = probe_cx23885;
499 break; 533 break;
500 } 534 }
501 if (NULL == probe) 535 if (NULL == probe)
diff --git a/drivers/media/video/ivtv/Kconfig b/drivers/media/video/ivtv/Kconfig
index e43beb2c9cbf..854cc9c30ca9 100644
--- a/drivers/media/video/ivtv/Kconfig
+++ b/drivers/media/video/ivtv/Kconfig
@@ -14,6 +14,7 @@ config VIDEO_IVTV
14 select VIDEO_CS53L32A 14 select VIDEO_CS53L32A
15 select VIDEO_WM8775 15 select VIDEO_WM8775
16 select VIDEO_WM8739 16 select VIDEO_WM8739
17 select VIDEO_VP27SMPX
17 select VIDEO_UPD64031A 18 select VIDEO_UPD64031A
18 select VIDEO_UPD64083 19 select VIDEO_UPD64083
19 ---help--- 20 ---help---
@@ -25,3 +26,19 @@ config VIDEO_IVTV
25 26
26 To compile this driver as a module, choose M here: the 27 To compile this driver as a module, choose M here: the
27 module will be called ivtv. 28 module will be called ivtv.
29
30config VIDEO_FB_IVTV
31 tristate "Conexant cx23415 framebuffer support"
32 depends on VIDEO_IVTV && FB && EXPERIMENTAL
33 select FB_CFB_FILLRECT
34 select FB_CFB_COPYAREA
35 select FB_CFB_IMAGEBLIT
36 ---help---
37 This is a framebuffer driver for the Conexant cx23415 MPEG
38 encoder/decoder.
39
40 This is used in the Hauppauge PVR-350 card. There is a driver
41 homepage at <http://www.ivtvdriver.org>.
42
43 To compile this driver as a module, choose M here: the
44 module will be called ivtvfb.
diff --git a/drivers/media/video/ivtv/Makefile b/drivers/media/video/ivtv/Makefile
index 7e95148fbf4f..e8eefd96d897 100644
--- a/drivers/media/video/ivtv/Makefile
+++ b/drivers/media/video/ivtv/Makefile
@@ -1,7 +1,8 @@
1ivtv-objs := ivtv-audio.o ivtv-cards.o ivtv-controls.o \ 1ivtv-objs := ivtv-routing.o ivtv-cards.o ivtv-controls.o \
2 ivtv-driver.o ivtv-fileops.o ivtv-firmware.o \ 2 ivtv-driver.o ivtv-fileops.o ivtv-firmware.o \
3 ivtv-gpio.o ivtv-i2c.o ivtv-ioctl.o ivtv-irq.o \ 3 ivtv-gpio.o ivtv-i2c.o ivtv-ioctl.o ivtv-irq.o \
4 ivtv-mailbox.o ivtv-queue.o ivtv-streams.o ivtv-udma.o \ 4 ivtv-mailbox.o ivtv-queue.o ivtv-streams.o ivtv-udma.o \
5 ivtv-vbi.o ivtv-video.o ivtv-yuv.o 5 ivtv-vbi.o ivtv-yuv.o
6 6
7obj-$(CONFIG_VIDEO_IVTV) += ivtv.o 7obj-$(CONFIG_VIDEO_IVTV) += ivtv.o
8obj-$(CONFIG_VIDEO_FB_IVTV) += ivtvfb.o
diff --git a/drivers/media/video/ivtv/ivtv-audio.c b/drivers/media/video/ivtv/ivtv-audio.c
deleted file mode 100644
index d702b8b539a1..000000000000
--- a/drivers/media/video/ivtv/ivtv-audio.c
+++ /dev/null
@@ -1,74 +0,0 @@
1/*
2 Audio-related ivtv functions.
3 Copyright (C) 2003-2004 Kevin Thayer <nufan_wfk at yahoo.com>
4 Copyright (C) 2005-2007 Hans Verkuil <hverkuil@xs4all.nl>
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#include "ivtv-driver.h"
22#include "ivtv-mailbox.h"
23#include "ivtv-i2c.h"
24#include "ivtv-gpio.h"
25#include "ivtv-cards.h"
26#include "ivtv-audio.h"
27#include <media/msp3400.h>
28#include <linux/videodev.h>
29
30/* Selects the audio input and output according to the current
31 settings. */
32int ivtv_audio_set_io(struct ivtv *itv)
33{
34 struct v4l2_routing route;
35 u32 audio_input;
36 int mux_input;
37
38 /* Determine which input to use */
39 if (test_bit(IVTV_F_I_RADIO_USER, &itv->i_flags)) {
40 audio_input = itv->card->radio_input.audio_input;
41 mux_input = itv->card->radio_input.muxer_input;
42 } else {
43 audio_input = itv->card->audio_inputs[itv->audio_input].audio_input;
44 mux_input = itv->card->audio_inputs[itv->audio_input].muxer_input;
45 }
46
47 /* handle muxer chips */
48 route.input = mux_input;
49 route.output = 0;
50 ivtv_i2c_hw(itv, itv->card->hw_muxer, VIDIOC_INT_S_AUDIO_ROUTING, &route);
51
52 route.input = audio_input;
53 if (itv->card->hw_audio & IVTV_HW_MSP34XX) {
54 route.output = MSP_OUTPUT(MSP_SC_IN_DSP_SCART1);
55 }
56 return ivtv_i2c_hw(itv, itv->card->hw_audio, VIDIOC_INT_S_AUDIO_ROUTING, &route);
57}
58
59void ivtv_audio_set_route(struct ivtv *itv, struct v4l2_routing *route)
60{
61 ivtv_i2c_hw(itv, itv->card->hw_audio, VIDIOC_INT_S_AUDIO_ROUTING, route);
62}
63
64void ivtv_audio_set_audio_clock_freq(struct ivtv *itv, u8 freq)
65{
66 static u32 freqs[3] = { 44100, 48000, 32000 };
67
68 /* The audio clock of the digitizer must match the codec sample
69 rate otherwise you get some very strange effects. */
70 if (freq > 2)
71 return;
72 ivtv_call_i2c_clients(itv, VIDIOC_INT_AUDIO_CLOCK_FREQ, &freqs[freq]);
73}
74
diff --git a/drivers/media/video/ivtv/ivtv-audio.h b/drivers/media/video/ivtv/ivtv-audio.h
deleted file mode 100644
index 9c42846d8124..000000000000
--- a/drivers/media/video/ivtv/ivtv-audio.h
+++ /dev/null
@@ -1,23 +0,0 @@
1/*
2 Audio-related ivtv functions.
3 Copyright (C) 2003-2004 Kevin Thayer <nufan_wfk at yahoo.com>
4 Copyright (C) 2005-2007 Hans Verkuil <hverkuil@xs4all.nl>
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21int ivtv_audio_set_io(struct ivtv *itv);
22void ivtv_audio_set_route(struct ivtv *itv, struct v4l2_routing *route);
23void ivtv_audio_set_audio_clock_freq(struct ivtv *itv, u8 freq);
diff --git a/drivers/media/video/ivtv/ivtv-cards.c b/drivers/media/video/ivtv/ivtv-cards.c
index 8eab02083887..b6a8be622d3c 100644
--- a/drivers/media/video/ivtv/ivtv-cards.c
+++ b/drivers/media/video/ivtv/ivtv-cards.c
@@ -616,7 +616,7 @@ static const struct ivtv_card ivtv_card_gv_mvprx = {
616 .hw_video = IVTV_HW_SAA7115 | IVTV_HW_UPD64031A | IVTV_HW_UPD6408X, 616 .hw_video = IVTV_HW_SAA7115 | IVTV_HW_UPD64031A | IVTV_HW_UPD6408X,
617 .hw_audio = IVTV_HW_GPIO, 617 .hw_audio = IVTV_HW_GPIO,
618 .hw_audio_ctrl = IVTV_HW_WM8739, 618 .hw_audio_ctrl = IVTV_HW_WM8739,
619 .hw_all = IVTV_HW_GPIO | IVTV_HW_SAA7115 | IVTV_HW_TVAUDIO | 619 .hw_all = IVTV_HW_GPIO | IVTV_HW_SAA7115 | IVTV_HW_VP27SMPX |
620 IVTV_HW_TUNER | IVTV_HW_WM8739 | 620 IVTV_HW_TUNER | IVTV_HW_WM8739 |
621 IVTV_HW_UPD64031A | IVTV_HW_UPD6408X, 621 IVTV_HW_UPD64031A | IVTV_HW_UPD6408X,
622 .video_inputs = { 622 .video_inputs = {
@@ -654,7 +654,7 @@ static const struct ivtv_card ivtv_card_gv_mvprx2e = {
654 .hw_audio = IVTV_HW_GPIO, 654 .hw_audio = IVTV_HW_GPIO,
655 .hw_audio_ctrl = IVTV_HW_WM8739, 655 .hw_audio_ctrl = IVTV_HW_WM8739,
656 .hw_all = IVTV_HW_GPIO | IVTV_HW_SAA7115 | IVTV_HW_TUNER | 656 .hw_all = IVTV_HW_GPIO | IVTV_HW_SAA7115 | IVTV_HW_TUNER |
657 IVTV_HW_TVAUDIO | IVTV_HW_WM8739, 657 IVTV_HW_VP27SMPX | IVTV_HW_WM8739,
658 .video_inputs = { 658 .video_inputs = {
659 { IVTV_CARD_INPUT_VID_TUNER, 0, IVTV_SAA71XX_COMPOSITE4 }, 659 { IVTV_CARD_INPUT_VID_TUNER, 0, IVTV_SAA71XX_COMPOSITE4 },
660 { IVTV_CARD_INPUT_SVIDEO1, 1, IVTV_SAA71XX_SVIDEO0 }, 660 { IVTV_CARD_INPUT_SVIDEO1, 1, IVTV_SAA71XX_SVIDEO0 },
@@ -823,9 +823,7 @@ static const struct ivtv_card ivtv_card_dctmvtvp1 = {
823 823
824/* ------------------------------------------------------------------------- */ 824/* ------------------------------------------------------------------------- */
825 825
826#ifdef HAVE_XC3028 826/* Yuan PG600-2/GotView PCI DVD Lite cards */
827
828/* Yuan PG600-2/GotView PCI DVD Lite/Club3D ZAP-TV1x01 cards */
829 827
830static const struct ivtv_card_pci_info ivtv_pci_pg600v2[] = { 828static const struct ivtv_card_pci_info ivtv_pci_pg600v2[] = {
831 { PCI_DEVICE_ID_IVTV16, IVTV_PCI_ID_YUAN3, 0x0600 }, 829 { PCI_DEVICE_ID_IVTV16, IVTV_PCI_ID_YUAN3, 0x0600 },
@@ -835,29 +833,87 @@ static const struct ivtv_card_pci_info ivtv_pci_pg600v2[] = {
835 833
836static const struct ivtv_card ivtv_card_pg600v2 = { 834static const struct ivtv_card ivtv_card_pg600v2 = {
837 .type = IVTV_CARD_PG600V2, 835 .type = IVTV_CARD_PG600V2,
838 .name = "Yuan PG600-2, GotView PCI DVD Lite, Club3D ZAP-TV1x01", 836 .name = "Yuan PG600-2, GotView PCI DVD Lite",
839 .v4l2_capabilities = IVTV_CAP_ENCODER, 837 .v4l2_capabilities = IVTV_CAP_ENCODER,
840 .hw_video = IVTV_HW_CX25840, 838 .hw_video = IVTV_HW_CX25840,
841 .hw_audio = IVTV_HW_CX25840, 839 .hw_audio = IVTV_HW_CX25840,
842 .hw_audio_ctrl = IVTV_HW_CX25840, 840 .hw_audio_ctrl = IVTV_HW_CX25840,
843 .hw_all = IVTV_HW_CX25840 | IVTV_HW_TUNER, 841 .hw_all = IVTV_HW_CX25840 | IVTV_HW_TUNER,
844 .video_inputs = { 842 .video_inputs = {
845 { IVTV_CARD_INPUT_VID_TUNER, 0, CX25840_COMPOSITE2 }, 843 { IVTV_CARD_INPUT_SVIDEO1, 0,
846 { IVTV_CARD_INPUT_SVIDEO1, 1,
847 CX25840_SVIDEO_LUMA3 | CX25840_SVIDEO_CHROMA4 }, 844 CX25840_SVIDEO_LUMA3 | CX25840_SVIDEO_CHROMA4 },
845 { IVTV_CARD_INPUT_COMPOSITE1, 0, CX25840_COMPOSITE1 },
848 }, 846 },
849 .audio_inputs = { 847 .audio_inputs = {
850 { IVTV_CARD_INPUT_AUD_TUNER, CX25840_AUDIO5 },
851 { IVTV_CARD_INPUT_LINE_IN1, CX25840_AUDIO_SERIAL }, 848 { IVTV_CARD_INPUT_LINE_IN1, CX25840_AUDIO_SERIAL },
852 }, 849 },
853 .radio_input = { IVTV_CARD_INPUT_AUD_TUNER, CX25840_AUDIO5 },
854 .tuners = { 850 .tuners = {
855 { .std = V4L2_STD_ALL, .tuner = TUNER_XCEIVE_XC3028 }, 851 { .std = V4L2_STD_ALL, .tuner = TUNER_XCEIVE_XC3028 },
856 }, 852 },
857 .gpio_init = { .direction = 0x1000, .initial_value = 0x1000 }, /* tuner reset */
858 .pci_list = ivtv_pci_pg600v2, 853 .pci_list = ivtv_pci_pg600v2,
859}; 854};
860#endif 855
856/* ------------------------------------------------------------------------- */
857
858/* Club3D ZAP-TV1x01 cards */
859
860static const struct ivtv_card_pci_info ivtv_pci_club3d[] = {
861 { PCI_DEVICE_ID_IVTV16, IVTV_PCI_ID_YUAN3, 0x0600 },
862 { 0, 0, 0 }
863};
864
865static const struct ivtv_card ivtv_card_club3d = {
866 .type = IVTV_CARD_CLUB3D,
867 .name = "Club3D ZAP-TV1x01",
868 .v4l2_capabilities = IVTV_CAP_ENCODER,
869 .hw_video = IVTV_HW_CX25840,
870 .hw_audio = IVTV_HW_CX25840,
871 .hw_audio_ctrl = IVTV_HW_CX25840,
872 .hw_all = IVTV_HW_CX25840 | IVTV_HW_TUNER,
873 .video_inputs = {
874 { IVTV_CARD_INPUT_SVIDEO1, 0,
875 CX25840_SVIDEO_LUMA3 | CX25840_SVIDEO_CHROMA4 },
876 { IVTV_CARD_INPUT_COMPOSITE1, 0, CX25840_COMPOSITE3 },
877 },
878 .audio_inputs = {
879 { IVTV_CARD_INPUT_LINE_IN1, CX25840_AUDIO_SERIAL },
880 },
881 .tuners = {
882 { .std = V4L2_STD_ALL, .tuner = TUNER_XCEIVE_XC3028 },
883 },
884 .pci_list = ivtv_pci_club3d,
885};
886
887/* ------------------------------------------------------------------------- */
888
889/* AVerTV MCE 116 Plus (M116) card */
890
891static const struct ivtv_card_pci_info ivtv_pci_avertv_mce116[] = {
892 { PCI_DEVICE_ID_IVTV16, IVTV_PCI_ID_AVERMEDIA, 0xc439 },
893 { 0, 0, 0 }
894};
895
896static const struct ivtv_card ivtv_card_avertv_mce116 = {
897 .type = IVTV_CARD_AVERTV_MCE116,
898 .name = "AVerTV MCE 116 Plus",
899 .v4l2_capabilities = IVTV_CAP_ENCODER,
900 .hw_video = IVTV_HW_CX25840,
901 .hw_audio = IVTV_HW_CX25840,
902 .hw_audio_ctrl = IVTV_HW_CX25840,
903 .hw_all = IVTV_HW_CX25840 | IVTV_HW_TUNER | IVTV_HW_WM8739,
904 .video_inputs = {
905 { IVTV_CARD_INPUT_SVIDEO1, 0, CX25840_SVIDEO3 },
906 { IVTV_CARD_INPUT_COMPOSITE1, 0, CX25840_COMPOSITE1 },
907 },
908 .audio_inputs = {
909 { IVTV_CARD_INPUT_LINE_IN1, CX25840_AUDIO_SERIAL, 1 },
910 },
911 .gpio_init = { .direction = 0xe000, .initial_value = 0x4000 }, /* enable line-in */
912 .tuners = {
913 { .std = V4L2_STD_ALL, .tuner = TUNER_XCEIVE_XC3028 },
914 },
915 .pci_list = ivtv_pci_avertv_mce116,
916};
861 917
862static const struct ivtv_card *ivtv_card_list[] = { 918static const struct ivtv_card *ivtv_card_list[] = {
863 &ivtv_card_pvr250, 919 &ivtv_card_pvr250,
@@ -878,9 +934,9 @@ static const struct ivtv_card *ivtv_card_list[] = {
878 &ivtv_card_gotview_pci_dvd2, 934 &ivtv_card_gotview_pci_dvd2,
879 &ivtv_card_yuan_mpc622, 935 &ivtv_card_yuan_mpc622,
880 &ivtv_card_dctmvtvp1, 936 &ivtv_card_dctmvtvp1,
881#ifdef HAVE_XC3028
882 &ivtv_card_pg600v2, 937 &ivtv_card_pg600v2,
883#endif 938 &ivtv_card_club3d,
939 &ivtv_card_avertv_mce116,
884 940
885 /* Variations of standard cards but with the same PCI IDs. 941 /* Variations of standard cards but with the same PCI IDs.
886 These cards must come last in this list. */ 942 These cards must come last in this list. */
diff --git a/drivers/media/video/ivtv/ivtv-cards.h b/drivers/media/video/ivtv/ivtv-cards.h
index 91e9e90c14a5..ff46e5ae8653 100644
--- a/drivers/media/video/ivtv/ivtv-cards.h
+++ b/drivers/media/video/ivtv/ivtv-cards.h
@@ -18,6 +18,68 @@
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */ 19 */
20 20
21#ifndef IVTV_CARDS_H
22#define IVTV_CARDS_H
23
24/* Supported cards */
25#define IVTV_CARD_PVR_250 0 /* WinTV PVR 250 */
26#define IVTV_CARD_PVR_350 1 /* encoder, decoder, tv-out */
27#define IVTV_CARD_PVR_150 2 /* WinTV PVR 150 and PVR 500 (really just two
28 PVR150s on one PCI board) */
29#define IVTV_CARD_M179 3 /* AVerMedia M179 (encoder only) */
30#define IVTV_CARD_MPG600 4 /* Kuroutoshikou ITVC16-STVLP/YUAN MPG600, encoder only */
31#define IVTV_CARD_MPG160 5 /* Kuroutoshikou ITVC15-STVLP/YUAN MPG160
32 cx23415 based, but does not have tv-out */
33#define IVTV_CARD_PG600 6 /* YUAN PG600/DIAMONDMM PVR-550 based on the CX Falcon 2 */
34#define IVTV_CARD_AVC2410 7 /* Adaptec AVC-2410 */
35#define IVTV_CARD_AVC2010 8 /* Adaptec AVD-2010 (No Tuner) */
36#define IVTV_CARD_TG5000TV 9 /* NAGASE TRANSGEAR 5000TV, encoder only */
37#define IVTV_CARD_VA2000MAX_SNT6 10 /* VA2000MAX-STN6 */
38#define IVTV_CARD_CX23416GYC 11 /* Kuroutoshikou CX23416GYC-STVLP (Yuan MPG600GR OEM) */
39#define IVTV_CARD_GV_MVPRX 12 /* I/O Data GV-MVP/RX, RX2, RX2W */
40#define IVTV_CARD_GV_MVPRX2E 13 /* I/O Data GV-MVP/RX2E */
41#define IVTV_CARD_GOTVIEW_PCI_DVD 14 /* GotView PCI DVD */
42#define IVTV_CARD_GOTVIEW_PCI_DVD2 15 /* GotView PCI DVD2 */
43#define IVTV_CARD_YUAN_MPC622 16 /* Yuan MPC622 miniPCI */
44#define IVTV_CARD_DCTMTVP1 17 /* DIGITAL COWBOY DCT-MTVP1 */
45#define IVTV_CARD_PG600V2 18 /* Yuan PG600V2/GotView PCI DVD Lite */
46#define IVTV_CARD_CLUB3D 19 /* Club3D ZAP-TV1x01 */
47#define IVTV_CARD_AVERTV_MCE116 20 /* AVerTV MCE 116 Plus */
48#define IVTV_CARD_LAST 20
49
50/* Variants of existing cards but with the same PCI IDs. The driver
51 detects these based on other device information.
52 These cards must always come last.
53 New cards must be inserted above, and the indices of the cards below
54 must be adjusted accordingly. */
55
56/* PVR-350 V1 (uses saa7114) */
57#define IVTV_CARD_PVR_350_V1 (IVTV_CARD_LAST+1)
58/* 2 variants of Kuroutoshikou CX23416GYC-STVLP (Yuan MPG600GR OEM) */
59#define IVTV_CARD_CX23416GYC_NOGR (IVTV_CARD_LAST+2)
60#define IVTV_CARD_CX23416GYC_NOGRYCS (IVTV_CARD_LAST+3)
61
62/* system vendor and device IDs */
63#define PCI_VENDOR_ID_ICOMP 0x4444
64#define PCI_DEVICE_ID_IVTV15 0x0803
65#define PCI_DEVICE_ID_IVTV16 0x0016
66
67/* subsystem vendor ID */
68#define IVTV_PCI_ID_HAUPPAUGE 0x0070
69#define IVTV_PCI_ID_HAUPPAUGE_ALT1 0x0270
70#define IVTV_PCI_ID_HAUPPAUGE_ALT2 0x4070
71#define IVTV_PCI_ID_ADAPTEC 0x9005
72#define IVTV_PCI_ID_AVERMEDIA 0x1461
73#define IVTV_PCI_ID_YUAN1 0x12ab
74#define IVTV_PCI_ID_YUAN2 0xff01
75#define IVTV_PCI_ID_YUAN3 0xffab
76#define IVTV_PCI_ID_YUAN4 0xfbab
77#define IVTV_PCI_ID_DIAMONDMM 0xff92
78#define IVTV_PCI_ID_IODATA 0x10fc
79#define IVTV_PCI_ID_MELCO 0x1154
80#define IVTV_PCI_ID_GOTVIEW1 0xffac
81#define IVTV_PCI_ID_GOTVIEW2 0xffad
82
21/* hardware flags */ 83/* hardware flags */
22#define IVTV_HW_CX25840 (1 << 0) 84#define IVTV_HW_CX25840 (1 << 0)
23#define IVTV_HW_SAA7115 (1 << 1) 85#define IVTV_HW_SAA7115 (1 << 1)
@@ -33,7 +95,8 @@
33#define IVTV_HW_UPD6408X (1 << 11) 95#define IVTV_HW_UPD6408X (1 << 11)
34#define IVTV_HW_SAA717X (1 << 12) 96#define IVTV_HW_SAA717X (1 << 12)
35#define IVTV_HW_WM8739 (1 << 13) 97#define IVTV_HW_WM8739 (1 << 13)
36#define IVTV_HW_GPIO (1 << 14) 98#define IVTV_HW_VP27SMPX (1 << 14)
99#define IVTV_HW_GPIO (1 << 15)
37 100
38#define IVTV_HW_SAA711X (IVTV_HW_SAA7115 | IVTV_HW_SAA7114) 101#define IVTV_HW_SAA711X (IVTV_HW_SAA7115 | IVTV_HW_SAA7114)
39 102
@@ -205,3 +268,5 @@ int ivtv_get_output(struct ivtv *itv, u16 index, struct v4l2_output *output);
205int ivtv_get_audio_input(struct ivtv *itv, u16 index, struct v4l2_audio *input); 268int ivtv_get_audio_input(struct ivtv *itv, u16 index, struct v4l2_audio *input);
206int ivtv_get_audio_output(struct ivtv *itv, u16 index, struct v4l2_audioout *output); 269int ivtv_get_audio_output(struct ivtv *itv, u16 index, struct v4l2_audioout *output);
207const struct ivtv_card *ivtv_get_card(u16 index); 270const struct ivtv_card *ivtv_get_card(u16 index);
271
272#endif
diff --git a/drivers/media/video/ivtv/ivtv-controls.c b/drivers/media/video/ivtv/ivtv-controls.c
index 7a876c3e5b19..8c02fa661591 100644
--- a/drivers/media/video/ivtv/ivtv-controls.c
+++ b/drivers/media/video/ivtv/ivtv-controls.c
@@ -21,7 +21,7 @@
21#include "ivtv-driver.h" 21#include "ivtv-driver.h"
22#include "ivtv-cards.h" 22#include "ivtv-cards.h"
23#include "ivtv-ioctl.h" 23#include "ivtv-ioctl.h"
24#include "ivtv-audio.h" 24#include "ivtv-routing.h"
25#include "ivtv-i2c.h" 25#include "ivtv-i2c.h"
26#include "ivtv-mailbox.h" 26#include "ivtv-mailbox.h"
27#include "ivtv-controls.h" 27#include "ivtv-controls.h"
@@ -231,8 +231,10 @@ int ivtv_control_ioctls(struct ivtv *itv, unsigned int cmd, void *arg)
231 } 231 }
232 IVTV_DEBUG_IOCTL("VIDIOC_S_EXT_CTRLS\n"); 232 IVTV_DEBUG_IOCTL("VIDIOC_S_EXT_CTRLS\n");
233 if (c->ctrl_class == V4L2_CTRL_CLASS_MPEG) { 233 if (c->ctrl_class == V4L2_CTRL_CLASS_MPEG) {
234 static u32 freqs[3] = { 44100, 48000, 32000 };
234 struct cx2341x_mpeg_params p = itv->params; 235 struct cx2341x_mpeg_params p = itv->params;
235 int err = cx2341x_ext_ctrls(&p, arg, cmd); 236 int err = cx2341x_ext_ctrls(&p, atomic_read(&itv->capturing), arg, cmd);
237 unsigned idx;
236 238
237 if (err) 239 if (err)
238 return err; 240 return err;
@@ -254,7 +256,11 @@ int ivtv_control_ioctls(struct ivtv *itv, unsigned int cmd, void *arg)
254 } 256 }
255 itv->params = p; 257 itv->params = p;
256 itv->dualwatch_stereo_mode = p.audio_properties & 0x0300; 258 itv->dualwatch_stereo_mode = p.audio_properties & 0x0300;
257 ivtv_audio_set_audio_clock_freq(itv, p.audio_properties & 0x03); 259 idx = p.audio_properties & 0x03;
260 /* The audio clock of the digitizer must match the codec sample
261 rate otherwise you get some very strange effects. */
262 if (idx < sizeof(freqs))
263 ivtv_call_i2c_clients(itv, VIDIOC_INT_AUDIO_CLOCK_FREQ, &freqs[idx]);
258 return err; 264 return err;
259 } 265 }
260 return -EINVAL; 266 return -EINVAL;
@@ -282,7 +288,7 @@ int ivtv_control_ioctls(struct ivtv *itv, unsigned int cmd, void *arg)
282 } 288 }
283 IVTV_DEBUG_IOCTL("VIDIOC_G_EXT_CTRLS\n"); 289 IVTV_DEBUG_IOCTL("VIDIOC_G_EXT_CTRLS\n");
284 if (c->ctrl_class == V4L2_CTRL_CLASS_MPEG) 290 if (c->ctrl_class == V4L2_CTRL_CLASS_MPEG)
285 return cx2341x_ext_ctrls(&itv->params, arg, cmd); 291 return cx2341x_ext_ctrls(&itv->params, 0, arg, cmd);
286 return -EINVAL; 292 return -EINVAL;
287 } 293 }
288 294
@@ -292,7 +298,7 @@ int ivtv_control_ioctls(struct ivtv *itv, unsigned int cmd, void *arg)
292 298
293 IVTV_DEBUG_IOCTL("VIDIOC_TRY_EXT_CTRLS\n"); 299 IVTV_DEBUG_IOCTL("VIDIOC_TRY_EXT_CTRLS\n");
294 if (c->ctrl_class == V4L2_CTRL_CLASS_MPEG) 300 if (c->ctrl_class == V4L2_CTRL_CLASS_MPEG)
295 return cx2341x_ext_ctrls(&itv->params, arg, cmd); 301 return cx2341x_ext_ctrls(&itv->params, atomic_read(&itv->capturing), arg, cmd);
296 return -EINVAL; 302 return -EINVAL;
297 } 303 }
298 304
diff --git a/drivers/media/video/ivtv/ivtv-controls.h b/drivers/media/video/ivtv/ivtv-controls.h
index 5a11149725ad..bb8a6a5ed2bc 100644
--- a/drivers/media/video/ivtv/ivtv-controls.h
+++ b/drivers/media/video/ivtv/ivtv-controls.h
@@ -18,4 +18,9 @@
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */ 19 */
20 20
21#ifndef IVTV_CONTROLS_H
22#define IVTV_CONTROLS_H
23
21int ivtv_control_ioctls(struct ivtv *itv, unsigned int cmd, void *arg); 24int ivtv_control_ioctls(struct ivtv *itv, unsigned int cmd, void *arg);
25
26#endif
diff --git a/drivers/media/video/ivtv/ivtv-driver.c b/drivers/media/video/ivtv/ivtv-driver.c
index d73d433a4ff6..511a66252413 100644
--- a/drivers/media/video/ivtv/ivtv-driver.c
+++ b/drivers/media/video/ivtv/ivtv-driver.c
@@ -52,11 +52,12 @@
52#include "ivtv-ioctl.h" 52#include "ivtv-ioctl.h"
53#include "ivtv-cards.h" 53#include "ivtv-cards.h"
54#include "ivtv-vbi.h" 54#include "ivtv-vbi.h"
55#include "ivtv-audio.h" 55#include "ivtv-routing.h"
56#include "ivtv-gpio.h" 56#include "ivtv-gpio.h"
57#include "ivtv-yuv.h" 57#include "ivtv-yuv.h"
58 58
59#include <media/tveeprom.h> 59#include <media/tveeprom.h>
60#include <media/saa7115.h>
60#include <media/v4l2-chip-ident.h> 61#include <media/v4l2-chip-ident.h>
61 62
62/* var to keep track of the number of array elements in use */ 63/* var to keep track of the number of array elements in use */
@@ -86,17 +87,16 @@ static struct pci_device_id ivtv_pci_tbl[] __devinitdata = {
86 87
87MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl); 88MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
88 89
89const u32 yuv_offset[4] = {
90 IVTV_YUV_BUFFER_OFFSET,
91 IVTV_YUV_BUFFER_OFFSET_1,
92 IVTV_YUV_BUFFER_OFFSET_2,
93 IVTV_YUV_BUFFER_OFFSET_3
94};
95
96/* Parameter declarations */ 90/* Parameter declarations */
97static int cardtype[IVTV_MAX_CARDS]; 91static int cardtype[IVTV_MAX_CARDS];
98static int tuner[IVTV_MAX_CARDS] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; 92static int tuner[IVTV_MAX_CARDS] = { -1, -1, -1, -1, -1, -1, -1, -1,
99static int radio[IVTV_MAX_CARDS] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; 93 -1, -1, -1, -1, -1, -1, -1, -1,
94 -1, -1, -1, -1, -1, -1, -1, -1,
95 -1, -1, -1, -1, -1, -1, -1, -1 };
96static int radio[IVTV_MAX_CARDS] = { -1, -1, -1, -1, -1, -1, -1, -1,
97 -1, -1, -1, -1, -1, -1, -1, -1,
98 -1, -1, -1, -1, -1, -1, -1, -1,
99 -1, -1, -1, -1, -1, -1, -1, -1 };
100 100
101static int cardtype_c = 1; 101static int cardtype_c = 1;
102static int tuner_c = 1; 102static int tuner_c = 1;
@@ -106,6 +106,18 @@ static char secam[] = "--";
106static char ntsc[] = "-"; 106static char ntsc[] = "-";
107 107
108/* Buffers */ 108/* Buffers */
109
110/* DMA Buffers, Default size in MB allocated */
111#define IVTV_DEFAULT_ENC_MPG_BUFFERS 4
112#define IVTV_DEFAULT_ENC_YUV_BUFFERS 2
113#define IVTV_DEFAULT_ENC_VBI_BUFFERS 1
114/* Exception: size in kB for this stream (MB is overkill) */
115#define IVTV_DEFAULT_ENC_PCM_BUFFERS 320
116#define IVTV_DEFAULT_DEC_MPG_BUFFERS 1
117#define IVTV_DEFAULT_DEC_YUV_BUFFERS 1
118/* Exception: size in kB for this stream (MB is way overkill) */
119#define IVTV_DEFAULT_DEC_VBI_BUFFERS 64
120
109static int enc_mpg_buffers = IVTV_DEFAULT_ENC_MPG_BUFFERS; 121static int enc_mpg_buffers = IVTV_DEFAULT_ENC_MPG_BUFFERS;
110static int enc_yuv_buffers = IVTV_DEFAULT_ENC_YUV_BUFFERS; 122static int enc_yuv_buffers = IVTV_DEFAULT_ENC_YUV_BUFFERS;
111static int enc_vbi_buffers = IVTV_DEFAULT_ENC_VBI_BUFFERS; 123static int enc_vbi_buffers = IVTV_DEFAULT_ENC_VBI_BUFFERS;
@@ -170,17 +182,27 @@ MODULE_PARM_DESC(cardtype,
170 "\t\t\t16 = GOTVIEW PCI DVD2 Deluxe\n" 182 "\t\t\t16 = GOTVIEW PCI DVD2 Deluxe\n"
171 "\t\t\t17 = Yuan MPC622\n" 183 "\t\t\t17 = Yuan MPC622\n"
172 "\t\t\t18 = Digital Cowboy DCT-MTVP1\n" 184 "\t\t\t18 = Digital Cowboy DCT-MTVP1\n"
173#ifdef HAVE_XC3028 185 "\t\t\t19 = Yuan PG600V2/GotView PCI DVD Lite\n"
174 "\t\t\t19 = Yuan PG600V2/GotView PCI DVD Lite/Club3D ZAP-TV1x01\n" 186 "\t\t\t20 = Club3D ZAP-TV1x01\n"
175#endif 187 "\t\t\t21 = AverTV MCE 116 Plus\n"
176 "\t\t\t 0 = Autodetect (default)\n" 188 "\t\t\t 0 = Autodetect (default)\n"
177 "\t\t\t-1 = Ignore this card\n\t\t"); 189 "\t\t\t-1 = Ignore this card\n\t\t");
178MODULE_PARM_DESC(pal, "Set PAL standard: B, G, H, D, K, I, M, N, Nc, 60"); 190MODULE_PARM_DESC(pal, "Set PAL standard: B, G, H, D, K, I, M, N, Nc, 60");
179MODULE_PARM_DESC(secam, "Set SECAM standard: B, G, H, D, K, L, LC"); 191MODULE_PARM_DESC(secam, "Set SECAM standard: B, G, H, D, K, L, LC");
180MODULE_PARM_DESC(ntsc, "Set NTSC standard: M, J, K"); 192MODULE_PARM_DESC(ntsc, "Set NTSC standard: M, J, K");
181MODULE_PARM_DESC(debug, 193MODULE_PARM_DESC(debug,
182 "Debug level (bitmask). Default: errors only\n" 194 "Debug level (bitmask). Default: 0\n"
183 "\t\t\t(debug = 1023 gives full debugging)"); 195 "\t\t\t 1/0x0001: warning\n"
196 "\t\t\t 2/0x0002: info\n"
197 "\t\t\t 4/0x0004: mailbox\n"
198 "\t\t\t 8/0x0008: ioctl\n"
199 "\t\t\t 16/0x0010: file\n"
200 "\t\t\t 32/0x0020: dma\n"
201 "\t\t\t 64/0x0040: irq\n"
202 "\t\t\t 128/0x0080: decoder\n"
203 "\t\t\t 256/0x0100: yuv\n"
204 "\t\t\t 512/0x0200: i2c\n"
205 "\t\t\t1024/0x0400: high volume\n");
184MODULE_PARM_DESC(ivtv_pci_latency, 206MODULE_PARM_DESC(ivtv_pci_latency,
185 "Change the PCI latency to 64 if lower: 0 = No, 1 = Yes,\n" 207 "Change the PCI latency to 64 if lower: 0 = No, 1 = Yes,\n"
186 "\t\t\tDefault: Yes"); 208 "\t\t\tDefault: Yes");
@@ -201,7 +223,7 @@ MODULE_PARM_DESC(enc_vbi_buffers,
201 "Encoder VBI Buffers (in MB)\n" 223 "Encoder VBI Buffers (in MB)\n"
202 "\t\t\tDefault: " __stringify(IVTV_DEFAULT_ENC_VBI_BUFFERS)); 224 "\t\t\tDefault: " __stringify(IVTV_DEFAULT_ENC_VBI_BUFFERS));
203MODULE_PARM_DESC(enc_pcm_buffers, 225MODULE_PARM_DESC(enc_pcm_buffers,
204 "Encoder PCM buffers (in MB)\n" 226 "Encoder PCM buffers (in kB)\n"
205 "\t\t\tDefault: " __stringify(IVTV_DEFAULT_ENC_PCM_BUFFERS)); 227 "\t\t\tDefault: " __stringify(IVTV_DEFAULT_ENC_PCM_BUFFERS));
206MODULE_PARM_DESC(dec_mpg_buffers, 228MODULE_PARM_DESC(dec_mpg_buffers,
207 "Decoder MPG buffers (in MB)\n" 229 "Decoder MPG buffers (in MB)\n"
@@ -210,7 +232,7 @@ MODULE_PARM_DESC(dec_yuv_buffers,
210 "Decoder YUV buffers (in MB)\n" 232 "Decoder YUV buffers (in MB)\n"
211 "\t\t\tDefault: " __stringify(IVTV_DEFAULT_DEC_YUV_BUFFERS)); 233 "\t\t\tDefault: " __stringify(IVTV_DEFAULT_DEC_YUV_BUFFERS));
212MODULE_PARM_DESC(dec_vbi_buffers, 234MODULE_PARM_DESC(dec_vbi_buffers,
213 "Decoder VBI buffers (in MB)\n" 235 "Decoder VBI buffers (in kB)\n"
214 "\t\t\tDefault: " __stringify(IVTV_DEFAULT_DEC_VBI_BUFFERS)); 236 "\t\t\tDefault: " __stringify(IVTV_DEFAULT_DEC_VBI_BUFFERS));
215MODULE_PARM_DESC(newi2c, 237MODULE_PARM_DESC(newi2c,
216 "Use new I2C implementation\n" 238 "Use new I2C implementation\n"
@@ -540,13 +562,13 @@ static void ivtv_process_options(struct ivtv *itv)
540 const char *chipname; 562 const char *chipname;
541 int i, j; 563 int i, j;
542 564
543 itv->options.megabytes[IVTV_ENC_STREAM_TYPE_MPG] = enc_mpg_buffers; 565 itv->options.kilobytes[IVTV_ENC_STREAM_TYPE_MPG] = enc_mpg_buffers * 1024;
544 itv->options.megabytes[IVTV_ENC_STREAM_TYPE_YUV] = enc_yuv_buffers; 566 itv->options.kilobytes[IVTV_ENC_STREAM_TYPE_YUV] = enc_yuv_buffers * 1024;
545 itv->options.megabytes[IVTV_ENC_STREAM_TYPE_VBI] = enc_vbi_buffers; 567 itv->options.kilobytes[IVTV_ENC_STREAM_TYPE_VBI] = enc_vbi_buffers * 1024;
546 itv->options.megabytes[IVTV_ENC_STREAM_TYPE_PCM] = enc_pcm_buffers; 568 itv->options.kilobytes[IVTV_ENC_STREAM_TYPE_PCM] = enc_pcm_buffers;
547 itv->options.megabytes[IVTV_DEC_STREAM_TYPE_MPG] = dec_mpg_buffers; 569 itv->options.kilobytes[IVTV_DEC_STREAM_TYPE_MPG] = dec_mpg_buffers * 1024;
548 itv->options.megabytes[IVTV_DEC_STREAM_TYPE_YUV] = dec_yuv_buffers; 570 itv->options.kilobytes[IVTV_DEC_STREAM_TYPE_YUV] = dec_yuv_buffers * 1024;
549 itv->options.megabytes[IVTV_DEC_STREAM_TYPE_VBI] = dec_vbi_buffers; 571 itv->options.kilobytes[IVTV_DEC_STREAM_TYPE_VBI] = dec_vbi_buffers;
550 itv->options.cardtype = cardtype[itv->num]; 572 itv->options.cardtype = cardtype[itv->num];
551 itv->options.tuner = tuner[itv->num]; 573 itv->options.tuner = tuner[itv->num];
552 itv->options.radio = radio[itv->num]; 574 itv->options.radio = radio[itv->num];
@@ -645,7 +667,7 @@ static int __devinit ivtv_init_struct1(struct ivtv *itv)
645 cx2341x_fill_defaults(&itv->params); 667 cx2341x_fill_defaults(&itv->params);
646 itv->params.port = CX2341X_PORT_MEMORY; 668 itv->params.port = CX2341X_PORT_MEMORY;
647 itv->params.capabilities = CX2341X_CAP_HAS_SLICED_VBI; 669 itv->params.capabilities = CX2341X_CAP_HAS_SLICED_VBI;
648 init_waitqueue_head(&itv->cap_w); 670 init_waitqueue_head(&itv->eos_waitq);
649 init_waitqueue_head(&itv->event_waitq); 671 init_waitqueue_head(&itv->event_waitq);
650 init_waitqueue_head(&itv->vsync_waitq); 672 init_waitqueue_head(&itv->vsync_waitq);
651 init_waitqueue_head(&itv->dma_waitq); 673 init_waitqueue_head(&itv->dma_waitq);
@@ -691,14 +713,6 @@ static void __devinit ivtv_init_struct2(struct ivtv *itv)
691 break; 713 break;
692 itv->nof_audio_inputs = i; 714 itv->nof_audio_inputs = i;
693 715
694 /* 0x00EF = saa7114(239) 0x00F0 = saa7115(240) 0x0106 = micro */
695 if (itv->card->hw_all & (IVTV_HW_SAA7115 | IVTV_HW_SAA717X))
696 itv->digitizer = 0xF1;
697 else if (itv->card->hw_all & IVTV_HW_SAA7114)
698 itv->digitizer = 0xEF;
699 else /* cx25840 */
700 itv->digitizer = 0x140;
701
702 if (itv->card->hw_all & IVTV_HW_CX25840) { 716 if (itv->card->hw_all & IVTV_HW_CX25840) {
703 itv->vbi.sliced_size = 288; /* multiple of 16, real size = 284 */ 717 itv->vbi.sliced_size = 288; /* multiple of 16, real size = 284 */
704 } else { 718 } else {
@@ -727,6 +741,7 @@ static int ivtv_setup_pci(struct ivtv *itv, struct pci_dev *dev,
727 const struct pci_device_id *pci_id) 741 const struct pci_device_id *pci_id)
728{ 742{
729 u16 cmd; 743 u16 cmd;
744 u8 card_rev;
730 unsigned char pci_latency; 745 unsigned char pci_latency;
731 746
732 IVTV_DEBUG_INFO("Enabling pci device\n"); 747 IVTV_DEBUG_INFO("Enabling pci device\n");
@@ -773,7 +788,7 @@ static int ivtv_setup_pci(struct ivtv *itv, struct pci_dev *dev,
773 } 788 }
774 IVTV_DEBUG_INFO("Bus Mastering Enabled.\n"); 789 IVTV_DEBUG_INFO("Bus Mastering Enabled.\n");
775 790
776 pci_read_config_byte(dev, PCI_CLASS_REVISION, &itv->card_rev); 791 pci_read_config_byte(dev, PCI_CLASS_REVISION, &card_rev);
777 pci_read_config_byte(dev, PCI_LATENCY_TIMER, &pci_latency); 792 pci_read_config_byte(dev, PCI_LATENCY_TIMER, &pci_latency);
778 793
779 if (pci_latency < 64 && ivtv_pci_latency) { 794 if (pci_latency < 64 && ivtv_pci_latency) {
@@ -790,7 +805,7 @@ static int ivtv_setup_pci(struct ivtv *itv, struct pci_dev *dev,
790 805
791 IVTV_DEBUG_INFO("%d (rev %d) at %02x:%02x.%x, " 806 IVTV_DEBUG_INFO("%d (rev %d) at %02x:%02x.%x, "
792 "irq: %d, latency: %d, memory: 0x%lx\n", 807 "irq: %d, latency: %d, memory: 0x%lx\n",
793 itv->dev->device, itv->card_rev, dev->bus->number, 808 itv->dev->device, card_rev, dev->bus->number,
794 PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn), 809 PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn),
795 itv->dev->irq, pci_latency, (unsigned long)itv->base_addr); 810 itv->dev->irq, pci_latency, (unsigned long)itv->base_addr);
796 811
@@ -808,18 +823,19 @@ static void ivtv_request_module(struct ivtv *itv, const char *name)
808 823
809static void ivtv_load_and_init_modules(struct ivtv *itv) 824static void ivtv_load_and_init_modules(struct ivtv *itv)
810{ 825{
811 struct v4l2_control ctrl;
812 u32 hw = itv->card->hw_all; 826 u32 hw = itv->card->hw_all;
813 int i; 827 int i;
814 828
815 /* load modules */ 829 /* load modules */
816#ifndef CONFIG_VIDEO_TUNER 830#ifndef CONFIG_VIDEO_TUNER
817 if (hw & IVTV_HW_TUNER) { 831 if (hw & IVTV_HW_TUNER) {
818 ivtv_request_module(itv, "tuner"); 832 if (itv->options.tuner == TUNER_XCEIVE_XC3028) {
819#ifdef HAVE_XC3028 833 IVTV_INFO("Xceive tuner not yet supported, only composite and S-Video inputs will be available\n");
820 if (itv->options.tuner == TUNER_XCEIVE_XC3028) 834 itv->tunerid = 1;
821 ivtv_request_module(itv, "xc3028-tuner"); 835 }
822#endif 836 else {
837 ivtv_request_module(itv, "tuner");
838 }
823 } 839 }
824#endif 840#endif
825#ifndef CONFIG_VIDEO_CX25840 841#ifndef CONFIG_VIDEO_CX25840
@@ -848,6 +864,10 @@ static void ivtv_load_and_init_modules(struct ivtv *itv)
848 if (hw & IVTV_HW_MSP34XX) 864 if (hw & IVTV_HW_MSP34XX)
849 ivtv_request_module(itv, "msp3400"); 865 ivtv_request_module(itv, "msp3400");
850#endif 866#endif
867#ifndef CONFIG_VIDEO_VP27SMPX
868 if (hw & IVTV_HW_VP27SMPX)
869 ivtv_request_module(itv, "vp27smpx");
870#endif
851 if (hw & IVTV_HW_TVAUDIO) 871 if (hw & IVTV_HW_TVAUDIO)
852 ivtv_request_module(itv, "tvaudio"); 872 ivtv_request_module(itv, "tvaudio");
853#ifndef CONFIG_VIDEO_WM8775 873#ifndef CONFIG_VIDEO_WM8775
@@ -888,13 +908,17 @@ static void ivtv_load_and_init_modules(struct ivtv *itv)
888 else if ((hw & IVTV_HW_UPD64031A) == 0) 908 else if ((hw & IVTV_HW_UPD64031A) == 0)
889 itv->card = ivtv_get_card(IVTV_CARD_CX23416GYC_NOGR); 909 itv->card = ivtv_get_card(IVTV_CARD_CX23416GYC_NOGR);
890 } 910 }
911 else if (itv->card->type == IVTV_CARD_GV_MVPRX ||
912 itv->card->type == IVTV_CARD_GV_MVPRX2E) {
913 struct v4l2_crystal_freq crystal_freq;
914
915 /* The crystal frequency of GVMVPRX is 24.576MHz */
916 crystal_freq.freq = SAA7115_FREQ_24_576_MHZ;
917 crystal_freq.flags = SAA7115_FREQ_FL_UCGC;
918 itv->video_dec_func(itv, VIDIOC_INT_S_CRYSTAL_FREQ, &crystal_freq);
919 }
891 920
892 if (hw & IVTV_HW_CX25840) { 921 if (hw & IVTV_HW_CX25840) {
893 /* CX25840_CID_ENABLE_PVR150_WORKAROUND */
894 ctrl.id = V4L2_CID_PRIVATE_BASE;
895 ctrl.value = itv->pvr150_workaround;
896 itv->video_dec_func(itv, VIDIOC_S_CTRL, &ctrl);
897
898 itv->vbi.raw_decoder_line_size = 1444; 922 itv->vbi.raw_decoder_line_size = 1444;
899 itv->vbi.raw_decoder_sav_odd_field = 0x20; 923 itv->vbi.raw_decoder_sav_odd_field = 0x20;
900 itv->vbi.raw_decoder_sav_even_field = 0x60; 924 itv->vbi.raw_decoder_sav_even_field = 0x60;
@@ -940,12 +964,9 @@ static int __devinit ivtv_probe(struct pci_dev *dev,
940 const struct pci_device_id *pci_id) 964 const struct pci_device_id *pci_id)
941{ 965{
942 int retval = 0; 966 int retval = 0;
943 int video_input;
944 int yuv_buf_size; 967 int yuv_buf_size;
945 int vbi_buf_size; 968 int vbi_buf_size;
946 int fw_retry_count = 3;
947 struct ivtv *itv; 969 struct ivtv *itv;
948 struct v4l2_frequency vf;
949 970
950 spin_lock(&ivtv_cards_lock); 971 spin_lock(&ivtv_cards_lock);
951 972
@@ -982,6 +1003,8 @@ static int __devinit ivtv_probe(struct pci_dev *dev,
982 1003
983 IVTV_DEBUG_INFO("base addr: 0x%08x\n", itv->base_addr); 1004 IVTV_DEBUG_INFO("base addr: 0x%08x\n", itv->base_addr);
984 1005
1006 mutex_lock(&itv->serialize_lock);
1007
985 /* PCI Device Setup */ 1008 /* PCI Device Setup */
986 if ((retval = ivtv_setup_pci(itv, dev, pci_id)) != 0) { 1009 if ((retval = ivtv_setup_pci(itv, dev, pci_id)) != 0) {
987 if (retval == -EIO) 1010 if (retval == -EIO)
@@ -1032,22 +1055,6 @@ static int __devinit ivtv_probe(struct pci_dev *dev,
1032 goto free_io; 1055 goto free_io;
1033 } 1056 }
1034 1057
1035 while (--fw_retry_count > 0) {
1036 /* load firmware */
1037 if (ivtv_firmware_init(itv) == 0)
1038 break;
1039 if (fw_retry_count > 1)
1040 IVTV_WARN("Retry loading firmware\n");
1041 }
1042 if (fw_retry_count == 0) {
1043 IVTV_ERR("Error initializing firmware\n");
1044 goto free_i2c;
1045 }
1046
1047 /* Try and get firmware versions */
1048 IVTV_DEBUG_INFO("Getting firmware version..\n");
1049 ivtv_firmware_versions(itv);
1050
1051 /* Check yuv output filter table */ 1058 /* Check yuv output filter table */
1052 if (itv->has_cx23415) ivtv_yuv_filter_check(itv); 1059 if (itv->has_cx23415) ivtv_yuv_filter_check(itv);
1053 1060
@@ -1135,43 +1142,22 @@ static int __devinit ivtv_probe(struct pci_dev *dev,
1135 if (itv->options.radio > 0) 1142 if (itv->options.radio > 0)
1136 itv->v4l2_cap |= V4L2_CAP_RADIO; 1143 itv->v4l2_cap |= V4L2_CAP_RADIO;
1137 1144
1138 if (itv->options.tuner > -1) { 1145 if (itv->options.tuner > -1 && itv->tunerid == 0) {
1139 struct tuner_setup setup; 1146 struct tuner_setup setup;
1140 1147
1141 setup.addr = ADDR_UNSET; 1148 setup.addr = ADDR_UNSET;
1142 setup.type = itv->options.tuner; 1149 setup.type = itv->options.tuner;
1143 setup.mode_mask = T_ANALOG_TV; /* matches TV tuners */ 1150 setup.mode_mask = T_ANALOG_TV; /* matches TV tuners */
1144#ifdef HAVE_XC3028
1145 setup.initmode = V4L2_TUNER_ANALOG_TV;
1146 if (itv->options.tuner == TUNER_XCEIVE_XC3028) {
1147 setup.gpio_write = ivtv_reset_tuner_gpio;
1148 setup.gpio_priv = itv;
1149 }
1150#endif
1151 ivtv_call_i2c_clients(itv, TUNER_SET_TYPE_ADDR, &setup); 1151 ivtv_call_i2c_clients(itv, TUNER_SET_TYPE_ADDR, &setup);
1152 } 1152 }
1153 1153
1154 vf.tuner = 0;
1155 vf.type = V4L2_TUNER_ANALOG_TV;
1156 vf.frequency = 6400; /* the tuner 'baseline' frequency */
1157 if (itv->std & V4L2_STD_NTSC_M) {
1158 /* Why on earth? */
1159 vf.frequency = 1076; /* ch. 4 67250*16/1000 */
1160 }
1161
1162 /* The tuner is fixed to the standard. The other inputs (e.g. S-Video) 1154 /* The tuner is fixed to the standard. The other inputs (e.g. S-Video)
1163 are not. */ 1155 are not. */
1164 itv->tuner_std = itv->std; 1156 itv->tuner_std = itv->std;
1165 1157
1166 video_input = itv->active_input; 1158 if (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT) {
1167 itv->active_input++; /* Force update of input */ 1159 ivtv_call_i2c_clients(itv, VIDIOC_INT_S_STD_OUTPUT, &itv->std);
1168 ivtv_v4l2_ioctls(itv, NULL, VIDIOC_S_INPUT, &video_input); 1160 }
1169
1170 /* Let the VIDIOC_S_STD ioctl do all the work, keeps the code
1171 in one place. */
1172 itv->std++; /* Force full standard initialization */
1173 itv->std_out = itv->std;
1174 ivtv_v4l2_ioctls(itv, NULL, VIDIOC_S_FREQUENCY, &vf);
1175 1161
1176 retval = ivtv_streams_setup(itv); 1162 retval = ivtv_streams_setup(itv);
1177 if (retval) { 1163 if (retval) {
@@ -1179,11 +1165,6 @@ static int __devinit ivtv_probe(struct pci_dev *dev,
1179 goto free_i2c; 1165 goto free_i2c;
1180 } 1166 }
1181 1167
1182 if (itv->card->v4l2_capabilities & V4L2_CAP_VIDEO_OUTPUT) {
1183 ivtv_init_mpeg_decoder(itv);
1184 }
1185 ivtv_v4l2_ioctls(itv, NULL, VIDIOC_S_STD, &itv->tuner_std);
1186
1187 IVTV_DEBUG_IRQ("Masking interrupts\n"); 1168 IVTV_DEBUG_IRQ("Masking interrupts\n");
1188 /* clear interrupt mask, effectively disabling interrupts */ 1169 /* clear interrupt mask, effectively disabling interrupts */
1189 ivtv_set_irq_mask(itv, 0xffffffff); 1170 ivtv_set_irq_mask(itv, 0xffffffff);
@@ -1195,26 +1176,8 @@ static int __devinit ivtv_probe(struct pci_dev *dev,
1195 IVTV_ERR("Failed to register irq %d\n", retval); 1176 IVTV_ERR("Failed to register irq %d\n", retval);
1196 goto free_streams; 1177 goto free_streams;
1197 } 1178 }
1198 1179 mutex_unlock(&itv->serialize_lock);
1199 /* On a cx23416 this seems to be able to enable DMA to the chip? */
1200 if (!itv->has_cx23415)
1201 write_reg_sync(0x03, IVTV_REG_DMACONTROL);
1202
1203 /* Default interrupts enabled. For the PVR350 this includes the
1204 decoder VSYNC interrupt, which is always on. It is not only used
1205 during decoding but also by the OSD.
1206 Some old PVR250 cards had a cx23415, so testing for that is too
1207 general. Instead test if the card has video output capability. */
1208 if (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT)
1209 ivtv_clear_irq_mask(itv, IVTV_IRQ_MASK_INIT | IVTV_IRQ_DEC_VSYNC);
1210 else
1211 ivtv_clear_irq_mask(itv, IVTV_IRQ_MASK_INIT);
1212
1213 if (itv->has_cx23415)
1214 ivtv_set_osd_alpha(itv);
1215
1216 IVTV_INFO("Initialized card #%d: %s\n", itv->num, itv->card_name); 1180 IVTV_INFO("Initialized card #%d: %s\n", itv->num, itv->card_name);
1217
1218 return 0; 1181 return 0;
1219 1182
1220 free_irq: 1183 free_irq:
@@ -1232,65 +1195,146 @@ static int __devinit ivtv_probe(struct pci_dev *dev,
1232 release_mem_region(itv->base_addr + IVTV_DECODER_OFFSET, IVTV_DECODER_SIZE); 1195 release_mem_region(itv->base_addr + IVTV_DECODER_OFFSET, IVTV_DECODER_SIZE);
1233 free_workqueue: 1196 free_workqueue:
1234 destroy_workqueue(itv->irq_work_queues); 1197 destroy_workqueue(itv->irq_work_queues);
1198 mutex_unlock(&itv->serialize_lock);
1235 err: 1199 err:
1236 if (retval == 0) 1200 if (retval == 0)
1237 retval = -ENODEV; 1201 retval = -ENODEV;
1238 IVTV_ERR("Error %d on initialization\n", retval); 1202 IVTV_ERR("Error %d on initialization\n", retval);
1239 1203
1204 spin_lock(&ivtv_cards_lock);
1240 kfree(ivtv_cards[ivtv_cards_active]); 1205 kfree(ivtv_cards[ivtv_cards_active]);
1241 ivtv_cards[ivtv_cards_active] = NULL; 1206 ivtv_cards[ivtv_cards_active] = NULL;
1207 spin_unlock(&ivtv_cards_lock);
1242 return retval; 1208 return retval;
1243} 1209}
1244 1210
1211int ivtv_init_on_first_open(struct ivtv *itv)
1212{
1213 struct v4l2_frequency vf;
1214 int fw_retry_count = 3;
1215 int video_input;
1216
1217 if (test_bit(IVTV_F_I_FAILED, &itv->i_flags))
1218 return -ENXIO;
1219
1220 if (test_and_set_bit(IVTV_F_I_INITED, &itv->i_flags))
1221 return 0;
1222
1223 while (--fw_retry_count > 0) {
1224 /* load firmware */
1225 if (ivtv_firmware_init(itv) == 0)
1226 break;
1227 if (fw_retry_count > 1)
1228 IVTV_WARN("Retry loading firmware\n");
1229 }
1230
1231 if (fw_retry_count == 0) {
1232 set_bit(IVTV_F_I_FAILED, &itv->i_flags);
1233 return -ENXIO;
1234 }
1235
1236 /* Try and get firmware versions */
1237 IVTV_DEBUG_INFO("Getting firmware version..\n");
1238 ivtv_firmware_versions(itv);
1239
1240 if (itv->card->hw_all & IVTV_HW_CX25840) {
1241 struct v4l2_control ctrl;
1242
1243 /* CX25840_CID_ENABLE_PVR150_WORKAROUND */
1244 ctrl.id = V4L2_CID_PRIVATE_BASE;
1245 ctrl.value = itv->pvr150_workaround;
1246 itv->video_dec_func(itv, VIDIOC_S_CTRL, &ctrl);
1247 }
1248
1249 vf.tuner = 0;
1250 vf.type = V4L2_TUNER_ANALOG_TV;
1251 vf.frequency = 6400; /* the tuner 'baseline' frequency */
1252
1253 /* Set initial frequency. For PAL/SECAM broadcasts no
1254 'default' channel exists AFAIK. */
1255 if (itv->std == V4L2_STD_NTSC_M_JP) {
1256 vf.frequency = 1460; /* ch. 1 91250*16/1000 */
1257 }
1258 else if (itv->std & V4L2_STD_NTSC_M) {
1259 vf.frequency = 1076; /* ch. 4 67250*16/1000 */
1260 }
1261
1262 video_input = itv->active_input;
1263 itv->active_input++; /* Force update of input */
1264 ivtv_v4l2_ioctls(itv, NULL, VIDIOC_S_INPUT, &video_input);
1265
1266 /* Let the VIDIOC_S_STD ioctl do all the work, keeps the code
1267 in one place. */
1268 itv->std++; /* Force full standard initialization */
1269 itv->std_out = itv->std;
1270 ivtv_v4l2_ioctls(itv, NULL, VIDIOC_S_FREQUENCY, &vf);
1271
1272 if (itv->card->v4l2_capabilities & V4L2_CAP_VIDEO_OUTPUT) {
1273 ivtv_init_mpeg_decoder(itv);
1274 }
1275 ivtv_v4l2_ioctls(itv, NULL, VIDIOC_S_STD, &itv->tuner_std);
1276
1277 /* On a cx23416 this seems to be able to enable DMA to the chip? */
1278 if (!itv->has_cx23415)
1279 write_reg_sync(0x03, IVTV_REG_DMACONTROL);
1280
1281 /* Default interrupts enabled. For the PVR350 this includes the
1282 decoder VSYNC interrupt, which is always on. It is not only used
1283 during decoding but also by the OSD.
1284 Some old PVR250 cards had a cx23415, so testing for that is too
1285 general. Instead test if the card has video output capability. */
1286 if (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT) {
1287 ivtv_clear_irq_mask(itv, IVTV_IRQ_MASK_INIT | IVTV_IRQ_DEC_VSYNC);
1288 ivtv_set_osd_alpha(itv);
1289 }
1290 else
1291 ivtv_clear_irq_mask(itv, IVTV_IRQ_MASK_INIT);
1292 return 0;
1293}
1294
1245static void ivtv_remove(struct pci_dev *pci_dev) 1295static void ivtv_remove(struct pci_dev *pci_dev)
1246{ 1296{
1247 struct ivtv *itv = pci_get_drvdata(pci_dev); 1297 struct ivtv *itv = pci_get_drvdata(pci_dev);
1248 1298
1249 IVTV_DEBUG_INFO("Removing Card #%d\n", itv->num); 1299 IVTV_DEBUG_INFO("Removing Card #%d\n", itv->num);
1250 1300
1251 /* Stop all captures */ 1301 if (test_bit(IVTV_F_I_INITED, &itv->i_flags)) {
1252 IVTV_DEBUG_INFO("Stopping all streams\n"); 1302 /* Stop all captures */
1253 if (atomic_read(&itv->capturing) > 0) 1303 IVTV_DEBUG_INFO("Stopping all streams\n");
1254 ivtv_stop_all_captures(itv); 1304 if (atomic_read(&itv->capturing) > 0)
1255 1305 ivtv_stop_all_captures(itv);
1256 /* Stop all decoding */ 1306
1257 IVTV_DEBUG_INFO("Stopping decoding\n"); 1307 /* Stop all decoding */
1258 if (atomic_read(&itv->decoding) > 0) { 1308 IVTV_DEBUG_INFO("Stopping decoding\n");
1259 int type; 1309 if (atomic_read(&itv->decoding) > 0) {
1260 1310 int type;
1261 if (test_bit(IVTV_F_I_DEC_YUV, &itv->i_flags)) 1311
1262 type = IVTV_DEC_STREAM_TYPE_YUV; 1312 if (test_bit(IVTV_F_I_DEC_YUV, &itv->i_flags))
1263 else 1313 type = IVTV_DEC_STREAM_TYPE_YUV;
1264 type = IVTV_DEC_STREAM_TYPE_MPG; 1314 else
1265 ivtv_stop_v4l2_decode_stream(&itv->streams[type], 1315 type = IVTV_DEC_STREAM_TYPE_MPG;
1266 VIDEO_CMD_STOP_TO_BLACK | VIDEO_CMD_STOP_IMMEDIATELY, 0); 1316 ivtv_stop_v4l2_decode_stream(&itv->streams[type],
1317 VIDEO_CMD_STOP_TO_BLACK | VIDEO_CMD_STOP_IMMEDIATELY, 0);
1318 }
1319 ivtv_halt_firmware(itv);
1267 } 1320 }
1268 1321
1269 /* Interrupts */ 1322 /* Interrupts */
1270 IVTV_DEBUG_INFO("Disabling interrupts\n");
1271 ivtv_set_irq_mask(itv, 0xffffffff); 1323 ivtv_set_irq_mask(itv, 0xffffffff);
1272 del_timer_sync(&itv->dma_timer); 1324 del_timer_sync(&itv->dma_timer);
1273 1325
1274 /* Stop all Work Queues */ 1326 /* Stop all Work Queues */
1275 IVTV_DEBUG_INFO("Stop Work Queues\n");
1276 flush_workqueue(itv->irq_work_queues); 1327 flush_workqueue(itv->irq_work_queues);
1277 destroy_workqueue(itv->irq_work_queues); 1328 destroy_workqueue(itv->irq_work_queues);
1278 1329
1279 IVTV_DEBUG_INFO("Stopping Firmware\n");
1280 ivtv_halt_firmware(itv);
1281
1282 IVTV_DEBUG_INFO("Unregistering v4l devices\n");
1283 ivtv_streams_cleanup(itv); 1330 ivtv_streams_cleanup(itv);
1284 IVTV_DEBUG_INFO("Freeing dma resources\n");
1285 ivtv_udma_free(itv); 1331 ivtv_udma_free(itv);
1286 1332
1287 exit_ivtv_i2c(itv); 1333 exit_ivtv_i2c(itv);
1288 1334
1289 IVTV_DEBUG_INFO(" Releasing irq\n");
1290 free_irq(itv->dev->irq, (void *)itv); 1335 free_irq(itv->dev->irq, (void *)itv);
1291 ivtv_iounmap(itv); 1336 ivtv_iounmap(itv);
1292 1337
1293 IVTV_DEBUG_INFO(" Releasing mem\n");
1294 release_mem_region(itv->base_addr, IVTV_ENCODER_SIZE); 1338 release_mem_region(itv->base_addr, IVTV_ENCODER_SIZE);
1295 release_mem_region(itv->base_addr + IVTV_REG_OFFSET, IVTV_REG_SIZE); 1339 release_mem_region(itv->base_addr + IVTV_REG_OFFSET, IVTV_REG_SIZE);
1296 if (itv->has_cx23415) 1340 if (itv->has_cx23415)
@@ -1322,9 +1366,9 @@ static int module_start(void)
1322 return -1; 1366 return -1;
1323 } 1367 }
1324 1368
1325 if (ivtv_debug < 0 || ivtv_debug > 1023) { 1369 if (ivtv_debug < 0 || ivtv_debug > 2047) {
1326 ivtv_debug = 0; 1370 ivtv_debug = 0;
1327 printk(KERN_INFO "ivtv: Debug value must be >= 0 and <= 1023\n"); 1371 printk(KERN_INFO "ivtv: Debug value must be >= 0 and <= 2047\n");
1328 } 1372 }
1329 1373
1330 if (pci_register_driver(&ivtv_pci_driver)) { 1374 if (pci_register_driver(&ivtv_pci_driver)) {
@@ -1341,6 +1385,7 @@ static void module_cleanup(void)
1341 1385
1342 pci_unregister_driver(&ivtv_pci_driver); 1386 pci_unregister_driver(&ivtv_pci_driver);
1343 1387
1388 spin_lock(&ivtv_cards_lock);
1344 for (i = 0; i < ivtv_cards_active; i++) { 1389 for (i = 0; i < ivtv_cards_active; i++) {
1345 if (ivtv_cards[i] == NULL) 1390 if (ivtv_cards[i] == NULL)
1346 continue; 1391 continue;
@@ -1349,13 +1394,15 @@ static void module_cleanup(void)
1349 } 1394 }
1350 kfree(ivtv_cards[i]); 1395 kfree(ivtv_cards[i]);
1351 } 1396 }
1397 spin_unlock(&ivtv_cards_lock);
1352} 1398}
1353 1399
1354/* Note: These symbols are exported because they are used by the ivtv-fb 1400/* Note: These symbols are exported because they are used by the ivtvfb
1355 framebuffer module and an infrared module for the IR-blaster. */ 1401 framebuffer module and an infrared module for the IR-blaster. */
1356EXPORT_SYMBOL(ivtv_set_irq_mask); 1402EXPORT_SYMBOL(ivtv_set_irq_mask);
1357EXPORT_SYMBOL(ivtv_cards_active); 1403EXPORT_SYMBOL(ivtv_cards_active);
1358EXPORT_SYMBOL(ivtv_cards); 1404EXPORT_SYMBOL(ivtv_cards);
1405EXPORT_SYMBOL(ivtv_cards_lock);
1359EXPORT_SYMBOL(ivtv_api); 1406EXPORT_SYMBOL(ivtv_api);
1360EXPORT_SYMBOL(ivtv_vapi); 1407EXPORT_SYMBOL(ivtv_vapi);
1361EXPORT_SYMBOL(ivtv_vapi_result); 1408EXPORT_SYMBOL(ivtv_vapi_result);
@@ -1366,6 +1413,7 @@ EXPORT_SYMBOL(ivtv_udma_setup);
1366EXPORT_SYMBOL(ivtv_udma_unmap); 1413EXPORT_SYMBOL(ivtv_udma_unmap);
1367EXPORT_SYMBOL(ivtv_udma_alloc); 1414EXPORT_SYMBOL(ivtv_udma_alloc);
1368EXPORT_SYMBOL(ivtv_udma_prepare); 1415EXPORT_SYMBOL(ivtv_udma_prepare);
1416EXPORT_SYMBOL(ivtv_init_on_first_open);
1369 1417
1370module_init(module_start); 1418module_init(module_start);
1371module_exit(module_cleanup); 1419module_exit(module_cleanup);
diff --git a/drivers/media/video/ivtv/ivtv-driver.h b/drivers/media/video/ivtv/ivtv-driver.h
index 8abb34a35816..3bda1df63cb6 100644
--- a/drivers/media/video/ivtv/ivtv-driver.h
+++ b/drivers/media/video/ivtv/ivtv-driver.h
@@ -38,7 +38,6 @@
38 38
39#include <linux/version.h> 39#include <linux/version.h>
40#include <linux/module.h> 40#include <linux/module.h>
41#include <linux/moduleparam.h>
42#include <linux/init.h> 41#include <linux/init.h>
43#include <linux/delay.h> 42#include <linux/delay.h>
44#include <linux/sched.h> 43#include <linux/sched.h>
@@ -63,77 +62,20 @@
63#include <media/tuner.h> 62#include <media/tuner.h>
64#include <media/cx2341x.h> 63#include <media/cx2341x.h>
65 64
66/* #define HAVE_XC3028 1 */ 65#include <linux/ivtv.h>
67 66
68#include <media/ivtv.h>
69 67
68/* Memory layout */
70#define IVTV_ENCODER_OFFSET 0x00000000 69#define IVTV_ENCODER_OFFSET 0x00000000
71#define IVTV_ENCODER_SIZE 0x00800000 /* Last half isn't needed 0x01000000 */ 70#define IVTV_ENCODER_SIZE 0x00800000 /* Total size is 0x01000000, but only first half is used */
72
73#define IVTV_DECODER_OFFSET 0x01000000 71#define IVTV_DECODER_OFFSET 0x01000000
74#define IVTV_DECODER_SIZE 0x00800000 /* Last half isn't needed 0x01000000 */ 72#define IVTV_DECODER_SIZE 0x00800000 /* Total size is 0x01000000, but only first half is used */
75
76#define IVTV_REG_OFFSET 0x02000000 73#define IVTV_REG_OFFSET 0x02000000
77#define IVTV_REG_SIZE 0x00010000 74#define IVTV_REG_SIZE 0x00010000
78 75
79/* Buffers on hardware offsets */ 76/* Maximum ivtv driver instances. Some people have a huge number of
80#define IVTV_YUV_BUFFER_OFFSET 0x001a8600 /* First YUV Buffer */ 77 capture cards, so set this to a high value. */
81#define IVTV_YUV_BUFFER_OFFSET_1 0x00240400 /* Second YUV Buffer */ 78#define IVTV_MAX_CARDS 32
82#define IVTV_YUV_BUFFER_OFFSET_2 0x002d8200 /* Third YUV Buffer */
83#define IVTV_YUV_BUFFER_OFFSET_3 0x00370000 /* Fourth YUV Buffer */
84#define IVTV_YUV_BUFFER_UV_OFFSET 0x65400 /* Offset to UV Buffer */
85
86/* Offset to filter table in firmware */
87#define IVTV_YUV_HORIZONTAL_FILTER_OFFSET 0x025d8
88#define IVTV_YUV_VERTICAL_FILTER_OFFSET 0x03358
89
90extern const u32 yuv_offset[4];
91
92/* Maximum ivtv driver instances.
93 Based on 6 PVR500s each with two PVR15s...
94 TODO: make this dynamic. I believe it is only a global in order to support
95 ivtv-fb. There must be a better way to do that. */
96#define IVTV_MAX_CARDS 12
97
98/* Supported cards */
99#define IVTV_CARD_PVR_250 0 /* WinTV PVR 250 */
100#define IVTV_CARD_PVR_350 1 /* encoder, decoder, tv-out */
101#define IVTV_CARD_PVR_150 2 /* WinTV PVR 150 and PVR 500 (really just two
102 PVR150s on one PCI board) */
103#define IVTV_CARD_M179 3 /* AVerMedia M179 (encoder only) */
104#define IVTV_CARD_MPG600 4 /* Kuroutoshikou ITVC16-STVLP/YUAN MPG600, encoder only */
105#define IVTV_CARD_MPG160 5 /* Kuroutoshikou ITVC15-STVLP/YUAN MPG160
106 cx23415 based, but does not have tv-out */
107#define IVTV_CARD_PG600 6 /* YUAN PG600/DIAMONDMM PVR-550 based on the CX Falcon 2 */
108#define IVTV_CARD_AVC2410 7 /* Adaptec AVC-2410 */
109#define IVTV_CARD_AVC2010 8 /* Adaptec AVD-2010 (No Tuner) */
110#define IVTV_CARD_TG5000TV 9 /* NAGASE TRANSGEAR 5000TV, encoder only */
111#define IVTV_CARD_VA2000MAX_SNT6 10 /* VA2000MAX-STN6 */
112#define IVTV_CARD_CX23416GYC 11 /* Kuroutoshikou CX23416GYC-STVLP (Yuan MPG600GR OEM) */
113#define IVTV_CARD_GV_MVPRX 12 /* I/O Data GV-MVP/RX, RX2, RX2W */
114#define IVTV_CARD_GV_MVPRX2E 13 /* I/O Data GV-MVP/RX2E */
115#define IVTV_CARD_GOTVIEW_PCI_DVD 14 /* GotView PCI DVD */
116#define IVTV_CARD_GOTVIEW_PCI_DVD2 15 /* GotView PCI DVD2 */
117#define IVTV_CARD_YUAN_MPC622 16 /* Yuan MPC622 miniPCI */
118#define IVTV_CARD_DCTMTVP1 17 /* DIGITAL COWBOY DCT-MTVP1 */
119#ifdef HAVE_XC3028
120#define IVTV_CARD_PG600V2 18 /* Yuan PG600V2/GotView PCI DVD Lite/Club3D ZAP-TV1x01 */
121#define IVTV_CARD_LAST 18
122#else
123#define IVTV_CARD_LAST 17
124#endif
125
126/* Variants of existing cards but with the same PCI IDs. The driver
127 detects these based on other device information.
128 These cards must always come last.
129 New cards must be inserted above, and the indices of the cards below
130 must be adjusted accordingly. */
131
132/* PVR-350 V1 (uses saa7114) */
133#define IVTV_CARD_PVR_350_V1 (IVTV_CARD_LAST+1)
134/* 2 variants of Kuroutoshikou CX23416GYC-STVLP (Yuan MPG600GR OEM) */
135#define IVTV_CARD_CX23416GYC_NOGR (IVTV_CARD_LAST+2)
136#define IVTV_CARD_CX23416GYC_NOGRYCS (IVTV_CARD_LAST+3)
137 79
138#define IVTV_ENC_STREAM_TYPE_MPG 0 80#define IVTV_ENC_STREAM_TYPE_MPG 0
139#define IVTV_ENC_STREAM_TYPE_YUV 1 81#define IVTV_ENC_STREAM_TYPE_YUV 1
@@ -146,70 +88,8 @@ extern const u32 yuv_offset[4];
146#define IVTV_DEC_STREAM_TYPE_YUV 8 88#define IVTV_DEC_STREAM_TYPE_YUV 8
147#define IVTV_MAX_STREAMS 9 89#define IVTV_MAX_STREAMS 9
148 90
149#define IVTV_V4L2_DEC_MPG_OFFSET 16 /* offset from 0 to register decoder mpg v4l2 minors on */
150#define IVTV_V4L2_ENC_PCM_OFFSET 24 /* offset from 0 to register pcm v4l2 minors on */
151#define IVTV_V4L2_ENC_YUV_OFFSET 32 /* offset from 0 to register yuv v4l2 minors on */
152#define IVTV_V4L2_DEC_YUV_OFFSET 48 /* offset from 0 to register decoder yuv v4l2 minors on */
153#define IVTV_V4L2_DEC_VBI_OFFSET 8 /* offset from 0 to register decoder vbi input v4l2 minors on */
154#define IVTV_V4L2_DEC_VOUT_OFFSET 16 /* offset from 0 to register vbi output v4l2 minors on */
155
156#define IVTV_ENC_MEM_START 0x00000000
157#define IVTV_DEC_MEM_START 0x01000000
158
159/* system vendor and device IDs */
160#define PCI_VENDOR_ID_ICOMP 0x4444
161#define PCI_DEVICE_ID_IVTV15 0x0803
162#define PCI_DEVICE_ID_IVTV16 0x0016
163
164/* subsystem vendor ID */
165#define IVTV_PCI_ID_HAUPPAUGE 0x0070
166#define IVTV_PCI_ID_HAUPPAUGE_ALT1 0x0270
167#define IVTV_PCI_ID_HAUPPAUGE_ALT2 0x4070
168#define IVTV_PCI_ID_ADAPTEC 0x9005
169#define IVTV_PCI_ID_AVERMEDIA 0x1461
170#define IVTV_PCI_ID_YUAN1 0x12ab
171#define IVTV_PCI_ID_YUAN2 0xff01
172#define IVTV_PCI_ID_YUAN3 0xffab
173#define IVTV_PCI_ID_YUAN4 0xfbab
174#define IVTV_PCI_ID_DIAMONDMM 0xff92
175#define IVTV_PCI_ID_IODATA 0x10fc
176#define IVTV_PCI_ID_MELCO 0x1154
177#define IVTV_PCI_ID_GOTVIEW1 0xffac
178#define IVTV_PCI_ID_GOTVIEW2 0xffad
179
180/* Decoder Buffer hardware size on Chip */
181#define IVTV_DEC_MAX_BUF 0x00100000 /* max bytes in decoder buffer */
182#define IVTV_DEC_MIN_BUF 0x00010000 /* min bytes in dec buffer */
183
184/* ======================================================================== */
185/* ========================== START USER SETTABLE DMA VARIABLES =========== */
186/* ======================================================================== */
187
188#define IVTV_DMA_SG_OSD_ENT (2883584/PAGE_SIZE) /* sg entities */ 91#define IVTV_DMA_SG_OSD_ENT (2883584/PAGE_SIZE) /* sg entities */
189 92
190/* DMA Buffers, Default size in MB allocated */
191#define IVTV_DEFAULT_ENC_MPG_BUFFERS 4
192#define IVTV_DEFAULT_ENC_YUV_BUFFERS 2
193#define IVTV_DEFAULT_ENC_VBI_BUFFERS 1
194#define IVTV_DEFAULT_ENC_PCM_BUFFERS 1
195#define IVTV_DEFAULT_DEC_MPG_BUFFERS 1
196#define IVTV_DEFAULT_DEC_YUV_BUFFERS 1
197#define IVTV_DEFAULT_DEC_VBI_BUFFERS 1
198
199/* ======================================================================== */
200/* ========================== END USER SETTABLE DMA VARIABLES ============= */
201/* ======================================================================== */
202
203/* Decoder Status Register */
204#define IVTV_DMA_ERR_LIST 0x00000010
205#define IVTV_DMA_ERR_WRITE 0x00000008
206#define IVTV_DMA_ERR_READ 0x00000004
207#define IVTV_DMA_SUCCESS_WRITE 0x00000002
208#define IVTV_DMA_SUCCESS_READ 0x00000001
209#define IVTV_DMA_READ_ERR (IVTV_DMA_ERR_LIST | IVTV_DMA_ERR_READ)
210#define IVTV_DMA_WRITE_ERR (IVTV_DMA_ERR_LIST | IVTV_DMA_ERR_WRITE)
211#define IVTV_DMA_ERR (IVTV_DMA_ERR_LIST | IVTV_DMA_ERR_WRITE | IVTV_DMA_ERR_READ)
212
213/* DMA Registers */ 93/* DMA Registers */
214#define IVTV_REG_DMAXFER (0x0000) 94#define IVTV_REG_DMAXFER (0x0000)
215#define IVTV_REG_DMASTATUS (0x0004) 95#define IVTV_REG_DMASTATUS (0x0004)
@@ -232,44 +112,24 @@ extern const u32 yuv_offset[4];
232#define IVTV_REG_VPU (0x9058) 112#define IVTV_REG_VPU (0x9058)
233#define IVTV_REG_APU (0xA064) 113#define IVTV_REG_APU (0xA064)
234 114
235#define IVTV_IRQ_ENC_START_CAP (0x1 << 31)
236#define IVTV_IRQ_ENC_EOS (0x1 << 30)
237#define IVTV_IRQ_ENC_VBI_CAP (0x1 << 29)
238#define IVTV_IRQ_ENC_VIM_RST (0x1 << 28)
239#define IVTV_IRQ_ENC_DMA_COMPLETE (0x1 << 27)
240#define IVTV_IRQ_ENC_PIO_COMPLETE (0x1 << 25)
241#define IVTV_IRQ_DEC_AUD_MODE_CHG (0x1 << 24)
242#define IVTV_IRQ_DEC_DATA_REQ (0x1 << 22)
243#define IVTV_IRQ_DEC_DMA_COMPLETE (0x1 << 20)
244#define IVTV_IRQ_DEC_VBI_RE_INSERT (0x1 << 19)
245#define IVTV_IRQ_DMA_ERR (0x1 << 18)
246#define IVTV_IRQ_DMA_WRITE (0x1 << 17)
247#define IVTV_IRQ_DMA_READ (0x1 << 16)
248#define IVTV_IRQ_DEC_VSYNC (0x1 << 10)
249
250/* IRQ Masks */
251#define IVTV_IRQ_MASK_INIT (IVTV_IRQ_DMA_ERR|IVTV_IRQ_ENC_DMA_COMPLETE|\
252 IVTV_IRQ_DMA_READ|IVTV_IRQ_ENC_PIO_COMPLETE)
253
254#define IVTV_IRQ_MASK_CAPTURE (IVTV_IRQ_ENC_START_CAP | IVTV_IRQ_ENC_EOS)
255#define IVTV_IRQ_MASK_DECODE (IVTV_IRQ_DEC_DATA_REQ|IVTV_IRQ_DEC_AUD_MODE_CHG)
256
257/* i2c stuff */ 115/* i2c stuff */
258#define I2C_CLIENTS_MAX 16 116#define I2C_CLIENTS_MAX 16
259 117
260/* debugging */ 118/* debugging */
119extern int ivtv_debug;
261 120
262#define IVTV_DBGFLG_WARN (1 << 0) 121#define IVTV_DBGFLG_WARN (1 << 0)
263#define IVTV_DBGFLG_INFO (1 << 1) 122#define IVTV_DBGFLG_INFO (1 << 1)
264#define IVTV_DBGFLG_API (1 << 2) 123#define IVTV_DBGFLG_MB (1 << 2)
265#define IVTV_DBGFLG_DMA (1 << 3) 124#define IVTV_DBGFLG_IOCTL (1 << 3)
266#define IVTV_DBGFLG_IOCTL (1 << 4) 125#define IVTV_DBGFLG_FILE (1 << 4)
267#define IVTV_DBGFLG_I2C (1 << 5) 126#define IVTV_DBGFLG_DMA (1 << 5)
268#define IVTV_DBGFLG_IRQ (1 << 6) 127#define IVTV_DBGFLG_IRQ (1 << 6)
269#define IVTV_DBGFLG_DEC (1 << 7) 128#define IVTV_DBGFLG_DEC (1 << 7)
270#define IVTV_DBGFLG_YUV (1 << 8) 129#define IVTV_DBGFLG_YUV (1 << 8)
130#define IVTV_DBGFLG_I2C (1 << 9)
271/* Flag to turn on high volume debugging */ 131/* Flag to turn on high volume debugging */
272#define IVTV_DBGFLG_HIGHVOL (1 << 9) 132#define IVTV_DBGFLG_HIGHVOL (1 << 10)
273 133
274/* NOTE: extra space before comma in 'itv->num , ## args' is required for 134/* NOTE: extra space before comma in 'itv->num , ## args' is required for
275 gcc-2.95, otherwise it won't compile. */ 135 gcc-2.95, otherwise it won't compile. */
@@ -278,58 +138,37 @@ extern const u32 yuv_offset[4];
278 if ((x) & ivtv_debug) \ 138 if ((x) & ivtv_debug) \
279 printk(KERN_INFO "ivtv%d " type ": " fmt, itv->num , ## args); \ 139 printk(KERN_INFO "ivtv%d " type ": " fmt, itv->num , ## args); \
280 } while (0) 140 } while (0)
281#define IVTV_DEBUG_WARN(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_WARN, "warning", fmt , ## args) 141#define IVTV_DEBUG_WARN(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_WARN, "warn", fmt , ## args)
282#define IVTV_DEBUG_INFO(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_INFO, "info",fmt , ## args) 142#define IVTV_DEBUG_INFO(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_INFO, "info", fmt , ## args)
283#define IVTV_DEBUG_API(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_API, "api", fmt , ## args) 143#define IVTV_DEBUG_MB(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_MB, "mb", fmt , ## args)
284#define IVTV_DEBUG_DMA(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_DMA, "dma", fmt , ## args) 144#define IVTV_DEBUG_DMA(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_DMA, "dma", fmt , ## args)
285#define IVTV_DEBUG_IOCTL(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_IOCTL, "ioctl", fmt , ## args) 145#define IVTV_DEBUG_IOCTL(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_IOCTL, "ioctl", fmt , ## args)
286#define IVTV_DEBUG_I2C(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_I2C, "i2c", fmt , ## args) 146#define IVTV_DEBUG_FILE(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_FILE, "file", fmt , ## args)
287#define IVTV_DEBUG_IRQ(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_IRQ, "irq", fmt , ## args) 147#define IVTV_DEBUG_I2C(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_I2C, "i2c", fmt , ## args)
288#define IVTV_DEBUG_DEC(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_DEC, "dec", fmt , ## args) 148#define IVTV_DEBUG_IRQ(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_IRQ, "irq", fmt , ## args)
289#define IVTV_DEBUG_YUV(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_YUV, "yuv", fmt , ## args) 149#define IVTV_DEBUG_DEC(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_DEC, "dec", fmt , ## args)
150#define IVTV_DEBUG_YUV(fmt, args...) IVTV_DEBUG(IVTV_DBGFLG_YUV, "yuv", fmt , ## args)
290 151
291#define IVTV_DEBUG_HIGH_VOL(x, type, fmt, args...) \ 152#define IVTV_DEBUG_HIGH_VOL(x, type, fmt, args...) \
292 do { \ 153 do { \
293 if (((x) & ivtv_debug) && (ivtv_debug & IVTV_DBGFLG_HIGHVOL)) \ 154 if (((x) & ivtv_debug) && (ivtv_debug & IVTV_DBGFLG_HIGHVOL)) \
294 printk(KERN_INFO "ivtv%d " type ": " fmt, itv->num , ## args); \ 155 printk(KERN_INFO "ivtv%d " type ": " fmt, itv->num , ## args); \
295 } while (0) 156 } while (0)
296#define IVTV_DEBUG_HI_WARN(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_WARN, "warning", fmt , ## args) 157#define IVTV_DEBUG_HI_WARN(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_WARN, "warn", fmt , ## args)
297#define IVTV_DEBUG_HI_INFO(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_INFO, "info",fmt , ## args) 158#define IVTV_DEBUG_HI_INFO(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_INFO, "info", fmt , ## args)
298#define IVTV_DEBUG_HI_API(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_API, "api", fmt , ## args) 159#define IVTV_DEBUG_HI_MB(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_MB, "mb", fmt , ## args)
299#define IVTV_DEBUG_HI_DMA(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_DMA, "dma", fmt , ## args) 160#define IVTV_DEBUG_HI_DMA(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_DMA, "dma", fmt , ## args)
300#define IVTV_DEBUG_HI_IOCTL(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_IOCTL, "ioctl", fmt , ## args) 161#define IVTV_DEBUG_HI_IOCTL(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_IOCTL, "ioctl", fmt , ## args)
301#define IVTV_DEBUG_HI_I2C(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_I2C, "i2c", fmt , ## args) 162#define IVTV_DEBUG_HI_FILE(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_FILE, "file", fmt , ## args)
302#define IVTV_DEBUG_HI_IRQ(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_IRQ, "irq", fmt , ## args) 163#define IVTV_DEBUG_HI_I2C(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_I2C, "i2c", fmt , ## args)
303#define IVTV_DEBUG_HI_DEC(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_DEC, "dec", fmt , ## args) 164#define IVTV_DEBUG_HI_IRQ(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_IRQ, "irq", fmt , ## args)
304#define IVTV_DEBUG_HI_YUV(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_YUV, "yuv", fmt , ## args) 165#define IVTV_DEBUG_HI_DEC(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_DEC, "dec", fmt , ## args)
305 166#define IVTV_DEBUG_HI_YUV(fmt, args...) IVTV_DEBUG_HIGH_VOL(IVTV_DBGFLG_YUV, "yuv", fmt , ## args)
306#define IVTV_FB_DEBUG(x, type, fmt, args...) \
307 do { \
308 if ((x) & ivtv_debug) \
309 printk(KERN_INFO "ivtv%d-fb " type ": " fmt, itv->num , ## args); \
310 } while (0)
311#define IVTV_FB_DEBUG_WARN(fmt, args...) IVTV_FB_DEBUG(IVTV_DBGFLG_WARN, "warning", fmt , ## args)
312#define IVTV_FB_DEBUG_INFO(fmt, args...) IVTV_FB_DEBUG(IVTV_DBGFLG_INFO, "info", fmt , ## args)
313#define IVTV_FB_DEBUG_API(fmt, args...) IVTV_FB_DEBUG(IVTV_DBGFLG_API, "api", fmt , ## args)
314#define IVTV_FB_DEBUG_DMA(fmt, args...) IVTV_FB_DEBUG(IVTV_DBGFLG_DMA, "dma", fmt , ## args)
315#define IVTV_FB_DEBUG_IOCTL(fmt, args...) IVTV_FB_DEBUG(IVTV_DBGFLG_IOCTL, "ioctl", fmt , ## args)
316#define IVTV_FB_DEBUG_I2C(fmt, args...) IVTV_FB_DEBUG(IVTV_DBGFLG_I2C, "i2c", fmt , ## args)
317#define IVTV_FB_DEBUG_IRQ(fmt, args...) IVTV_FB_DEBUG(IVTV_DBGFLG_IRQ, "irq", fmt , ## args)
318#define IVTV_FB_DEBUG_DEC(fmt, args...) IVTV_FB_DEBUG(IVTV_DBGFLG_DEC, "dec", fmt , ## args)
319#define IVTV_FB_DEBUG_YUV(fmt, args...) IVTV_FB_DEBUG(IVTV_DBGFLG_YUV, "yuv", fmt , ## args)
320 167
321/* Standard kernel messages */ 168/* Standard kernel messages */
322#define IVTV_ERR(fmt, args...) printk(KERN_ERR "ivtv%d: " fmt, itv->num , ## args) 169#define IVTV_ERR(fmt, args...) printk(KERN_ERR "ivtv%d: " fmt, itv->num , ## args)
323#define IVTV_WARN(fmt, args...) printk(KERN_WARNING "ivtv%d: " fmt, itv->num , ## args) 170#define IVTV_WARN(fmt, args...) printk(KERN_WARNING "ivtv%d: " fmt, itv->num , ## args)
324#define IVTV_INFO(fmt, args...) printk(KERN_INFO "ivtv%d: " fmt, itv->num , ## args) 171#define IVTV_INFO(fmt, args...) printk(KERN_INFO "ivtv%d: " fmt, itv->num , ## args)
325#define IVTV_FB_ERR(fmt, args...) printk(KERN_ERR "ivtv%d-fb: " fmt, itv->num , ## args)
326#define IVTV_FB_WARN(fmt, args...) printk(KERN_WARNING "ivtv%d-fb: " fmt, itv->num , ## args)
327#define IVTV_FB_INFO(fmt, args...) printk(KERN_INFO "ivtv%d-fb: " fmt, itv->num , ## args)
328
329/* Values for IVTV_API_DEC_PLAYBACK_SPEED mpeg_frame_type_mask parameter: */
330#define MPEG_FRAME_TYPE_IFRAME 1
331#define MPEG_FRAME_TYPE_IFRAME_PFRAME 3
332#define MPEG_FRAME_TYPE_ALL 7
333 172
334/* output modes (cx23415 only) */ 173/* output modes (cx23415 only) */
335#define OUT_NONE 0 174#define OUT_NONE 0
@@ -340,22 +179,14 @@ extern const u32 yuv_offset[4];
340 179
341#define IVTV_MAX_PGM_INDEX (400) 180#define IVTV_MAX_PGM_INDEX (400)
342 181
343extern int ivtv_debug;
344
345
346struct ivtv_options { 182struct ivtv_options {
347 int megabytes[IVTV_MAX_STREAMS]; /* Size in megabytes of each stream */ 183 int kilobytes[IVTV_MAX_STREAMS]; /* size in kilobytes of each stream */
348 int cardtype; /* force card type on load */ 184 int cardtype; /* force card type on load */
349 int tuner; /* set tuner on load */ 185 int tuner; /* set tuner on load */
350 int radio; /* enable/disable radio */ 186 int radio; /* enable/disable radio */
351 int newi2c; /* New I2C algorithm */ 187 int newi2c; /* new I2C algorithm */
352}; 188};
353 189
354#define IVTV_MBOX_DMA_START 6
355#define IVTV_MBOX_DMA_END 8
356#define IVTV_MBOX_DMA 9
357#define IVTV_MBOX_FIELD_DISPLAYED 8
358
359/* ivtv-specific mailbox template */ 190/* ivtv-specific mailbox template */
360struct ivtv_mailbox { 191struct ivtv_mailbox {
361 u32 flags; 192 u32 flags;
@@ -379,7 +210,7 @@ struct ivtv_mailbox_data {
379}; 210};
380 211
381/* per-buffer bit flags */ 212/* per-buffer bit flags */
382#define IVTV_F_B_NEED_BUF_SWAP 0 /* this buffer should be byte swapped */ 213#define IVTV_F_B_NEED_BUF_SWAP (1 << 0) /* this buffer should be byte swapped */
383 214
384/* per-stream, s_flags */ 215/* per-stream, s_flags */
385#define IVTV_F_S_DMA_PENDING 0 /* this stream has pending DMA */ 216#define IVTV_F_S_DMA_PENDING 0 /* this stream has pending DMA */
@@ -400,24 +231,25 @@ struct ivtv_mailbox_data {
400#define IVTV_F_I_DMA 0 /* DMA in progress */ 231#define IVTV_F_I_DMA 0 /* DMA in progress */
401#define IVTV_F_I_UDMA 1 /* UDMA in progress */ 232#define IVTV_F_I_UDMA 1 /* UDMA in progress */
402#define IVTV_F_I_UDMA_PENDING 2 /* UDMA pending */ 233#define IVTV_F_I_UDMA_PENDING 2 /* UDMA pending */
403#define IVTV_F_I_SPEED_CHANGE 3 /* A speed change is in progress */ 234#define IVTV_F_I_SPEED_CHANGE 3 /* a speed change is in progress */
404#define IVTV_F_I_EOS 4 /* End of encoder stream reached */ 235#define IVTV_F_I_EOS 4 /* end of encoder stream reached */
405#define IVTV_F_I_RADIO_USER 5 /* The radio tuner is selected */ 236#define IVTV_F_I_RADIO_USER 5 /* the radio tuner is selected */
406#define IVTV_F_I_DIG_RST 6 /* Reset digitizer */ 237#define IVTV_F_I_DIG_RST 6 /* reset digitizer */
407#define IVTV_F_I_DEC_YUV 7 /* YUV instead of MPG is being decoded */ 238#define IVTV_F_I_DEC_YUV 7 /* YUV instead of MPG is being decoded */
408#define IVTV_F_I_ENC_VBI 8 /* VBI DMA */
409#define IVTV_F_I_UPDATE_CC 9 /* CC should be updated */ 239#define IVTV_F_I_UPDATE_CC 9 /* CC should be updated */
410#define IVTV_F_I_UPDATE_WSS 10 /* WSS should be updated */ 240#define IVTV_F_I_UPDATE_WSS 10 /* WSS should be updated */
411#define IVTV_F_I_UPDATE_VPS 11 /* VPS should be updated */ 241#define IVTV_F_I_UPDATE_VPS 11 /* VPS should be updated */
412#define IVTV_F_I_DECODING_YUV 12 /* this stream is YUV frame decoding */ 242#define IVTV_F_I_DECODING_YUV 12 /* this stream is YUV frame decoding */
413#define IVTV_F_I_ENC_PAUSED 13 /* the encoder is paused */ 243#define IVTV_F_I_ENC_PAUSED 13 /* the encoder is paused */
414#define IVTV_F_I_VALID_DEC_TIMINGS 14 /* last_dec_timing is valid */ 244#define IVTV_F_I_VALID_DEC_TIMINGS 14 /* last_dec_timing is valid */
415#define IVTV_F_I_HAVE_WORK 15 /* Used in the interrupt handler: there is work to be done */ 245#define IVTV_F_I_HAVE_WORK 15 /* used in the interrupt handler: there is work to be done */
416#define IVTV_F_I_WORK_HANDLER_VBI 16 /* there is work to be done for VBI */ 246#define IVTV_F_I_WORK_HANDLER_VBI 16 /* there is work to be done for VBI */
417#define IVTV_F_I_WORK_HANDLER_YUV 17 /* there is work to be done for YUV */ 247#define IVTV_F_I_WORK_HANDLER_YUV 17 /* there is work to be done for YUV */
418#define IVTV_F_I_WORK_HANDLER_PIO 18 /* there is work to be done for PIO */ 248#define IVTV_F_I_WORK_HANDLER_PIO 18 /* there is work to be done for PIO */
419#define IVTV_F_I_PIO 19 /* PIO in progress */ 249#define IVTV_F_I_PIO 19 /* PIO in progress */
420#define IVTV_F_I_DEC_PAUSED 20 /* the decoder is paused */ 250#define IVTV_F_I_DEC_PAUSED 20 /* the decoder is paused */
251#define IVTV_F_I_INITED 21 /* set after first open */
252#define IVTV_F_I_FAILED 22 /* set if first open failed */
421 253
422/* Event notifications */ 254/* Event notifications */
423#define IVTV_F_I_EV_DEC_STOPPED 28 /* decoder stopped event */ 255#define IVTV_F_I_EV_DEC_STOPPED 28 /* decoder stopped event */
@@ -426,7 +258,7 @@ struct ivtv_mailbox_data {
426#define IVTV_F_I_EV_VSYNC_ENABLED 31 /* VSYNC event enabled */ 258#define IVTV_F_I_EV_VSYNC_ENABLED 31 /* VSYNC event enabled */
427 259
428/* Scatter-Gather array element, used in DMA transfers */ 260/* Scatter-Gather array element, used in DMA transfers */
429struct ivtv_SG_element { 261struct ivtv_sg_element {
430 u32 src; 262 u32 src;
431 u32 dst; 263 u32 dst;
432 u32 size; 264 u32 size;
@@ -436,9 +268,11 @@ struct ivtv_user_dma {
436 struct mutex lock; 268 struct mutex lock;
437 int page_count; 269 int page_count;
438 struct page *map[IVTV_DMA_SG_OSD_ENT]; 270 struct page *map[IVTV_DMA_SG_OSD_ENT];
271 /* Needed when dealing with highmem userspace buffers */
272 struct page *bouncemap[IVTV_DMA_SG_OSD_ENT];
439 273
440 /* Base Dev SG Array for cx23415/6 */ 274 /* Base Dev SG Array for cx23415/6 */
441 struct ivtv_SG_element SGarray[IVTV_DMA_SG_OSD_ENT]; 275 struct ivtv_sg_element SGarray[IVTV_DMA_SG_OSD_ENT];
442 dma_addr_t SG_handle; 276 dma_addr_t SG_handle;
443 int SG_length; 277 int SG_length;
444 278
@@ -458,21 +292,21 @@ struct ivtv_dma_page_info {
458struct ivtv_buffer { 292struct ivtv_buffer {
459 struct list_head list; 293 struct list_head list;
460 dma_addr_t dma_handle; 294 dma_addr_t dma_handle;
461 unsigned long b_flags; 295 unsigned short b_flags;
296 unsigned short dma_xfer_cnt;
462 char *buf; 297 char *buf;
463
464 u32 bytesused; 298 u32 bytesused;
465 u32 readpos; 299 u32 readpos;
466}; 300};
467 301
468struct ivtv_queue { 302struct ivtv_queue {
469 struct list_head list; 303 struct list_head list; /* the list of buffers in this queue */
470 u32 buffers; 304 u32 buffers; /* number of buffers in this queue */
471 u32 length; 305 u32 length; /* total number of bytes of available buffer space */
472 u32 bytesused; 306 u32 bytesused; /* total number of bytes used in this queue */
473}; 307};
474 308
475struct ivtv; /* forward reference */ 309struct ivtv; /* forward reference */
476 310
477struct ivtv_stream { 311struct ivtv_stream {
478 /* These first four fields are always set, even if the stream 312 /* These first four fields are always set, even if the stream
@@ -483,11 +317,13 @@ struct ivtv_stream {
483 int type; /* stream type */ 317 int type; /* stream type */
484 318
485 u32 id; 319 u32 id;
486 spinlock_t qlock; /* locks access to the queues */ 320 spinlock_t qlock; /* locks access to the queues */
487 unsigned long s_flags; /* status flags, see above */ 321 unsigned long s_flags; /* status flags, see above */
488 int dma; /* can be PCI_DMA_TODEVICE, 322 int dma; /* can be PCI_DMA_TODEVICE, PCI_DMA_FROMDEVICE or PCI_DMA_NONE */
489 PCI_DMA_FROMDEVICE or 323 u32 pending_offset;
490 PCI_DMA_NONE */ 324 u32 pending_backup;
325 u64 pending_pts;
326
491 u32 dma_offset; 327 u32 dma_offset;
492 u32 dma_backup; 328 u32 dma_backup;
493 u64 dma_pts; 329 u64 dma_pts;
@@ -508,47 +344,53 @@ struct ivtv_stream {
508 struct ivtv_queue q_dma; /* waiting for DMA */ 344 struct ivtv_queue q_dma; /* waiting for DMA */
509 struct ivtv_queue q_predma; /* waiting for DMA */ 345 struct ivtv_queue q_predma; /* waiting for DMA */
510 346
347 /* DMA xfer counter, buffers belonging to the same DMA
348 xfer will have the same dma_xfer_cnt. */
349 u16 dma_xfer_cnt;
350
511 /* Base Dev SG Array for cx23415/6 */ 351 /* Base Dev SG Array for cx23415/6 */
512 struct ivtv_SG_element *SGarray; 352 struct ivtv_sg_element *sg_pending;
513 struct ivtv_SG_element *PIOarray; 353 struct ivtv_sg_element *sg_processing;
514 dma_addr_t SG_handle; 354 struct ivtv_sg_element *sg_dma;
515 int SG_length; 355 dma_addr_t sg_handle;
356 int sg_pending_size;
357 int sg_processing_size;
358 int sg_processed;
516 359
517 /* SG List of Buffers */ 360 /* SG List of Buffers */
518 struct scatterlist *SGlist; 361 struct scatterlist *SGlist;
519}; 362};
520 363
521struct ivtv_open_id { 364struct ivtv_open_id {
522 u32 open_id; 365 u32 open_id; /* unique ID for this file descriptor */
523 int type; 366 int type; /* stream type */
524 enum v4l2_priority prio; 367 int yuv_frames; /* 1: started OUT_UDMA_YUV output mode */
368 enum v4l2_priority prio; /* priority */
525 struct ivtv *itv; 369 struct ivtv *itv;
526}; 370};
527 371
528#define IVTV_YUV_UPDATE_HORIZONTAL 0x01
529#define IVTV_YUV_UPDATE_VERTICAL 0x02
530
531struct yuv_frame_info 372struct yuv_frame_info
532{ 373{
533 u32 update; 374 u32 update;
534 int src_x; 375 s32 src_x;
535 int src_y; 376 s32 src_y;
536 unsigned int src_w; 377 u32 src_w;
537 unsigned int src_h; 378 u32 src_h;
538 int dst_x; 379 s32 dst_x;
539 int dst_y; 380 s32 dst_y;
540 unsigned int dst_w; 381 u32 dst_w;
541 unsigned int dst_h; 382 u32 dst_h;
542 int pan_x; 383 s32 pan_x;
543 int pan_y; 384 s32 pan_y;
544 u32 vis_w; 385 u32 vis_w;
545 u32 vis_h; 386 u32 vis_h;
546 u32 interlaced_y; 387 u32 interlaced_y;
547 u32 interlaced_uv; 388 u32 interlaced_uv;
548 int tru_x; 389 s32 tru_x;
549 u32 tru_w; 390 u32 tru_w;
550 u32 tru_h; 391 u32 tru_h;
551 u32 offset_y; 392 u32 offset_y;
393 s32 lace_mode;
552}; 394};
553 395
554#define IVTV_YUV_MODE_INTERLACED 0x00 396#define IVTV_YUV_MODE_INTERLACED 0x00
@@ -621,7 +463,6 @@ struct yuv_playback_info
621 int decode_height; 463 int decode_height;
622 464
623 int frame_interlaced; 465 int frame_interlaced;
624 int frame_interlaced_last;
625 466
626 int lace_mode; 467 int lace_mode;
627 int lace_threshold; 468 int lace_threshold;
@@ -632,6 +473,11 @@ struct yuv_playback_info
632 473
633 u32 yuv_forced_update; 474 u32 yuv_forced_update;
634 int update_frame; 475 int update_frame;
476
477 int sync_field[4]; /* Field to sync on */
478 int field_delay[4]; /* Flag to extend duration of previous frame */
479 u8 fields_lapsed; /* Counter used when delaying a frame */
480
635 struct yuv_frame_info new_frame_info[4]; 481 struct yuv_frame_info new_frame_info[4];
636 struct yuv_frame_info old_frame_info; 482 struct yuv_frame_info old_frame_info;
637 struct yuv_frame_info old_frame_info_args; 483 struct yuv_frame_info old_frame_info_args;
@@ -643,37 +489,61 @@ struct yuv_playback_info
643#define IVTV_VBI_FRAMES 32 489#define IVTV_VBI_FRAMES 32
644 490
645/* VBI data */ 491/* VBI data */
492struct vbi_cc {
493 u8 odd[2]; /* two-byte payload of odd field */
494 u8 even[2]; /* two-byte payload of even field */;
495};
496
497struct vbi_vps {
498 u8 data[5]; /* five-byte VPS payload */
499};
500
646struct vbi_info { 501struct vbi_info {
647 u32 dec_start; 502 /* VBI general data, does not change during streaming */
648 u32 enc_start, enc_size; 503
649 int fpi; 504 u32 raw_decoder_line_size; /* raw VBI line size from digitizer */
650 u32 frame; 505 u8 raw_decoder_sav_odd_field; /* raw VBI Start Active Video digitizer code of odd field */
651 u32 dma_offset; 506 u8 raw_decoder_sav_even_field; /* raw VBI Start Active Video digitizer code of even field */
652 u8 cc_data_odd[256]; 507 u32 sliced_decoder_line_size; /* sliced VBI line size from digitizer */
653 u8 cc_data_even[256]; 508 u8 sliced_decoder_sav_odd_field; /* sliced VBI Start Active Video digitizer code of odd field */
654 int cc_pos; 509 u8 sliced_decoder_sav_even_field; /* sliced VBI Start Active Video digitizer code of even field */
655 u8 cc_no_update; 510
656 u8 vps[5]; 511 u32 start[2]; /* start of first VBI line in the odd/even fields */
657 u8 vps_found; 512 u32 count; /* number of VBI lines per field */
658 int wss; 513 u32 raw_size; /* size of raw VBI line from the digitizer */
659 u8 wss_found; 514 u32 sliced_size; /* size of sliced VBI line from the digitizer */
660 u8 wss_no_update; 515
661 u32 raw_decoder_line_size; 516 u32 dec_start; /* start in decoder memory of VBI re-insertion buffers */
662 u8 raw_decoder_sav_odd_field; 517 u32 enc_start; /* start in encoder memory of VBI capture buffers */
663 u8 raw_decoder_sav_even_field; 518 u32 enc_size; /* size of VBI capture area */
664 u32 sliced_decoder_line_size; 519 int fpi; /* number of VBI frames per interrupt */
665 u8 sliced_decoder_sav_odd_field; 520
666 u8 sliced_decoder_sav_even_field; 521 struct v4l2_format in; /* current VBI capture format */
667 struct v4l2_format in; 522 struct v4l2_sliced_vbi_format *sliced_in; /* convenience pointer to sliced struct in vbi.in union */
668 /* convenience pointer to sliced struct in vbi_in union */ 523 int insert_mpeg; /* if non-zero, then embed VBI data in MPEG stream */
669 struct v4l2_sliced_vbi_format *sliced_in; 524
670 u32 service_set_in; 525 /* Raw VBI compatibility hack */
671 int insert_mpeg; 526
672 527 u32 frame; /* frame counter hack needed for backwards compatibility
673 /* Buffer for the maximum of 2 * 18 * packet_size sliced VBI lines. 528 of old VBI software */
674 One for /dev/vbi0 and one for /dev/vbi8 */ 529
675 struct v4l2_sliced_vbi_data sliced_data[36]; 530 /* Sliced VBI output data */
676 struct v4l2_sliced_vbi_data sliced_dec_data[36]; 531
532 struct vbi_cc cc_payload[256]; /* sliced VBI CC payload array: it is an array to
533 prevent dropping CC data if they couldn't be
534 processed fast enough */
535 int cc_payload_idx; /* index in cc_payload */
536 u8 cc_missing_cnt; /* counts number of frames without CC for passthrough mode */
537 int wss_payload; /* sliced VBI WSS payload */
538 u8 wss_missing_cnt; /* counts number of frames without WSS for passthrough mode */
539 struct vbi_vps vps_payload; /* sliced VBI VPS payload */
540
541 /* Sliced VBI capture data */
542
543 struct v4l2_sliced_vbi_data sliced_data[36]; /* sliced VBI storage for VBI encoder stream */
544 struct v4l2_sliced_vbi_data sliced_dec_data[36];/* sliced VBI storage for VBI decoder stream */
545
546 /* VBI Embedding data */
677 547
678 /* Buffer for VBI data inserted into MPEG stream. 548 /* Buffer for VBI data inserted into MPEG stream.
679 The first byte is a dummy byte that's never used. 549 The first byte is a dummy byte that's never used.
@@ -690,12 +560,9 @@ struct vbi_info {
690 This pointer array will allocate 2049 bytes to store each VBI frame. */ 560 This pointer array will allocate 2049 bytes to store each VBI frame. */
691 u8 *sliced_mpeg_data[IVTV_VBI_FRAMES]; 561 u8 *sliced_mpeg_data[IVTV_VBI_FRAMES];
692 u32 sliced_mpeg_size[IVTV_VBI_FRAMES]; 562 u32 sliced_mpeg_size[IVTV_VBI_FRAMES];
693 struct ivtv_buffer sliced_mpeg_buf; 563 struct ivtv_buffer sliced_mpeg_buf; /* temporary buffer holding data from sliced_mpeg_data */
694 u32 inserted_frame; 564 u32 inserted_frame; /* index in sliced_mpeg_size of next sliced data
695 565 to be inserted in the MPEG stream */
696 u32 start[2], count;
697 u32 raw_size;
698 u32 sliced_size;
699}; 566};
700 567
701/* forward declaration of struct defined in ivtv-cards.h */ 568/* forward declaration of struct defined in ivtv-cards.h */
@@ -703,131 +570,132 @@ struct ivtv_card;
703 570
704/* Struct to hold info about ivtv cards */ 571/* Struct to hold info about ivtv cards */
705struct ivtv { 572struct ivtv {
706 int num; /* board number, -1 during init! */ 573 /* General fixed card data */
707 char name[8]; /* board name for printk and interrupts (e.g. 'ivtv0') */ 574 int num; /* board number, -1 during init! */
708 struct pci_dev *dev; /* PCI device */ 575 char name[8]; /* board name for printk and interrupts (e.g. 'ivtv0') */
576 struct pci_dev *dev; /* PCI device */
709 const struct ivtv_card *card; /* card information */ 577 const struct ivtv_card *card; /* card information */
710 const char *card_name; /* full name of the card */ 578 const char *card_name; /* full name of the card */
711 u8 has_cx23415; /* 1 if it is a cx23415 based card, 0 for cx23416 */ 579 u8 has_cx23415; /* 1 if it is a cx23415 based card, 0 for cx23416 */
712 u8 is_50hz; 580 u8 pvr150_workaround; /* 1 if the cx25840 needs to workaround a PVR150 bug */
713 u8 is_60hz; 581 u8 nof_inputs; /* number of video inputs */
714 u8 is_out_50hz; 582 u8 nof_audio_inputs; /* number of audio inputs */
715 u8 is_out_60hz; 583 u32 v4l2_cap; /* V4L2 capabilities of card */
716 u8 pvr150_workaround; /* 1 if the cx25840 needs to workaround a PVR150 bug */ 584 u32 hw_flags; /* hardware description of the board */
717 u8 nof_inputs; /* number of video inputs */ 585 int tunerid; /* userspace tuner ID for experimental Xceive tuner support */
718 u8 nof_audio_inputs; /* number of audio inputs */ 586 v4l2_std_id tuner_std; /* the norm of the card's tuner (fixed) */
719 u32 v4l2_cap; /* V4L2 capabilities of card */ 587 /* controlling video decoder function */
720 u32 hw_flags; /* Hardware description of the board */
721
722 /* controlling Video decoder function */
723 int (*video_dec_func)(struct ivtv *, unsigned int, void *); 588 int (*video_dec_func)(struct ivtv *, unsigned int, void *);
589 u32 base_addr; /* PCI resource base address */
590 volatile void __iomem *enc_mem; /* pointer to mapped encoder memory */
591 volatile void __iomem *dec_mem; /* pointer to mapped decoder memory */
592 volatile void __iomem *reg_mem; /* pointer to mapped registers */
593 struct ivtv_options options; /* user options */
594
595
596 /* High-level state info */
597 unsigned long i_flags; /* global ivtv flags */
598 u8 is_50hz; /* 1 if the current capture standard is 50 Hz */
599 u8 is_60hz /* 1 if the current capture standard is 60 Hz */;
600 u8 is_out_50hz /* 1 if the current TV output standard is 50 Hz */;
601 u8 is_out_60hz /* 1 if the current TV output standard is 60 Hz */;
602 int output_mode; /* decoder output mode: NONE, MPG, YUV, UDMA YUV, passthrough */
603 u32 audio_input; /* current audio input */
604 u32 active_input; /* current video input */
605 u32 active_output; /* current video output */
606 v4l2_std_id std; /* current capture TV standard */
607 v4l2_std_id std_out; /* current TV output standard */
608 u8 audio_stereo_mode; /* decoder setting how to handle stereo MPEG audio */
609 u8 audio_bilingual_mode; /* decoder setting how to handle bilingual MPEG audio */
610 struct cx2341x_mpeg_params params; /* current encoder parameters */
611
612
613 /* Locking */
614 spinlock_t lock; /* lock access to this struct */
615 struct mutex serialize_lock; /* mutex used to serialize open/close/start/stop/ioctl operations */
616
617
618 /* Streams */
619 int stream_buf_size[IVTV_MAX_STREAMS]; /* stream buffer size */
620 struct ivtv_stream streams[IVTV_MAX_STREAMS]; /* stream data */
621 atomic_t capturing; /* count number of active capture streams */
622 atomic_t decoding; /* count number of active decoding streams */
623
624
625 /* Interrupts & DMA */
626 u32 irqmask; /* active interrupts */
627 u32 irq_rr_idx; /* round-robin stream index */
628 struct workqueue_struct *irq_work_queues; /* workqueue for PIO/YUV/VBI actions */
629 struct work_struct irq_work_queue; /* work entry */
630 spinlock_t dma_reg_lock; /* lock access to DMA engine registers */
631 int cur_dma_stream; /* index of current stream doing DMA (-1 if none) */
632 int cur_pio_stream; /* index of current stream doing PIO (-1 if none) */
633 u32 dma_data_req_offset; /* store offset in decoder memory of current DMA request */
634 u32 dma_data_req_size; /* store size of current DMA request */
635 int dma_retries; /* current DMA retry attempt */
636 struct ivtv_user_dma udma; /* user based DMA for OSD */
637 struct timer_list dma_timer; /* timer used to catch unfinished DMAs */
638 u32 last_vsync_field; /* last seen vsync field */
639 wait_queue_head_t dma_waitq; /* wake up when the current DMA is finished */
640 wait_queue_head_t eos_waitq; /* wake up when EOS arrives */
641 wait_queue_head_t event_waitq; /* wake up when the next decoder event arrives */
642 wait_queue_head_t vsync_waitq; /* wake up when the next decoder vsync arrives */
643
644
645 /* Mailbox */
646 struct ivtv_mailbox_data enc_mbox; /* encoder mailboxes */
647 struct ivtv_mailbox_data dec_mbox; /* decoder mailboxes */
648 struct ivtv_api_cache api_cache[256]; /* cached API commands */
649
650
651 /* I2C */
652 struct i2c_adapter i2c_adap;
653 struct i2c_algo_bit_data i2c_algo;
654 struct i2c_client i2c_client;
655 struct i2c_client *i2c_clients[I2C_CLIENTS_MAX];/* pointers to all I2C clients */
656 int i2c_state; /* i2c bit state */
657 struct mutex i2c_bus_lock; /* lock i2c bus */
658
659
660 /* Program Index information */
661 u32 pgm_info_offset; /* start of pgm info in encoder memory */
662 u32 pgm_info_num; /* number of elements in the pgm cyclic buffer in encoder memory */
663 u32 pgm_info_write_idx; /* last index written by the card that was transferred to pgm_info[] */
664 u32 pgm_info_read_idx; /* last index in pgm_info read by the application */
665 struct v4l2_enc_idx_entry pgm_info[IVTV_MAX_PGM_INDEX]; /* filled from the pgm cyclic buffer on the card */
666
667
668 /* Miscellaneous */
669 u32 open_id; /* incremented each time an open occurs, is >= 1 */
670 struct v4l2_prio_state prio; /* priority state */
671 int search_pack_header; /* 1 if ivtv_copy_buf_to_user() is scanning for a pack header (0xba) */
672 int speed; /* current playback speed setting */
673 u8 speed_mute_audio; /* 1 if audio should be muted when fast forward */
674 u64 mpg_data_received; /* number of bytes received from the MPEG stream */
675 u64 vbi_data_inserted; /* number of VBI bytes inserted into the MPEG stream */
676 u32 last_dec_timing[3]; /* cache last retrieved pts/scr/frame values */
677 unsigned long dualwatch_jiffies;/* jiffies value of the previous dualwatch check */
678 u16 dualwatch_stereo_mode; /* current detected dualwatch stereo mode */
679
680
681 /* VBI state info */
682 struct vbi_info vbi; /* VBI-specific data */
683
684
685 /* YUV playback */
686 struct yuv_playback_info yuv_info; /* YUV playback data */
724 687
725 struct ivtv_options options; /* User options */
726 int stream_buf_size[IVTV_MAX_STREAMS]; /* Stream buffer size */
727 struct ivtv_stream streams[IVTV_MAX_STREAMS]; /* Stream data */
728 int speed;
729 u8 speed_mute_audio;
730 unsigned long i_flags; /* global ivtv flags */
731 atomic_t capturing; /* count number of active capture streams */
732 atomic_t decoding; /* count number of active decoding streams */
733 u32 irq_rr_idx; /* Round-robin stream index */
734 int cur_dma_stream; /* index of stream doing DMA */
735 int cur_pio_stream; /* index of stream doing PIO */
736 u32 dma_data_req_offset;
737 u32 dma_data_req_size;
738 int output_mode; /* NONE, MPG, YUV, UDMA YUV, passthrough */
739 spinlock_t lock; /* lock access to this struct */
740 int search_pack_header;
741
742 spinlock_t dma_reg_lock; /* lock access to DMA engine registers */
743 struct mutex serialize_lock; /* lock used to serialize starting streams */
744
745 /* User based DMA for OSD */
746 struct ivtv_user_dma udma;
747
748 int open_id; /* incremented each time an open occurs, used as unique ID.
749 starts at 1, so 0 can be used as uninitialized value
750 in the stream->id. */
751
752 u32 base_addr;
753 u32 irqmask;
754
755 struct v4l2_prio_state prio;
756 struct workqueue_struct *irq_work_queues;
757 struct work_struct irq_work_queue;
758 struct timer_list dma_timer; /* Timer used to catch unfinished DMAs */
759
760 struct vbi_info vbi;
761
762 struct ivtv_mailbox_data enc_mbox;
763 struct ivtv_mailbox_data dec_mbox;
764 struct ivtv_api_cache api_cache[256]; /* Cached API Commands */
765
766 u8 card_rev;
767 volatile void __iomem *enc_mem, *dec_mem, *reg_mem;
768
769 u32 pgm_info_offset;
770 u32 pgm_info_num;
771 u32 pgm_info_write_idx;
772 u32 pgm_info_read_idx;
773 struct v4l2_enc_idx_entry pgm_info[IVTV_MAX_PGM_INDEX];
774
775 u64 mpg_data_received;
776 u64 vbi_data_inserted;
777
778 wait_queue_head_t cap_w;
779 /* when the next decoder event arrives this queue is woken up */
780 wait_queue_head_t event_waitq;
781 /* when the next decoder vsync arrives this queue is woken up */
782 wait_queue_head_t vsync_waitq;
783 /* when the current DMA is finished this queue is woken up */
784 wait_queue_head_t dma_waitq;
785 688
786 /* OSD support */ 689 /* OSD support */
787 unsigned long osd_video_pbase; 690 unsigned long osd_video_pbase;
788 int osd_global_alpha_state; /* 0=off : 1=on */ 691 int osd_global_alpha_state; /* 1 = global alpha is on */
789 int osd_local_alpha_state; /* 0=off : 1=on */ 692 int osd_local_alpha_state; /* 1 = local alpha is on */
790 int osd_color_key_state; /* 0=off : 1=on */ 693 int osd_chroma_key_state; /* 1 = chroma-keying is on */
791 u8 osd_global_alpha; /* Current global alpha */ 694 u8 osd_global_alpha; /* current global alpha */
792 u32 osd_color_key; /* Current color key */ 695 u32 osd_chroma_key; /* current chroma key */
793 u32 osd_pixelformat; /* Current pixel format */ 696 struct v4l2_rect osd_rect; /* current OSD position and size */
794 struct v4l2_rect osd_rect; /* Current OSD position and size */ 697 struct v4l2_rect main_rect; /* current Main window position and size */
795 struct v4l2_rect main_rect; /* Current Main window position and size */ 698 struct osd_info *osd_info; /* ivtvfb private OSD info */
796
797 u32 last_dec_timing[3]; /* Store last retrieved pts/scr/frame values */
798
799 /* i2c */
800 struct i2c_adapter i2c_adap;
801 struct i2c_algo_bit_data i2c_algo;
802 struct i2c_client i2c_client;
803 struct mutex i2c_bus_lock;
804 int i2c_state;
805 struct i2c_client *i2c_clients[I2C_CLIENTS_MAX];
806
807 /* v4l2 and User settings */
808
809 /* codec settings */
810 struct cx2341x_mpeg_params params;
811 u32 audio_input;
812 u32 active_input;
813 u32 active_output;
814 v4l2_std_id std;
815 v4l2_std_id std_out;
816 v4l2_std_id tuner_std; /* The norm of the tuner (fixed) */
817 u8 audio_stereo_mode;
818 u8 audio_bilingual_mode;
819
820 /* dualwatch */
821 unsigned long dualwatch_jiffies;
822 u16 dualwatch_stereo_mode;
823
824 /* Digitizer type */
825 int digitizer; /* 0x00EF = saa7114 0x00FO = saa7115 0x0106 = mic */
826
827 u32 lastVsyncFrame;
828
829 struct yuv_playback_info yuv_info;
830 struct osd_info *osd_info;
831}; 699};
832 700
833/* Globals */ 701/* Globals */
@@ -858,6 +726,9 @@ int ivtv_waitq(wait_queue_head_t *waitq);
858struct tveeprom; /* forward reference */ 726struct tveeprom; /* forward reference */
859void ivtv_read_eeprom(struct ivtv *itv, struct tveeprom *tv); 727void ivtv_read_eeprom(struct ivtv *itv, struct tveeprom *tv);
860 728
729/* First-open initialization: load firmware, init cx25840, etc. */
730int ivtv_init_on_first_open(struct ivtv *itv);
731
861/* This is a PCI post thing, where if the pci register is not read, then 732/* This is a PCI post thing, where if the pci register is not read, then
862 the write doesn't always take effect right away. By reading back the 733 the write doesn't always take effect right away. By reading back the
863 register any pending PCI writes will be performed (in order), and so 734 register any pending PCI writes will be performed (in order), and so
@@ -885,4 +756,4 @@ void ivtv_read_eeprom(struct ivtv *itv, struct tveeprom *tv);
885#define write_dec_sync(val, addr) \ 756#define write_dec_sync(val, addr) \
886 do { write_dec(val, addr); read_dec(addr); } while (0) 757 do { write_dec(val, addr); read_dec(addr); } while (0)
887 758
888#endif /* IVTV_DRIVER_H */ 759#endif
diff --git a/drivers/media/video/ivtv/ivtv-fileops.c b/drivers/media/video/ivtv/ivtv-fileops.c
index 66ea3cbc369c..da50fa4a72a5 100644
--- a/drivers/media/video/ivtv/ivtv-fileops.c
+++ b/drivers/media/video/ivtv/ivtv-fileops.c
@@ -27,10 +27,9 @@
27#include "ivtv-irq.h" 27#include "ivtv-irq.h"
28#include "ivtv-vbi.h" 28#include "ivtv-vbi.h"
29#include "ivtv-mailbox.h" 29#include "ivtv-mailbox.h"
30#include "ivtv-audio.h" 30#include "ivtv-routing.h"
31#include "ivtv-streams.h" 31#include "ivtv-streams.h"
32#include "ivtv-yuv.h" 32#include "ivtv-yuv.h"
33#include "ivtv-controls.h"
34#include "ivtv-ioctl.h" 33#include "ivtv-ioctl.h"
35#include "ivtv-cards.h" 34#include "ivtv-cards.h"
36#include <media/saa7115.h> 35#include <media/saa7115.h>
@@ -247,8 +246,9 @@ static struct ivtv_buffer *ivtv_get_buffer(struct ivtv_stream *s, int non_block,
247 /* do we have new data? */ 246 /* do we have new data? */
248 buf = ivtv_dequeue(s, &s->q_full); 247 buf = ivtv_dequeue(s, &s->q_full);
249 if (buf) { 248 if (buf) {
250 if (!test_and_clear_bit(IVTV_F_B_NEED_BUF_SWAP, &buf->b_flags)) 249 if ((buf->b_flags & IVTV_F_B_NEED_BUF_SWAP) == 0)
251 return buf; 250 return buf;
251 buf->b_flags &= ~IVTV_F_B_NEED_BUF_SWAP;
252 if (s->type == IVTV_ENC_STREAM_TYPE_MPG) 252 if (s->type == IVTV_ENC_STREAM_TYPE_MPG)
253 /* byteswap MPG data */ 253 /* byteswap MPG data */
254 ivtv_buf_swap(buf); 254 ivtv_buf_swap(buf);
@@ -258,19 +258,19 @@ static struct ivtv_buffer *ivtv_get_buffer(struct ivtv_stream *s, int non_block,
258 } 258 }
259 return buf; 259 return buf;
260 } 260 }
261 /* return if file was opened with O_NONBLOCK */
262 if (non_block) {
263 *err = -EAGAIN;
264 return NULL;
265 }
266 261
267 /* return if end of stream */ 262 /* return if end of stream */
268 if (s->type != IVTV_DEC_STREAM_TYPE_VBI && !test_bit(IVTV_F_S_STREAMING, &s->s_flags)) { 263 if (s->type != IVTV_DEC_STREAM_TYPE_VBI && !test_bit(IVTV_F_S_STREAMING, &s->s_flags)) {
269 clear_bit(IVTV_F_S_STREAMOFF, &s->s_flags);
270 IVTV_DEBUG_INFO("EOS %s\n", s->name); 264 IVTV_DEBUG_INFO("EOS %s\n", s->name);
271 return NULL; 265 return NULL;
272 } 266 }
273 267
268 /* return if file was opened with O_NONBLOCK */
269 if (non_block) {
270 *err = -EAGAIN;
271 return NULL;
272 }
273
274 /* wait for more data to arrive */ 274 /* wait for more data to arrive */
275 prepare_to_wait(&s->waitq, &wait, TASK_INTERRUPTIBLE); 275 prepare_to_wait(&s->waitq, &wait, TASK_INTERRUPTIBLE);
276 /* New buffers might have become available before we were added to the waitqueue */ 276 /* New buffers might have become available before we were added to the waitqueue */
@@ -378,10 +378,20 @@ static ssize_t ivtv_read(struct ivtv_stream *s, char __user *ubuf, size_t tot_co
378 int rc; 378 int rc;
379 379
380 buf = ivtv_get_buffer(s, non_block, &rc); 380 buf = ivtv_get_buffer(s, non_block, &rc);
381 if (buf == NULL && rc == -EAGAIN && tot_written) 381 /* if there is no data available... */
382 break; 382 if (buf == NULL) {
383 if (buf == NULL) 383 /* if we got data, then return that regardless */
384 if (tot_written)
385 break;
386 /* EOS condition */
387 if (rc == 0) {
388 clear_bit(IVTV_F_S_STREAMOFF, &s->s_flags);
389 clear_bit(IVTV_F_S_APPL_IO, &s->s_flags);
390 ivtv_release_stream(s);
391 }
392 /* set errno */
384 return rc; 393 return rc;
394 }
385 rc = ivtv_copy_buf_to_user(s, buf, ubuf + tot_written, tot_count - tot_written); 395 rc = ivtv_copy_buf_to_user(s, buf, ubuf + tot_written, tot_count - tot_written);
386 if (buf != &itv->vbi.sliced_mpeg_buf) { 396 if (buf != &itv->vbi.sliced_mpeg_buf) {
387 ivtv_enqueue(s, buf, (buf->readpos == buf->bytesused) ? &s->q_free : &s->q_io); 397 ivtv_enqueue(s, buf, (buf->readpos == buf->bytesused) ? &s->q_free : &s->q_io);
@@ -408,7 +418,7 @@ static ssize_t ivtv_read_pos(struct ivtv_stream *s, char __user *ubuf, size_t co
408 ssize_t rc = count ? ivtv_read(s, ubuf, count, non_block) : 0; 418 ssize_t rc = count ? ivtv_read(s, ubuf, count, non_block) : 0;
409 struct ivtv *itv = s->itv; 419 struct ivtv *itv = s->itv;
410 420
411 IVTV_DEBUG_HI_INFO("read %zd from %s, got %zd\n", count, s->name, rc); 421 IVTV_DEBUG_HI_FILE("read %zd from %s, got %zd\n", count, s->name, rc);
412 if (rc > 0) 422 if (rc > 0)
413 pos += rc; 423 pos += rc;
414 return rc; 424 return rc;
@@ -499,9 +509,11 @@ ssize_t ivtv_v4l2_read(struct file * filp, char __user *buf, size_t count, loff_
499 struct ivtv_stream *s = &itv->streams[id->type]; 509 struct ivtv_stream *s = &itv->streams[id->type];
500 int rc; 510 int rc;
501 511
502 IVTV_DEBUG_HI_IOCTL("read %zd bytes from %s\n", count, s->name); 512 IVTV_DEBUG_HI_FILE("read %zd bytes from %s\n", count, s->name);
503 513
514 mutex_lock(&itv->serialize_lock);
504 rc = ivtv_start_capture(id); 515 rc = ivtv_start_capture(id);
516 mutex_unlock(&itv->serialize_lock);
505 if (rc) 517 if (rc)
506 return rc; 518 return rc;
507 return ivtv_read_pos(s, buf, count, pos, filp->f_flags & O_NONBLOCK); 519 return ivtv_read_pos(s, buf, count, pos, filp->f_flags & O_NONBLOCK);
@@ -537,7 +549,7 @@ ssize_t ivtv_v4l2_write(struct file *filp, const char __user *user_buf, size_t c
537 int rc; 549 int rc;
538 DEFINE_WAIT(wait); 550 DEFINE_WAIT(wait);
539 551
540 IVTV_DEBUG_HI_IOCTL("write %zd bytes to %s\n", count, s->name); 552 IVTV_DEBUG_HI_FILE("write %zd bytes to %s\n", count, s->name);
541 553
542 if (s->type != IVTV_DEC_STREAM_TYPE_MPG && 554 if (s->type != IVTV_DEC_STREAM_TYPE_MPG &&
543 s->type != IVTV_DEC_STREAM_TYPE_YUV && 555 s->type != IVTV_DEC_STREAM_TYPE_YUV &&
@@ -551,8 +563,11 @@ ssize_t ivtv_v4l2_write(struct file *filp, const char __user *user_buf, size_t c
551 563
552 /* This stream does not need to start any decoding */ 564 /* This stream does not need to start any decoding */
553 if (s->type == IVTV_DEC_STREAM_TYPE_VOUT) { 565 if (s->type == IVTV_DEC_STREAM_TYPE_VOUT) {
566 int elems = count / sizeof(struct v4l2_sliced_vbi_data);
567
554 set_bit(IVTV_F_S_APPL_IO, &s->s_flags); 568 set_bit(IVTV_F_S_APPL_IO, &s->s_flags);
555 return ivtv_write_vbi(itv, user_buf, count); 569 ivtv_write_vbi(itv, (const struct v4l2_sliced_vbi_data *)user_buf, elems);
570 return elems * sizeof(struct v4l2_sliced_vbi_data);
556 } 571 }
557 572
558 mode = s->type == IVTV_DEC_STREAM_TYPE_MPG ? OUT_MPG : OUT_YUV; 573 mode = s->type == IVTV_DEC_STREAM_TYPE_MPG ? OUT_MPG : OUT_YUV;
@@ -612,7 +627,9 @@ retry:
612 } 627 }
613 628
614 /* Start decoder (returns 0 if already started) */ 629 /* Start decoder (returns 0 if already started) */
630 mutex_lock(&itv->serialize_lock);
615 rc = ivtv_start_decoding(id, itv->speed); 631 rc = ivtv_start_decoding(id, itv->speed);
632 mutex_unlock(&itv->serialize_lock);
616 if (rc) { 633 if (rc) {
617 IVTV_DEBUG_WARN("Failed start decode stream %s\n", s->name); 634 IVTV_DEBUG_WARN("Failed start decode stream %s\n", s->name);
618 635
@@ -645,7 +662,7 @@ retry:
645 to transfer the rest. */ 662 to transfer the rest. */
646 if (count && !(filp->f_flags & O_NONBLOCK)) 663 if (count && !(filp->f_flags & O_NONBLOCK))
647 goto retry; 664 goto retry;
648 IVTV_DEBUG_HI_INFO("Wrote %d bytes to %s (%d)\n", bytes_written, s->name, s->q_full.bytesused); 665 IVTV_DEBUG_HI_FILE("Wrote %d bytes to %s (%d)\n", bytes_written, s->name, s->q_full.bytesused);
649 return bytes_written; 666 return bytes_written;
650} 667}
651 668
@@ -657,6 +674,7 @@ unsigned int ivtv_v4l2_dec_poll(struct file *filp, poll_table *wait)
657 int res = 0; 674 int res = 0;
658 675
659 /* add stream's waitq to the poll list */ 676 /* add stream's waitq to the poll list */
677 IVTV_DEBUG_HI_FILE("Decoder poll\n");
660 poll_wait(filp, &s->waitq, wait); 678 poll_wait(filp, &s->waitq, wait);
661 679
662 set_bit(IVTV_F_I_EV_VSYNC_ENABLED, &itv->i_flags); 680 set_bit(IVTV_F_I_EV_VSYNC_ENABLED, &itv->i_flags);
@@ -679,16 +697,21 @@ unsigned int ivtv_v4l2_enc_poll(struct file *filp, poll_table * wait)
679 697
680 /* Start a capture if there is none */ 698 /* Start a capture if there is none */
681 if (!eof && !test_bit(IVTV_F_S_STREAMING, &s->s_flags)) { 699 if (!eof && !test_bit(IVTV_F_S_STREAMING, &s->s_flags)) {
682 int rc = ivtv_start_capture(id); 700 int rc;
683 701
702 mutex_lock(&itv->serialize_lock);
703 rc = ivtv_start_capture(id);
704 mutex_unlock(&itv->serialize_lock);
684 if (rc) { 705 if (rc) {
685 IVTV_DEBUG_INFO("Could not start capture for %s (%d)\n", 706 IVTV_DEBUG_INFO("Could not start capture for %s (%d)\n",
686 s->name, rc); 707 s->name, rc);
687 return POLLERR; 708 return POLLERR;
688 } 709 }
710 IVTV_DEBUG_FILE("Encoder poll started capture\n");
689 } 711 }
690 712
691 /* add stream's waitq to the poll list */ 713 /* add stream's waitq to the poll list */
714 IVTV_DEBUG_HI_FILE("Encoder poll\n");
692 poll_wait(filp, &s->waitq, wait); 715 poll_wait(filp, &s->waitq, wait);
693 716
694 if (eof || s->q_full.length) 717 if (eof || s->q_full.length)
@@ -701,7 +724,7 @@ void ivtv_stop_capture(struct ivtv_open_id *id, int gop_end)
701 struct ivtv *itv = id->itv; 724 struct ivtv *itv = id->itv;
702 struct ivtv_stream *s = &itv->streams[id->type]; 725 struct ivtv_stream *s = &itv->streams[id->type];
703 726
704 IVTV_DEBUG_IOCTL("close() of %s\n", s->name); 727 IVTV_DEBUG_FILE("close() of %s\n", s->name);
705 728
706 /* 'Unclaim' this stream */ 729 /* 'Unclaim' this stream */
707 730
@@ -728,10 +751,11 @@ void ivtv_stop_capture(struct ivtv_open_id *id, int gop_end)
728 ivtv_stop_v4l2_encode_stream(s, gop_end); 751 ivtv_stop_v4l2_encode_stream(s, gop_end);
729 } 752 }
730 } 753 }
731 clear_bit(IVTV_F_S_APPL_IO, &s->s_flags); 754 if (!gop_end) {
732 clear_bit(IVTV_F_S_STREAMOFF, &s->s_flags); 755 clear_bit(IVTV_F_S_APPL_IO, &s->s_flags);
733 756 clear_bit(IVTV_F_S_STREAMOFF, &s->s_flags);
734 ivtv_release_stream(s); 757 ivtv_release_stream(s);
758 }
735} 759}
736 760
737static void ivtv_stop_decoding(struct ivtv_open_id *id, int flags, u64 pts) 761static void ivtv_stop_decoding(struct ivtv_open_id *id, int flags, u64 pts)
@@ -739,13 +763,14 @@ static void ivtv_stop_decoding(struct ivtv_open_id *id, int flags, u64 pts)
739 struct ivtv *itv = id->itv; 763 struct ivtv *itv = id->itv;
740 struct ivtv_stream *s = &itv->streams[id->type]; 764 struct ivtv_stream *s = &itv->streams[id->type];
741 765
742 IVTV_DEBUG_IOCTL("close() of %s\n", s->name); 766 IVTV_DEBUG_FILE("close() of %s\n", s->name);
743 767
744 /* Stop decoding */ 768 /* Stop decoding */
745 if (test_bit(IVTV_F_S_STREAMING, &s->s_flags)) { 769 if (test_bit(IVTV_F_S_STREAMING, &s->s_flags)) {
746 IVTV_DEBUG_INFO("close stopping decode\n"); 770 IVTV_DEBUG_INFO("close stopping decode\n");
747 771
748 ivtv_stop_v4l2_decode_stream(s, flags, pts); 772 ivtv_stop_v4l2_decode_stream(s, flags, pts);
773 itv->output_mode = OUT_NONE;
749 } 774 }
750 clear_bit(IVTV_F_S_APPL_IO, &s->s_flags); 775 clear_bit(IVTV_F_S_APPL_IO, &s->s_flags);
751 clear_bit(IVTV_F_S_STREAMOFF, &s->s_flags); 776 clear_bit(IVTV_F_S_STREAMOFF, &s->s_flags);
@@ -753,11 +778,7 @@ static void ivtv_stop_decoding(struct ivtv_open_id *id, int flags, u64 pts)
753 /* Restore registers we've changed & clean up any mess we've made */ 778 /* Restore registers we've changed & clean up any mess we've made */
754 ivtv_yuv_close(itv); 779 ivtv_yuv_close(itv);
755 } 780 }
756 if (s->type == IVTV_DEC_STREAM_TYPE_YUV && itv->output_mode == OUT_YUV) 781 if (itv->output_mode == OUT_UDMA_YUV && id->yuv_frames)
757 itv->output_mode = OUT_NONE;
758 else if (s->type == IVTV_DEC_STREAM_TYPE_YUV && itv->output_mode == OUT_UDMA_YUV)
759 itv->output_mode = OUT_NONE;
760 else if (s->type == IVTV_DEC_STREAM_TYPE_MPG && itv->output_mode == OUT_MPG)
761 itv->output_mode = OUT_NONE; 782 itv->output_mode = OUT_NONE;
762 783
763 itv->speed = 0; 784 itv->speed = 0;
@@ -771,7 +792,7 @@ int ivtv_v4l2_close(struct inode *inode, struct file *filp)
771 struct ivtv *itv = id->itv; 792 struct ivtv *itv = id->itv;
772 struct ivtv_stream *s = &itv->streams[id->type]; 793 struct ivtv_stream *s = &itv->streams[id->type];
773 794
774 IVTV_DEBUG_IOCTL("close() of %s\n", s->name); 795 IVTV_DEBUG_FILE("close %s\n", s->name);
775 796
776 v4l2_prio_close(&itv->prio, &id->prio); 797 v4l2_prio_close(&itv->prio, &id->prio);
777 798
@@ -784,6 +805,7 @@ int ivtv_v4l2_close(struct inode *inode, struct file *filp)
784 /* 'Unclaim' this stream */ 805 /* 'Unclaim' this stream */
785 806
786 /* Stop radio */ 807 /* Stop radio */
808 mutex_lock(&itv->serialize_lock);
787 if (id->type == IVTV_ENC_STREAM_TYPE_RAD) { 809 if (id->type == IVTV_ENC_STREAM_TYPE_RAD) {
788 /* Closing radio device, return to TV mode */ 810 /* Closing radio device, return to TV mode */
789 ivtv_mute(itv); 811 ivtv_mute(itv);
@@ -809,56 +831,35 @@ int ivtv_v4l2_close(struct inode *inode, struct file *filp)
809 ivtv_stop_decoding(id, VIDEO_CMD_STOP_TO_BLACK | VIDEO_CMD_STOP_IMMEDIATELY, 0); 831 ivtv_stop_decoding(id, VIDEO_CMD_STOP_TO_BLACK | VIDEO_CMD_STOP_IMMEDIATELY, 0);
810 832
811 /* If all output streams are closed, and if the user doesn't have 833 /* If all output streams are closed, and if the user doesn't have
812 IVTV_DEC_STREAM_TYPE_VOUT open, then disable VBI on TV-out. */ 834 IVTV_DEC_STREAM_TYPE_VOUT open, then disable CC on TV-out. */
813 if (itv->output_mode == OUT_NONE && !test_bit(IVTV_F_S_APPL_IO, &s_vout->s_flags)) { 835 if (itv->output_mode == OUT_NONE && !test_bit(IVTV_F_S_APPL_IO, &s_vout->s_flags)) {
814 /* disable VBI on TV-out */ 836 /* disable CC on TV-out */
815 ivtv_disable_vbi(itv); 837 ivtv_disable_cc(itv);
816 } 838 }
817 } else { 839 } else {
818 ivtv_stop_capture(id, 0); 840 ivtv_stop_capture(id, 0);
819 } 841 }
820 kfree(id); 842 kfree(id);
843 mutex_unlock(&itv->serialize_lock);
821 return 0; 844 return 0;
822} 845}
823 846
824int ivtv_v4l2_open(struct inode *inode, struct file *filp) 847static int ivtv_serialized_open(struct ivtv_stream *s, struct file *filp)
825{ 848{
826 int x, y = 0; 849 struct ivtv *itv = s->itv;
827 struct ivtv_open_id *item; 850 struct ivtv_open_id *item;
828 struct ivtv *itv = NULL;
829 struct ivtv_stream *s = NULL;
830 int minor = iminor(inode);
831
832 /* Find which card this open was on */
833 spin_lock(&ivtv_cards_lock);
834 for (x = 0; itv == NULL && x < ivtv_cards_active; x++) {
835 /* find out which stream this open was on */
836 for (y = 0; y < IVTV_MAX_STREAMS; y++) {
837 s = &ivtv_cards[x]->streams[y];
838 if (s->v4l2dev && s->v4l2dev->minor == minor) {
839 itv = ivtv_cards[x];
840 break;
841 }
842 }
843 }
844 spin_unlock(&ivtv_cards_lock);
845 851
846 if (itv == NULL) { 852 IVTV_DEBUG_FILE("open %s\n", s->name);
847 /* Couldn't find a device registered
848 on that minor, shouldn't happen! */
849 printk(KERN_WARNING "ivtv: No ivtv device found on minor %d\n", minor);
850 return -ENXIO;
851 }
852 853
853 if (y == IVTV_DEC_STREAM_TYPE_MPG && 854 if (s->type == IVTV_DEC_STREAM_TYPE_MPG &&
854 test_bit(IVTV_F_S_CLAIMED, &itv->streams[IVTV_DEC_STREAM_TYPE_YUV].s_flags)) 855 test_bit(IVTV_F_S_CLAIMED, &itv->streams[IVTV_DEC_STREAM_TYPE_YUV].s_flags))
855 return -EBUSY; 856 return -EBUSY;
856 857
857 if (y == IVTV_DEC_STREAM_TYPE_YUV && 858 if (s->type == IVTV_DEC_STREAM_TYPE_YUV &&
858 test_bit(IVTV_F_S_CLAIMED, &itv->streams[IVTV_DEC_STREAM_TYPE_MPG].s_flags)) 859 test_bit(IVTV_F_S_CLAIMED, &itv->streams[IVTV_DEC_STREAM_TYPE_MPG].s_flags))
859 return -EBUSY; 860 return -EBUSY;
860 861
861 if (y == IVTV_DEC_STREAM_TYPE_YUV) { 862 if (s->type == IVTV_DEC_STREAM_TYPE_YUV) {
862 if (read_reg(0x82c) == 0) { 863 if (read_reg(0x82c) == 0) {
863 IVTV_ERR("Tried to open YUV output device but need to send data to mpeg decoder before it can be used\n"); 864 IVTV_ERR("Tried to open YUV output device but need to send data to mpeg decoder before it can be used\n");
864 /* return -ENODEV; */ 865 /* return -ENODEV; */
@@ -873,7 +874,7 @@ int ivtv_v4l2_open(struct inode *inode, struct file *filp)
873 return -ENOMEM; 874 return -ENOMEM;
874 } 875 }
875 item->itv = itv; 876 item->itv = itv;
876 item->type = y; 877 item->type = s->type;
877 v4l2_prio_open(&itv->prio, &item->prio); 878 v4l2_prio_open(&itv->prio, &item->prio);
878 879
879 item->open_id = itv->open_id++; 880 item->open_id = itv->open_id++;
@@ -887,12 +888,20 @@ int ivtv_v4l2_open(struct inode *inode, struct file *filp)
887 return -EBUSY; 888 return -EBUSY;
888 } 889 }
889 890
891 if (!test_bit(IVTV_F_I_RADIO_USER, &itv->i_flags)) {
892 if (atomic_read(&itv->capturing) > 0) {
893 /* switching to radio while capture is
894 in progress is not polite */
895 kfree(item);
896 return -EBUSY;
897 }
898 }
899 /* Mark that the radio is being used. */
900 set_bit(IVTV_F_I_RADIO_USER, &itv->i_flags);
890 /* We have the radio */ 901 /* We have the radio */
891 ivtv_mute(itv); 902 ivtv_mute(itv);
892 /* Switch tuner to radio */ 903 /* Switch tuner to radio */
893 ivtv_call_i2c_clients(itv, AUDC_SET_RADIO, NULL); 904 ivtv_call_i2c_clients(itv, AUDC_SET_RADIO, NULL);
894 /* Mark that the radio is being used. */
895 set_bit(IVTV_F_I_RADIO_USER, &itv->i_flags);
896 /* Select the correct audio input (i.e. radio tuner) */ 905 /* Select the correct audio input (i.e. radio tuner) */
897 ivtv_audio_set_io(itv); 906 ivtv_audio_set_io(itv);
898 if (itv->hw_flags & IVTV_HW_SAA711X) 907 if (itv->hw_flags & IVTV_HW_SAA711X)
@@ -907,45 +916,65 @@ int ivtv_v4l2_open(struct inode *inode, struct file *filp)
907 } 916 }
908 917
909 /* YUV or MPG Decoding Mode? */ 918 /* YUV or MPG Decoding Mode? */
910 if (y == IVTV_DEC_STREAM_TYPE_MPG) 919 if (s->type == IVTV_DEC_STREAM_TYPE_MPG)
911 clear_bit(IVTV_F_I_DEC_YUV, &itv->i_flags); 920 clear_bit(IVTV_F_I_DEC_YUV, &itv->i_flags);
912 else if (y == IVTV_DEC_STREAM_TYPE_YUV) 921 else if (s->type == IVTV_DEC_STREAM_TYPE_YUV)
913 {
914 set_bit(IVTV_F_I_DEC_YUV, &itv->i_flags); 922 set_bit(IVTV_F_I_DEC_YUV, &itv->i_flags);
915 }
916
917 return 0; 923 return 0;
918} 924}
919 925
920void ivtv_mute(struct ivtv *itv) 926int ivtv_v4l2_open(struct inode *inode, struct file *filp)
921{ 927{
922 struct v4l2_control ctrl = { V4L2_CID_AUDIO_MUTE, 1 }; 928 int res, x, y = 0;
929 struct ivtv *itv = NULL;
930 struct ivtv_stream *s = NULL;
931 int minor = iminor(inode);
932
933 /* Find which card this open was on */
934 spin_lock(&ivtv_cards_lock);
935 for (x = 0; itv == NULL && x < ivtv_cards_active; x++) {
936 /* find out which stream this open was on */
937 for (y = 0; y < IVTV_MAX_STREAMS; y++) {
938 s = &ivtv_cards[x]->streams[y];
939 if (s->v4l2dev && s->v4l2dev->minor == minor) {
940 itv = ivtv_cards[x];
941 break;
942 }
943 }
944 }
945 spin_unlock(&ivtv_cards_lock);
946
947 if (itv == NULL) {
948 /* Couldn't find a device registered
949 on that minor, shouldn't happen! */
950 IVTV_WARN("No ivtv device found on minor %d\n", minor);
951 return -ENXIO;
952 }
923 953
924 /* Mute sound to avoid pop */ 954 mutex_lock(&itv->serialize_lock);
925 ivtv_control_ioctls(itv, VIDIOC_S_CTRL, &ctrl); 955 if (ivtv_init_on_first_open(itv)) {
956 IVTV_ERR("Failed to initialize on minor %d\n", minor);
957 mutex_unlock(&itv->serialize_lock);
958 return -ENXIO;
959 }
960 res = ivtv_serialized_open(s, filp);
961 mutex_unlock(&itv->serialize_lock);
962 return res;
963}
926 964
965void ivtv_mute(struct ivtv *itv)
966{
927 if (atomic_read(&itv->capturing)) 967 if (atomic_read(&itv->capturing))
928 ivtv_vapi(itv, CX2341X_ENC_MUTE_AUDIO, 1, 1); 968 ivtv_vapi(itv, CX2341X_ENC_MUTE_AUDIO, 1, 1);
929
930 IVTV_DEBUG_INFO("Mute\n"); 969 IVTV_DEBUG_INFO("Mute\n");
931} 970}
932 971
933void ivtv_unmute(struct ivtv *itv) 972void ivtv_unmute(struct ivtv *itv)
934{ 973{
935 struct v4l2_control ctrl = { V4L2_CID_AUDIO_MUTE, 0 };
936
937 /* initialize or refresh input */
938 if (atomic_read(&itv->capturing) == 0)
939 ivtv_vapi(itv, CX2341X_ENC_INITIALIZE_INPUT, 0);
940
941 ivtv_msleep_timeout(100, 0);
942
943 if (atomic_read(&itv->capturing)) { 974 if (atomic_read(&itv->capturing)) {
975 ivtv_msleep_timeout(100, 0);
944 ivtv_vapi(itv, CX2341X_ENC_MISC, 1, 12); 976 ivtv_vapi(itv, CX2341X_ENC_MISC, 1, 12);
945 ivtv_vapi(itv, CX2341X_ENC_MUTE_AUDIO, 1, 0); 977 ivtv_vapi(itv, CX2341X_ENC_MUTE_AUDIO, 1, 0);
946 } 978 }
947
948 /* Unmute */
949 ivtv_control_ioctls(itv, VIDIOC_S_CTRL, &ctrl);
950 IVTV_DEBUG_INFO("Unmute\n"); 979 IVTV_DEBUG_INFO("Unmute\n");
951} 980}
diff --git a/drivers/media/video/ivtv/ivtv-fileops.h b/drivers/media/video/ivtv/ivtv-fileops.h
index 74a1745fabbc..2c8d5186c9c3 100644
--- a/drivers/media/video/ivtv/ivtv-fileops.h
+++ b/drivers/media/video/ivtv/ivtv-fileops.h
@@ -18,6 +18,9 @@
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */ 19 */
20 20
21#ifndef IVTV_FILEOPS_H
22#define IVTV_FILEOPS_H
23
21/* Testing/Debugging */ 24/* Testing/Debugging */
22int ivtv_v4l2_open(struct inode *inode, struct file *filp); 25int ivtv_v4l2_open(struct inode *inode, struct file *filp);
23ssize_t ivtv_v4l2_read(struct file *filp, char __user *buf, size_t count, 26ssize_t ivtv_v4l2_read(struct file *filp, char __user *buf, size_t count,
@@ -42,3 +45,5 @@ int ivtv_claim_stream(struct ivtv_open_id *id, int type);
42 45
43/* Release a previously claimed stream. */ 46/* Release a previously claimed stream. */
44void ivtv_release_stream(struct ivtv_stream *s); 47void ivtv_release_stream(struct ivtv_stream *s);
48
49#endif
diff --git a/drivers/media/video/ivtv/ivtv-firmware.h b/drivers/media/video/ivtv/ivtv-firmware.h
index 8b2ffe658905..041ba94e65bc 100644
--- a/drivers/media/video/ivtv/ivtv-firmware.h
+++ b/drivers/media/video/ivtv/ivtv-firmware.h
@@ -19,7 +19,12 @@
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */ 20 */
21 21
22#ifndef IVTV_FIRMWARE_H
23#define IVTV_FIRMWARE_H
24
22int ivtv_firmware_init(struct ivtv *itv); 25int ivtv_firmware_init(struct ivtv *itv);
23void ivtv_firmware_versions(struct ivtv *itv); 26void ivtv_firmware_versions(struct ivtv *itv);
24void ivtv_halt_firmware(struct ivtv *itv); 27void ivtv_halt_firmware(struct ivtv *itv);
25void ivtv_init_mpeg_decoder(struct ivtv *itv); 28void ivtv_init_mpeg_decoder(struct ivtv *itv);
29
30#endif
diff --git a/drivers/media/video/ivtv/ivtv-gpio.c b/drivers/media/video/ivtv/ivtv-gpio.c
index 6a5a7aa66976..132fb5f71366 100644
--- a/drivers/media/video/ivtv/ivtv-gpio.c
+++ b/drivers/media/video/ivtv/ivtv-gpio.c
@@ -122,30 +122,6 @@ void ivtv_reset_ir_gpio(struct ivtv *itv)
122 write_reg(curdir, IVTV_REG_GPIO_DIR); 122 write_reg(curdir, IVTV_REG_GPIO_DIR);
123} 123}
124 124
125#ifdef HAVE_XC3028
126int ivtv_reset_tuner_gpio(enum v4l2_tuner_type mode, void *priv, int ptr)
127{
128 int curdir, curout;
129 struct ivtv *itv = (struct ivtv *) priv;
130
131 if (itv->card->type != IVTV_CARD_PG600V2 || itv->options.tuner != TUNER_XCEIVE_XC3028)
132 return -EINVAL;
133 IVTV_INFO("Resetting tuner\n");
134 curout = read_reg(IVTV_REG_GPIO_OUT);
135 curdir = read_reg(IVTV_REG_GPIO_DIR);
136 curdir |= (1 << 12); /* GPIO bit 12 */
137
138 curout &= ~(1 << 12);
139 write_reg(curout, IVTV_REG_GPIO_OUT);
140 schedule_timeout_interruptible(msecs_to_jiffies(1));
141
142 curout |= (1 << 12);
143 write_reg(curout, IVTV_REG_GPIO_OUT);
144 schedule_timeout_interruptible(msecs_to_jiffies(1));
145
146 return 0;
147}
148#endif
149 125
150void ivtv_gpio_init(struct ivtv *itv) 126void ivtv_gpio_init(struct ivtv *itv)
151{ 127{
diff --git a/drivers/media/video/ivtv/ivtv-gpio.h b/drivers/media/video/ivtv/ivtv-gpio.h
index c301d2a39346..964a265d91a9 100644
--- a/drivers/media/video/ivtv/ivtv-gpio.h
+++ b/drivers/media/video/ivtv/ivtv-gpio.h
@@ -18,8 +18,13 @@
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */ 19 */
20 20
21#ifndef IVTV_GPIO_H
22#define IVTV_GPIO_H
23
21/* GPIO stuff */ 24/* GPIO stuff */
22void ivtv_gpio_init(struct ivtv *itv); 25void ivtv_gpio_init(struct ivtv *itv);
23void ivtv_reset_ir_gpio(struct ivtv *itv); 26void ivtv_reset_ir_gpio(struct ivtv *itv);
24int ivtv_reset_tuner_gpio(enum v4l2_tuner_type mode, void *priv, int ptr); 27int ivtv_reset_tuner_gpio(void *dev, int cmd, int value);
25int ivtv_gpio(struct ivtv *itv, unsigned int command, void *arg); 28int ivtv_gpio(struct ivtv *itv, unsigned int command, void *arg);
29
30#endif
diff --git a/drivers/media/video/ivtv/ivtv-i2c.c b/drivers/media/video/ivtv/ivtv-i2c.c
index b3557435456d..285fca676a69 100644
--- a/drivers/media/video/ivtv/ivtv-i2c.c
+++ b/drivers/media/video/ivtv/ivtv-i2c.c
@@ -109,6 +109,7 @@ static const u8 hw_driverids[] = {
109 I2C_DRIVERID_UPD64083, 109 I2C_DRIVERID_UPD64083,
110 I2C_DRIVERID_SAA717X, 110 I2C_DRIVERID_SAA717X,
111 I2C_DRIVERID_WM8739, 111 I2C_DRIVERID_WM8739,
112 I2C_DRIVERID_VP27SMPX,
112 0 /* IVTV_HW_GPIO dummy driver ID */ 113 0 /* IVTV_HW_GPIO dummy driver ID */
113}; 114};
114 115
@@ -128,6 +129,7 @@ static const char * const hw_drivernames[] = {
128 "upd64083", 129 "upd64083",
129 "saa717x", 130 "saa717x",
130 "wm8739", 131 "wm8739",
132 "vp27smpx",
131 "gpio", 133 "gpio",
132}; 134};
133 135
@@ -534,14 +536,13 @@ static struct i2c_adapter ivtv_i2c_adap_template = {
534#endif 536#endif
535}; 537};
536 538
537static struct i2c_algo_bit_data ivtv_i2c_algo_template = { 539static const struct i2c_algo_bit_data ivtv_i2c_algo_template = {
538 NULL, /* ?? */ 540 .setsda = ivtv_setsda_old,
539 ivtv_setsda_old, /* setsda function */ 541 .setscl = ivtv_setscl_old,
540 ivtv_setscl_old, /* " */ 542 .getsda = ivtv_getsda_old,
541 ivtv_getsda_old, /* " */ 543 .getscl = ivtv_getscl_old,
542 ivtv_getscl_old, /* " */ 544 .udelay = 5,
543 10, /* udelay */ 545 .timeout = 200,
544 200 /* timeout */
545}; 546};
546 547
547static struct i2c_client ivtv_i2c_client_template = { 548static struct i2c_client ivtv_i2c_client_template = {
diff --git a/drivers/media/video/ivtv/ivtv-i2c.h b/drivers/media/video/ivtv/ivtv-i2c.h
index 5d210adb5c52..677c3292855e 100644
--- a/drivers/media/video/ivtv/ivtv-i2c.h
+++ b/drivers/media/video/ivtv/ivtv-i2c.h
@@ -18,6 +18,9 @@
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */ 19 */
20 20
21#ifndef IVTV_I2C_H
22#define IVTV_I2C_H
23
21int ivtv_cx25840(struct ivtv *itv, unsigned int cmd, void *arg); 24int ivtv_cx25840(struct ivtv *itv, unsigned int cmd, void *arg);
22int ivtv_saa7115(struct ivtv *itv, unsigned int cmd, void *arg); 25int ivtv_saa7115(struct ivtv *itv, unsigned int cmd, void *arg);
23int ivtv_saa7127(struct ivtv *itv, unsigned int cmd, void *arg); 26int ivtv_saa7127(struct ivtv *itv, unsigned int cmd, void *arg);
@@ -34,3 +37,5 @@ void ivtv_call_i2c_clients(struct ivtv *itv, unsigned int cmd, void *arg);
34/* init + register i2c algo-bit adapter */ 37/* init + register i2c algo-bit adapter */
35int __devinit init_ivtv_i2c(struct ivtv *itv); 38int __devinit init_ivtv_i2c(struct ivtv *itv);
36void __devexit exit_ivtv_i2c(struct ivtv *itv); 39void __devexit exit_ivtv_i2c(struct ivtv *itv);
40
41#endif
diff --git a/drivers/media/video/ivtv/ivtv-ioctl.c b/drivers/media/video/ivtv/ivtv-ioctl.c
index dfe0aedc60fd..206eee7542db 100644
--- a/drivers/media/video/ivtv/ivtv-ioctl.c
+++ b/drivers/media/video/ivtv/ivtv-ioctl.c
@@ -25,8 +25,7 @@
25#include "ivtv-queue.h" 25#include "ivtv-queue.h"
26#include "ivtv-fileops.h" 26#include "ivtv-fileops.h"
27#include "ivtv-vbi.h" 27#include "ivtv-vbi.h"
28#include "ivtv-audio.h" 28#include "ivtv-routing.h"
29#include "ivtv-video.h"
30#include "ivtv-streams.h" 29#include "ivtv-streams.h"
31#include "ivtv-yuv.h" 30#include "ivtv-yuv.h"
32#include "ivtv-ioctl.h" 31#include "ivtv-ioctl.h"
@@ -164,7 +163,7 @@ void ivtv_set_osd_alpha(struct ivtv *itv)
164{ 163{
165 ivtv_vapi(itv, CX2341X_OSD_SET_GLOBAL_ALPHA, 3, 164 ivtv_vapi(itv, CX2341X_OSD_SET_GLOBAL_ALPHA, 3,
166 itv->osd_global_alpha_state, itv->osd_global_alpha, !itv->osd_local_alpha_state); 165 itv->osd_global_alpha_state, itv->osd_global_alpha, !itv->osd_local_alpha_state);
167 ivtv_vapi(itv, CX2341X_OSD_SET_CHROMA_KEY, 2, itv->osd_color_key_state, itv->osd_color_key); 166 ivtv_vapi(itv, CX2341X_OSD_SET_CHROMA_KEY, 2, itv->osd_chroma_key_state, itv->osd_chroma_key);
168} 167}
169 168
170int ivtv_set_speed(struct ivtv *itv, int speed) 169int ivtv_set_speed(struct ivtv *itv, int speed)
@@ -427,7 +426,7 @@ static int ivtv_get_fmt(struct ivtv *itv, int streamtype, struct v4l2_format *fm
427 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY: 426 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
428 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT)) 427 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
429 return -EINVAL; 428 return -EINVAL;
430 fmt->fmt.win.chromakey = itv->osd_color_key; 429 fmt->fmt.win.chromakey = itv->osd_chroma_key;
431 fmt->fmt.win.global_alpha = itv->osd_global_alpha; 430 fmt->fmt.win.global_alpha = itv->osd_global_alpha;
432 break; 431 break;
433 432
@@ -547,7 +546,7 @@ static int ivtv_try_or_set_fmt(struct ivtv *itv, int streamtype,
547 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT)) 546 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
548 return -EINVAL; 547 return -EINVAL;
549 if (set_fmt) { 548 if (set_fmt) {
550 itv->osd_color_key = fmt->fmt.win.chromakey; 549 itv->osd_chroma_key = fmt->fmt.win.chromakey;
551 itv->osd_global_alpha = fmt->fmt.win.global_alpha; 550 itv->osd_global_alpha = fmt->fmt.win.global_alpha;
552 ivtv_set_osd_alpha(itv); 551 ivtv_set_osd_alpha(itv);
553 } 552 }
@@ -584,9 +583,7 @@ static int ivtv_try_or_set_fmt(struct ivtv *itv, int streamtype,
584 583
585 /* set raw VBI format */ 584 /* set raw VBI format */
586 if (fmt->type == V4L2_BUF_TYPE_VBI_CAPTURE) { 585 if (fmt->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
587 if (set_fmt && streamtype == IVTV_ENC_STREAM_TYPE_VBI && 586 if (set_fmt && atomic_read(&itv->capturing) > 0) {
588 itv->vbi.sliced_in->service_set &&
589 atomic_read(&itv->capturing) > 0) {
590 return -EBUSY; 587 return -EBUSY;
591 } 588 }
592 if (set_fmt) { 589 if (set_fmt) {
@@ -624,7 +621,7 @@ static int ivtv_try_or_set_fmt(struct ivtv *itv, int streamtype,
624 return 0; 621 return 0;
625 if (set == 0) 622 if (set == 0)
626 return -EINVAL; 623 return -EINVAL;
627 if (atomic_read(&itv->capturing) > 0 && itv->vbi.sliced_in->service_set == 0) { 624 if (atomic_read(&itv->capturing) > 0) {
628 return -EBUSY; 625 return -EBUSY;
629 } 626 }
630 itv->video_dec_func(itv, VIDIOC_S_FMT, fmt); 627 itv->video_dec_func(itv, VIDIOC_S_FMT, fmt);
@@ -677,13 +674,21 @@ static int ivtv_debug_ioctls(struct file *filp, unsigned int cmd, void *arg)
677 case VIDIOC_INT_S_AUDIO_ROUTING: { 674 case VIDIOC_INT_S_AUDIO_ROUTING: {
678 struct v4l2_routing *route = arg; 675 struct v4l2_routing *route = arg;
679 676
680 ivtv_audio_set_route(itv, route); 677 ivtv_i2c_hw(itv, itv->card->hw_audio, VIDIOC_INT_S_AUDIO_ROUTING, route);
681 break; 678 break;
682 } 679 }
683 680
684 case VIDIOC_INT_RESET: 681 case VIDIOC_INT_RESET: {
685 ivtv_reset_ir_gpio(itv); 682 u32 val = *(u32 *)arg;
683
684 if ((val == 0 && itv->options.newi2c) || (val & 0x01)) {
685 ivtv_reset_ir_gpio(itv);
686 }
687 if (val & 0x02) {
688 itv->video_dec_func(itv, cmd, 0);
689 }
686 break; 690 break;
691 }
687 692
688 default: 693 default:
689 return -EINVAL; 694 return -EINVAL;
@@ -694,6 +699,7 @@ static int ivtv_debug_ioctls(struct file *filp, unsigned int cmd, void *arg)
694int ivtv_v4l2_ioctls(struct ivtv *itv, struct file *filp, unsigned int cmd, void *arg) 699int ivtv_v4l2_ioctls(struct ivtv *itv, struct file *filp, unsigned int cmd, void *arg)
695{ 700{
696 struct ivtv_open_id *id = NULL; 701 struct ivtv_open_id *id = NULL;
702 u32 data[CX2341X_MBOX_MAX_DATA];
697 703
698 if (filp) id = (struct ivtv_open_id *)filp->private_data; 704 if (filp) id = (struct ivtv_open_id *)filp->private_data;
699 705
@@ -898,6 +904,9 @@ int ivtv_v4l2_ioctls(struct ivtv *itv, struct file *filp, unsigned int cmd, void
898 IVTV_DEBUG_INFO("Input unchanged\n"); 904 IVTV_DEBUG_INFO("Input unchanged\n");
899 break; 905 break;
900 } 906 }
907 if (atomic_read(&itv->capturing) > 0) {
908 return -EBUSY;
909 }
901 IVTV_DEBUG_INFO("Changing input from %d to %d\n", 910 IVTV_DEBUG_INFO("Changing input from %d to %d\n",
902 itv->active_input, inp); 911 itv->active_input, inp);
903 912
@@ -1127,12 +1136,14 @@ int ivtv_v4l2_ioctls(struct ivtv *itv, struct file *filp, unsigned int cmd, void
1127 memset(&enc->raw, 0, sizeof(enc->raw)); 1136 memset(&enc->raw, 0, sizeof(enc->raw));
1128 switch (enc->cmd) { 1137 switch (enc->cmd) {
1129 case V4L2_ENC_CMD_START: 1138 case V4L2_ENC_CMD_START:
1139 IVTV_DEBUG_IOCTL("V4L2_ENC_CMD_START\n");
1130 enc->flags = 0; 1140 enc->flags = 0;
1131 if (try) 1141 if (try)
1132 return 0; 1142 return 0;
1133 return ivtv_start_capture(id); 1143 return ivtv_start_capture(id);
1134 1144
1135 case V4L2_ENC_CMD_STOP: 1145 case V4L2_ENC_CMD_STOP:
1146 IVTV_DEBUG_IOCTL("V4L2_ENC_CMD_STOP\n");
1136 enc->flags &= V4L2_ENC_CMD_STOP_AT_GOP_END; 1147 enc->flags &= V4L2_ENC_CMD_STOP_AT_GOP_END;
1137 if (try) 1148 if (try)
1138 return 0; 1149 return 0;
@@ -1140,6 +1151,7 @@ int ivtv_v4l2_ioctls(struct ivtv *itv, struct file *filp, unsigned int cmd, void
1140 return 0; 1151 return 0;
1141 1152
1142 case V4L2_ENC_CMD_PAUSE: 1153 case V4L2_ENC_CMD_PAUSE:
1154 IVTV_DEBUG_IOCTL("V4L2_ENC_CMD_PAUSE\n");
1143 enc->flags = 0; 1155 enc->flags = 0;
1144 if (try) 1156 if (try)
1145 return 0; 1157 return 0;
@@ -1152,6 +1164,7 @@ int ivtv_v4l2_ioctls(struct ivtv *itv, struct file *filp, unsigned int cmd, void
1152 break; 1164 break;
1153 1165
1154 case V4L2_ENC_CMD_RESUME: 1166 case V4L2_ENC_CMD_RESUME:
1167 IVTV_DEBUG_IOCTL("V4L2_ENC_CMD_RESUME\n");
1155 enc->flags = 0; 1168 enc->flags = 0;
1156 if (try) 1169 if (try)
1157 return 0; 1170 return 0;
@@ -1163,6 +1176,7 @@ int ivtv_v4l2_ioctls(struct ivtv *itv, struct file *filp, unsigned int cmd, void
1163 ivtv_unmute(itv); 1176 ivtv_unmute(itv);
1164 break; 1177 break;
1165 default: 1178 default:
1179 IVTV_DEBUG_IOCTL("Unknown cmd %d\n", enc->cmd);
1166 return -EINVAL; 1180 return -EINVAL;
1167 } 1181 }
1168 break; 1182 break;
@@ -1170,22 +1184,58 @@ int ivtv_v4l2_ioctls(struct ivtv *itv, struct file *filp, unsigned int cmd, void
1170 1184
1171 case VIDIOC_G_FBUF: { 1185 case VIDIOC_G_FBUF: {
1172 struct v4l2_framebuffer *fb = arg; 1186 struct v4l2_framebuffer *fb = arg;
1187 int pixfmt;
1188 static u32 pixel_format[16] = {
1189 V4L2_PIX_FMT_PAL8, /* Uses a 256-entry RGB colormap */
1190 V4L2_PIX_FMT_RGB565,
1191 V4L2_PIX_FMT_RGB555,
1192 V4L2_PIX_FMT_RGB444,
1193 V4L2_PIX_FMT_RGB32,
1194 0,
1195 0,
1196 0,
1197 V4L2_PIX_FMT_PAL8, /* Uses a 256-entry YUV colormap */
1198 V4L2_PIX_FMT_YUV565,
1199 V4L2_PIX_FMT_YUV555,
1200 V4L2_PIX_FMT_YUV444,
1201 V4L2_PIX_FMT_YUV32,
1202 0,
1203 0,
1204 0,
1205 };
1173 1206
1174 memset(fb, 0, sizeof(*fb)); 1207 memset(fb, 0, sizeof(*fb));
1175 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT_OVERLAY)) 1208 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT_OVERLAY))
1176 return -EINVAL; 1209 return -EINVAL;
1177 fb->capability = V4L2_FBUF_CAP_EXTERNOVERLAY | V4L2_FBUF_CAP_CHROMAKEY | 1210 fb->capability = V4L2_FBUF_CAP_EXTERNOVERLAY | V4L2_FBUF_CAP_CHROMAKEY |
1178 V4L2_FBUF_CAP_LOCAL_ALPHA | V4L2_FBUF_CAP_GLOBAL_ALPHA; 1211 V4L2_FBUF_CAP_GLOBAL_ALPHA;
1179 fb->fmt.pixelformat = itv->osd_pixelformat; 1212 ivtv_vapi_result(itv, data, CX2341X_OSD_GET_STATE, 0);
1213 data[0] |= (read_reg(0x2a00) >> 7) & 0x40;
1214 pixfmt = (data[0] >> 3) & 0xf;
1215 fb->fmt.pixelformat = pixel_format[pixfmt];
1180 fb->fmt.width = itv->osd_rect.width; 1216 fb->fmt.width = itv->osd_rect.width;
1181 fb->fmt.height = itv->osd_rect.height; 1217 fb->fmt.height = itv->osd_rect.height;
1182 fb->base = (void *)itv->osd_video_pbase; 1218 fb->base = (void *)itv->osd_video_pbase;
1219 if (itv->osd_chroma_key_state)
1220 fb->flags |= V4L2_FBUF_FLAG_CHROMAKEY;
1183 if (itv->osd_global_alpha_state) 1221 if (itv->osd_global_alpha_state)
1184 fb->flags |= V4L2_FBUF_FLAG_GLOBAL_ALPHA; 1222 fb->flags |= V4L2_FBUF_FLAG_GLOBAL_ALPHA;
1185 if (itv->osd_local_alpha_state) 1223 pixfmt &= 7;
1186 fb->flags |= V4L2_FBUF_FLAG_LOCAL_ALPHA; 1224 /* no local alpha for RGB565 or unknown formats */
1187 if (itv->osd_color_key_state) 1225 if (pixfmt == 1 || pixfmt > 4)
1188 fb->flags |= V4L2_FBUF_FLAG_CHROMAKEY; 1226 break;
1227 /* 16-bit formats have inverted local alpha */
1228 if (pixfmt == 2 || pixfmt == 3)
1229 fb->capability |= V4L2_FBUF_CAP_LOCAL_INV_ALPHA;
1230 else
1231 fb->capability |= V4L2_FBUF_CAP_LOCAL_ALPHA;
1232 if (itv->osd_local_alpha_state) {
1233 /* 16-bit formats have inverted local alpha */
1234 if (pixfmt == 2 || pixfmt == 3)
1235 fb->flags |= V4L2_FBUF_FLAG_LOCAL_INV_ALPHA;
1236 else
1237 fb->flags |= V4L2_FBUF_FLAG_LOCAL_ALPHA;
1238 }
1189 break; 1239 break;
1190 } 1240 }
1191 1241
@@ -1195,12 +1245,22 @@ int ivtv_v4l2_ioctls(struct ivtv *itv, struct file *filp, unsigned int cmd, void
1195 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT_OVERLAY)) 1245 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT_OVERLAY))
1196 return -EINVAL; 1246 return -EINVAL;
1197 itv->osd_global_alpha_state = (fb->flags & V4L2_FBUF_FLAG_GLOBAL_ALPHA) != 0; 1247 itv->osd_global_alpha_state = (fb->flags & V4L2_FBUF_FLAG_GLOBAL_ALPHA) != 0;
1198 itv->osd_local_alpha_state = (fb->flags & V4L2_FBUF_FLAG_LOCAL_ALPHA) != 0; 1248 itv->osd_local_alpha_state =
1199 itv->osd_color_key_state = (fb->flags & V4L2_FBUF_FLAG_CHROMAKEY) != 0; 1249 (fb->flags & (V4L2_FBUF_FLAG_LOCAL_ALPHA|V4L2_FBUF_FLAG_LOCAL_INV_ALPHA)) != 0;
1250 itv->osd_chroma_key_state = (fb->flags & V4L2_FBUF_FLAG_CHROMAKEY) != 0;
1200 ivtv_set_osd_alpha(itv); 1251 ivtv_set_osd_alpha(itv);
1201 break; 1252 break;
1202 } 1253 }
1203 1254
1255 case VIDIOC_OVERLAY: {
1256 int *on = arg;
1257
1258 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT_OVERLAY))
1259 return -EINVAL;
1260 ivtv_vapi(itv, CX2341X_OSD_SET_STATE, 1, *on != 0);
1261 break;
1262 }
1263
1204 case VIDIOC_LOG_STATUS: 1264 case VIDIOC_LOG_STATUS:
1205 { 1265 {
1206 int has_output = itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT; 1266 int has_output = itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT;
@@ -1209,6 +1269,7 @@ int ivtv_v4l2_ioctls(struct ivtv *itv, struct file *filp, unsigned int cmd, void
1209 int i; 1269 int i;
1210 1270
1211 IVTV_INFO("================= START STATUS CARD #%d =================\n", itv->num); 1271 IVTV_INFO("================= START STATUS CARD #%d =================\n", itv->num);
1272 IVTV_INFO("Version: %s Card: %s\n", IVTV_VERSION, itv->card_name);
1212 if (itv->hw_flags & IVTV_HW_TVEEPROM) { 1273 if (itv->hw_flags & IVTV_HW_TVEEPROM) {
1213 struct tveeprom tv; 1274 struct tveeprom tv;
1214 1275
@@ -1217,32 +1278,72 @@ int ivtv_v4l2_ioctls(struct ivtv *itv, struct file *filp, unsigned int cmd, void
1217 ivtv_call_i2c_clients(itv, VIDIOC_LOG_STATUS, NULL); 1278 ivtv_call_i2c_clients(itv, VIDIOC_LOG_STATUS, NULL);
1218 ivtv_get_input(itv, itv->active_input, &vidin); 1279 ivtv_get_input(itv, itv->active_input, &vidin);
1219 ivtv_get_audio_input(itv, itv->audio_input, &audin); 1280 ivtv_get_audio_input(itv, itv->audio_input, &audin);
1220 IVTV_INFO("Video Input: %s\n", vidin.name); 1281 IVTV_INFO("Video Input: %s\n", vidin.name);
1221 IVTV_INFO("Audio Input: %s\n", audin.name); 1282 IVTV_INFO("Audio Input: %s%s\n", audin.name,
1283 (itv->dualwatch_stereo_mode & ~0x300) == 0x200 ? " (Bilingual)" : "");
1222 if (has_output) { 1284 if (has_output) {
1223 struct v4l2_output vidout; 1285 struct v4l2_output vidout;
1224 struct v4l2_audioout audout; 1286 struct v4l2_audioout audout;
1225 int mode = itv->output_mode; 1287 int mode = itv->output_mode;
1226 static const char * const output_modes[] = { 1288 static const char * const output_modes[5] = {
1227 "None", 1289 "None",
1228 "MPEG Streaming", 1290 "MPEG Streaming",
1229 "YUV Streaming", 1291 "YUV Streaming",
1230 "YUV Frames", 1292 "YUV Frames",
1231 "Passthrough", 1293 "Passthrough",
1232 }; 1294 };
1295 static const char * const audio_modes[5] = {
1296 "Stereo",
1297 "Left",
1298 "Right",
1299 "Mono",
1300 "Swapped"
1301 };
1302 static const char * const alpha_mode[4] = {
1303 "None",
1304 "Global",
1305 "Local",
1306 "Global and Local"
1307 };
1308 static const char * const pixel_format[16] = {
1309 "ARGB Indexed",
1310 "RGB 5:6:5",
1311 "ARGB 1:5:5:5",
1312 "ARGB 1:4:4:4",
1313 "ARGB 8:8:8:8",
1314 "5",
1315 "6",
1316 "7",
1317 "AYUV Indexed",
1318 "YUV 5:6:5",
1319 "AYUV 1:5:5:5",
1320 "AYUV 1:4:4:4",
1321 "AYUV 8:8:8:8",
1322 "13",
1323 "14",
1324 "15",
1325 };
1233 1326
1234 ivtv_get_output(itv, itv->active_output, &vidout); 1327 ivtv_get_output(itv, itv->active_output, &vidout);
1235 ivtv_get_audio_output(itv, 0, &audout); 1328 ivtv_get_audio_output(itv, 0, &audout);
1236 IVTV_INFO("Video Output: %s\n", vidout.name); 1329 IVTV_INFO("Video Output: %s\n", vidout.name);
1237 IVTV_INFO("Audio Output: %s\n", audout.name); 1330 IVTV_INFO("Audio Output: %s (Stereo/Bilingual: %s/%s)\n", audout.name,
1331 audio_modes[itv->audio_stereo_mode],
1332 audio_modes[itv->audio_bilingual_mode]);
1238 if (mode < 0 || mode > OUT_PASSTHROUGH) 1333 if (mode < 0 || mode > OUT_PASSTHROUGH)
1239 mode = OUT_NONE; 1334 mode = OUT_NONE;
1240 IVTV_INFO("Output Mode: %s\n", output_modes[mode]); 1335 IVTV_INFO("Output Mode: %s\n", output_modes[mode]);
1336 ivtv_vapi_result(itv, data, CX2341X_OSD_GET_STATE, 0);
1337 data[0] |= (read_reg(0x2a00) >> 7) & 0x40;
1338 IVTV_INFO("Overlay: %s, Alpha: %s, Pixel Format: %s\n",
1339 data[0] & 1 ? "On" : "Off",
1340 alpha_mode[(data[0] >> 1) & 0x3],
1341 pixel_format[(data[0] >> 3) & 0xf]);
1241 } 1342 }
1242 IVTV_INFO("Tuner: %s\n", 1343 IVTV_INFO("Tuner: %s\n",
1243 test_bit(IVTV_F_I_RADIO_USER, &itv->i_flags) ? "Radio" : "TV"); 1344 test_bit(IVTV_F_I_RADIO_USER, &itv->i_flags) ? "Radio" : "TV");
1244 cx2341x_log_status(&itv->params, itv->name); 1345 cx2341x_log_status(&itv->params, itv->name);
1245 IVTV_INFO("Version: %s Status flags: 0x%08lx\n", IVTV_VERSION, itv->i_flags); 1346 IVTV_INFO("Status flags: 0x%08lx\n", itv->i_flags);
1246 for (i = 0; i < IVTV_MAX_STREAMS; i++) { 1347 for (i = 0; i < IVTV_MAX_STREAMS; i++) {
1247 struct ivtv_stream *s = &itv->streams[i]; 1348 struct ivtv_stream *s = &itv->streams[i];
1248 1349
@@ -1252,7 +1353,7 @@ int ivtv_v4l2_ioctls(struct ivtv *itv, struct file *filp, unsigned int cmd, void
1252 (s->buffers - s->q_free.buffers) * 100 / s->buffers, 1353 (s->buffers - s->q_free.buffers) * 100 / s->buffers,
1253 (s->buffers * s->buf_size) / 1024, s->buffers); 1354 (s->buffers * s->buf_size) / 1024, s->buffers);
1254 } 1355 }
1255 IVTV_INFO("Read MPEG/VBI: %lld/%lld bytes\n", (long long)itv->mpg_data_received, (long long)itv->vbi_data_inserted); 1356 IVTV_INFO("Read MPG/VBI: %lld/%lld bytes\n", (long long)itv->mpg_data_received, (long long)itv->vbi_data_inserted);
1256 IVTV_INFO("================== END STATUS CARD #%d ==================\n", itv->num); 1357 IVTV_INFO("================== END STATUS CARD #%d ==================\n", itv->num);
1257 break; 1358 break;
1258 } 1359 }
@@ -1288,6 +1389,8 @@ static int ivtv_decoder_ioctls(struct file *filp, unsigned int cmd, void *arg)
1288 ivtv_release_stream(s); 1389 ivtv_release_stream(s);
1289 return -EBUSY; 1390 return -EBUSY;
1290 } 1391 }
1392 /* Mark that this file handle started the UDMA_YUV mode */
1393 id->yuv_frames = 1;
1291 if (args->y_source == NULL) 1394 if (args->y_source == NULL)
1292 return 0; 1395 return 0;
1293 return ivtv_yuv_prep_frame(itv, args); 1396 return ivtv_yuv_prep_frame(itv, args);
@@ -1396,9 +1499,9 @@ static int ivtv_decoder_ioctls(struct file *filp, unsigned int cmd, void *arg)
1396 int try = (cmd == VIDEO_TRY_COMMAND); 1499 int try = (cmd == VIDEO_TRY_COMMAND);
1397 1500
1398 if (try) 1501 if (try)
1399 IVTV_DEBUG_IOCTL("VIDEO_TRY_COMMAND\n"); 1502 IVTV_DEBUG_IOCTL("VIDEO_TRY_COMMAND %d\n", vc->cmd);
1400 else 1503 else
1401 IVTV_DEBUG_IOCTL("VIDEO_COMMAND\n"); 1504 IVTV_DEBUG_IOCTL("VIDEO_COMMAND %d\n", vc->cmd);
1402 return ivtv_video_command(itv, id, vc, try); 1505 return ivtv_video_command(itv, id, vc, try);
1403 } 1506 }
1404 1507
@@ -1429,11 +1532,15 @@ static int ivtv_decoder_ioctls(struct file *filp, unsigned int cmd, void *arg)
1429 return 0; 1532 return 0;
1430 if (nonblocking) 1533 if (nonblocking)
1431 return -EAGAIN; 1534 return -EAGAIN;
1432 /* wait for event */ 1535 /* Wait for event. Note that serialize_lock is locked,
1536 so to allow other processes to access the driver while
1537 we are waiting unlock first and later lock again. */
1538 mutex_unlock(&itv->serialize_lock);
1433 prepare_to_wait(&itv->event_waitq, &wait, TASK_INTERRUPTIBLE); 1539 prepare_to_wait(&itv->event_waitq, &wait, TASK_INTERRUPTIBLE);
1434 if ((itv->i_flags & (IVTV_F_I_EV_DEC_STOPPED|IVTV_F_I_EV_VSYNC)) == 0) 1540 if ((itv->i_flags & (IVTV_F_I_EV_DEC_STOPPED|IVTV_F_I_EV_VSYNC)) == 0)
1435 schedule(); 1541 schedule();
1436 finish_wait(&itv->event_waitq, &wait); 1542 finish_wait(&itv->event_waitq, &wait);
1543 mutex_lock(&itv->serialize_lock);
1437 if (signal_pending(current)) { 1544 if (signal_pending(current)) {
1438 /* return if a signal was received */ 1545 /* return if a signal was received */
1439 IVTV_DEBUG_INFO("User stopped wait for event\n"); 1546 IVTV_DEBUG_INFO("User stopped wait for event\n");
@@ -1470,6 +1577,7 @@ static int ivtv_v4l2_do_ioctl(struct inode *inode, struct file *filp,
1470 case VIDIOC_S_AUDOUT: 1577 case VIDIOC_S_AUDOUT:
1471 case VIDIOC_S_EXT_CTRLS: 1578 case VIDIOC_S_EXT_CTRLS:
1472 case VIDIOC_S_FBUF: 1579 case VIDIOC_S_FBUF:
1580 case VIDIOC_OVERLAY:
1473 ret = v4l2_prio_check(&itv->prio, &id->prio); 1581 ret = v4l2_prio_check(&itv->prio, &id->prio);
1474 if (ret) 1582 if (ret)
1475 return ret; 1583 return ret;
@@ -1523,6 +1631,7 @@ static int ivtv_v4l2_do_ioctl(struct inode *inode, struct file *filp,
1523 case VIDIOC_TRY_ENCODER_CMD: 1631 case VIDIOC_TRY_ENCODER_CMD:
1524 case VIDIOC_G_FBUF: 1632 case VIDIOC_G_FBUF:
1525 case VIDIOC_S_FBUF: 1633 case VIDIOC_S_FBUF:
1634 case VIDIOC_OVERLAY:
1526 if (ivtv_debug & IVTV_DBGFLG_IOCTL) { 1635 if (ivtv_debug & IVTV_DBGFLG_IOCTL) {
1527 printk(KERN_INFO "ivtv%d ioctl: ", itv->num); 1636 printk(KERN_INFO "ivtv%d ioctl: ", itv->num);
1528 v4l_printk_ioctl(cmd); 1637 v4l_printk_ioctl(cmd);
@@ -1563,12 +1672,9 @@ static int ivtv_v4l2_do_ioctl(struct inode *inode, struct file *filp,
1563 return 0; 1672 return 0;
1564} 1673}
1565 1674
1566int ivtv_v4l2_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, 1675static int ivtv_serialized_ioctl(struct ivtv *itv, struct inode *inode, struct file *filp,
1567 unsigned long arg) 1676 unsigned int cmd, unsigned long arg)
1568{ 1677{
1569 struct ivtv_open_id *id = (struct ivtv_open_id *)filp->private_data;
1570 struct ivtv *itv = id->itv;
1571
1572 /* Filter dvb ioctls that cannot be handled by video_usercopy */ 1678 /* Filter dvb ioctls that cannot be handled by video_usercopy */
1573 switch (cmd) { 1679 switch (cmd) {
1574 case VIDEO_SELECT_SOURCE: 1680 case VIDEO_SELECT_SOURCE:
@@ -1603,3 +1709,16 @@ int ivtv_v4l2_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
1603 } 1709 }
1604 return video_usercopy(inode, filp, cmd, arg, ivtv_v4l2_do_ioctl); 1710 return video_usercopy(inode, filp, cmd, arg, ivtv_v4l2_do_ioctl);
1605} 1711}
1712
1713int ivtv_v4l2_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
1714 unsigned long arg)
1715{
1716 struct ivtv_open_id *id = (struct ivtv_open_id *)filp->private_data;
1717 struct ivtv *itv = id->itv;
1718 int res;
1719
1720 mutex_lock(&itv->serialize_lock);
1721 res = ivtv_serialized_ioctl(itv, inode, filp, cmd, arg);
1722 mutex_unlock(&itv->serialize_lock);
1723 return res;
1724}
diff --git a/drivers/media/video/ivtv/ivtv-ioctl.h b/drivers/media/video/ivtv/ivtv-ioctl.h
index cbccf7a9f65c..a03351b6853d 100644
--- a/drivers/media/video/ivtv/ivtv-ioctl.h
+++ b/drivers/media/video/ivtv/ivtv-ioctl.h
@@ -18,6 +18,9 @@
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */ 19 */
20 20
21#ifndef IVTV_IOCTL_H
22#define IVTV_IOCTL_H
23
21u16 service2vbi(int type); 24u16 service2vbi(int type);
22void expand_service_set(struct v4l2_sliced_vbi_format *fmt, int is_pal); 25void expand_service_set(struct v4l2_sliced_vbi_format *fmt, int is_pal);
23u16 get_service_set(struct v4l2_sliced_vbi_format *fmt); 26u16 get_service_set(struct v4l2_sliced_vbi_format *fmt);
@@ -26,3 +29,5 @@ int ivtv_v4l2_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
26int ivtv_v4l2_ioctls(struct ivtv *itv, struct file *filp, unsigned int cmd, void *arg); 29int ivtv_v4l2_ioctls(struct ivtv *itv, struct file *filp, unsigned int cmd, void *arg);
27void ivtv_set_osd_alpha(struct ivtv *itv); 30void ivtv_set_osd_alpha(struct ivtv *itv);
28int ivtv_set_speed(struct ivtv *itv, int speed); 31int ivtv_set_speed(struct ivtv *itv, int speed);
32
33#endif
diff --git a/drivers/media/video/ivtv/ivtv-irq.c b/drivers/media/video/ivtv/ivtv-irq.c
index fcd6e7f5f121..fd1688e4757d 100644
--- a/drivers/media/video/ivtv/ivtv-irq.c
+++ b/drivers/media/video/ivtv/ivtv-irq.c
@@ -19,12 +19,9 @@
19 */ 19 */
20 20
21#include "ivtv-driver.h" 21#include "ivtv-driver.h"
22#include "ivtv-firmware.h"
23#include "ivtv-fileops.h"
24#include "ivtv-queue.h" 22#include "ivtv-queue.h"
25#include "ivtv-udma.h" 23#include "ivtv-udma.h"
26#include "ivtv-irq.h" 24#include "ivtv-irq.h"
27#include "ivtv-ioctl.h"
28#include "ivtv-mailbox.h" 25#include "ivtv-mailbox.h"
29#include "ivtv-vbi.h" 26#include "ivtv-vbi.h"
30#include "ivtv-yuv.h" 27#include "ivtv-yuv.h"
@@ -45,7 +42,6 @@ static void ivtv_pio_work_handler(struct ivtv *itv)
45{ 42{
46 struct ivtv_stream *s = &itv->streams[itv->cur_pio_stream]; 43 struct ivtv_stream *s = &itv->streams[itv->cur_pio_stream];
47 struct ivtv_buffer *buf; 44 struct ivtv_buffer *buf;
48 struct list_head *p;
49 int i = 0; 45 int i = 0;
50 46
51 IVTV_DEBUG_HI_DMA("ivtv_pio_work_handler\n"); 47 IVTV_DEBUG_HI_DMA("ivtv_pio_work_handler\n");
@@ -57,21 +53,19 @@ static void ivtv_pio_work_handler(struct ivtv *itv)
57 return; 53 return;
58 } 54 }
59 IVTV_DEBUG_HI_DMA("Process PIO %s\n", s->name); 55 IVTV_DEBUG_HI_DMA("Process PIO %s\n", s->name);
60 buf = list_entry(s->q_dma.list.next, struct ivtv_buffer, list); 56 list_for_each_entry(buf, &s->q_dma.list, list) {
61 list_for_each(p, &s->q_dma.list) { 57 u32 size = s->sg_processing[i].size & 0x3ffff;
62 struct ivtv_buffer *buf = list_entry(p, struct ivtv_buffer, list);
63 u32 size = s->PIOarray[i].size & 0x3ffff;
64 58
65 /* Copy the data from the card to the buffer */ 59 /* Copy the data from the card to the buffer */
66 if (s->type == IVTV_DEC_STREAM_TYPE_VBI) { 60 if (s->type == IVTV_DEC_STREAM_TYPE_VBI) {
67 memcpy_fromio(buf->buf, itv->dec_mem + s->PIOarray[i].src - IVTV_DECODER_OFFSET, size); 61 memcpy_fromio(buf->buf, itv->dec_mem + s->sg_processing[i].src - IVTV_DECODER_OFFSET, size);
68 } 62 }
69 else { 63 else {
70 memcpy_fromio(buf->buf, itv->enc_mem + s->PIOarray[i].src, size); 64 memcpy_fromio(buf->buf, itv->enc_mem + s->sg_processing[i].src, size);
71 } 65 }
72 if (s->PIOarray[i].size & 0x80000000)
73 break;
74 i++; 66 i++;
67 if (i == s->sg_processing_size)
68 break;
75 } 69 }
76 write_reg(IVTV_IRQ_ENC_PIO_COMPLETE, 0x44); 70 write_reg(IVTV_IRQ_ENC_PIO_COMPLETE, 0x44);
77} 71}
@@ -100,12 +94,11 @@ static int stream_enc_dma_append(struct ivtv_stream *s, u32 data[CX2341X_MBOX_MA
100{ 94{
101 struct ivtv *itv = s->itv; 95 struct ivtv *itv = s->itv;
102 struct ivtv_buffer *buf; 96 struct ivtv_buffer *buf;
103 struct list_head *p;
104 u32 bytes_needed = 0; 97 u32 bytes_needed = 0;
105 u32 offset, size; 98 u32 offset, size;
106 u32 UVoffset = 0, UVsize = 0; 99 u32 UVoffset = 0, UVsize = 0;
107 int skip_bufs = s->q_predma.buffers; 100 int skip_bufs = s->q_predma.buffers;
108 int idx = s->SG_length; 101 int idx = s->sg_pending_size;
109 int rc; 102 int rc;
110 103
111 /* sanity checks */ 104 /* sanity checks */
@@ -123,7 +116,7 @@ static int stream_enc_dma_append(struct ivtv_stream *s, u32 data[CX2341X_MBOX_MA
123 case IVTV_ENC_STREAM_TYPE_MPG: 116 case IVTV_ENC_STREAM_TYPE_MPG:
124 offset = data[1]; 117 offset = data[1];
125 size = data[2]; 118 size = data[2];
126 s->dma_pts = 0; 119 s->pending_pts = 0;
127 break; 120 break;
128 121
129 case IVTV_ENC_STREAM_TYPE_YUV: 122 case IVTV_ENC_STREAM_TYPE_YUV:
@@ -131,13 +124,13 @@ static int stream_enc_dma_append(struct ivtv_stream *s, u32 data[CX2341X_MBOX_MA
131 size = data[2]; 124 size = data[2];
132 UVoffset = data[3]; 125 UVoffset = data[3];
133 UVsize = data[4]; 126 UVsize = data[4];
134 s->dma_pts = ((u64) data[5] << 32) | data[6]; 127 s->pending_pts = ((u64) data[5] << 32) | data[6];
135 break; 128 break;
136 129
137 case IVTV_ENC_STREAM_TYPE_PCM: 130 case IVTV_ENC_STREAM_TYPE_PCM:
138 offset = data[1] + 12; 131 offset = data[1] + 12;
139 size = data[2] - 12; 132 size = data[2] - 12;
140 s->dma_pts = read_dec(offset - 8) | 133 s->pending_pts = read_dec(offset - 8) |
141 ((u64)(read_dec(offset - 12)) << 32); 134 ((u64)(read_dec(offset - 12)) << 32);
142 if (itv->has_cx23415) 135 if (itv->has_cx23415)
143 offset += IVTV_DECODER_OFFSET; 136 offset += IVTV_DECODER_OFFSET;
@@ -150,13 +143,13 @@ static int stream_enc_dma_append(struct ivtv_stream *s, u32 data[CX2341X_MBOX_MA
150 IVTV_DEBUG_INFO("VBI offset == 0\n"); 143 IVTV_DEBUG_INFO("VBI offset == 0\n");
151 return -1; 144 return -1;
152 } 145 }
153 s->dma_pts = read_enc(offset - 4) | ((u64)read_enc(offset - 8) << 32); 146 s->pending_pts = read_enc(offset - 4) | ((u64)read_enc(offset - 8) << 32);
154 break; 147 break;
155 148
156 case IVTV_DEC_STREAM_TYPE_VBI: 149 case IVTV_DEC_STREAM_TYPE_VBI:
157 size = read_dec(itv->vbi.dec_start + 4) + 8; 150 size = read_dec(itv->vbi.dec_start + 4) + 8;
158 offset = read_dec(itv->vbi.dec_start) + itv->vbi.dec_start; 151 offset = read_dec(itv->vbi.dec_start) + itv->vbi.dec_start;
159 s->dma_pts = 0; 152 s->pending_pts = 0;
160 offset += IVTV_DECODER_OFFSET; 153 offset += IVTV_DECODER_OFFSET;
161 break; 154 break;
162 default: 155 default:
@@ -165,17 +158,17 @@ static int stream_enc_dma_append(struct ivtv_stream *s, u32 data[CX2341X_MBOX_MA
165 } 158 }
166 159
167 /* if this is the start of the DMA then fill in the magic cookie */ 160 /* if this is the start of the DMA then fill in the magic cookie */
168 if (s->SG_length == 0) { 161 if (s->sg_pending_size == 0 && ivtv_use_dma(s)) {
169 if (itv->has_cx23415 && (s->type == IVTV_ENC_STREAM_TYPE_PCM || 162 if (itv->has_cx23415 && (s->type == IVTV_ENC_STREAM_TYPE_PCM ||
170 s->type == IVTV_DEC_STREAM_TYPE_VBI)) { 163 s->type == IVTV_DEC_STREAM_TYPE_VBI)) {
171 s->dma_backup = read_dec(offset - IVTV_DECODER_OFFSET); 164 s->pending_backup = read_dec(offset - IVTV_DECODER_OFFSET);
172 write_dec_sync(cpu_to_le32(DMA_MAGIC_COOKIE), offset - IVTV_DECODER_OFFSET); 165 write_dec_sync(cpu_to_le32(DMA_MAGIC_COOKIE), offset - IVTV_DECODER_OFFSET);
173 } 166 }
174 else { 167 else {
175 s->dma_backup = read_enc(offset); 168 s->pending_backup = read_enc(offset);
176 write_enc_sync(cpu_to_le32(DMA_MAGIC_COOKIE), offset); 169 write_enc_sync(cpu_to_le32(DMA_MAGIC_COOKIE), offset);
177 } 170 }
178 s->dma_offset = offset; 171 s->pending_offset = offset;
179 } 172 }
180 173
181 bytes_needed = size; 174 bytes_needed = size;
@@ -202,18 +195,17 @@ static int stream_enc_dma_append(struct ivtv_stream *s, u32 data[CX2341X_MBOX_MA
202 } 195 }
203 s->buffers_stolen = rc; 196 s->buffers_stolen = rc;
204 197
205 /* got the buffers, now fill in SGarray (DMA) */ 198 /* got the buffers, now fill in sg_pending */
206 buf = list_entry(s->q_predma.list.next, struct ivtv_buffer, list); 199 buf = list_entry(s->q_predma.list.next, struct ivtv_buffer, list);
207 memset(buf->buf, 0, 128); 200 memset(buf->buf, 0, 128);
208 list_for_each(p, &s->q_predma.list) { 201 list_for_each_entry(buf, &s->q_predma.list, list) {
209 struct ivtv_buffer *buf = list_entry(p, struct ivtv_buffer, list);
210
211 if (skip_bufs-- > 0) 202 if (skip_bufs-- > 0)
212 continue; 203 continue;
213 s->SGarray[idx].dst = cpu_to_le32(buf->dma_handle); 204 s->sg_pending[idx].dst = buf->dma_handle;
214 s->SGarray[idx].src = cpu_to_le32(offset); 205 s->sg_pending[idx].src = offset;
215 s->SGarray[idx].size = cpu_to_le32(s->buf_size); 206 s->sg_pending[idx].size = s->buf_size;
216 buf->bytesused = (size < s->buf_size) ? size : s->buf_size; 207 buf->bytesused = (size < s->buf_size) ? size : s->buf_size;
208 buf->dma_xfer_cnt = s->dma_xfer_cnt;
217 209
218 s->q_predma.bytesused += buf->bytesused; 210 s->q_predma.bytesused += buf->bytesused;
219 size -= buf->bytesused; 211 size -= buf->bytesused;
@@ -229,7 +221,7 @@ static int stream_enc_dma_append(struct ivtv_stream *s, u32 data[CX2341X_MBOX_MA
229 } 221 }
230 idx++; 222 idx++;
231 } 223 }
232 s->SG_length = idx; 224 s->sg_pending_size = idx;
233 return 0; 225 return 0;
234} 226}
235 227
@@ -251,7 +243,7 @@ static void dma_post(struct ivtv_stream *s)
251 /* Sync Buffer */ 243 /* Sync Buffer */
252 ivtv_buf_sync_for_cpu(s, buf); 244 ivtv_buf_sync_for_cpu(s, buf);
253 245
254 if (x == 0) { 246 if (x == 0 && ivtv_use_dma(s)) {
255 offset = s->dma_last_offset; 247 offset = s->dma_last_offset;
256 if (u32buf[offset / 4] != DMA_MAGIC_COOKIE) 248 if (u32buf[offset / 4] != DMA_MAGIC_COOKIE)
257 { 249 {
@@ -286,14 +278,12 @@ static void dma_post(struct ivtv_stream *s)
286 /* flag byteswap ABCD -> DCBA for MPG & VBI data outside irq */ 278 /* flag byteswap ABCD -> DCBA for MPG & VBI data outside irq */
287 if (s->type == IVTV_ENC_STREAM_TYPE_MPG || 279 if (s->type == IVTV_ENC_STREAM_TYPE_MPG ||
288 s->type == IVTV_ENC_STREAM_TYPE_VBI) 280 s->type == IVTV_ENC_STREAM_TYPE_VBI)
289 set_bit(IVTV_F_B_NEED_BUF_SWAP, &buf->b_flags); 281 buf->b_flags |= IVTV_F_B_NEED_BUF_SWAP;
290 } 282 }
291 if (buf) 283 if (buf)
292 buf->bytesused += s->dma_last_offset; 284 buf->bytesused += s->dma_last_offset;
293 if (buf && s->type == IVTV_DEC_STREAM_TYPE_VBI) { 285 if (buf && s->type == IVTV_DEC_STREAM_TYPE_VBI) {
294 list_for_each(p, &s->q_dma.list) { 286 list_for_each_entry(buf, &s->q_dma.list, list) {
295 buf = list_entry(p, struct ivtv_buffer, list);
296
297 /* Parse and Groom VBI Data */ 287 /* Parse and Groom VBI Data */
298 s->q_dma.bytesused -= buf->bytesused; 288 s->q_dma.bytesused -= buf->bytesused;
299 ivtv_process_vbi_data(itv, buf, 0, s->type); 289 ivtv_process_vbi_data(itv, buf, 0, s->type);
@@ -313,7 +303,6 @@ void ivtv_dma_stream_dec_prepare(struct ivtv_stream *s, u32 offset, int lock)
313{ 303{
314 struct ivtv *itv = s->itv; 304 struct ivtv *itv = s->itv;
315 struct ivtv_buffer *buf; 305 struct ivtv_buffer *buf;
316 struct list_head *p;
317 u32 y_size = itv->params.height * itv->params.width; 306 u32 y_size = itv->params.height * itv->params.width;
318 u32 uv_offset = offset + IVTV_YUV_BUFFER_UV_OFFSET; 307 u32 uv_offset = offset + IVTV_YUV_BUFFER_UV_OFFSET;
319 int y_done = 0; 308 int y_done = 0;
@@ -322,18 +311,15 @@ void ivtv_dma_stream_dec_prepare(struct ivtv_stream *s, u32 offset, int lock)
322 int idx = 0; 311 int idx = 0;
323 312
324 IVTV_DEBUG_HI_DMA("DEC PREPARE DMA %s: %08x %08x\n", s->name, s->q_predma.bytesused, offset); 313 IVTV_DEBUG_HI_DMA("DEC PREPARE DMA %s: %08x %08x\n", s->name, s->q_predma.bytesused, offset);
325 buf = list_entry(s->q_predma.list.next, struct ivtv_buffer, list); 314 list_for_each_entry(buf, &s->q_predma.list, list) {
326 list_for_each(p, &s->q_predma.list) {
327 struct ivtv_buffer *buf = list_entry(p, struct ivtv_buffer, list);
328
329 /* YUV UV Offset from Y Buffer */ 315 /* YUV UV Offset from Y Buffer */
330 if (s->type == IVTV_DEC_STREAM_TYPE_YUV && !y_done && bytes_written >= y_size) { 316 if (s->type == IVTV_DEC_STREAM_TYPE_YUV && !y_done && bytes_written >= y_size) {
331 offset = uv_offset; 317 offset = uv_offset;
332 y_done = 1; 318 y_done = 1;
333 } 319 }
334 s->SGarray[idx].src = cpu_to_le32(buf->dma_handle); 320 s->sg_pending[idx].src = buf->dma_handle;
335 s->SGarray[idx].dst = cpu_to_le32(offset); 321 s->sg_pending[idx].dst = offset;
336 s->SGarray[idx].size = cpu_to_le32(buf->bytesused); 322 s->sg_pending[idx].size = buf->bytesused;
337 323
338 offset += buf->bytesused; 324 offset += buf->bytesused;
339 bytes_written += buf->bytesused; 325 bytes_written += buf->bytesused;
@@ -342,10 +328,7 @@ void ivtv_dma_stream_dec_prepare(struct ivtv_stream *s, u32 offset, int lock)
342 ivtv_buf_sync_for_device(s, buf); 328 ivtv_buf_sync_for_device(s, buf);
343 idx++; 329 idx++;
344 } 330 }
345 s->SG_length = idx; 331 s->sg_pending_size = idx;
346
347 /* Mark last buffer size for Interrupt flag */
348 s->SGarray[s->SG_length - 1].size |= cpu_to_le32(0x80000000);
349 332
350 /* Sync Hardware SG List of buffers */ 333 /* Sync Hardware SG List of buffers */
351 ivtv_stream_sync_for_device(s); 334 ivtv_stream_sync_for_device(s);
@@ -361,6 +344,34 @@ void ivtv_dma_stream_dec_prepare(struct ivtv_stream *s, u32 offset, int lock)
361 spin_unlock_irqrestore(&itv->dma_reg_lock, flags); 344 spin_unlock_irqrestore(&itv->dma_reg_lock, flags);
362} 345}
363 346
347static void ivtv_dma_enc_start_xfer(struct ivtv_stream *s)
348{
349 struct ivtv *itv = s->itv;
350
351 s->sg_dma->src = cpu_to_le32(s->sg_processing[s->sg_processed].src);
352 s->sg_dma->dst = cpu_to_le32(s->sg_processing[s->sg_processed].dst);
353 s->sg_dma->size = cpu_to_le32(s->sg_processing[s->sg_processed].size | 0x80000000);
354 s->sg_processed++;
355 /* Sync Hardware SG List of buffers */
356 ivtv_stream_sync_for_device(s);
357 write_reg(s->sg_handle, IVTV_REG_ENCDMAADDR);
358 write_reg_sync(read_reg(IVTV_REG_DMAXFER) | 0x02, IVTV_REG_DMAXFER);
359}
360
361static void ivtv_dma_dec_start_xfer(struct ivtv_stream *s)
362{
363 struct ivtv *itv = s->itv;
364
365 s->sg_dma->src = cpu_to_le32(s->sg_processing[s->sg_processed].src);
366 s->sg_dma->dst = cpu_to_le32(s->sg_processing[s->sg_processed].dst);
367 s->sg_dma->size = cpu_to_le32(s->sg_processing[s->sg_processed].size | 0x80000000);
368 s->sg_processed++;
369 /* Sync Hardware SG List of buffers */
370 ivtv_stream_sync_for_device(s);
371 write_reg(s->sg_handle, IVTV_REG_DECDMAADDR);
372 write_reg_sync(read_reg(IVTV_REG_DMAXFER) | 0x01, IVTV_REG_DMAXFER);
373}
374
364/* start the encoder DMA */ 375/* start the encoder DMA */
365static void ivtv_dma_enc_start(struct ivtv_stream *s) 376static void ivtv_dma_enc_start(struct ivtv_stream *s)
366{ 377{
@@ -374,8 +385,7 @@ static void ivtv_dma_enc_start(struct ivtv_stream *s)
374 ivtv_queue_move(s, &s->q_predma, NULL, &s->q_dma, s->q_predma.bytesused); 385 ivtv_queue_move(s, &s->q_predma, NULL, &s->q_dma, s->q_predma.bytesused);
375 386
376 if (ivtv_use_dma(s)) 387 if (ivtv_use_dma(s))
377 s->SGarray[s->SG_length - 1].size = 388 s->sg_pending[s->sg_pending_size - 1].size += 256;
378 cpu_to_le32(le32_to_cpu(s->SGarray[s->SG_length - 1].size) + 256);
379 389
380 /* If this is an MPEG stream, and VBI data is also pending, then append the 390 /* If this is an MPEG stream, and VBI data is also pending, then append the
381 VBI DMA to the MPEG DMA and transfer both sets of data at once. 391 VBI DMA to the MPEG DMA and transfer both sets of data at once.
@@ -386,43 +396,39 @@ static void ivtv_dma_enc_start(struct ivtv_stream *s)
386 sure we only use the MPEG DMA to transfer the VBI DMA if both are in 396 sure we only use the MPEG DMA to transfer the VBI DMA if both are in
387 use. This way no conflicts occur. */ 397 use. This way no conflicts occur. */
388 clear_bit(IVTV_F_S_DMA_HAS_VBI, &s->s_flags); 398 clear_bit(IVTV_F_S_DMA_HAS_VBI, &s->s_flags);
389 if (s->type == IVTV_ENC_STREAM_TYPE_MPG && s_vbi->SG_length && 399 if (s->type == IVTV_ENC_STREAM_TYPE_MPG && s_vbi->sg_pending_size &&
390 s->SG_length + s_vbi->SG_length <= s->buffers) { 400 s->sg_pending_size + s_vbi->sg_pending_size <= s->buffers) {
391 ivtv_queue_move(s_vbi, &s_vbi->q_predma, NULL, &s_vbi->q_dma, s_vbi->q_predma.bytesused); 401 ivtv_queue_move(s_vbi, &s_vbi->q_predma, NULL, &s_vbi->q_dma, s_vbi->q_predma.bytesused);
392 if (ivtv_use_dma(s_vbi)) 402 if (ivtv_use_dma(s_vbi))
393 s_vbi->SGarray[s_vbi->SG_length - 1].size = cpu_to_le32(le32_to_cpu(s_vbi->SGarray[s->SG_length - 1].size) + 256); 403 s_vbi->sg_pending[s_vbi->sg_pending_size - 1].size += 256;
394 for (i = 0; i < s_vbi->SG_length; i++) { 404 for (i = 0; i < s_vbi->sg_pending_size; i++) {
395 s->SGarray[s->SG_length++] = s_vbi->SGarray[i]; 405 s->sg_pending[s->sg_pending_size++] = s_vbi->sg_pending[i];
396 } 406 }
397 itv->vbi.dma_offset = s_vbi->dma_offset; 407 s_vbi->dma_offset = s_vbi->pending_offset;
398 s_vbi->SG_length = 0; 408 s_vbi->sg_pending_size = 0;
409 s_vbi->dma_xfer_cnt++;
399 set_bit(IVTV_F_S_DMA_HAS_VBI, &s->s_flags); 410 set_bit(IVTV_F_S_DMA_HAS_VBI, &s->s_flags);
400 IVTV_DEBUG_HI_DMA("include DMA for %s\n", s->name); 411 IVTV_DEBUG_HI_DMA("include DMA for %s\n", s->name);
401 } 412 }
402 413
403 /* Mark last buffer size for Interrupt flag */ 414 s->dma_xfer_cnt++;
404 s->SGarray[s->SG_length - 1].size |= cpu_to_le32(0x80000000); 415 memcpy(s->sg_processing, s->sg_pending, sizeof(struct ivtv_sg_element) * s->sg_pending_size);
405 416 s->sg_processing_size = s->sg_pending_size;
406 if (s->type == IVTV_ENC_STREAM_TYPE_VBI) 417 s->sg_pending_size = 0;
407 set_bit(IVTV_F_I_ENC_VBI, &itv->i_flags); 418 s->sg_processed = 0;
408 else 419 s->dma_offset = s->pending_offset;
409 clear_bit(IVTV_F_I_ENC_VBI, &itv->i_flags); 420 s->dma_backup = s->pending_backup;
421 s->dma_pts = s->pending_pts;
410 422
411 if (ivtv_use_pio(s)) { 423 if (ivtv_use_pio(s)) {
412 for (i = 0; i < s->SG_length; i++) {
413 s->PIOarray[i].src = le32_to_cpu(s->SGarray[i].src);
414 s->PIOarray[i].size = le32_to_cpu(s->SGarray[i].size);
415 }
416 set_bit(IVTV_F_I_WORK_HANDLER_PIO, &itv->i_flags); 424 set_bit(IVTV_F_I_WORK_HANDLER_PIO, &itv->i_flags);
417 set_bit(IVTV_F_I_HAVE_WORK, &itv->i_flags); 425 set_bit(IVTV_F_I_HAVE_WORK, &itv->i_flags);
418 set_bit(IVTV_F_I_PIO, &itv->i_flags); 426 set_bit(IVTV_F_I_PIO, &itv->i_flags);
419 itv->cur_pio_stream = s->type; 427 itv->cur_pio_stream = s->type;
420 } 428 }
421 else { 429 else {
422 /* Sync Hardware SG List of buffers */ 430 itv->dma_retries = 0;
423 ivtv_stream_sync_for_device(s); 431 ivtv_dma_enc_start_xfer(s);
424 write_reg(s->SG_handle, IVTV_REG_ENCDMAADDR);
425 write_reg_sync(read_reg(IVTV_REG_DMAXFER) | 0x02, IVTV_REG_DMAXFER);
426 set_bit(IVTV_F_I_DMA, &itv->i_flags); 432 set_bit(IVTV_F_I_DMA, &itv->i_flags);
427 itv->cur_dma_stream = s->type; 433 itv->cur_dma_stream = s->type;
428 itv->dma_timer.expires = jiffies + msecs_to_jiffies(100); 434 itv->dma_timer.expires = jiffies + msecs_to_jiffies(100);
@@ -436,10 +442,15 @@ static void ivtv_dma_dec_start(struct ivtv_stream *s)
436 442
437 if (s->q_predma.bytesused) 443 if (s->q_predma.bytesused)
438 ivtv_queue_move(s, &s->q_predma, NULL, &s->q_dma, s->q_predma.bytesused); 444 ivtv_queue_move(s, &s->q_predma, NULL, &s->q_dma, s->q_predma.bytesused);
445 s->dma_xfer_cnt++;
446 memcpy(s->sg_processing, s->sg_pending, sizeof(struct ivtv_sg_element) * s->sg_pending_size);
447 s->sg_processing_size = s->sg_pending_size;
448 s->sg_pending_size = 0;
449 s->sg_processed = 0;
450
439 IVTV_DEBUG_HI_DMA("start DMA for %s\n", s->name); 451 IVTV_DEBUG_HI_DMA("start DMA for %s\n", s->name);
440 /* put SG Handle into register 0x0c */ 452 itv->dma_retries = 0;
441 write_reg(s->SG_handle, IVTV_REG_DECDMAADDR); 453 ivtv_dma_dec_start_xfer(s);
442 write_reg_sync(read_reg(IVTV_REG_DMAXFER) | 0x01, IVTV_REG_DMAXFER);
443 set_bit(IVTV_F_I_DMA, &itv->i_flags); 454 set_bit(IVTV_F_I_DMA, &itv->i_flags);
444 itv->cur_dma_stream = s->type; 455 itv->cur_dma_stream = s->type;
445 itv->dma_timer.expires = jiffies + msecs_to_jiffies(100); 456 itv->dma_timer.expires = jiffies + msecs_to_jiffies(100);
@@ -450,27 +461,44 @@ static void ivtv_irq_dma_read(struct ivtv *itv)
450{ 461{
451 struct ivtv_stream *s = NULL; 462 struct ivtv_stream *s = NULL;
452 struct ivtv_buffer *buf; 463 struct ivtv_buffer *buf;
453 int hw_stream_type; 464 int hw_stream_type = 0;
454 465
455 IVTV_DEBUG_HI_IRQ("DEC DMA READ\n"); 466 IVTV_DEBUG_HI_IRQ("DEC DMA READ\n");
456 del_timer(&itv->dma_timer); 467 if (!test_bit(IVTV_F_I_UDMA, &itv->i_flags) && itv->cur_dma_stream < 0) {
457 if (read_reg(IVTV_REG_DMASTATUS) & 0x14) { 468 del_timer(&itv->dma_timer);
458 IVTV_DEBUG_WARN("DEC DMA ERROR %x\n", read_reg(IVTV_REG_DMASTATUS)); 469 return;
459 write_reg(read_reg(IVTV_REG_DMASTATUS) & 3, IVTV_REG_DMASTATUS);
460 } 470 }
471
461 if (!test_bit(IVTV_F_I_UDMA, &itv->i_flags)) { 472 if (!test_bit(IVTV_F_I_UDMA, &itv->i_flags)) {
462 if (test_bit(IVTV_F_I_DEC_YUV, &itv->i_flags)) { 473 s = &itv->streams[itv->cur_dma_stream];
463 s = &itv->streams[IVTV_DEC_STREAM_TYPE_YUV]; 474 ivtv_stream_sync_for_cpu(s);
464 hw_stream_type = 2; 475
476 if (read_reg(IVTV_REG_DMASTATUS) & 0x14) {
477 IVTV_DEBUG_WARN("DEC DMA ERROR %x (xfer %d of %d, retry %d)\n",
478 read_reg(IVTV_REG_DMASTATUS),
479 s->sg_processed, s->sg_processing_size, itv->dma_retries);
480 write_reg(read_reg(IVTV_REG_DMASTATUS) & 3, IVTV_REG_DMASTATUS);
481 if (itv->dma_retries == 3) {
482 /* Too many retries, give up on this frame */
483 itv->dma_retries = 0;
484 s->sg_processed = s->sg_processing_size;
485 }
486 else {
487 /* Retry, starting with the first xfer segment.
488 Just retrying the current segment is not sufficient. */
489 s->sg_processed = 0;
490 itv->dma_retries++;
491 }
465 } 492 }
466 else { 493 if (s->sg_processed < s->sg_processing_size) {
467 s = &itv->streams[IVTV_DEC_STREAM_TYPE_MPG]; 494 /* DMA next buffer */
468 hw_stream_type = 0; 495 ivtv_dma_dec_start_xfer(s);
496 return;
469 } 497 }
498 if (s->type == IVTV_DEC_STREAM_TYPE_YUV)
499 hw_stream_type = 2;
470 IVTV_DEBUG_HI_DMA("DEC DATA READ %s: %d\n", s->name, s->q_dma.bytesused); 500 IVTV_DEBUG_HI_DMA("DEC DATA READ %s: %d\n", s->name, s->q_dma.bytesused);
471 501
472 ivtv_stream_sync_for_cpu(s);
473
474 /* For some reason must kick the firmware, like PIO mode, 502 /* For some reason must kick the firmware, like PIO mode,
475 I think this tells the firmware we are done and the size 503 I think this tells the firmware we are done and the size
476 of the xfer so it can calculate what we need next. 504 of the xfer so it can calculate what we need next.
@@ -487,6 +515,7 @@ static void ivtv_irq_dma_read(struct ivtv *itv)
487 } 515 }
488 wake_up(&s->waitq); 516 wake_up(&s->waitq);
489 } 517 }
518 del_timer(&itv->dma_timer);
490 clear_bit(IVTV_F_I_UDMA, &itv->i_flags); 519 clear_bit(IVTV_F_I_UDMA, &itv->i_flags);
491 clear_bit(IVTV_F_I_DMA, &itv->i_flags); 520 clear_bit(IVTV_F_I_DMA, &itv->i_flags);
492 itv->cur_dma_stream = -1; 521 itv->cur_dma_stream = -1;
@@ -498,33 +527,46 @@ static void ivtv_irq_enc_dma_complete(struct ivtv *itv)
498 u32 data[CX2341X_MBOX_MAX_DATA]; 527 u32 data[CX2341X_MBOX_MAX_DATA];
499 struct ivtv_stream *s; 528 struct ivtv_stream *s;
500 529
501 del_timer(&itv->dma_timer);
502 ivtv_api_get_data(&itv->enc_mbox, IVTV_MBOX_DMA_END, data); 530 ivtv_api_get_data(&itv->enc_mbox, IVTV_MBOX_DMA_END, data);
503 IVTV_DEBUG_HI_IRQ("ENC DMA COMPLETE %x %d\n", data[0], data[1]); 531 IVTV_DEBUG_HI_IRQ("ENC DMA COMPLETE %x %d (%d)\n", data[0], data[1], itv->cur_dma_stream);
504 if (test_and_clear_bit(IVTV_F_I_ENC_VBI, &itv->i_flags)) 532 if (itv->cur_dma_stream < 0) {
505 data[1] = 3; 533 del_timer(&itv->dma_timer);
506 else if (data[1] > 2)
507 return; 534 return;
508 s = &itv->streams[ivtv_stream_map[data[1]]]; 535 }
536 s = &itv->streams[itv->cur_dma_stream];
537 ivtv_stream_sync_for_cpu(s);
538
509 if (data[0] & 0x18) { 539 if (data[0] & 0x18) {
510 IVTV_DEBUG_WARN("ENC DMA ERROR %x\n", data[0]); 540 IVTV_DEBUG_WARN("ENC DMA ERROR %x (offset %08x, xfer %d of %d, retry %d)\n", data[0],
541 s->dma_offset, s->sg_processed, s->sg_processing_size, itv->dma_retries);
511 write_reg(read_reg(IVTV_REG_DMASTATUS) & 3, IVTV_REG_DMASTATUS); 542 write_reg(read_reg(IVTV_REG_DMASTATUS) & 3, IVTV_REG_DMASTATUS);
512 ivtv_vapi(itv, CX2341X_ENC_SCHED_DMA_TO_HOST, 3, 0, 0, data[1]); 543 if (itv->dma_retries == 3) {
544 /* Too many retries, give up on this frame */
545 itv->dma_retries = 0;
546 s->sg_processed = s->sg_processing_size;
547 }
548 else {
549 /* Retry, starting with the first xfer segment.
550 Just retrying the current segment is not sufficient. */
551 s->sg_processed = 0;
552 itv->dma_retries++;
553 }
554 }
555 if (s->sg_processed < s->sg_processing_size) {
556 /* DMA next buffer */
557 ivtv_dma_enc_start_xfer(s);
558 return;
513 } 559 }
514 s->SG_length = 0; 560 del_timer(&itv->dma_timer);
515 clear_bit(IVTV_F_I_DMA, &itv->i_flags); 561 clear_bit(IVTV_F_I_DMA, &itv->i_flags);
516 itv->cur_dma_stream = -1; 562 itv->cur_dma_stream = -1;
517 dma_post(s); 563 dma_post(s);
518 ivtv_stream_sync_for_cpu(s);
519 if (test_and_clear_bit(IVTV_F_S_DMA_HAS_VBI, &s->s_flags)) { 564 if (test_and_clear_bit(IVTV_F_S_DMA_HAS_VBI, &s->s_flags)) {
520 u32 tmp;
521
522 s = &itv->streams[IVTV_ENC_STREAM_TYPE_VBI]; 565 s = &itv->streams[IVTV_ENC_STREAM_TYPE_VBI];
523 tmp = s->dma_offset;
524 s->dma_offset = itv->vbi.dma_offset;
525 dma_post(s); 566 dma_post(s);
526 s->dma_offset = tmp;
527 } 567 }
568 s->sg_processing_size = 0;
569 s->sg_processed = 0;
528 wake_up(&itv->dma_waitq); 570 wake_up(&itv->dma_waitq);
529} 571}
530 572
@@ -538,8 +580,6 @@ static void ivtv_irq_enc_pio_complete(struct ivtv *itv)
538 } 580 }
539 s = &itv->streams[itv->cur_pio_stream]; 581 s = &itv->streams[itv->cur_pio_stream];
540 IVTV_DEBUG_HI_IRQ("ENC PIO COMPLETE %s\n", s->name); 582 IVTV_DEBUG_HI_IRQ("ENC PIO COMPLETE %s\n", s->name);
541 s->SG_length = 0;
542 clear_bit(IVTV_F_I_ENC_VBI, &itv->i_flags);
543 clear_bit(IVTV_F_I_PIO, &itv->i_flags); 583 clear_bit(IVTV_F_I_PIO, &itv->i_flags);
544 itv->cur_pio_stream = -1; 584 itv->cur_pio_stream = -1;
545 dma_post(s); 585 dma_post(s);
@@ -551,13 +591,8 @@ static void ivtv_irq_enc_pio_complete(struct ivtv *itv)
551 ivtv_vapi(itv, CX2341X_ENC_SCHED_DMA_TO_HOST, 3, 0, 0, 2); 591 ivtv_vapi(itv, CX2341X_ENC_SCHED_DMA_TO_HOST, 3, 0, 0, 2);
552 clear_bit(IVTV_F_I_PIO, &itv->i_flags); 592 clear_bit(IVTV_F_I_PIO, &itv->i_flags);
553 if (test_and_clear_bit(IVTV_F_S_DMA_HAS_VBI, &s->s_flags)) { 593 if (test_and_clear_bit(IVTV_F_S_DMA_HAS_VBI, &s->s_flags)) {
554 u32 tmp;
555
556 s = &itv->streams[IVTV_ENC_STREAM_TYPE_VBI]; 594 s = &itv->streams[IVTV_ENC_STREAM_TYPE_VBI];
557 tmp = s->dma_offset;
558 s->dma_offset = itv->vbi.dma_offset;
559 dma_post(s); 595 dma_post(s);
560 s->dma_offset = tmp;
561 } 596 }
562 wake_up(&itv->dma_waitq); 597 wake_up(&itv->dma_waitq);
563} 598}
@@ -569,19 +604,23 @@ static void ivtv_irq_dma_err(struct ivtv *itv)
569 del_timer(&itv->dma_timer); 604 del_timer(&itv->dma_timer);
570 ivtv_api_get_data(&itv->enc_mbox, IVTV_MBOX_DMA_END, data); 605 ivtv_api_get_data(&itv->enc_mbox, IVTV_MBOX_DMA_END, data);
571 IVTV_DEBUG_WARN("DMA ERROR %08x %08x %08x %d\n", data[0], data[1], 606 IVTV_DEBUG_WARN("DMA ERROR %08x %08x %08x %d\n", data[0], data[1],
572 read_reg(IVTV_REG_DMASTATUS), itv->cur_dma_stream); 607 read_reg(IVTV_REG_DMASTATUS), itv->cur_dma_stream);
608 write_reg(read_reg(IVTV_REG_DMASTATUS) & 3, IVTV_REG_DMASTATUS);
573 if (!test_bit(IVTV_F_I_UDMA, &itv->i_flags) && 609 if (!test_bit(IVTV_F_I_UDMA, &itv->i_flags) &&
574 itv->cur_dma_stream >= 0 && itv->cur_dma_stream < IVTV_MAX_STREAMS) { 610 itv->cur_dma_stream >= 0 && itv->cur_dma_stream < IVTV_MAX_STREAMS) {
575 struct ivtv_stream *s = &itv->streams[itv->cur_dma_stream]; 611 struct ivtv_stream *s = &itv->streams[itv->cur_dma_stream];
576 612
577 /* retry */ 613 /* retry */
578 write_reg(read_reg(IVTV_REG_DMASTATUS) & 3, IVTV_REG_DMASTATUS);
579 if (s->type >= IVTV_DEC_STREAM_TYPE_MPG) 614 if (s->type >= IVTV_DEC_STREAM_TYPE_MPG)
580 ivtv_dma_dec_start(s); 615 ivtv_dma_dec_start(s);
581 else 616 else
582 ivtv_dma_enc_start(s); 617 ivtv_dma_enc_start(s);
583 return; 618 return;
584 } 619 }
620 if (test_bit(IVTV_F_I_UDMA, &itv->i_flags)) {
621 ivtv_udma_start(itv);
622 return;
623 }
585 clear_bit(IVTV_F_I_UDMA, &itv->i_flags); 624 clear_bit(IVTV_F_I_UDMA, &itv->i_flags);
586 clear_bit(IVTV_F_I_DMA, &itv->i_flags); 625 clear_bit(IVTV_F_I_DMA, &itv->i_flags);
587 itv->cur_dma_stream = -1; 626 itv->cur_dma_stream = -1;
@@ -625,14 +664,12 @@ static void ivtv_irq_enc_vbi_cap(struct ivtv *itv)
625 DMA the data. Since at most four VBI DMA buffers are available, 664 DMA the data. Since at most four VBI DMA buffers are available,
626 we just drop the old requests when there are already three 665 we just drop the old requests when there are already three
627 requests queued. */ 666 requests queued. */
628 if (s->SG_length > 2) { 667 if (s->sg_pending_size > 2) {
629 struct list_head *p; 668 struct ivtv_buffer *buf;
630 list_for_each(p, &s->q_predma.list) { 669 list_for_each_entry(buf, &s->q_predma.list, list)
631 struct ivtv_buffer *buf = list_entry(p, struct ivtv_buffer, list);
632 ivtv_buf_sync_for_cpu(s, buf); 670 ivtv_buf_sync_for_cpu(s, buf);
633 }
634 ivtv_queue_move(s, &s->q_predma, NULL, &s->q_free, 0); 671 ivtv_queue_move(s, &s->q_predma, NULL, &s->q_free, 0);
635 s->SG_length = 0; 672 s->sg_pending_size = 0;
636 } 673 }
637 /* if we can append the data, and the MPEG stream isn't capturing, 674 /* if we can append the data, and the MPEG stream isn't capturing,
638 then start a DMA request for just the VBI data. */ 675 then start a DMA request for just the VBI data. */
@@ -698,23 +735,27 @@ static void ivtv_irq_vsync(struct ivtv *itv)
698 735
699 if (0) IVTV_DEBUG_IRQ("DEC VSYNC\n"); 736 if (0) IVTV_DEBUG_IRQ("DEC VSYNC\n");
700 737
701 if (((frame ^ itv->yuv_info.lace_sync_field) == 0 && ((itv->lastVsyncFrame & 1) ^ itv->yuv_info.lace_sync_field)) || 738 if (((frame ^ itv->yuv_info.sync_field[last_dma_frame]) == 0 &&
702 (frame != (itv->lastVsyncFrame & 1) && !itv->yuv_info.frame_interlaced)) { 739 ((itv->last_vsync_field & 1) ^ itv->yuv_info.sync_field[last_dma_frame])) ||
740 (frame != (itv->last_vsync_field & 1) && !itv->yuv_info.frame_interlaced)) {
703 int next_dma_frame = last_dma_frame; 741 int next_dma_frame = last_dma_frame;
704 742
705 if (next_dma_frame >= 0 && next_dma_frame != atomic_read(&itv->yuv_info.next_fill_frame)) { 743 if (!(itv->yuv_info.frame_interlaced && itv->yuv_info.field_delay[next_dma_frame] && itv->yuv_info.fields_lapsed < 1)) {
706 write_reg(yuv_offset[next_dma_frame] >> 4, 0x82c); 744 if (next_dma_frame >= 0 && next_dma_frame != atomic_read(&itv->yuv_info.next_fill_frame)) {
707 write_reg((yuv_offset[next_dma_frame] + IVTV_YUV_BUFFER_UV_OFFSET) >> 4, 0x830); 745 write_reg(yuv_offset[next_dma_frame] >> 4, 0x82c);
708 write_reg(yuv_offset[next_dma_frame] >> 4, 0x834); 746 write_reg((yuv_offset[next_dma_frame] + IVTV_YUV_BUFFER_UV_OFFSET) >> 4, 0x830);
709 write_reg((yuv_offset[next_dma_frame] + IVTV_YUV_BUFFER_UV_OFFSET) >> 4, 0x838); 747 write_reg(yuv_offset[next_dma_frame] >> 4, 0x834);
710 next_dma_frame = (next_dma_frame + 1) & 0x3; 748 write_reg((yuv_offset[next_dma_frame] + IVTV_YUV_BUFFER_UV_OFFSET) >> 4, 0x838);
711 atomic_set(&itv->yuv_info.next_dma_frame, next_dma_frame); 749 next_dma_frame = (next_dma_frame + 1) & 0x3;
750 atomic_set(&itv->yuv_info.next_dma_frame, next_dma_frame);
751 itv->yuv_info.fields_lapsed = -1;
752 }
712 } 753 }
713 } 754 }
714 if (frame != (itv->lastVsyncFrame & 1)) { 755 if (frame != (itv->last_vsync_field & 1)) {
715 struct ivtv_stream *s = ivtv_get_output_stream(itv); 756 struct ivtv_stream *s = ivtv_get_output_stream(itv);
716 757
717 itv->lastVsyncFrame += 1; 758 itv->last_vsync_field += 1;
718 if (frame == 0) { 759 if (frame == 0) {
719 clear_bit(IVTV_F_I_VALID_DEC_TIMINGS, &itv->i_flags); 760 clear_bit(IVTV_F_I_VALID_DEC_TIMINGS, &itv->i_flags);
720 clear_bit(IVTV_F_I_EV_VSYNC_FIELD, &itv->i_flags); 761 clear_bit(IVTV_F_I_EV_VSYNC_FIELD, &itv->i_flags);
@@ -731,7 +772,10 @@ static void ivtv_irq_vsync(struct ivtv *itv)
731 wake_up(&s->waitq); 772 wake_up(&s->waitq);
732 773
733 /* Send VBI to saa7127 */ 774 /* Send VBI to saa7127 */
734 if (frame) { 775 if (frame && (itv->output_mode == OUT_PASSTHROUGH ||
776 test_bit(IVTV_F_I_UPDATE_WSS, &itv->i_flags) ||
777 test_bit(IVTV_F_I_UPDATE_VPS, &itv->i_flags) ||
778 test_bit(IVTV_F_I_UPDATE_CC, &itv->i_flags))) {
735 set_bit(IVTV_F_I_WORK_HANDLER_VBI, &itv->i_flags); 779 set_bit(IVTV_F_I_WORK_HANDLER_VBI, &itv->i_flags);
736 set_bit(IVTV_F_I_HAVE_WORK, &itv->i_flags); 780 set_bit(IVTV_F_I_HAVE_WORK, &itv->i_flags);
737 } 781 }
@@ -749,10 +793,12 @@ static void ivtv_irq_vsync(struct ivtv *itv)
749 set_bit(IVTV_F_I_HAVE_WORK, &itv->i_flags); 793 set_bit(IVTV_F_I_HAVE_WORK, &itv->i_flags);
750 } 794 }
751 } 795 }
796
797 itv->yuv_info.fields_lapsed ++;
752 } 798 }
753} 799}
754 800
755#define IVTV_IRQ_DMA (IVTV_IRQ_DMA_READ | IVTV_IRQ_ENC_DMA_COMPLETE | IVTV_IRQ_DMA_ERR | IVTV_IRQ_ENC_START_CAP | IVTV_IRQ_ENC_VBI_CAP | IVTV_IRQ_DEC_DATA_REQ) 801#define IVTV_IRQ_DMA (IVTV_IRQ_DMA_READ | IVTV_IRQ_ENC_DMA_COMPLETE | IVTV_IRQ_DMA_ERR | IVTV_IRQ_ENC_START_CAP | IVTV_IRQ_ENC_VBI_CAP | IVTV_IRQ_DEC_DATA_REQ | IVTV_IRQ_DEC_VBI_RE_INSERT)
756 802
757irqreturn_t ivtv_irq_handler(int irq, void *dev_id) 803irqreturn_t ivtv_irq_handler(int irq, void *dev_id)
758{ 804{
@@ -777,7 +823,7 @@ irqreturn_t ivtv_irq_handler(int irq, void *dev_id)
777 */ 823 */
778 if (~itv->irqmask & IVTV_IRQ_DEC_VSYNC) { 824 if (~itv->irqmask & IVTV_IRQ_DEC_VSYNC) {
779 /* vsync is enabled, see if we're in a new field */ 825 /* vsync is enabled, see if we're in a new field */
780 if ((itv->lastVsyncFrame & 1) != (read_reg(0x28c0) & 1)) { 826 if ((itv->last_vsync_field & 1) != (read_reg(0x28c0) & 1)) {
781 /* New field, looks like we missed it */ 827 /* New field, looks like we missed it */
782 IVTV_DEBUG_YUV("VSync interrupt missed %d\n",read_reg(0x28c0)>>16); 828 IVTV_DEBUG_YUV("VSync interrupt missed %d\n",read_reg(0x28c0)>>16);
783 vsync_force = 1; 829 vsync_force = 1;
@@ -831,7 +877,7 @@ irqreturn_t ivtv_irq_handler(int irq, void *dev_id)
831 if (combo & IVTV_IRQ_ENC_EOS) { 877 if (combo & IVTV_IRQ_ENC_EOS) {
832 IVTV_DEBUG_IRQ("ENC EOS\n"); 878 IVTV_DEBUG_IRQ("ENC EOS\n");
833 set_bit(IVTV_F_I_EOS, &itv->i_flags); 879 set_bit(IVTV_F_I_EOS, &itv->i_flags);
834 wake_up(&itv->cap_w); 880 wake_up(&itv->eos_waitq);
835 } 881 }
836 882
837 if (combo & IVTV_IRQ_DEC_DATA_REQ) { 883 if (combo & IVTV_IRQ_DEC_DATA_REQ) {
@@ -853,8 +899,9 @@ irqreturn_t ivtv_irq_handler(int irq, void *dev_id)
853 } 899 }
854 900
855 if ((combo & IVTV_IRQ_DMA) && !test_bit(IVTV_F_I_DMA, &itv->i_flags)) { 901 if ((combo & IVTV_IRQ_DMA) && !test_bit(IVTV_F_I_DMA, &itv->i_flags)) {
902 itv->irq_rr_idx++;
856 for (i = 0; i < IVTV_MAX_STREAMS; i++) { 903 for (i = 0; i < IVTV_MAX_STREAMS; i++) {
857 int idx = (i + itv->irq_rr_idx++) % IVTV_MAX_STREAMS; 904 int idx = (i + itv->irq_rr_idx) % IVTV_MAX_STREAMS;
858 struct ivtv_stream *s = &itv->streams[idx]; 905 struct ivtv_stream *s = &itv->streams[idx];
859 906
860 if (!test_and_clear_bit(IVTV_F_S_DMA_PENDING, &s->s_flags)) 907 if (!test_and_clear_bit(IVTV_F_S_DMA_PENDING, &s->s_flags))
@@ -871,8 +918,9 @@ irqreturn_t ivtv_irq_handler(int irq, void *dev_id)
871 } 918 }
872 919
873 if ((combo & IVTV_IRQ_DMA) && !test_bit(IVTV_F_I_PIO, &itv->i_flags)) { 920 if ((combo & IVTV_IRQ_DMA) && !test_bit(IVTV_F_I_PIO, &itv->i_flags)) {
921 itv->irq_rr_idx++;
874 for (i = 0; i < IVTV_MAX_STREAMS; i++) { 922 for (i = 0; i < IVTV_MAX_STREAMS; i++) {
875 int idx = (i + itv->irq_rr_idx++) % IVTV_MAX_STREAMS; 923 int idx = (i + itv->irq_rr_idx) % IVTV_MAX_STREAMS;
876 struct ivtv_stream *s = &itv->streams[idx]; 924 struct ivtv_stream *s = &itv->streams[idx];
877 925
878 if (!test_and_clear_bit(IVTV_F_S_PIO_PENDING, &s->s_flags)) 926 if (!test_and_clear_bit(IVTV_F_S_PIO_PENDING, &s->s_flags))
@@ -883,8 +931,9 @@ irqreturn_t ivtv_irq_handler(int irq, void *dev_id)
883 } 931 }
884 } 932 }
885 933
886 if (test_and_clear_bit(IVTV_F_I_HAVE_WORK, &itv->i_flags)) 934 if (test_and_clear_bit(IVTV_F_I_HAVE_WORK, &itv->i_flags)) {
887 queue_work(itv->irq_work_queues, &itv->irq_work_queue); 935 queue_work(itv->irq_work_queues, &itv->irq_work_queue);
936 }
888 937
889 spin_unlock(&itv->dma_reg_lock); 938 spin_unlock(&itv->dma_reg_lock);
890 939
diff --git a/drivers/media/video/ivtv/ivtv-irq.h b/drivers/media/video/ivtv/ivtv-irq.h
index a43348a30309..f879a5822e71 100644
--- a/drivers/media/video/ivtv/ivtv-irq.h
+++ b/drivers/media/video/ivtv/ivtv-irq.h
@@ -19,8 +19,35 @@
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */ 20 */
21 21
22#ifndef IVTV_IRQ_H
23#define IVTV_IRQ_H
24
25#define IVTV_IRQ_ENC_START_CAP (0x1 << 31)
26#define IVTV_IRQ_ENC_EOS (0x1 << 30)
27#define IVTV_IRQ_ENC_VBI_CAP (0x1 << 29)
28#define IVTV_IRQ_ENC_VIM_RST (0x1 << 28)
29#define IVTV_IRQ_ENC_DMA_COMPLETE (0x1 << 27)
30#define IVTV_IRQ_ENC_PIO_COMPLETE (0x1 << 25)
31#define IVTV_IRQ_DEC_AUD_MODE_CHG (0x1 << 24)
32#define IVTV_IRQ_DEC_DATA_REQ (0x1 << 22)
33#define IVTV_IRQ_DEC_DMA_COMPLETE (0x1 << 20)
34#define IVTV_IRQ_DEC_VBI_RE_INSERT (0x1 << 19)
35#define IVTV_IRQ_DMA_ERR (0x1 << 18)
36#define IVTV_IRQ_DMA_WRITE (0x1 << 17)
37#define IVTV_IRQ_DMA_READ (0x1 << 16)
38#define IVTV_IRQ_DEC_VSYNC (0x1 << 10)
39
40/* IRQ Masks */
41#define IVTV_IRQ_MASK_INIT (IVTV_IRQ_DMA_ERR|IVTV_IRQ_ENC_DMA_COMPLETE|\
42 IVTV_IRQ_DMA_READ|IVTV_IRQ_ENC_PIO_COMPLETE)
43
44#define IVTV_IRQ_MASK_CAPTURE (IVTV_IRQ_ENC_START_CAP | IVTV_IRQ_ENC_EOS)
45#define IVTV_IRQ_MASK_DECODE (IVTV_IRQ_DEC_DATA_REQ|IVTV_IRQ_DEC_AUD_MODE_CHG)
46
22irqreturn_t ivtv_irq_handler(int irq, void *dev_id); 47irqreturn_t ivtv_irq_handler(int irq, void *dev_id);
23 48
24void ivtv_irq_work_handler(struct work_struct *work); 49void ivtv_irq_work_handler(struct work_struct *work);
25void ivtv_dma_stream_dec_prepare(struct ivtv_stream *s, u32 offset, int lock); 50void ivtv_dma_stream_dec_prepare(struct ivtv_stream *s, u32 offset, int lock);
26void ivtv_unfinished_dma(unsigned long arg); 51void ivtv_unfinished_dma(unsigned long arg);
52
53#endif
diff --git a/drivers/media/video/ivtv/ivtv-mailbox.c b/drivers/media/video/ivtv/ivtv-mailbox.c
index 5e3b679202ae..b05436da7136 100644
--- a/drivers/media/video/ivtv/ivtv-mailbox.c
+++ b/drivers/media/video/ivtv/ivtv-mailbox.c
@@ -225,15 +225,15 @@ static int ivtv_api_call(struct ivtv *itv, int cmd, int args, u32 data[])
225 } 225 }
226 if (args < 0 || args > CX2341X_MBOX_MAX_DATA || 226 if (args < 0 || args > CX2341X_MBOX_MAX_DATA ||
227 cmd < 0 || cmd > 255 || api_info[cmd].name == NULL) { 227 cmd < 0 || cmd > 255 || api_info[cmd].name == NULL) {
228 IVTV_ERR("Invalid API call: cmd = 0x%02x, args = %d\n", cmd, args); 228 IVTV_ERR("Invalid MB call: cmd = 0x%02x, args = %d\n", cmd, args);
229 return -EINVAL; 229 return -EINVAL;
230 } 230 }
231 231
232 if (api_info[cmd].flags & API_HIGH_VOL) { 232 if (api_info[cmd].flags & API_HIGH_VOL) {
233 IVTV_DEBUG_HI_API("API Call: %s\n", api_info[cmd].name); 233 IVTV_DEBUG_HI_MB("MB Call: %s\n", api_info[cmd].name);
234 } 234 }
235 else { 235 else {
236 IVTV_DEBUG_API("API Call: %s\n", api_info[cmd].name); 236 IVTV_DEBUG_MB("MB Call: %s\n", api_info[cmd].name);
237 } 237 }
238 238
239 /* clear possibly uninitialized part of data array */ 239 /* clear possibly uninitialized part of data array */
diff --git a/drivers/media/video/ivtv/ivtv-mailbox.h b/drivers/media/video/ivtv/ivtv-mailbox.h
index 79b8aec14370..71a54eef8fc7 100644
--- a/drivers/media/video/ivtv/ivtv-mailbox.h
+++ b/drivers/media/video/ivtv/ivtv-mailbox.h
@@ -18,8 +18,16 @@
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */ 19 */
20 20
21#ifndef IVTV_MAILBOX_H
22#define IVTV_MAILBOX_H
23
24#define IVTV_MBOX_DMA_END 8
25#define IVTV_MBOX_DMA 9
26
21void ivtv_api_get_data(struct ivtv_mailbox_data *mbox, int mb, u32 data[]); 27void ivtv_api_get_data(struct ivtv_mailbox_data *mbox, int mb, u32 data[]);
22int ivtv_api(struct ivtv *itv, int cmd, int args, u32 data[]); 28int ivtv_api(struct ivtv *itv, int cmd, int args, u32 data[]);
23int ivtv_vapi_result(struct ivtv *itv, u32 data[CX2341X_MBOX_MAX_DATA], int cmd, int args, ...); 29int ivtv_vapi_result(struct ivtv *itv, u32 data[CX2341X_MBOX_MAX_DATA], int cmd, int args, ...);
24int ivtv_vapi(struct ivtv *itv, int cmd, int args, ...); 30int ivtv_vapi(struct ivtv *itv, int cmd, int args, ...);
25int ivtv_api_func(void *priv, int cmd, int in, int out, u32 data[CX2341X_MBOX_MAX_DATA]); 31int ivtv_api_func(void *priv, int cmd, int in, int out, u32 data[CX2341X_MBOX_MAX_DATA]);
32
33#endif
diff --git a/drivers/media/video/ivtv/ivtv-queue.c b/drivers/media/video/ivtv/ivtv-queue.c
index a04f9387f63d..39a216713244 100644
--- a/drivers/media/video/ivtv/ivtv-queue.c
+++ b/drivers/media/video/ivtv/ivtv-queue.c
@@ -20,9 +20,7 @@
20 */ 20 */
21 21
22#include "ivtv-driver.h" 22#include "ivtv-driver.h"
23#include "ivtv-streams.h"
24#include "ivtv-queue.h" 23#include "ivtv-queue.h"
25#include "ivtv-mailbox.h"
26 24
27int ivtv_buf_copy_from_user(struct ivtv_stream *s, struct ivtv_buffer *buf, const char __user *src, int copybytes) 25int ivtv_buf_copy_from_user(struct ivtv_stream *s, struct ivtv_buffer *buf, const char __user *src, int copybytes)
28{ 26{
@@ -60,6 +58,7 @@ void ivtv_enqueue(struct ivtv_stream *s, struct ivtv_buffer *buf, struct ivtv_qu
60 buf->bytesused = 0; 58 buf->bytesused = 0;
61 buf->readpos = 0; 59 buf->readpos = 0;
62 buf->b_flags = 0; 60 buf->b_flags = 0;
61 buf->dma_xfer_cnt = 0;
63 } 62 }
64 spin_lock_irqsave(&s->qlock, flags); 63 spin_lock_irqsave(&s->qlock, flags);
65 list_add_tail(&buf->list, &q->list); 64 list_add_tail(&buf->list, &q->list);
@@ -87,7 +86,7 @@ struct ivtv_buffer *ivtv_dequeue(struct ivtv_stream *s, struct ivtv_queue *q)
87} 86}
88 87
89static void ivtv_queue_move_buf(struct ivtv_stream *s, struct ivtv_queue *from, 88static void ivtv_queue_move_buf(struct ivtv_stream *s, struct ivtv_queue *from,
90 struct ivtv_queue *to, int clear, int full) 89 struct ivtv_queue *to, int clear)
91{ 90{
92 struct ivtv_buffer *buf = list_entry(from->list.next, struct ivtv_buffer, list); 91 struct ivtv_buffer *buf = list_entry(from->list.next, struct ivtv_buffer, list);
93 92
@@ -97,13 +96,7 @@ static void ivtv_queue_move_buf(struct ivtv_stream *s, struct ivtv_queue *from,
97 from->bytesused -= buf->bytesused - buf->readpos; 96 from->bytesused -= buf->bytesused - buf->readpos;
98 /* special handling for q_free */ 97 /* special handling for q_free */
99 if (clear) 98 if (clear)
100 buf->bytesused = buf->readpos = buf->b_flags = 0; 99 buf->bytesused = buf->readpos = buf->b_flags = buf->dma_xfer_cnt = 0;
101 else if (full) {
102 /* special handling for stolen buffers, assume
103 all bytes are used. */
104 buf->bytesused = s->buf_size;
105 buf->readpos = buf->b_flags = 0;
106 }
107 to->buffers++; 100 to->buffers++;
108 to->length += s->buf_size; 101 to->length += s->buf_size;
109 to->bytesused += buf->bytesused - buf->readpos; 102 to->bytesused += buf->bytesused - buf->readpos;
@@ -112,7 +105,7 @@ static void ivtv_queue_move_buf(struct ivtv_stream *s, struct ivtv_queue *from,
112/* Move 'needed_bytes' worth of buffers from queue 'from' into queue 'to'. 105/* Move 'needed_bytes' worth of buffers from queue 'from' into queue 'to'.
113 If 'needed_bytes' == 0, then move all buffers from 'from' into 'to'. 106 If 'needed_bytes' == 0, then move all buffers from 'from' into 'to'.
114 If 'steal' != NULL, then buffers may also taken from that queue if 107 If 'steal' != NULL, then buffers may also taken from that queue if
115 needed. 108 needed, but only if 'from' is the free queue.
116 109
117 The buffer is automatically cleared if it goes to the free queue. It is 110 The buffer is automatically cleared if it goes to the free queue. It is
118 also cleared if buffers need to be taken from the 'steal' queue and 111 also cleared if buffers need to be taken from the 'steal' queue and
@@ -133,7 +126,7 @@ int ivtv_queue_move(struct ivtv_stream *s, struct ivtv_queue *from, struct ivtv_
133 int rc = 0; 126 int rc = 0;
134 int from_free = from == &s->q_free; 127 int from_free = from == &s->q_free;
135 int to_free = to == &s->q_free; 128 int to_free = to == &s->q_free;
136 int bytes_available; 129 int bytes_available, bytes_steal;
137 130
138 spin_lock_irqsave(&s->qlock, flags); 131 spin_lock_irqsave(&s->qlock, flags);
139 if (needed_bytes == 0) { 132 if (needed_bytes == 0) {
@@ -142,32 +135,47 @@ int ivtv_queue_move(struct ivtv_stream *s, struct ivtv_queue *from, struct ivtv_
142 } 135 }
143 136
144 bytes_available = from_free ? from->length : from->bytesused; 137 bytes_available = from_free ? from->length : from->bytesused;
145 bytes_available += steal ? steal->length : 0; 138 bytes_steal = (from_free && steal) ? steal->length : 0;
146 139
147 if (bytes_available < needed_bytes) { 140 if (bytes_available + bytes_steal < needed_bytes) {
148 spin_unlock_irqrestore(&s->qlock, flags); 141 spin_unlock_irqrestore(&s->qlock, flags);
149 return -ENOMEM; 142 return -ENOMEM;
150 } 143 }
144 while (bytes_available < needed_bytes) {
145 struct ivtv_buffer *buf = list_entry(steal->list.prev, struct ivtv_buffer, list);
146 u16 dma_xfer_cnt = buf->dma_xfer_cnt;
147
148 /* move buffers from the tail of the 'steal' queue to the tail of the
149 'from' queue. Always copy all the buffers with the same dma_xfer_cnt
150 value, this ensures that you do not end up with partial frame data
151 if one frame is stored in multiple buffers. */
152 while (dma_xfer_cnt == buf->dma_xfer_cnt) {
153 list_move_tail(steal->list.prev, &from->list);
154 rc++;
155 steal->buffers--;
156 steal->length -= s->buf_size;
157 steal->bytesused -= buf->bytesused - buf->readpos;
158 buf->bytesused = buf->readpos = buf->b_flags = buf->dma_xfer_cnt = 0;
159 from->buffers++;
160 from->length += s->buf_size;
161 bytes_available += s->buf_size;
162 if (list_empty(&steal->list))
163 break;
164 buf = list_entry(steal->list.prev, struct ivtv_buffer, list);
165 }
166 }
151 if (from_free) { 167 if (from_free) {
152 u32 old_length = to->length; 168 u32 old_length = to->length;
153 169
154 while (to->length - old_length < needed_bytes) { 170 while (to->length - old_length < needed_bytes) {
155 if (list_empty(&from->list)) 171 ivtv_queue_move_buf(s, from, to, 1);
156 from = steal;
157 if (from == steal)
158 rc++; /* keep track of 'stolen' buffers */
159 ivtv_queue_move_buf(s, from, to, 1, 0);
160 } 172 }
161 } 173 }
162 else { 174 else {
163 u32 old_bytesused = to->bytesused; 175 u32 old_bytesused = to->bytesused;
164 176
165 while (to->bytesused - old_bytesused < needed_bytes) { 177 while (to->bytesused - old_bytesused < needed_bytes) {
166 if (list_empty(&from->list)) 178 ivtv_queue_move_buf(s, from, to, to_free);
167 from = steal;
168 if (from == steal)
169 rc++; /* keep track of 'stolen' buffers */
170 ivtv_queue_move_buf(s, from, to, to_free, rc);
171 } 179 }
172 } 180 }
173 spin_unlock_irqrestore(&s->qlock, flags); 181 spin_unlock_irqrestore(&s->qlock, flags);
@@ -185,7 +193,7 @@ void ivtv_flush_queues(struct ivtv_stream *s)
185int ivtv_stream_alloc(struct ivtv_stream *s) 193int ivtv_stream_alloc(struct ivtv_stream *s)
186{ 194{
187 struct ivtv *itv = s->itv; 195 struct ivtv *itv = s->itv;
188 int SGsize = sizeof(struct ivtv_SG_element) * s->buffers; 196 int SGsize = sizeof(struct ivtv_sg_element) * s->buffers;
189 int i; 197 int i;
190 198
191 if (s->buffers == 0) 199 if (s->buffers == 0)
@@ -195,27 +203,33 @@ int ivtv_stream_alloc(struct ivtv_stream *s)
195 s->dma != PCI_DMA_NONE ? "DMA " : "", 203 s->dma != PCI_DMA_NONE ? "DMA " : "",
196 s->name, s->buffers, s->buf_size, s->buffers * s->buf_size / 1024); 204 s->name, s->buffers, s->buf_size, s->buffers * s->buf_size / 1024);
197 205
198 if (ivtv_might_use_pio(s)) { 206 s->sg_pending = kzalloc(SGsize, GFP_KERNEL);
199 s->PIOarray = (struct ivtv_SG_element *)kzalloc(SGsize, GFP_KERNEL); 207 if (s->sg_pending == NULL) {
200 if (s->PIOarray == NULL) { 208 IVTV_ERR("Could not allocate sg_pending for %s stream\n", s->name);
201 IVTV_ERR("Could not allocate PIOarray for %s stream\n", s->name); 209 return -ENOMEM;
202 return -ENOMEM;
203 }
204 } 210 }
211 s->sg_pending_size = 0;
205 212
206 /* Allocate DMA SG Arrays */ 213 s->sg_processing = kzalloc(SGsize, GFP_KERNEL);
207 s->SGarray = (struct ivtv_SG_element *)kzalloc(SGsize, GFP_KERNEL); 214 if (s->sg_processing == NULL) {
208 if (s->SGarray == NULL) { 215 IVTV_ERR("Could not allocate sg_processing for %s stream\n", s->name);
209 IVTV_ERR("Could not allocate SGarray for %s stream\n", s->name); 216 kfree(s->sg_pending);
210 if (ivtv_might_use_pio(s)) { 217 s->sg_pending = NULL;
211 kfree(s->PIOarray); 218 return -ENOMEM;
212 s->PIOarray = NULL; 219 }
213 } 220 s->sg_processing_size = 0;
221
222 s->sg_dma = kzalloc(sizeof(struct ivtv_sg_element), GFP_KERNEL);
223 if (s->sg_dma == NULL) {
224 IVTV_ERR("Could not allocate sg_dma for %s stream\n", s->name);
225 kfree(s->sg_pending);
226 s->sg_pending = NULL;
227 kfree(s->sg_processing);
228 s->sg_processing = NULL;
214 return -ENOMEM; 229 return -ENOMEM;
215 } 230 }
216 s->SG_length = 0;
217 if (ivtv_might_use_dma(s)) { 231 if (ivtv_might_use_dma(s)) {
218 s->SG_handle = pci_map_single(itv->dev, s->SGarray, SGsize, s->dma); 232 s->sg_handle = pci_map_single(itv->dev, s->sg_dma, sizeof(struct ivtv_sg_element), s->dma);
219 ivtv_stream_sync_for_cpu(s); 233 ivtv_stream_sync_for_cpu(s);
220 } 234 }
221 235
@@ -262,16 +276,19 @@ void ivtv_stream_free(struct ivtv_stream *s)
262 } 276 }
263 277
264 /* Free SG Array/Lists */ 278 /* Free SG Array/Lists */
265 if (s->SGarray != NULL) { 279 if (s->sg_dma != NULL) {
266 if (s->SG_handle != IVTV_DMA_UNMAPPED) { 280 if (s->sg_handle != IVTV_DMA_UNMAPPED) {
267 pci_unmap_single(s->itv->dev, s->SG_handle, 281 pci_unmap_single(s->itv->dev, s->sg_handle,
268 sizeof(struct ivtv_SG_element) * s->buffers, PCI_DMA_TODEVICE); 282 sizeof(struct ivtv_sg_element), PCI_DMA_TODEVICE);
269 s->SG_handle = IVTV_DMA_UNMAPPED; 283 s->sg_handle = IVTV_DMA_UNMAPPED;
270 } 284 }
271 kfree(s->SGarray); 285 kfree(s->sg_pending);
272 kfree(s->PIOarray); 286 kfree(s->sg_processing);
273 s->PIOarray = NULL; 287 kfree(s->sg_dma);
274 s->SGarray = NULL; 288 s->sg_pending = NULL;
275 s->SG_length = 0; 289 s->sg_processing = NULL;
290 s->sg_dma = NULL;
291 s->sg_pending_size = 0;
292 s->sg_processing_size = 0;
276 } 293 }
277} 294}
diff --git a/drivers/media/video/ivtv/ivtv-queue.h b/drivers/media/video/ivtv/ivtv-queue.h
index 2ed8d548255d..7cfc0c9ab050 100644
--- a/drivers/media/video/ivtv/ivtv-queue.h
+++ b/drivers/media/video/ivtv/ivtv-queue.h
@@ -19,6 +19,9 @@
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */ 20 */
21 21
22#ifndef IVTV_QUEUE_H
23#define IVTV_QUEUE_H
24
22#define IVTV_DMA_UNMAPPED ((u32) -1) 25#define IVTV_DMA_UNMAPPED ((u32) -1)
23#define SLICED_VBI_PIO 1 26#define SLICED_VBI_PIO 1
24 27
@@ -79,13 +82,15 @@ void ivtv_stream_free(struct ivtv_stream *s);
79static inline void ivtv_stream_sync_for_cpu(struct ivtv_stream *s) 82static inline void ivtv_stream_sync_for_cpu(struct ivtv_stream *s)
80{ 83{
81 if (ivtv_use_dma(s)) 84 if (ivtv_use_dma(s))
82 pci_dma_sync_single_for_cpu(s->itv->dev, s->SG_handle, 85 pci_dma_sync_single_for_cpu(s->itv->dev, s->sg_handle,
83 sizeof(struct ivtv_SG_element) * s->buffers, PCI_DMA_TODEVICE); 86 sizeof(struct ivtv_sg_element), PCI_DMA_TODEVICE);
84} 87}
85 88
86static inline void ivtv_stream_sync_for_device(struct ivtv_stream *s) 89static inline void ivtv_stream_sync_for_device(struct ivtv_stream *s)
87{ 90{
88 if (ivtv_use_dma(s)) 91 if (ivtv_use_dma(s))
89 pci_dma_sync_single_for_device(s->itv->dev, s->SG_handle, 92 pci_dma_sync_single_for_device(s->itv->dev, s->sg_handle,
90 sizeof(struct ivtv_SG_element) * s->buffers, PCI_DMA_TODEVICE); 93 sizeof(struct ivtv_sg_element), PCI_DMA_TODEVICE);
91} 94}
95
96#endif
diff --git a/drivers/media/video/ivtv/ivtv-routing.c b/drivers/media/video/ivtv/ivtv-routing.c
new file mode 100644
index 000000000000..398bd33033ed
--- /dev/null
+++ b/drivers/media/video/ivtv/ivtv-routing.c
@@ -0,0 +1,116 @@
1/*
2 Audio/video-routing-related ivtv functions.
3 Copyright (C) 2003-2004 Kevin Thayer <nufan_wfk at yahoo.com>
4 Copyright (C) 2005-2007 Hans Verkuil <hverkuil@xs4all.nl>
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#include "ivtv-driver.h"
22#include "ivtv-i2c.h"
23#include "ivtv-cards.h"
24#include "ivtv-gpio.h"
25#include "ivtv-routing.h"
26
27#include <media/msp3400.h>
28#include <media/upd64031a.h>
29#include <media/upd64083.h>
30
31/* Selects the audio input and output according to the current
32 settings. */
33void ivtv_audio_set_io(struct ivtv *itv)
34{
35 struct v4l2_routing route;
36 u32 audio_input;
37 int mux_input;
38
39 /* Determine which input to use */
40 if (test_bit(IVTV_F_I_RADIO_USER, &itv->i_flags)) {
41 audio_input = itv->card->radio_input.audio_input;
42 mux_input = itv->card->radio_input.muxer_input;
43 } else {
44 audio_input = itv->card->audio_inputs[itv->audio_input].audio_input;
45 mux_input = itv->card->audio_inputs[itv->audio_input].muxer_input;
46 }
47
48 /* handle muxer chips */
49 route.input = mux_input;
50 route.output = 0;
51 ivtv_i2c_hw(itv, itv->card->hw_muxer, VIDIOC_INT_S_AUDIO_ROUTING, &route);
52
53 route.input = audio_input;
54 if (itv->card->hw_audio & IVTV_HW_MSP34XX) {
55 route.output = MSP_OUTPUT(MSP_SC_IN_DSP_SCART1);
56 }
57 ivtv_i2c_hw(itv, itv->card->hw_audio, VIDIOC_INT_S_AUDIO_ROUTING, &route);
58}
59
60/* Selects the video input and output according to the current
61 settings. */
62void ivtv_video_set_io(struct ivtv *itv)
63{
64 struct v4l2_routing route;
65 int inp = itv->active_input;
66 u32 type;
67
68 route.input = itv->card->video_inputs[inp].video_input;
69 route.output = 0;
70 itv->video_dec_func(itv, VIDIOC_INT_S_VIDEO_ROUTING, &route);
71
72 type = itv->card->video_inputs[inp].video_type;
73
74 if (type == IVTV_CARD_INPUT_VID_TUNER) {
75 route.input = 0; /* Tuner */
76 } else if (type < IVTV_CARD_INPUT_COMPOSITE1) {
77 route.input = 2; /* S-Video */
78 } else {
79 route.input = 1; /* Composite */
80 }
81
82 if (itv->card->hw_video & IVTV_HW_GPIO)
83 ivtv_gpio(itv, VIDIOC_INT_S_VIDEO_ROUTING, &route);
84
85 if (itv->card->hw_video & IVTV_HW_UPD64031A) {
86 if (type == IVTV_CARD_INPUT_VID_TUNER ||
87 type >= IVTV_CARD_INPUT_COMPOSITE1) {
88 /* Composite: GR on, connect to 3DYCS */
89 route.input = UPD64031A_GR_ON | UPD64031A_3DYCS_COMPOSITE;
90 } else {
91 /* S-Video: GR bypassed, turn it off */
92 route.input = UPD64031A_GR_OFF | UPD64031A_3DYCS_DISABLE;
93 }
94 route.input |= itv->card->gr_config;
95
96 ivtv_upd64031a(itv, VIDIOC_INT_S_VIDEO_ROUTING, &route);
97 }
98
99 if (itv->card->hw_video & IVTV_HW_UPD6408X) {
100 route.input = UPD64083_YCS_MODE;
101 if (type > IVTV_CARD_INPUT_VID_TUNER &&
102 type < IVTV_CARD_INPUT_COMPOSITE1) {
103 /* S-Video uses YCNR mode and internal Y-ADC, the upd64031a
104 is not used. */
105 route.input |= UPD64083_YCNR_MODE;
106 }
107 else if (itv->card->hw_video & IVTV_HW_UPD64031A) {
108 /* Use upd64031a output for tuner and composite(CX23416GYC only) inputs */
109 if ((type == IVTV_CARD_INPUT_VID_TUNER)||
110 (itv->card->type == IVTV_CARD_CX23416GYC)) {
111 route.input |= UPD64083_EXT_Y_ADC;
112 }
113 }
114 ivtv_upd64083(itv, VIDIOC_INT_S_VIDEO_ROUTING, &route);
115 }
116}
diff --git a/drivers/media/video/ivtv/ivtv-routing.h b/drivers/media/video/ivtv/ivtv-routing.h
new file mode 100644
index 000000000000..c72a9731ca01
--- /dev/null
+++ b/drivers/media/video/ivtv/ivtv-routing.h
@@ -0,0 +1,27 @@
1/*
2 Audio/video-routing-related ivtv functions.
3 Copyright (C) 2003-2004 Kevin Thayer <nufan_wfk at yahoo.com>
4 Copyright (C) 2005-2007 Hans Verkuil <hverkuil@xs4all.nl>
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#ifndef IVTV_ROUTING_H
22#define IVTV_ROUTING_H
23
24void ivtv_audio_set_io(struct ivtv *itv);
25void ivtv_video_set_io(struct ivtv *itv);
26
27#endif
diff --git a/drivers/media/video/ivtv/ivtv-streams.c b/drivers/media/video/ivtv/ivtv-streams.c
index 51df3f855031..fd135985e70f 100644
--- a/drivers/media/video/ivtv/ivtv-streams.c
+++ b/drivers/media/video/ivtv/ivtv-streams.c
@@ -35,16 +35,13 @@
35 35
36#include "ivtv-driver.h" 36#include "ivtv-driver.h"
37#include "ivtv-fileops.h" 37#include "ivtv-fileops.h"
38#include "ivtv-i2c.h"
39#include "ivtv-queue.h" 38#include "ivtv-queue.h"
40#include "ivtv-mailbox.h" 39#include "ivtv-mailbox.h"
41#include "ivtv-audio.h"
42#include "ivtv-video.h"
43#include "ivtv-vbi.h"
44#include "ivtv-ioctl.h" 40#include "ivtv-ioctl.h"
45#include "ivtv-irq.h" 41#include "ivtv-irq.h"
46#include "ivtv-streams.h" 42#include "ivtv-yuv.h"
47#include "ivtv-cards.h" 43#include "ivtv-cards.h"
44#include "ivtv-streams.h"
48 45
49static struct file_operations ivtv_v4l2_enc_fops = { 46static struct file_operations ivtv_v4l2_enc_fops = {
50 .owner = THIS_MODULE, 47 .owner = THIS_MODULE,
@@ -66,6 +63,13 @@ static struct file_operations ivtv_v4l2_dec_fops = {
66 .poll = ivtv_v4l2_dec_poll, 63 .poll = ivtv_v4l2_dec_poll,
67}; 64};
68 65
66#define IVTV_V4L2_DEC_MPG_OFFSET 16 /* offset from 0 to register decoder mpg v4l2 minors on */
67#define IVTV_V4L2_ENC_PCM_OFFSET 24 /* offset from 0 to register pcm v4l2 minors on */
68#define IVTV_V4L2_ENC_YUV_OFFSET 32 /* offset from 0 to register yuv v4l2 minors on */
69#define IVTV_V4L2_DEC_YUV_OFFSET 48 /* offset from 0 to register decoder yuv v4l2 minors on */
70#define IVTV_V4L2_DEC_VBI_OFFSET 8 /* offset from 0 to register decoder vbi input v4l2 minors on */
71#define IVTV_V4L2_DEC_VOUT_OFFSET 16 /* offset from 0 to register vbi output v4l2 minors on */
72
69static struct { 73static struct {
70 const char *name; 74 const char *name;
71 int vfl_type; 75 int vfl_type;
@@ -75,7 +79,7 @@ static struct {
75 struct file_operations *fops; 79 struct file_operations *fops;
76} ivtv_stream_info[] = { 80} ivtv_stream_info[] = {
77 { /* IVTV_ENC_STREAM_TYPE_MPG */ 81 { /* IVTV_ENC_STREAM_TYPE_MPG */
78 "encoder MPEG", 82 "encoder MPG",
79 VFL_TYPE_GRABBER, 0, 83 VFL_TYPE_GRABBER, 0,
80 PCI_DMA_FROMDEVICE, 0, V4L2_BUF_TYPE_VIDEO_CAPTURE, 84 PCI_DMA_FROMDEVICE, 0, V4L2_BUF_TYPE_VIDEO_CAPTURE,
81 &ivtv_v4l2_enc_fops 85 &ivtv_v4l2_enc_fops
@@ -93,7 +97,7 @@ static struct {
93 &ivtv_v4l2_enc_fops 97 &ivtv_v4l2_enc_fops
94 }, 98 },
95 { /* IVTV_ENC_STREAM_TYPE_PCM */ 99 { /* IVTV_ENC_STREAM_TYPE_PCM */
96 "encoder PCM audio", 100 "encoder PCM",
97 VFL_TYPE_GRABBER, IVTV_V4L2_ENC_PCM_OFFSET, 101 VFL_TYPE_GRABBER, IVTV_V4L2_ENC_PCM_OFFSET,
98 PCI_DMA_FROMDEVICE, 0, V4L2_BUF_TYPE_PRIVATE, 102 PCI_DMA_FROMDEVICE, 0, V4L2_BUF_TYPE_PRIVATE,
99 &ivtv_v4l2_enc_fops 103 &ivtv_v4l2_enc_fops
@@ -105,7 +109,7 @@ static struct {
105 &ivtv_v4l2_enc_fops 109 &ivtv_v4l2_enc_fops
106 }, 110 },
107 { /* IVTV_DEC_STREAM_TYPE_MPG */ 111 { /* IVTV_DEC_STREAM_TYPE_MPG */
108 "decoder MPEG", 112 "decoder MPG",
109 VFL_TYPE_GRABBER, IVTV_V4L2_DEC_MPG_OFFSET, 113 VFL_TYPE_GRABBER, IVTV_V4L2_DEC_MPG_OFFSET,
110 PCI_DMA_TODEVICE, 0, V4L2_BUF_TYPE_VIDEO_OUTPUT, 114 PCI_DMA_TODEVICE, 0, V4L2_BUF_TYPE_VIDEO_OUTPUT,
111 &ivtv_v4l2_dec_fops 115 &ivtv_v4l2_dec_fops
@@ -150,11 +154,11 @@ static void ivtv_stream_init(struct ivtv *itv, int type)
150 s->dma = ivtv_stream_info[type].dma; 154 s->dma = ivtv_stream_info[type].dma;
151 s->buf_size = itv->stream_buf_size[type]; 155 s->buf_size = itv->stream_buf_size[type];
152 if (s->buf_size) 156 if (s->buf_size)
153 s->buffers = itv->options.megabytes[type] * 1024 * 1024 / s->buf_size; 157 s->buffers = (itv->options.kilobytes[type] * 1024 + s->buf_size - 1) / s->buf_size;
154 spin_lock_init(&s->qlock); 158 spin_lock_init(&s->qlock);
155 init_waitqueue_head(&s->waitq); 159 init_waitqueue_head(&s->waitq);
156 s->id = -1; 160 s->id = -1;
157 s->SG_handle = IVTV_DMA_UNMAPPED; 161 s->sg_handle = IVTV_DMA_UNMAPPED;
158 ivtv_queue_init(&s->q_free); 162 ivtv_queue_init(&s->q_free);
159 ivtv_queue_init(&s->q_full); 163 ivtv_queue_init(&s->q_full);
160 ivtv_queue_init(&s->q_dma); 164 ivtv_queue_init(&s->q_dma);
@@ -192,7 +196,7 @@ static int ivtv_reg_dev(struct ivtv *itv, int type)
192 /* User explicitly selected 0 buffers for these streams, so don't 196 /* User explicitly selected 0 buffers for these streams, so don't
193 create them. */ 197 create them. */
194 if (minor >= 0 && ivtv_stream_info[type].dma != PCI_DMA_NONE && 198 if (minor >= 0 && ivtv_stream_info[type].dma != PCI_DMA_NONE &&
195 itv->options.megabytes[type] == 0) { 199 itv->options.kilobytes[type] == 0) {
196 IVTV_INFO("Disabled %s device\n", ivtv_stream_info[type].name); 200 IVTV_INFO("Disabled %s device\n", ivtv_stream_info[type].name);
197 return 0; 201 return 0;
198 } 202 }
@@ -238,18 +242,18 @@ static int ivtv_reg_dev(struct ivtv *itv, int type)
238 242
239 switch (vfl_type) { 243 switch (vfl_type) {
240 case VFL_TYPE_GRABBER: 244 case VFL_TYPE_GRABBER:
241 IVTV_INFO("Registered device video%d for %s (%d MB)\n", 245 IVTV_INFO("Registered device video%d for %s (%d kB)\n",
242 s->v4l2dev->minor, s->name, itv->options.megabytes[type]); 246 s->v4l2dev->minor, s->name, itv->options.kilobytes[type]);
243 break; 247 break;
244 case VFL_TYPE_RADIO: 248 case VFL_TYPE_RADIO:
245 IVTV_INFO("Registered device radio%d for %s\n", 249 IVTV_INFO("Registered device radio%d for %s\n",
246 s->v4l2dev->minor - MINOR_VFL_TYPE_RADIO_MIN, s->name); 250 s->v4l2dev->minor - MINOR_VFL_TYPE_RADIO_MIN, s->name);
247 break; 251 break;
248 case VFL_TYPE_VBI: 252 case VFL_TYPE_VBI:
249 if (itv->options.megabytes[type]) 253 if (itv->options.kilobytes[type])
250 IVTV_INFO("Registered device vbi%d for %s (%d MB)\n", 254 IVTV_INFO("Registered device vbi%d for %s (%d kB)\n",
251 s->v4l2dev->minor - MINOR_VFL_TYPE_VBI_MIN, 255 s->v4l2dev->minor - MINOR_VFL_TYPE_VBI_MIN,
252 s->name, itv->options.megabytes[type]); 256 s->name, itv->options.kilobytes[type]);
253 else 257 else
254 IVTV_INFO("Registered device vbi%d for %s\n", 258 IVTV_INFO("Registered device vbi%d for %s\n",
255 s->v4l2dev->minor - MINOR_VFL_TYPE_VBI_MIN, s->name); 259 s->v4l2dev->minor - MINOR_VFL_TYPE_VBI_MIN, s->name);
@@ -314,28 +318,9 @@ static void ivtv_vbi_setup(struct ivtv *itv)
314 int lines; 318 int lines;
315 int i; 319 int i;
316 320
317 /* If Embed then streamtype must be Program */
318 /* TODO: should we really do this? */
319 if (0 && !raw && itv->vbi.insert_mpeg) {
320 itv->params.stream_type = 0;
321
322 /* assign stream type */
323 ivtv_vapi(itv, CX2341X_ENC_SET_STREAM_TYPE, 1, itv->params.stream_type);
324 }
325
326 /* Reset VBI */ 321 /* Reset VBI */
327 ivtv_vapi(itv, CX2341X_ENC_SET_VBI_LINE, 5, 0xffff , 0, 0, 0, 0); 322 ivtv_vapi(itv, CX2341X_ENC_SET_VBI_LINE, 5, 0xffff , 0, 0, 0, 0);
328 323
329 if (itv->is_60hz) {
330 itv->vbi.count = 12;
331 itv->vbi.start[0] = 10;
332 itv->vbi.start[1] = 273;
333 } else { /* PAL/SECAM */
334 itv->vbi.count = 18;
335 itv->vbi.start[0] = 6;
336 itv->vbi.start[1] = 318;
337 }
338
339 /* setup VBI registers */ 324 /* setup VBI registers */
340 itv->video_dec_func(itv, VIDIOC_S_FMT, &itv->vbi.in); 325 itv->video_dec_func(itv, VIDIOC_S_FMT, &itv->vbi.in);
341 326
@@ -409,8 +394,8 @@ static void ivtv_vbi_setup(struct ivtv *itv)
409 if (!itv->vbi.fpi) 394 if (!itv->vbi.fpi)
410 itv->vbi.fpi = 1; 395 itv->vbi.fpi = 1;
411 396
412 IVTV_DEBUG_INFO("Setup VBI start 0x%08x frames %d fpi %d lines 0x%08x\n", 397 IVTV_DEBUG_INFO("Setup VBI start 0x%08x frames %d fpi %d\n",
413 itv->vbi.enc_start, data[1], itv->vbi.fpi, itv->digitizer); 398 itv->vbi.enc_start, data[1], itv->vbi.fpi);
414 399
415 /* select VBI lines. 400 /* select VBI lines.
416 Note that the sliced argument seems to have no effect. */ 401 Note that the sliced argument seems to have no effect. */
@@ -446,9 +431,6 @@ int ivtv_start_v4l2_encode_stream(struct ivtv_stream *s)
446 if (s->v4l2dev == NULL) 431 if (s->v4l2dev == NULL)
447 return -EINVAL; 432 return -EINVAL;
448 433
449 /* Big serialization lock to ensure no two streams are started
450 simultaneously: that can give all sorts of weird results. */
451 mutex_lock(&itv->serialize_lock);
452 IVTV_DEBUG_INFO("Start encoder stream %s\n", s->name); 434 IVTV_DEBUG_INFO("Start encoder stream %s\n", s->name);
453 435
454 switch (s->type) { 436 switch (s->type) {
@@ -490,7 +472,6 @@ int ivtv_start_v4l2_encode_stream(struct ivtv_stream *s)
490 0, sizeof(itv->vbi.sliced_mpeg_size)); 472 0, sizeof(itv->vbi.sliced_mpeg_size));
491 break; 473 break;
492 default: 474 default:
493 mutex_unlock(&itv->serialize_lock);
494 return -EINVAL; 475 return -EINVAL;
495 } 476 }
496 s->subtype = subtype; 477 s->subtype = subtype;
@@ -503,6 +484,8 @@ int ivtv_start_v4l2_encode_stream(struct ivtv_stream *s)
503 clear_bit(IVTV_F_S_STREAMOFF, &s->s_flags); 484 clear_bit(IVTV_F_S_STREAMOFF, &s->s_flags);
504 485
505 if (atomic_read(&itv->capturing) == 0) { 486 if (atomic_read(&itv->capturing) == 0) {
487 int digitizer;
488
506 /* Always use frame based mode. Experiments have demonstrated that byte 489 /* Always use frame based mode. Experiments have demonstrated that byte
507 stream based mode results in dropped frames and corruption. Not often, 490 stream based mode results in dropped frames and corruption. Not often,
508 but occasionally. Many thanks go to Leonard Orb who spent a lot of 491 but occasionally. Many thanks go to Leonard Orb who spent a lot of
@@ -528,7 +511,14 @@ int ivtv_start_v4l2_encode_stream(struct ivtv_stream *s)
528 ivtv_vapi(itv, CX2341X_ENC_SET_PLACEHOLDER, 12, 511 ivtv_vapi(itv, CX2341X_ENC_SET_PLACEHOLDER, 12,
529 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); 512 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
530 513
531 ivtv_vapi(itv, CX2341X_ENC_SET_NUM_VSYNC_LINES, 2, itv->digitizer, itv->digitizer); 514 if (itv->card->hw_all & (IVTV_HW_SAA7115 | IVTV_HW_SAA717X))
515 digitizer = 0xF1;
516 else if (itv->card->hw_all & IVTV_HW_SAA7114)
517 digitizer = 0xEF;
518 else /* cx25840 */
519 digitizer = 0x140;
520
521 ivtv_vapi(itv, CX2341X_ENC_SET_NUM_VSYNC_LINES, 2, digitizer, digitizer);
532 522
533 /* Setup VBI */ 523 /* Setup VBI */
534 if (itv->v4l2_cap & V4L2_CAP_VBI_CAPTURE) { 524 if (itv->v4l2_cap & V4L2_CAP_VBI_CAPTURE) {
@@ -563,16 +553,16 @@ int ivtv_start_v4l2_encode_stream(struct ivtv_stream *s)
563 clear_bit(IVTV_F_I_EOS, &itv->i_flags); 553 clear_bit(IVTV_F_I_EOS, &itv->i_flags);
564 554
565 /* Initialize Digitizer for Capture */ 555 /* Initialize Digitizer for Capture */
556 itv->video_dec_func(itv, VIDIOC_STREAMOFF, 0);
557 ivtv_msleep_timeout(300, 1);
566 ivtv_vapi(itv, CX2341X_ENC_INITIALIZE_INPUT, 0); 558 ivtv_vapi(itv, CX2341X_ENC_INITIALIZE_INPUT, 0);
567 559 itv->video_dec_func(itv, VIDIOC_STREAMON, 0);
568 ivtv_msleep_timeout(100, 0);
569 } 560 }
570 561
571 /* begin_capture */ 562 /* begin_capture */
572 if (ivtv_vapi(itv, CX2341X_ENC_START_CAPTURE, 2, captype, subtype)) 563 if (ivtv_vapi(itv, CX2341X_ENC_START_CAPTURE, 2, captype, subtype))
573 { 564 {
574 IVTV_DEBUG_WARN( "Error starting capture!\n"); 565 IVTV_DEBUG_WARN( "Error starting capture!\n");
575 mutex_unlock(&itv->serialize_lock);
576 return -EINVAL; 566 return -EINVAL;
577 } 567 }
578 568
@@ -588,7 +578,6 @@ int ivtv_start_v4l2_encode_stream(struct ivtv_stream *s)
588 578
589 /* you're live! sit back and await interrupts :) */ 579 /* you're live! sit back and await interrupts :) */
590 atomic_inc(&itv->capturing); 580 atomic_inc(&itv->capturing);
591 mutex_unlock(&itv->serialize_lock);
592 return 0; 581 return 0;
593} 582}
594 583
@@ -676,10 +665,10 @@ int ivtv_start_v4l2_decode_stream(struct ivtv_stream *s, int gop_offset)
676 clear_bit(IVTV_F_S_STREAMOFF, &s->s_flags); 665 clear_bit(IVTV_F_S_STREAMOFF, &s->s_flags);
677 666
678 /* Zero out decoder counters */ 667 /* Zero out decoder counters */
679 writel(0, &itv->dec_mbox.mbox[IVTV_MBOX_FIELD_DISPLAYED].data[0]); 668 writel(0, &itv->dec_mbox.mbox[IVTV_MBOX_DMA_END].data[0]);
680 writel(0, &itv->dec_mbox.mbox[IVTV_MBOX_FIELD_DISPLAYED].data[1]); 669 writel(0, &itv->dec_mbox.mbox[IVTV_MBOX_DMA_END].data[1]);
681 writel(0, &itv->dec_mbox.mbox[IVTV_MBOX_FIELD_DISPLAYED].data[2]); 670 writel(0, &itv->dec_mbox.mbox[IVTV_MBOX_DMA_END].data[2]);
682 writel(0, &itv->dec_mbox.mbox[IVTV_MBOX_FIELD_DISPLAYED].data[3]); 671 writel(0, &itv->dec_mbox.mbox[IVTV_MBOX_DMA_END].data[3]);
683 writel(0, &itv->dec_mbox.mbox[IVTV_MBOX_DMA].data[0]); 672 writel(0, &itv->dec_mbox.mbox[IVTV_MBOX_DMA].data[0]);
684 writel(0, &itv->dec_mbox.mbox[IVTV_MBOX_DMA].data[1]); 673 writel(0, &itv->dec_mbox.mbox[IVTV_MBOX_DMA].data[1]);
685 writel(0, &itv->dec_mbox.mbox[IVTV_MBOX_DMA].data[2]); 674 writel(0, &itv->dec_mbox.mbox[IVTV_MBOX_DMA].data[2]);
@@ -720,9 +709,7 @@ int ivtv_stop_v4l2_encode_stream(struct ivtv_stream *s, int gop_end)
720 struct ivtv *itv = s->itv; 709 struct ivtv *itv = s->itv;
721 DECLARE_WAITQUEUE(wait, current); 710 DECLARE_WAITQUEUE(wait, current);
722 int cap_type; 711 int cap_type;
723 unsigned long then;
724 int stopmode; 712 int stopmode;
725 u32 data[CX2341X_MBOX_MAX_DATA];
726 713
727 if (s->v4l2dev == NULL) 714 if (s->v4l2dev == NULL)
728 return -EINVAL; 715 return -EINVAL;
@@ -764,15 +751,13 @@ int ivtv_stop_v4l2_encode_stream(struct ivtv_stream *s, int gop_end)
764 /* when: 0 = end of GOP 1 = NOW!, type: 0 = mpeg, subtype: 3 = video+audio */ 751 /* when: 0 = end of GOP 1 = NOW!, type: 0 = mpeg, subtype: 3 = video+audio */
765 ivtv_vapi(itv, CX2341X_ENC_STOP_CAPTURE, 3, stopmode, cap_type, s->subtype); 752 ivtv_vapi(itv, CX2341X_ENC_STOP_CAPTURE, 3, stopmode, cap_type, s->subtype);
766 753
767 then = jiffies;
768
769 if (!test_bit(IVTV_F_S_PASSTHROUGH, &s->s_flags)) { 754 if (!test_bit(IVTV_F_S_PASSTHROUGH, &s->s_flags)) {
770 if (s->type == IVTV_ENC_STREAM_TYPE_MPG && gop_end) { 755 if (s->type == IVTV_ENC_STREAM_TYPE_MPG && gop_end) {
771 /* only run these if we're shutting down the last cap */ 756 /* only run these if we're shutting down the last cap */
772 unsigned long duration; 757 unsigned long duration;
758 unsigned long then = jiffies;
773 759
774 then = jiffies; 760 add_wait_queue(&itv->eos_waitq, &wait);
775 add_wait_queue(&itv->cap_w, &wait);
776 761
777 set_current_state(TASK_INTERRUPTIBLE); 762 set_current_state(TASK_INTERRUPTIBLE);
778 763
@@ -798,31 +783,12 @@ int ivtv_stop_v4l2_encode_stream(struct ivtv_stream *s, int gop_end)
798 IVTV_DEBUG_INFO("%s: EOS took %lu ms to occur.\n", s->name, duration); 783 IVTV_DEBUG_INFO("%s: EOS took %lu ms to occur.\n", s->name, duration);
799 } 784 }
800 set_current_state(TASK_RUNNING); 785 set_current_state(TASK_RUNNING);
801 remove_wait_queue(&itv->cap_w, &wait); 786 remove_wait_queue(&itv->eos_waitq, &wait);
787 set_bit(IVTV_F_S_STREAMOFF, &s->s_flags);
802 } 788 }
803 789
804 then = jiffies; 790 /* Handle any pending interrupts */
805 /* Make sure DMA is complete */ 791 ivtv_msleep_timeout(100, 1);
806 add_wait_queue(&s->waitq, &wait);
807 do {
808 /* check if DMA is pending */
809 if ((s->type == IVTV_ENC_STREAM_TYPE_MPG) && /* MPG Only */
810 (read_reg(IVTV_REG_DMASTATUS) & 0x02)) {
811 /* Check for last DMA */
812 ivtv_vapi_result(itv, data, CX2341X_ENC_GET_SEQ_END, 2, 0, 0);
813
814 if (data[0] == 1) {
815 IVTV_DEBUG_DMA("%s: Last DMA of size 0x%08x\n", s->name, data[1]);
816 break;
817 }
818 } else if (read_reg(IVTV_REG_DMASTATUS) & 0x02) {
819 break;
820 }
821 } while (!ivtv_msleep_timeout(10, 1) &&
822 then + msecs_to_jiffies(2000) > jiffies);
823
824 set_current_state(TASK_RUNNING);
825 remove_wait_queue(&s->waitq, &wait);
826 } 792 }
827 793
828 atomic_dec(&itv->capturing); 794 atomic_dec(&itv->capturing);
@@ -830,19 +796,16 @@ int ivtv_stop_v4l2_encode_stream(struct ivtv_stream *s, int gop_end)
830 /* Clear capture and no-read bits */ 796 /* Clear capture and no-read bits */
831 clear_bit(IVTV_F_S_STREAMING, &s->s_flags); 797 clear_bit(IVTV_F_S_STREAMING, &s->s_flags);
832 798
833 /* ensure these global cleanup actions are done only once */
834 mutex_lock(&itv->serialize_lock);
835
836 if (s->type == IVTV_ENC_STREAM_TYPE_VBI) 799 if (s->type == IVTV_ENC_STREAM_TYPE_VBI)
837 ivtv_set_irq_mask(itv, IVTV_IRQ_ENC_VBI_CAP); 800 ivtv_set_irq_mask(itv, IVTV_IRQ_ENC_VBI_CAP);
838 801
839 if (atomic_read(&itv->capturing) > 0) { 802 if (atomic_read(&itv->capturing) > 0) {
840 mutex_unlock(&itv->serialize_lock);
841 return 0; 803 return 0;
842 } 804 }
843 805
844 /* Set the following Interrupt mask bits for capture */ 806 /* Set the following Interrupt mask bits for capture */
845 ivtv_set_irq_mask(itv, IVTV_IRQ_MASK_CAPTURE); 807 ivtv_set_irq_mask(itv, IVTV_IRQ_MASK_CAPTURE);
808 del_timer(&itv->dma_timer);
846 809
847 /* event notification (off) */ 810 /* event notification (off) */
848 if (test_and_clear_bit(IVTV_F_I_DIG_RST, &itv->i_flags)) { 811 if (test_and_clear_bit(IVTV_F_I_DIG_RST, &itv->i_flags)) {
@@ -853,7 +816,6 @@ int ivtv_stop_v4l2_encode_stream(struct ivtv_stream *s, int gop_end)
853 } 816 }
854 817
855 wake_up(&s->waitq); 818 wake_up(&s->waitq);
856 mutex_unlock(&itv->serialize_lock);
857 819
858 return 0; 820 return 0;
859} 821}
@@ -900,6 +862,7 @@ int ivtv_stop_v4l2_decode_stream(struct ivtv_stream *s, int flags, u64 pts)
900 ivtv_vapi(itv, CX2341X_DEC_SET_EVENT_NOTIFICATION, 4, 0, 0, IVTV_IRQ_DEC_AUD_MODE_CHG, -1); 862 ivtv_vapi(itv, CX2341X_DEC_SET_EVENT_NOTIFICATION, 4, 0, 0, IVTV_IRQ_DEC_AUD_MODE_CHG, -1);
901 863
902 ivtv_set_irq_mask(itv, IVTV_IRQ_MASK_DECODE); 864 ivtv_set_irq_mask(itv, IVTV_IRQ_MASK_DECODE);
865 del_timer(&itv->dma_timer);
903 866
904 clear_bit(IVTV_F_S_NEEDS_DATA, &s->s_flags); 867 clear_bit(IVTV_F_S_NEEDS_DATA, &s->s_flags);
905 clear_bit(IVTV_F_S_STREAMING, &s->s_flags); 868 clear_bit(IVTV_F_S_STREAMING, &s->s_flags);
diff --git a/drivers/media/video/ivtv/ivtv-streams.h b/drivers/media/video/ivtv/ivtv-streams.h
index 8597b75384a7..8f5f5b1c7c89 100644
--- a/drivers/media/video/ivtv/ivtv-streams.h
+++ b/drivers/media/video/ivtv/ivtv-streams.h
@@ -18,6 +18,9 @@
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */ 19 */
20 20
21#ifndef IVTV_STREAMS_H
22#define IVTV_STREAMS_H
23
21int ivtv_streams_setup(struct ivtv *itv); 24int ivtv_streams_setup(struct ivtv *itv);
22void ivtv_streams_cleanup(struct ivtv *itv); 25void ivtv_streams_cleanup(struct ivtv *itv);
23 26
@@ -29,3 +32,5 @@ int ivtv_stop_v4l2_decode_stream(struct ivtv_stream *s, int flags, u64 pts);
29 32
30void ivtv_stop_all_captures(struct ivtv *itv); 33void ivtv_stop_all_captures(struct ivtv *itv);
31int ivtv_passthrough_mode(struct ivtv *itv, int enable); 34int ivtv_passthrough_mode(struct ivtv *itv, int enable);
35
36#endif
diff --git a/drivers/media/video/ivtv/ivtv-udma.c b/drivers/media/video/ivtv/ivtv-udma.c
index bd642e1aafc3..c4626d1cdf41 100644
--- a/drivers/media/video/ivtv/ivtv-udma.c
+++ b/drivers/media/video/ivtv/ivtv-udma.c
@@ -21,7 +21,6 @@
21 */ 21 */
22 22
23#include "ivtv-driver.h" 23#include "ivtv-driver.h"
24#include "ivtv-streams.h"
25#include "ivtv-udma.h" 24#include "ivtv-udma.h"
26 25
27void ivtv_udma_get_page_info(struct ivtv_dma_page_info *dma_page, unsigned long first, unsigned long size) 26void ivtv_udma_get_page_info(struct ivtv_dma_page_info *dma_page, unsigned long first, unsigned long size)
@@ -38,19 +37,37 @@ void ivtv_udma_get_page_info(struct ivtv_dma_page_info *dma_page, unsigned long
38int ivtv_udma_fill_sg_list (struct ivtv_user_dma *dma, struct ivtv_dma_page_info *dma_page, int map_offset) 37int ivtv_udma_fill_sg_list (struct ivtv_user_dma *dma, struct ivtv_dma_page_info *dma_page, int map_offset)
39{ 38{
40 int i, offset; 39 int i, offset;
40 unsigned long flags;
41
42 if (map_offset < 0)
43 return map_offset;
41 44
42 offset = dma_page->offset; 45 offset = dma_page->offset;
43 46
44 /* Fill SG Array with new values */ 47 /* Fill SG Array with new values */
45 for (i = 0; i < dma_page->page_count; i++) { 48 for (i = 0; i < dma_page->page_count; i++) {
46 if (i == dma_page->page_count - 1) { 49 unsigned int len = (i == dma_page->page_count - 1) ?
47 dma->SGlist[map_offset].length = dma_page->tail; 50 dma_page->tail : PAGE_SIZE - offset;
51
52 dma->SGlist[map_offset].length = len;
53 dma->SGlist[map_offset].offset = offset;
54 if (PageHighMem(dma->map[map_offset])) {
55 void *src;
56
57 if (dma->bouncemap[map_offset] == NULL)
58 dma->bouncemap[map_offset] = alloc_page(GFP_KERNEL);
59 if (dma->bouncemap[map_offset] == NULL)
60 return -1;
61 local_irq_save(flags);
62 src = kmap_atomic(dma->map[map_offset], KM_BOUNCE_READ) + offset;
63 memcpy(page_address(dma->bouncemap[map_offset]) + offset, src, len);
64 kunmap_atomic(src, KM_BOUNCE_READ);
65 local_irq_restore(flags);
66 dma->SGlist[map_offset].page = dma->bouncemap[map_offset];
48 } 67 }
49 else { 68 else {
50 dma->SGlist[map_offset].length = PAGE_SIZE - offset; 69 dma->SGlist[map_offset].page = dma->map[map_offset];
51 } 70 }
52 dma->SGlist[map_offset].offset = offset;
53 dma->SGlist[map_offset].page = dma->map[map_offset];
54 offset = 0; 71 offset = 0;
55 map_offset++; 72 map_offset++;
56 } 73 }
@@ -89,7 +106,7 @@ int ivtv_udma_setup(struct ivtv *itv, unsigned long ivtv_dest_addr,
89{ 106{
90 struct ivtv_dma_page_info user_dma; 107 struct ivtv_dma_page_info user_dma;
91 struct ivtv_user_dma *dma = &itv->udma; 108 struct ivtv_user_dma *dma = &itv->udma;
92 int err; 109 int i, err;
93 110
94 IVTV_DEBUG_DMA("ivtv_udma_setup, dst: 0x%08x\n", (unsigned int)ivtv_dest_addr); 111 IVTV_DEBUG_DMA("ivtv_udma_setup, dst: 0x%08x\n", (unsigned int)ivtv_dest_addr);
95 112
@@ -123,7 +140,13 @@ int ivtv_udma_setup(struct ivtv *itv, unsigned long ivtv_dest_addr,
123 dma->page_count = user_dma.page_count; 140 dma->page_count = user_dma.page_count;
124 141
125 /* Fill SG List with new values */ 142 /* Fill SG List with new values */
126 ivtv_udma_fill_sg_list(dma, &user_dma, 0); 143 if (ivtv_udma_fill_sg_list(dma, &user_dma, 0) < 0) {
144 for (i = 0; i < dma->page_count; i++) {
145 put_page(dma->map[i]);
146 }
147 dma->page_count = 0;
148 return -ENOMEM;
149 }
127 150
128 /* Map SG List */ 151 /* Map SG List */
129 dma->SG_length = pci_map_sg(itv->dev, dma->SGlist, dma->page_count, PCI_DMA_TODEVICE); 152 dma->SG_length = pci_map_sg(itv->dev, dma->SGlist, dma->page_count, PCI_DMA_TODEVICE);
@@ -166,6 +189,8 @@ void ivtv_udma_unmap(struct ivtv *itv)
166 189
167void ivtv_udma_free(struct ivtv *itv) 190void ivtv_udma_free(struct ivtv *itv)
168{ 191{
192 int i;
193
169 /* Unmap SG Array */ 194 /* Unmap SG Array */
170 if (itv->udma.SG_handle) { 195 if (itv->udma.SG_handle) {
171 pci_unmap_single(itv->dev, itv->udma.SG_handle, 196 pci_unmap_single(itv->dev, itv->udma.SG_handle,
@@ -176,6 +201,11 @@ void ivtv_udma_free(struct ivtv *itv)
176 if (itv->udma.SG_length) { 201 if (itv->udma.SG_length) {
177 pci_unmap_sg(itv->dev, itv->udma.SGlist, itv->udma.page_count, PCI_DMA_TODEVICE); 202 pci_unmap_sg(itv->dev, itv->udma.SGlist, itv->udma.page_count, PCI_DMA_TODEVICE);
178 } 203 }
204
205 for (i = 0; i < IVTV_DMA_SG_OSD_ENT; i++) {
206 if (itv->udma.bouncemap[i])
207 __free_page(itv->udma.bouncemap[i]);
208 }
179} 209}
180 210
181void ivtv_udma_start(struct ivtv *itv) 211void ivtv_udma_start(struct ivtv *itv)
diff --git a/drivers/media/video/ivtv/ivtv-udma.h b/drivers/media/video/ivtv/ivtv-udma.h
index e131bccedec0..df727e23be0a 100644
--- a/drivers/media/video/ivtv/ivtv-udma.h
+++ b/drivers/media/video/ivtv/ivtv-udma.h
@@ -18,6 +18,9 @@
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */ 19 */
20 20
21#ifndef IVTV_UDMA_H
22#define IVTV_UDMA_H
23
21/* User DMA functions */ 24/* User DMA functions */
22void ivtv_udma_get_page_info(struct ivtv_dma_page_info *dma_page, unsigned long first, unsigned long size); 25void ivtv_udma_get_page_info(struct ivtv_dma_page_info *dma_page, unsigned long first, unsigned long size);
23int ivtv_udma_fill_sg_list(struct ivtv_user_dma *dma, struct ivtv_dma_page_info *dma_page, int map_offset); 26int ivtv_udma_fill_sg_list(struct ivtv_user_dma *dma, struct ivtv_dma_page_info *dma_page, int map_offset);
@@ -41,3 +44,5 @@ static inline void ivtv_udma_sync_for_cpu(struct ivtv *itv)
41 pci_dma_sync_single_for_cpu((struct pci_dev *)itv->dev, itv->udma.SG_handle, 44 pci_dma_sync_single_for_cpu((struct pci_dev *)itv->dev, itv->udma.SG_handle,
42 sizeof(itv->udma.SGarray), PCI_DMA_TODEVICE); 45 sizeof(itv->udma.SGarray), PCI_DMA_TODEVICE);
43} 46}
47
48#endif
diff --git a/drivers/media/video/ivtv/ivtv-vbi.c b/drivers/media/video/ivtv/ivtv-vbi.c
index a7282a91bd97..c151bcf5519a 100644
--- a/drivers/media/video/ivtv/ivtv-vbi.c
+++ b/drivers/media/video/ivtv/ivtv-vbi.c
@@ -18,10 +18,69 @@
18 */ 18 */
19 19
20#include "ivtv-driver.h" 20#include "ivtv-driver.h"
21#include "ivtv-video.h" 21#include "ivtv-i2c.h"
22#include "ivtv-vbi.h"
23#include "ivtv-ioctl.h" 22#include "ivtv-ioctl.h"
24#include "ivtv-queue.h" 23#include "ivtv-queue.h"
24#include "ivtv-vbi.h"
25
26static void ivtv_set_vps(struct ivtv *itv, int enabled)
27{
28 struct v4l2_sliced_vbi_data data;
29
30 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
31 return;
32 data.id = V4L2_SLICED_VPS;
33 data.field = 0;
34 data.line = enabled ? 16 : 0;
35 data.data[2] = itv->vbi.vps_payload.data[0];
36 data.data[8] = itv->vbi.vps_payload.data[1];
37 data.data[9] = itv->vbi.vps_payload.data[2];
38 data.data[10] = itv->vbi.vps_payload.data[3];
39 data.data[11] = itv->vbi.vps_payload.data[4];
40 ivtv_saa7127(itv, VIDIOC_INT_S_VBI_DATA, &data);
41}
42
43static void ivtv_set_cc(struct ivtv *itv, int mode, const struct vbi_cc *cc)
44{
45 struct v4l2_sliced_vbi_data data;
46
47 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
48 return;
49 data.id = V4L2_SLICED_CAPTION_525;
50 data.field = 0;
51 data.line = (mode & 1) ? 21 : 0;
52 data.data[0] = cc->odd[0];
53 data.data[1] = cc->odd[1];
54 ivtv_saa7127(itv, VIDIOC_INT_S_VBI_DATA, &data);
55 data.field = 1;
56 data.line = (mode & 2) ? 21 : 0;
57 data.data[0] = cc->even[0];
58 data.data[1] = cc->even[1];
59 ivtv_saa7127(itv, VIDIOC_INT_S_VBI_DATA, &data);
60}
61
62static void ivtv_set_wss(struct ivtv *itv, int enabled, int mode)
63{
64 struct v4l2_sliced_vbi_data data;
65
66 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
67 return;
68 /* When using a 50 Hz system, always turn on the
69 wide screen signal with 4x3 ratio as the default.
70 Turning this signal on and off can confuse certain
71 TVs. As far as I can tell there is no reason not to
72 transmit this signal. */
73 if ((itv->std & V4L2_STD_625_50) && !enabled) {
74 enabled = 1;
75 mode = 0x08; /* 4x3 full format */
76 }
77 data.id = V4L2_SLICED_WSS_625;
78 data.field = 0;
79 data.line = enabled ? 23 : 0;
80 data.data[0] = mode & 0xff;
81 data.data[1] = (mode >> 8) & 0xff;
82 ivtv_saa7127(itv, VIDIOC_INT_S_VBI_DATA, &data);
83}
25 84
26static int odd_parity(u8 c) 85static int odd_parity(u8 c)
27{ 86{
@@ -32,62 +91,50 @@ static int odd_parity(u8 c)
32 return c & 1; 91 return c & 1;
33} 92}
34 93
35static void passthrough_vbi_data(struct ivtv *itv, int cnt) 94void ivtv_write_vbi(struct ivtv *itv, const struct v4l2_sliced_vbi_data *sliced, size_t cnt)
36{ 95{
37 int wss = 0; 96 struct vbi_info *vi = &itv->vbi;
38 u8 cc[4] = { 0x80, 0x80, 0x80, 0x80 }; 97 struct vbi_cc cc = { .odd = { 0x80, 0x80 }, .even = { 0x80, 0x80 } };
39 u8 vps[13];
40 int found_cc = 0; 98 int found_cc = 0;
41 int found_wss = 0; 99 size_t i;
42 int found_vps = 0;
43 int cc_pos = itv->vbi.cc_pos;
44 int i;
45 100
46 for (i = 0; i < cnt; i++) { 101 for (i = 0; i < cnt; i++) {
47 struct v4l2_sliced_vbi_data *d = itv->vbi.sliced_dec_data + i; 102 const struct v4l2_sliced_vbi_data *d = sliced + i;
48 103
49 if (d->id == V4L2_SLICED_CAPTION_525 && d->line == 21) { 104 if (d->id == V4L2_SLICED_CAPTION_525 && d->line == 21) {
50 found_cc = 1;
51 if (d->field) { 105 if (d->field) {
52 cc[2] = d->data[0]; 106 cc.even[0] = d->data[0];
53 cc[3] = d->data[1]; 107 cc.even[1] = d->data[1];
54 } else { 108 } else {
55 cc[0] = d->data[0]; 109 cc.odd[0] = d->data[0];
56 cc[1] = d->data[1]; 110 cc.odd[1] = d->data[1];
57 } 111 }
112 found_cc = 1;
58 } 113 }
59 else if (d->id == V4L2_SLICED_VPS && d->line == 16 && d->field == 0) { 114 else if (d->id == V4L2_SLICED_VPS && d->line == 16 && d->field == 0) {
60 memcpy(vps, d->data, sizeof(vps)); 115 struct vbi_vps vps;
61 found_vps = 1; 116
117 vps.data[0] = d->data[2];
118 vps.data[1] = d->data[8];
119 vps.data[2] = d->data[9];
120 vps.data[3] = d->data[10];
121 vps.data[4] = d->data[11];
122 if (memcmp(&vps, &vi->vps_payload, sizeof(vps))) {
123 vi->vps_payload = vps;
124 set_bit(IVTV_F_I_UPDATE_VPS, &itv->i_flags);
125 }
62 } 126 }
63 else if (d->id == V4L2_SLICED_WSS_625 && d->line == 23 && d->field == 0) { 127 else if (d->id == V4L2_SLICED_WSS_625 && d->line == 23 && d->field == 0) {
64 wss = d->data[0] | d->data[1] << 8; 128 int wss = d->data[0] | d->data[1] << 8;
65 found_wss = 1;
66 }
67 }
68
69 if (itv->vbi.wss_found != found_wss || itv->vbi.wss != wss) {
70 itv->vbi.wss = wss;
71 itv->vbi.wss_found = found_wss;
72 set_bit(IVTV_F_I_UPDATE_WSS, &itv->i_flags);
73 }
74 129
75 if (found_vps || itv->vbi.vps_found) { 130 if (vi->wss_payload != wss) {
76 itv->vbi.vps[0] = vps[2]; 131 vi->wss_payload = wss;
77 itv->vbi.vps[1] = vps[8]; 132 set_bit(IVTV_F_I_UPDATE_WSS, &itv->i_flags);
78 itv->vbi.vps[2] = vps[9]; 133 }
79 itv->vbi.vps[3] = vps[10]; 134 }
80 itv->vbi.vps[4] = vps[11];
81 itv->vbi.vps_found = found_vps;
82 set_bit(IVTV_F_I_UPDATE_VPS, &itv->i_flags);
83 } 135 }
84 136 if (found_cc && vi->cc_payload_idx < sizeof(vi->cc_payload)) {
85 if (found_cc && cc_pos < sizeof(itv->vbi.cc_data_even)) { 137 vi->cc_payload[vi->cc_payload_idx++] = cc;
86 itv->vbi.cc_data_odd[cc_pos] = cc[0];
87 itv->vbi.cc_data_odd[cc_pos + 1] = cc[1];
88 itv->vbi.cc_data_even[cc_pos] = cc[2];
89 itv->vbi.cc_data_even[cc_pos + 1] = cc[3];
90 itv->vbi.cc_pos = cc_pos + 2;
91 set_bit(IVTV_F_I_UPDATE_CC, &itv->i_flags); 138 set_bit(IVTV_F_I_UPDATE_CC, &itv->i_flags);
92 } 139 }
93} 140}
@@ -163,8 +210,8 @@ static int ivtv_convert_ivtv_vbi(struct ivtv *itv, u8 *p)
163 linemask[1] = 0xf; 210 linemask[1] = 0xf;
164 p += 4; 211 p += 4;
165 } else { 212 } else {
166 /* unknown VBI data stream */ 213 /* unknown VBI data, convert to empty VBI frame */
167 return 0; 214 linemask[0] = linemask[1] = 0;
168 } 215 }
169 for (i = 0; i < 36; i++) { 216 for (i = 0; i < 36; i++) {
170 int err = 0; 217 int err = 0;
@@ -211,69 +258,6 @@ static int ivtv_convert_ivtv_vbi(struct ivtv *itv, u8 *p)
211 return line * sizeof(itv->vbi.sliced_dec_data[0]); 258 return line * sizeof(itv->vbi.sliced_dec_data[0]);
212} 259}
213 260
214ssize_t ivtv_write_vbi(struct ivtv *itv, const char __user *ubuf, size_t count)
215{
216 /* Should be a __user pointer, but sparse doesn't parse this bit correctly. */
217 const struct v4l2_sliced_vbi_data *p = (const struct v4l2_sliced_vbi_data *)ubuf;
218 u8 cc[4] = { 0x80, 0x80, 0x80, 0x80 };
219 int found_cc = 0;
220 int cc_pos = itv->vbi.cc_pos;
221
222 while (count >= sizeof(struct v4l2_sliced_vbi_data)) {
223 switch (p->id) {
224 case V4L2_SLICED_CAPTION_525:
225 if (p->line == 21) {
226 found_cc = 1;
227 if (p->field) {
228 cc[2] = p->data[0];
229 cc[3] = p->data[1];
230 } else {
231 cc[0] = p->data[0];
232 cc[1] = p->data[1];
233 }
234 }
235 break;
236
237 case V4L2_SLICED_VPS:
238 if (p->line == 16 && p->field == 0) {
239 itv->vbi.vps[0] = p->data[2];
240 itv->vbi.vps[1] = p->data[8];
241 itv->vbi.vps[2] = p->data[9];
242 itv->vbi.vps[3] = p->data[10];
243 itv->vbi.vps[4] = p->data[11];
244 itv->vbi.vps_found = 1;
245 set_bit(IVTV_F_I_UPDATE_VPS, &itv->i_flags);
246 }
247 break;
248
249 case V4L2_SLICED_WSS_625:
250 if (p->line == 23 && p->field == 0) {
251 /* No lock needed for WSS */
252 itv->vbi.wss = p->data[0] | (p->data[1] << 8);
253 itv->vbi.wss_found = 1;
254 set_bit(IVTV_F_I_UPDATE_WSS, &itv->i_flags);
255 }
256 break;
257
258 default:
259 break;
260 }
261 count -= sizeof(*p);
262 p++;
263 }
264
265 if (found_cc && cc_pos < sizeof(itv->vbi.cc_data_even)) {
266 itv->vbi.cc_data_odd[cc_pos] = cc[0];
267 itv->vbi.cc_data_odd[cc_pos + 1] = cc[1];
268 itv->vbi.cc_data_even[cc_pos] = cc[2];
269 itv->vbi.cc_data_even[cc_pos + 1] = cc[3];
270 itv->vbi.cc_pos = cc_pos + 2;
271 set_bit(IVTV_F_I_UPDATE_CC, &itv->i_flags);
272 }
273
274 return (const char __user *)p - ubuf;
275}
276
277/* Compress raw VBI format, removes leading SAV codes and surplus space after the 261/* Compress raw VBI format, removes leading SAV codes and surplus space after the
278 field. 262 field.
279 Returns new compressed size. */ 263 Returns new compressed size. */
@@ -422,108 +406,95 @@ void ivtv_process_vbi_data(struct ivtv *itv, struct ivtv_buffer *buf,
422 memcpy(buf->buf, itv->vbi.sliced_dec_data, cnt); 406 memcpy(buf->buf, itv->vbi.sliced_dec_data, cnt);
423 buf->bytesused = cnt; 407 buf->bytesused = cnt;
424 408
425 passthrough_vbi_data(itv, cnt / sizeof(itv->vbi.sliced_dec_data[0])); 409 ivtv_write_vbi(itv, itv->vbi.sliced_dec_data,
410 cnt / sizeof(itv->vbi.sliced_dec_data[0]));
426 return; 411 return;
427 } 412 }
428} 413}
429 414
430void ivtv_disable_vbi(struct ivtv *itv) 415void ivtv_disable_cc(struct ivtv *itv)
431{ 416{
432 clear_bit(IVTV_F_I_UPDATE_WSS, &itv->i_flags); 417 struct vbi_cc cc = { .odd = { 0x80, 0x80 }, .even = { 0x80, 0x80 } };
433 clear_bit(IVTV_F_I_UPDATE_VPS, &itv->i_flags); 418
434 clear_bit(IVTV_F_I_UPDATE_CC, &itv->i_flags); 419 clear_bit(IVTV_F_I_UPDATE_CC, &itv->i_flags);
435 ivtv_set_wss(itv, 0, 0); 420 ivtv_set_cc(itv, 0, &cc);
436 ivtv_set_cc(itv, 0, 0, 0, 0, 0); 421 itv->vbi.cc_payload_idx = 0;
437 ivtv_set_vps(itv, 0, 0, 0, 0, 0, 0);
438 itv->vbi.vps_found = itv->vbi.wss_found = 0;
439 itv->vbi.wss = 0;
440 itv->vbi.cc_pos = 0;
441} 422}
442 423
443 424
444void ivtv_vbi_work_handler(struct ivtv *itv) 425void ivtv_vbi_work_handler(struct ivtv *itv)
445{ 426{
427 struct vbi_info *vi = &itv->vbi;
446 struct v4l2_sliced_vbi_data data; 428 struct v4l2_sliced_vbi_data data;
429 struct vbi_cc cc = { .odd = { 0x80, 0x80 }, .even = { 0x80, 0x80 } };
447 430
448 /* Lock */ 431 /* Lock */
449 if (itv->output_mode == OUT_PASSTHROUGH) { 432 if (itv->output_mode == OUT_PASSTHROUGH) {
450 /* Note: currently only the saa7115 is used in a PVR350,
451 so these commands are for now saa7115 specific. */
452 if (itv->is_50hz) { 433 if (itv->is_50hz) {
453 data.id = V4L2_SLICED_WSS_625; 434 data.id = V4L2_SLICED_WSS_625;
454 data.field = 0; 435 data.field = 0;
455 436
456 if (itv->video_dec_func(itv, VIDIOC_INT_G_VBI_DATA, &data) == 0) { 437 if (itv->video_dec_func(itv, VIDIOC_INT_G_VBI_DATA, &data) == 0) {
457 ivtv_set_wss(itv, 1, data.data[0] & 0xf); 438 ivtv_set_wss(itv, 1, data.data[0] & 0xf);
458 itv->vbi.wss_no_update = 0; 439 vi->wss_missing_cnt = 0;
459 } else if (itv->vbi.wss_no_update == 4) { 440 } else if (vi->wss_missing_cnt == 4) {
460 ivtv_set_wss(itv, 1, 0x8); /* 4x3 full format */ 441 ivtv_set_wss(itv, 1, 0x8); /* 4x3 full format */
461 } else { 442 } else {
462 itv->vbi.wss_no_update++; 443 vi->wss_missing_cnt++;
463 } 444 }
464 } 445 }
465 else { 446 else {
466 u8 c1 = 0, c2 = 0, c3 = 0, c4 = 0;
467 int mode = 0; 447 int mode = 0;
468 448
469 data.id = V4L2_SLICED_CAPTION_525; 449 data.id = V4L2_SLICED_CAPTION_525;
470 data.field = 0; 450 data.field = 0;
471 if (itv->video_dec_func(itv, VIDIOC_INT_G_VBI_DATA, &data) == 0) { 451 if (itv->video_dec_func(itv, VIDIOC_INT_G_VBI_DATA, &data) == 0) {
472 mode |= 1; 452 mode |= 1;
473 c1 = data.data[0]; 453 cc.odd[0] = data.data[0];
474 c2 = data.data[1]; 454 cc.odd[1] = data.data[1];
475 } 455 }
476 data.field = 1; 456 data.field = 1;
477 if (itv->video_dec_func(itv, VIDIOC_INT_G_VBI_DATA, &data) == 0) { 457 if (itv->video_dec_func(itv, VIDIOC_INT_G_VBI_DATA, &data) == 0) {
478 mode |= 2; 458 mode |= 2;
479 c3 = data.data[0]; 459 cc.even[0] = data.data[0];
480 c4 = data.data[1]; 460 cc.even[1] = data.data[1];
481 } 461 }
482 if (mode) { 462 if (mode) {
483 itv->vbi.cc_no_update = 0; 463 vi->cc_missing_cnt = 0;
484 ivtv_set_cc(itv, mode, c1, c2, c3, c4); 464 ivtv_set_cc(itv, mode, &cc);
485 } else if (itv->vbi.cc_no_update == 4) { 465 } else if (vi->cc_missing_cnt == 4) {
486 ivtv_set_cc(itv, 0, 0, 0, 0, 0); 466 ivtv_set_cc(itv, 0, &cc);
487 } else { 467 } else {
488 itv->vbi.cc_no_update++; 468 vi->cc_missing_cnt++;
489 } 469 }
490 } 470 }
491 return; 471 return;
492 } 472 }
493 473
494 if (test_and_clear_bit(IVTV_F_I_UPDATE_WSS, &itv->i_flags)) { 474 if (test_and_clear_bit(IVTV_F_I_UPDATE_WSS, &itv->i_flags)) {
495 /* Lock */ 475 ivtv_set_wss(itv, 1, vi->wss_payload & 0xf);
496 ivtv_set_wss(itv, itv->vbi.wss_found, itv->vbi.wss & 0xf);
497 } 476 }
498 477
499 if (test_and_clear_bit(IVTV_F_I_UPDATE_CC, &itv->i_flags)) { 478 if (test_bit(IVTV_F_I_UPDATE_CC, &itv->i_flags)) {
500 if (itv->vbi.cc_pos == 0) { 479 if (vi->cc_payload_idx == 0) {
501 ivtv_set_cc(itv, 3, 0x80, 0x80, 0x80, 0x80); 480 clear_bit(IVTV_F_I_UPDATE_CC, &itv->i_flags);
481 ivtv_set_cc(itv, 3, &cc);
502 } 482 }
503 while (itv->vbi.cc_pos) { 483 while (vi->cc_payload_idx) {
504 u8 cc_odd0 = itv->vbi.cc_data_odd[0]; 484 cc = vi->cc_payload[0];
505 u8 cc_odd1 = itv->vbi.cc_data_odd[1]; 485
506 u8 cc_even0 = itv->vbi.cc_data_even[0]; 486 memcpy(vi->cc_payload, vi->cc_payload + 1,
507 u8 cc_even1 = itv->vbi.cc_data_even[1]; 487 sizeof(vi->cc_payload) - sizeof(vi->cc_payload[0]));
508 488 vi->cc_payload_idx--;
509 memcpy(itv->vbi.cc_data_odd, itv->vbi.cc_data_odd + 2, sizeof(itv->vbi.cc_data_odd) - 2); 489 if (vi->cc_payload_idx && cc.odd[0] == 0x80 && cc.odd[1] == 0x80)
510 memcpy(itv->vbi.cc_data_even, itv->vbi.cc_data_even + 2, sizeof(itv->vbi.cc_data_even) - 2);
511 itv->vbi.cc_pos -= 2;
512 if (itv->vbi.cc_pos && cc_odd0 == 0x80 && cc_odd1 == 0x80)
513 continue; 490 continue;
514 491
515 /* Send to Saa7127 */ 492 ivtv_set_cc(itv, 3, &cc);
516 ivtv_set_cc(itv, 3, cc_odd0, cc_odd1, cc_even0, cc_even1);
517 if (itv->vbi.cc_pos == 0)
518 set_bit(IVTV_F_I_UPDATE_CC, &itv->i_flags);
519 break; 493 break;
520 } 494 }
521 } 495 }
522 496
523 if (test_and_clear_bit(IVTV_F_I_UPDATE_VPS, &itv->i_flags)) { 497 if (test_and_clear_bit(IVTV_F_I_UPDATE_VPS, &itv->i_flags)) {
524 /* Lock */ 498 ivtv_set_vps(itv, 1);
525 ivtv_set_vps(itv, itv->vbi.vps_found,
526 itv->vbi.vps[0], itv->vbi.vps[1],
527 itv->vbi.vps[2], itv->vbi.vps[3], itv->vbi.vps[4]);
528 } 499 }
529} 500}
diff --git a/drivers/media/video/ivtv/ivtv-vbi.h b/drivers/media/video/ivtv/ivtv-vbi.h
index ec211b49702c..970567b9194d 100644
--- a/drivers/media/video/ivtv/ivtv-vbi.h
+++ b/drivers/media/video/ivtv/ivtv-vbi.h
@@ -17,10 +17,15 @@
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */ 18 */
19 19
20ssize_t ivtv_write_vbi(struct ivtv *itv, const char __user *ubuf, size_t count); 20#ifndef IVTV_VBI_H
21#define IVTV_VBI_H
22
23void ivtv_write_vbi(struct ivtv *itv, const struct v4l2_sliced_vbi_data *sliced, size_t count);
21void ivtv_process_vbi_data(struct ivtv *itv, struct ivtv_buffer *buf, 24void ivtv_process_vbi_data(struct ivtv *itv, struct ivtv_buffer *buf,
22 u64 pts_stamp, int streamtype); 25 u64 pts_stamp, int streamtype);
23int ivtv_used_line(struct ivtv *itv, int line, int field); 26int ivtv_used_line(struct ivtv *itv, int line, int field);
24void ivtv_disable_vbi(struct ivtv *itv); 27void ivtv_disable_cc(struct ivtv *itv);
25void ivtv_set_vbi(unsigned long arg); 28void ivtv_set_vbi(unsigned long arg);
26void ivtv_vbi_work_handler(struct ivtv *itv); 29void ivtv_vbi_work_handler(struct ivtv *itv);
30
31#endif
diff --git a/drivers/media/video/ivtv/ivtv-version.h b/drivers/media/video/ivtv/ivtv-version.h
index 85530a3cd369..d050de2a7229 100644
--- a/drivers/media/video/ivtv/ivtv-version.h
+++ b/drivers/media/video/ivtv/ivtv-version.h
@@ -17,10 +17,15 @@
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */ 18 */
19 19
20#ifndef IVTV_VERSION_H
21#define IVTV_VERSION_H
22
20#define IVTV_DRIVER_NAME "ivtv" 23#define IVTV_DRIVER_NAME "ivtv"
21#define IVTV_DRIVER_VERSION_MAJOR 1 24#define IVTV_DRIVER_VERSION_MAJOR 1
22#define IVTV_DRIVER_VERSION_MINOR 0 25#define IVTV_DRIVER_VERSION_MINOR 1
23#define IVTV_DRIVER_VERSION_PATCHLEVEL 0 26#define IVTV_DRIVER_VERSION_PATCHLEVEL 0
24 27
25#define IVTV_VERSION __stringify(IVTV_DRIVER_VERSION_MAJOR) "." __stringify(IVTV_DRIVER_VERSION_MINOR) "." __stringify(IVTV_DRIVER_VERSION_PATCHLEVEL) 28#define IVTV_VERSION __stringify(IVTV_DRIVER_VERSION_MAJOR) "." __stringify(IVTV_DRIVER_VERSION_MINOR) "." __stringify(IVTV_DRIVER_VERSION_PATCHLEVEL)
26#define IVTV_DRIVER_VERSION KERNEL_VERSION(IVTV_DRIVER_VERSION_MAJOR,IVTV_DRIVER_VERSION_MINOR,IVTV_DRIVER_VERSION_PATCHLEVEL) 29#define IVTV_DRIVER_VERSION KERNEL_VERSION(IVTV_DRIVER_VERSION_MAJOR,IVTV_DRIVER_VERSION_MINOR,IVTV_DRIVER_VERSION_PATCHLEVEL)
30
31#endif
diff --git a/drivers/media/video/ivtv/ivtv-video.c b/drivers/media/video/ivtv/ivtv-video.c
deleted file mode 100644
index 5858b197d510..000000000000
--- a/drivers/media/video/ivtv/ivtv-video.c
+++ /dev/null
@@ -1,142 +0,0 @@
1/*
2 saa7127 interface functions
3 Copyright (C) 2004-2007 Hans Verkuil <hverkuil@xs4all.nl>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
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#include "ivtv-driver.h"
21#include "ivtv-video.h"
22#include "ivtv-i2c.h"
23#include "ivtv-gpio.h"
24#include "ivtv-cards.h"
25#include <media/upd64031a.h>
26#include <media/upd64083.h>
27
28void ivtv_set_vps(struct ivtv *itv, int enabled, u8 vps1, u8 vps2, u8 vps3,
29 u8 vps4, u8 vps5)
30{
31 struct v4l2_sliced_vbi_data data;
32
33 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
34 return;
35 data.id = V4L2_SLICED_VPS;
36 data.field = 0;
37 data.line = enabled ? 16 : 0;
38 data.data[4] = vps1;
39 data.data[10] = vps2;
40 data.data[11] = vps3;
41 data.data[12] = vps4;
42 data.data[13] = vps5;
43 ivtv_saa7127(itv, VIDIOC_INT_S_VBI_DATA, &data);
44}
45
46void ivtv_set_cc(struct ivtv *itv, int mode, u8 cc1, u8 cc2, u8 cc3, u8 cc4)
47{
48 struct v4l2_sliced_vbi_data data;
49
50 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
51 return;
52 data.id = V4L2_SLICED_CAPTION_525;
53 data.field = 0;
54 data.line = (mode & 1) ? 21 : 0;
55 data.data[0] = cc1;
56 data.data[1] = cc2;
57 ivtv_saa7127(itv, VIDIOC_INT_S_VBI_DATA, &data);
58 data.field = 1;
59 data.line = (mode & 2) ? 21 : 0;
60 data.data[0] = cc3;
61 data.data[1] = cc4;
62 ivtv_saa7127(itv, VIDIOC_INT_S_VBI_DATA, &data);
63}
64
65void ivtv_set_wss(struct ivtv *itv, int enabled, int mode)
66{
67 struct v4l2_sliced_vbi_data data;
68
69 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
70 return;
71 /* When using a 50 Hz system, always turn on the
72 wide screen signal with 4x3 ratio as the default.
73 Turning this signal on and off can confuse certain
74 TVs. As far as I can tell there is no reason not to
75 transmit this signal. */
76 if ((itv->std & V4L2_STD_625_50) && !enabled) {
77 enabled = 1;
78 mode = 0x08; /* 4x3 full format */
79 }
80 data.id = V4L2_SLICED_WSS_625;
81 data.field = 0;
82 data.line = enabled ? 23 : 0;
83 data.data[0] = mode & 0xff;
84 data.data[1] = (mode >> 8) & 0xff;
85 ivtv_saa7127(itv, VIDIOC_INT_S_VBI_DATA, &data);
86}
87
88void ivtv_video_set_io(struct ivtv *itv)
89{
90 struct v4l2_routing route;
91 int inp = itv->active_input;
92 u32 type;
93
94 route.input = itv->card->video_inputs[inp].video_input;
95 route.output = 0;
96 itv->video_dec_func(itv, VIDIOC_INT_S_VIDEO_ROUTING, &route);
97
98 type = itv->card->video_inputs[inp].video_type;
99
100 if (type == IVTV_CARD_INPUT_VID_TUNER) {
101 route.input = 0; /* Tuner */
102 } else if (type < IVTV_CARD_INPUT_COMPOSITE1) {
103 route.input = 2; /* S-Video */
104 } else {
105 route.input = 1; /* Composite */
106 }
107
108 if (itv->card->hw_video & IVTV_HW_GPIO)
109 ivtv_gpio(itv, VIDIOC_INT_S_VIDEO_ROUTING, &route);
110
111 if (itv->card->hw_video & IVTV_HW_UPD64031A) {
112 if (type == IVTV_CARD_INPUT_VID_TUNER ||
113 type >= IVTV_CARD_INPUT_COMPOSITE1) {
114 /* Composite: GR on, connect to 3DYCS */
115 route.input = UPD64031A_GR_ON | UPD64031A_3DYCS_COMPOSITE;
116 } else {
117 /* S-Video: GR bypassed, turn it off */
118 route.input = UPD64031A_GR_OFF | UPD64031A_3DYCS_DISABLE;
119 }
120 route.input |= itv->card->gr_config;
121
122 ivtv_upd64031a(itv, VIDIOC_INT_S_VIDEO_ROUTING, &route);
123 }
124
125 if (itv->card->hw_video & IVTV_HW_UPD6408X) {
126 route.input = UPD64083_YCS_MODE;
127 if (type > IVTV_CARD_INPUT_VID_TUNER &&
128 type < IVTV_CARD_INPUT_COMPOSITE1) {
129 /* S-Video uses YCNR mode and internal Y-ADC, the upd64031a
130 is not used. */
131 route.input |= UPD64083_YCNR_MODE;
132 }
133 else if (itv->card->hw_video & IVTV_HW_UPD64031A) {
134 /* Use upd64031a output for tuner and composite(CX23416GYC only) inputs */
135 if ((type == IVTV_CARD_INPUT_VID_TUNER)||
136 (itv->card->type == IVTV_CARD_CX23416GYC)) {
137 route.input |= UPD64083_EXT_Y_ADC;
138 }
139 }
140 ivtv_upd64083(itv, VIDIOC_INT_S_VIDEO_ROUTING, &route);
141 }
142}
diff --git a/drivers/media/video/ivtv/ivtv-video.h b/drivers/media/video/ivtv/ivtv-video.h
deleted file mode 100644
index c8ade5d3c413..000000000000
--- a/drivers/media/video/ivtv/ivtv-video.h
+++ /dev/null
@@ -1,24 +0,0 @@
1/*
2 saa7127 interface functions
3 Copyright (C) 2004-2007 Hans Verkuil <hverkuil@xs4all.nl>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
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
20void ivtv_set_wss(struct ivtv *itv, int enabled, int mode);
21void ivtv_set_cc(struct ivtv *itv, int mode, u8 cc1, u8 cc2, u8 cc3, u8 cc4);
22void ivtv_set_vps(struct ivtv *itv, int enabled, u8 vps1, u8 vps2, u8 vps3,
23 u8 vps4, u8 vps5);
24void ivtv_video_set_io(struct ivtv *itv);
diff --git a/drivers/media/video/ivtv/ivtv-yuv.c b/drivers/media/video/ivtv/ivtv-yuv.c
index bcea09542e5a..e2288f224ab6 100644
--- a/drivers/media/video/ivtv/ivtv-yuv.c
+++ b/drivers/media/video/ivtv/ivtv-yuv.c
@@ -19,11 +19,16 @@
19 */ 19 */
20 20
21#include "ivtv-driver.h" 21#include "ivtv-driver.h"
22#include "ivtv-queue.h"
23#include "ivtv-udma.h" 22#include "ivtv-udma.h"
24#include "ivtv-irq.h"
25#include "ivtv-yuv.h" 23#include "ivtv-yuv.h"
26 24
25const u32 yuv_offset[4] = {
26 IVTV_YUV_BUFFER_OFFSET,
27 IVTV_YUV_BUFFER_OFFSET_1,
28 IVTV_YUV_BUFFER_OFFSET_2,
29 IVTV_YUV_BUFFER_OFFSET_3
30};
31
27static int ivtv_yuv_prep_user_dma(struct ivtv *itv, struct ivtv_user_dma *dma, 32static int ivtv_yuv_prep_user_dma(struct ivtv *itv, struct ivtv_user_dma *dma,
28 struct ivtv_dma_frame *args) 33 struct ivtv_dma_frame *args)
29{ 34{
@@ -37,7 +42,7 @@ static int ivtv_yuv_prep_user_dma(struct ivtv *itv, struct ivtv_user_dma *dma,
37 int y_decode_height, uv_decode_height, y_size; 42 int y_decode_height, uv_decode_height, y_size;
38 int frame = atomic_read(&itv->yuv_info.next_fill_frame); 43 int frame = atomic_read(&itv->yuv_info.next_fill_frame);
39 44
40 y_buffer_offset = IVTV_DEC_MEM_START + yuv_offset[frame]; 45 y_buffer_offset = IVTV_DECODER_OFFSET + yuv_offset[frame];
41 uv_buffer_offset = y_buffer_offset + IVTV_YUV_BUFFER_UV_OFFSET; 46 uv_buffer_offset = y_buffer_offset + IVTV_YUV_BUFFER_UV_OFFSET;
42 47
43 y_decode_height = uv_decode_height = args->src.height + args->src.top; 48 y_decode_height = uv_decode_height = args->src.height + args->src.top;
@@ -83,7 +88,14 @@ static int ivtv_yuv_prep_user_dma(struct ivtv *itv, struct ivtv_user_dma *dma,
83 } 88 }
84 89
85 /* Fill & map SG List */ 90 /* Fill & map SG List */
86 ivtv_udma_fill_sg_list (dma, &uv_dma, ivtv_udma_fill_sg_list (dma, &y_dma, 0)); 91 if (ivtv_udma_fill_sg_list (dma, &uv_dma, ivtv_udma_fill_sg_list (dma, &y_dma, 0)) < 0) {
92 IVTV_DEBUG_WARN("could not allocate bounce buffers for highmem userspace buffers\n");
93 for (i = 0; i < dma->page_count; i++) {
94 put_page(dma->map[i]);
95 }
96 dma->page_count = 0;
97 return -ENOMEM;
98 }
87 dma->SG_length = pci_map_sg(itv->dev, dma->SGlist, dma->page_count, PCI_DMA_TODEVICE); 99 dma->SG_length = pci_map_sg(itv->dev, dma->SGlist, dma->page_count, PCI_DMA_TODEVICE);
88 100
89 /* Fill SG Array with new values */ 101 /* Fill SG Array with new values */
@@ -94,7 +106,7 @@ static int ivtv_yuv_prep_user_dma(struct ivtv *itv, struct ivtv_user_dma *dma,
94 if (itv->yuv_info.blanking_dmaptr) { 106 if (itv->yuv_info.blanking_dmaptr) {
95 dma->SGarray[dma->SG_length].size = cpu_to_le32(720*16); 107 dma->SGarray[dma->SG_length].size = cpu_to_le32(720*16);
96 dma->SGarray[dma->SG_length].src = cpu_to_le32(itv->yuv_info.blanking_dmaptr); 108 dma->SGarray[dma->SG_length].src = cpu_to_le32(itv->yuv_info.blanking_dmaptr);
97 dma->SGarray[dma->SG_length].dst = cpu_to_le32(IVTV_DEC_MEM_START + yuv_offset[frame]); 109 dma->SGarray[dma->SG_length].dst = cpu_to_le32(IVTV_DECODER_OFFSET + yuv_offset[frame]);
98 dma->SG_length++; 110 dma->SG_length++;
99 } 111 }
100 } 112 }
@@ -612,7 +624,6 @@ static void ivtv_yuv_handle_vertical(struct ivtv *itv, struct yuv_frame_info *wi
612 itv->yuv_info.v_filter_2 = v_filter_2; 624 itv->yuv_info.v_filter_2 = v_filter_2;
613 } 625 }
614 626
615 itv->yuv_info.frame_interlaced_last = itv->yuv_info.frame_interlaced;
616} 627}
617 628
618/* Modify the supplied coordinate information to fit the visible osd area */ 629/* Modify the supplied coordinate information to fit the visible osd area */
@@ -799,6 +810,7 @@ static u32 ivtv_yuv_window_setup (struct ivtv *itv, struct yuv_frame_info *windo
799 (itv->yuv_info.old_frame_info.src_y != window->src_y) || 810 (itv->yuv_info.old_frame_info.src_y != window->src_y) ||
800 (itv->yuv_info.old_frame_info.pan_y != window->pan_y) || 811 (itv->yuv_info.old_frame_info.pan_y != window->pan_y) ||
801 (itv->yuv_info.old_frame_info.vis_h != window->vis_h) || 812 (itv->yuv_info.old_frame_info.vis_h != window->vis_h) ||
813 (itv->yuv_info.old_frame_info.lace_mode != window->lace_mode) ||
802 (itv->yuv_info.old_frame_info.interlaced_y != window->interlaced_y) || 814 (itv->yuv_info.old_frame_info.interlaced_y != window->interlaced_y) ||
803 (itv->yuv_info.old_frame_info.interlaced_uv != window->interlaced_uv)) { 815 (itv->yuv_info.old_frame_info.interlaced_uv != window->interlaced_uv)) {
804 yuv_update |= IVTV_YUV_UPDATE_VERTICAL; 816 yuv_update |= IVTV_YUV_UPDATE_VERTICAL;
@@ -898,8 +910,21 @@ static void ivtv_yuv_init (struct ivtv *itv)
898 itv->yuv_info.decode_height = 480; 910 itv->yuv_info.decode_height = 480;
899 911
900 /* If no visible size set, assume full size */ 912 /* If no visible size set, assume full size */
901 if (!itv->yuv_info.osd_vis_w) itv->yuv_info.osd_vis_w = 720 - itv->yuv_info.osd_x_offset; 913 if (!itv->yuv_info.osd_vis_w)
902 if (!itv->yuv_info.osd_vis_h) itv->yuv_info.osd_vis_h = itv->yuv_info.decode_height - itv->yuv_info.osd_y_offset; 914 itv->yuv_info.osd_vis_w = 720 - itv->yuv_info.osd_x_offset;
915
916 if (!itv->yuv_info.osd_vis_h) {
917 itv->yuv_info.osd_vis_h = itv->yuv_info.decode_height - itv->yuv_info.osd_y_offset;
918 } else {
919 /* If output video standard has changed, requested height may
920 not be legal */
921 if (itv->yuv_info.osd_vis_h + itv->yuv_info.osd_y_offset > itv->yuv_info.decode_height) {
922 IVTV_DEBUG_WARN("Clipping yuv output - fb size (%d) exceeds video standard limit (%d)\n",
923 itv->yuv_info.osd_vis_h + itv->yuv_info.osd_y_offset,
924 itv->yuv_info.decode_height);
925 itv->yuv_info.osd_vis_h = itv->yuv_info.decode_height - itv->yuv_info.osd_y_offset;
926 }
927 }
903 928
904 /* We need a buffer for blanking when Y plane is offset - non-fatal if we can't get one */ 929 /* We need a buffer for blanking when Y plane is offset - non-fatal if we can't get one */
905 itv->yuv_info.blanking_ptr = kzalloc(720*16,GFP_KERNEL); 930 itv->yuv_info.blanking_ptr = kzalloc(720*16,GFP_KERNEL);
@@ -927,6 +952,7 @@ int ivtv_yuv_prep_frame(struct ivtv *itv, struct ivtv_dma_frame *args)
927 int rc = 0; 952 int rc = 0;
928 int got_sig = 0; 953 int got_sig = 0;
929 int frame, next_fill_frame, last_fill_frame; 954 int frame, next_fill_frame, last_fill_frame;
955 int register_update = 0;
930 956
931 IVTV_DEBUG_INFO("yuv_prep_frame\n"); 957 IVTV_DEBUG_INFO("yuv_prep_frame\n");
932 958
@@ -940,6 +966,7 @@ int ivtv_yuv_prep_frame(struct ivtv *itv, struct ivtv_dma_frame *args)
940 /* Buffers are full - Overwrite the last frame */ 966 /* Buffers are full - Overwrite the last frame */
941 next_fill_frame = frame; 967 next_fill_frame = frame;
942 frame = (frame - 1) & 3; 968 frame = (frame - 1) & 3;
969 register_update = itv->yuv_info.new_frame_info[frame].update;
943 } 970 }
944 971
945 /* Take a snapshot of the yuv coordinate information */ 972 /* Take a snapshot of the yuv coordinate information */
@@ -955,6 +982,9 @@ int ivtv_yuv_prep_frame(struct ivtv *itv, struct ivtv_dma_frame *args)
955 itv->yuv_info.new_frame_info[frame].tru_w = args->src_width; 982 itv->yuv_info.new_frame_info[frame].tru_w = args->src_width;
956 itv->yuv_info.new_frame_info[frame].tru_h = args->src_height; 983 itv->yuv_info.new_frame_info[frame].tru_h = args->src_height;
957 984
985 /* Snapshot field order */
986 itv->yuv_info.sync_field[frame] = itv->yuv_info.lace_sync_field;
987
958 /* Are we going to offset the Y plane */ 988 /* Are we going to offset the Y plane */
959 if (args->src.height + args->src.top < 512-16) 989 if (args->src.height + args->src.top < 512-16)
960 itv->yuv_info.new_frame_info[frame].offset_y = 1; 990 itv->yuv_info.new_frame_info[frame].offset_y = 1;
@@ -970,6 +1000,7 @@ int ivtv_yuv_prep_frame(struct ivtv *itv, struct ivtv_dma_frame *args)
970 itv->yuv_info.new_frame_info[frame].update = 0; 1000 itv->yuv_info.new_frame_info[frame].update = 0;
971 itv->yuv_info.new_frame_info[frame].interlaced_y = 0; 1001 itv->yuv_info.new_frame_info[frame].interlaced_y = 0;
972 itv->yuv_info.new_frame_info[frame].interlaced_uv = 0; 1002 itv->yuv_info.new_frame_info[frame].interlaced_uv = 0;
1003 itv->yuv_info.new_frame_info[frame].lace_mode = itv->yuv_info.lace_mode;
973 1004
974 if (memcmp (&itv->yuv_info.old_frame_info_args, &itv->yuv_info.new_frame_info[frame], 1005 if (memcmp (&itv->yuv_info.old_frame_info_args, &itv->yuv_info.new_frame_info[frame],
975 sizeof (itv->yuv_info.new_frame_info[frame]))) { 1006 sizeof (itv->yuv_info.new_frame_info[frame]))) {
@@ -978,6 +1009,14 @@ int ivtv_yuv_prep_frame(struct ivtv *itv, struct ivtv_dma_frame *args)
978/* IVTV_DEBUG_YUV ("Requesting register update for frame %d\n",frame); */ 1009/* IVTV_DEBUG_YUV ("Requesting register update for frame %d\n",frame); */
979 } 1010 }
980 1011
1012 itv->yuv_info.new_frame_info[frame].update |= register_update;
1013
1014 /* Should this frame be delayed ? */
1015 if (itv->yuv_info.sync_field[frame] != itv->yuv_info.sync_field[(frame - 1) & 3])
1016 itv->yuv_info.field_delay[frame] = 1;
1017 else
1018 itv->yuv_info.field_delay[frame] = 0;
1019
981 /* DMA the frame */ 1020 /* DMA the frame */
982 mutex_lock(&itv->udma.lock); 1021 mutex_lock(&itv->udma.lock);
983 1022
diff --git a/drivers/media/video/ivtv/ivtv-yuv.h b/drivers/media/video/ivtv/ivtv-yuv.h
index 88972d3f77c4..f7215eeca018 100644
--- a/drivers/media/video/ivtv/ivtv-yuv.h
+++ b/drivers/media/video/ivtv/ivtv-yuv.h
@@ -18,7 +18,28 @@
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */ 19 */
20 20
21#ifndef IVTV_YUV_H
22#define IVTV_YUV_H
23
24/* Buffers on hardware offsets */
25#define IVTV_YUV_BUFFER_OFFSET 0x001a8600 /* First YUV Buffer */
26#define IVTV_YUV_BUFFER_OFFSET_1 0x00240400 /* Second YUV Buffer */
27#define IVTV_YUV_BUFFER_OFFSET_2 0x002d8200 /* Third YUV Buffer */
28#define IVTV_YUV_BUFFER_OFFSET_3 0x00370000 /* Fourth YUV Buffer */
29#define IVTV_YUV_BUFFER_UV_OFFSET 0x65400 /* Offset to UV Buffer */
30
31/* Offset to filter table in firmware */
32#define IVTV_YUV_HORIZONTAL_FILTER_OFFSET 0x025d8
33#define IVTV_YUV_VERTICAL_FILTER_OFFSET 0x03358
34
35#define IVTV_YUV_UPDATE_HORIZONTAL 0x01
36#define IVTV_YUV_UPDATE_VERTICAL 0x02
37
38extern const u32 yuv_offset[4];
39
21int ivtv_yuv_filter_check(struct ivtv *itv); 40int ivtv_yuv_filter_check(struct ivtv *itv);
22int ivtv_yuv_prep_frame(struct ivtv *itv, struct ivtv_dma_frame *args); 41int ivtv_yuv_prep_frame(struct ivtv *itv, struct ivtv_dma_frame *args);
23void ivtv_yuv_close(struct ivtv *itv); 42void ivtv_yuv_close(struct ivtv *itv);
24void ivtv_yuv_work_handler (struct ivtv *itv); 43void ivtv_yuv_work_handler (struct ivtv *itv);
44
45#endif
diff --git a/drivers/media/video/ivtv/ivtvfb.c b/drivers/media/video/ivtv/ivtvfb.c
new file mode 100644
index 000000000000..9684048fe56c
--- /dev/null
+++ b/drivers/media/video/ivtv/ivtvfb.c
@@ -0,0 +1,1190 @@
1/*
2 On Screen Display cx23415 Framebuffer driver
3
4 This module presents the cx23415 OSD (onscreen display) framebuffer memory
5 as a standard Linux /dev/fb style framebuffer device. The framebuffer has
6 support for 8, 16 & 32 bpp packed pixel formats with alpha channel. In 16bpp
7 mode, there is a choice of a three color depths (12, 15 or 16 bits), but no
8 local alpha. The colorspace is selectable between rgb & yuv.
9 Depending on the TV standard configured in the ivtv module at load time,
10 the initial resolution is either 640x400 (NTSC) or 640x480 (PAL) at 8bpp.
11 Video timings are locked to ensure a vertical refresh rate of 50Hz (PAL)
12 or 59.94 (NTSC)
13
14 Copyright (c) 2003 Matt T. Yourst <yourst@yourst.com>
15
16 Derived from drivers/video/vesafb.c
17 Portions (c) 1998 Gerd Knorr <kraxel@goldbach.in-berlin.de>
18
19 2.6 kernel port:
20 Copyright (C) 2004 Matthias Badaire
21
22 Copyright (C) 2004 Chris Kennedy <c@groovy.org>
23
24 Copyright (C) 2006 Ian Armstrong <ian@iarmst.demon.co.uk>
25
26 This program is free software; you can redistribute it and/or modify
27 it under the terms of the GNU General Public License as published by
28 the Free Software Foundation; either version 2 of the License, or
29 (at your option) any later version.
30
31 This program is distributed in the hope that it will be useful,
32 but WITHOUT ANY WARRANTY; without even the implied warranty of
33 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 GNU General Public License for more details.
35
36 You should have received a copy of the GNU General Public License
37 along with this program; if not, write to the Free Software
38 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
39 */
40
41#include <linux/module.h>
42#include <linux/kernel.h>
43#include <linux/fb.h>
44#include <linux/ivtvfb.h>
45
46#ifdef CONFIG_MTRR
47#include <asm/mtrr.h>
48#endif
49
50#include "ivtv-driver.h"
51#include "ivtv-udma.h"
52#include "ivtv-mailbox.h"
53
54/* card parameters */
55static int ivtvfb_card_id = -1;
56static int ivtvfb_debug = 0;
57static int osd_laced;
58static int osd_compat;
59static int osd_depth;
60static int osd_upper;
61static int osd_left;
62static int osd_yres;
63static int osd_xres;
64
65module_param(ivtvfb_card_id, int, 0444);
66module_param_named(debug,ivtvfb_debug, int, 0644);
67module_param(osd_laced, bool, 0444);
68module_param(osd_compat, bool, 0444);
69module_param(osd_depth, int, 0444);
70module_param(osd_upper, int, 0444);
71module_param(osd_left, int, 0444);
72module_param(osd_yres, int, 0444);
73module_param(osd_xres, int, 0444);
74
75MODULE_PARM_DESC(ivtvfb_card_id,
76 "Only use framebuffer of the specified ivtv card (0-31)\n"
77 "\t\t\tdefault -1: initialize all available framebuffers");
78
79MODULE_PARM_DESC(debug,
80 "Debug level (bitmask). Default: errors only\n"
81 "\t\t\t(debug = 3 gives full debugging)");
82
83MODULE_PARM_DESC(osd_compat,
84 "Compatibility mode - Display size is locked (use for old X drivers)\n"
85 "\t\t\t0=off\n"
86 "\t\t\t1=on\n"
87 "\t\t\tdefault off");
88
89/* Why upper, left, xres, yres, depth, laced ? To match terminology used
90 by fbset.
91 Why start at 1 for left & upper coordinate ? Because X doesn't allow 0 */
92
93MODULE_PARM_DESC(osd_laced,
94 "Interlaced mode\n"
95 "\t\t\t0=off\n"
96 "\t\t\t1=on\n"
97 "\t\t\tdefault off");
98
99MODULE_PARM_DESC(osd_depth,
100 "Bits per pixel - 8, 16, 32\n"
101 "\t\t\tdefault 8");
102
103MODULE_PARM_DESC(osd_upper,
104 "Vertical start position\n"
105 "\t\t\tdefault 0 (Centered)");
106
107MODULE_PARM_DESC(osd_left,
108 "Horizontal start position\n"
109 "\t\t\tdefault 0 (Centered)");
110
111MODULE_PARM_DESC(osd_yres,
112 "Display height\n"
113 "\t\t\tdefault 480 (PAL)\n"
114 "\t\t\t 400 (NTSC)");
115
116MODULE_PARM_DESC(osd_xres,
117 "Display width\n"
118 "\t\t\tdefault 640");
119
120MODULE_AUTHOR("Kevin Thayer, Chris Kennedy, Hans Verkuil, John Harvey, Ian Armstrong");
121MODULE_LICENSE("GPL");
122
123/* --------------------------------------------------------------------- */
124
125#define IVTVFB_DBGFLG_WARN (1 << 0)
126#define IVTVFB_DBGFLG_INFO (1 << 1)
127
128#define IVTVFB_DEBUG(x, type, fmt, args...) \
129 do { \
130 if ((x) & ivtvfb_debug) \
131 printk(KERN_INFO "ivtvfb%d " type ": " fmt, itv->num , ## args); \
132 } while (0)
133#define IVTVFB_DEBUG_WARN(fmt, args...) IVTVFB_DEBUG(IVTVFB_DBGFLG_WARN, "warning", fmt , ## args)
134#define IVTVFB_DEBUG_INFO(fmt, args...) IVTVFB_DEBUG(IVTVFB_DBGFLG_INFO, "info", fmt , ## args)
135
136/* Standard kernel messages */
137#define IVTVFB_ERR(fmt, args...) printk(KERN_ERR "ivtvfb%d: " fmt, itv->num , ## args)
138#define IVTVFB_WARN(fmt, args...) printk(KERN_WARNING "ivtvfb%d: " fmt, itv->num , ## args)
139#define IVTVFB_INFO(fmt, args...) printk(KERN_INFO "ivtvfb%d: " fmt, itv->num , ## args)
140
141/* --------------------------------------------------------------------- */
142
143#define IVTV_OSD_MAX_WIDTH 720
144#define IVTV_OSD_MAX_HEIGHT 576
145
146#define IVTV_OSD_BPP_8 0x00
147#define IVTV_OSD_BPP_16_444 0x03
148#define IVTV_OSD_BPP_16_555 0x02
149#define IVTV_OSD_BPP_16_565 0x01
150#define IVTV_OSD_BPP_32 0x04
151
152struct osd_info {
153 /* Physical base address */
154 unsigned long video_pbase;
155 /* Relative base address (relative to start of decoder memory) */
156 u32 video_rbase;
157 /* Mapped base address */
158 volatile char __iomem *video_vbase;
159 /* Buffer size */
160 u32 video_buffer_size;
161
162#ifdef CONFIG_MTRR
163 /* video_base rounded down as required by hardware MTRRs */
164 unsigned long fb_start_aligned_physaddr;
165 /* video_base rounded up as required by hardware MTRRs */
166 unsigned long fb_end_aligned_physaddr;
167#endif
168
169 /* Current osd mode */
170 int osd_mode;
171
172 /* Store the buffer offset */
173 int set_osd_coords_x;
174 int set_osd_coords_y;
175
176 /* Current dimensions (NOT VISIBLE SIZE!) */
177 int display_width;
178 int display_height;
179 int display_byte_stride;
180
181 /* Current bits per pixel */
182 int bits_per_pixel;
183 int bytes_per_pixel;
184
185 /* Frame buffer stuff */
186 struct fb_info ivtvfb_info;
187 struct fb_var_screeninfo ivtvfb_defined;
188 struct fb_fix_screeninfo ivtvfb_fix;
189};
190
191struct ivtv_osd_coords {
192 unsigned long offset;
193 unsigned long max_offset;
194 int pixel_stride;
195 int lines;
196 int x;
197 int y;
198};
199
200/* --------------------------------------------------------------------- */
201
202/* ivtv API calls for framebuffer related support */
203
204static int ivtvfb_get_framebuffer(struct ivtv *itv, u32 *fbbase,
205 u32 *fblength)
206{
207 u32 data[CX2341X_MBOX_MAX_DATA];
208 int rc;
209
210 rc = ivtv_vapi_result(itv, data, CX2341X_OSD_GET_FRAMEBUFFER, 0);
211 *fbbase = data[0];
212 *fblength = data[1];
213 return rc;
214}
215
216static int ivtvfb_get_osd_coords(struct ivtv *itv,
217 struct ivtv_osd_coords *osd)
218{
219 struct osd_info *oi = itv->osd_info;
220 u32 data[CX2341X_MBOX_MAX_DATA];
221
222 ivtv_vapi_result(itv, data, CX2341X_OSD_GET_OSD_COORDS, 0);
223
224 osd->offset = data[0] - oi->video_rbase;
225 osd->max_offset = oi->display_width * oi->display_height * 4;
226 osd->pixel_stride = data[1];
227 osd->lines = data[2];
228 osd->x = data[3];
229 osd->y = data[4];
230 return 0;
231}
232
233static int ivtvfb_set_osd_coords(struct ivtv *itv, const struct ivtv_osd_coords *osd)
234{
235 struct osd_info *oi = itv->osd_info;
236
237 oi->display_width = osd->pixel_stride;
238 oi->display_byte_stride = osd->pixel_stride * oi->bytes_per_pixel;
239 oi->set_osd_coords_x += osd->x;
240 oi->set_osd_coords_y = osd->y;
241
242 return ivtv_vapi(itv, CX2341X_OSD_SET_OSD_COORDS, 5,
243 osd->offset + oi->video_rbase,
244 osd->pixel_stride,
245 osd->lines, osd->x, osd->y);
246}
247
248static int ivtvfb_set_display_window(struct ivtv *itv, struct v4l2_rect *ivtv_window)
249{
250 int osd_height_limit = itv->is_50hz ? 576 : 480;
251
252 /* Only fail if resolution too high, otherwise fudge the start coords. */
253 if ((ivtv_window->height > osd_height_limit) || (ivtv_window->width > IVTV_OSD_MAX_WIDTH))
254 return -EINVAL;
255
256 /* Ensure we don't exceed display limits */
257 if (ivtv_window->top + ivtv_window->height > osd_height_limit) {
258 IVTVFB_DEBUG_WARN("ivtv_ioctl_fb_set_display_window - Invalid height setting (%d, %d)\n",
259 ivtv_window->top, ivtv_window->height);
260 ivtv_window->top = osd_height_limit - ivtv_window->height;
261 }
262
263 if (ivtv_window->left + ivtv_window->width > IVTV_OSD_MAX_WIDTH) {
264 IVTVFB_DEBUG_WARN("ivtv_ioctl_fb_set_display_window - Invalid width setting (%d, %d)\n",
265 ivtv_window->left, ivtv_window->width);
266 ivtv_window->left = IVTV_OSD_MAX_WIDTH - ivtv_window->width;
267 }
268
269 /* Set the OSD origin */
270 write_reg((ivtv_window->top << 16) | ivtv_window->left, 0x02a04);
271
272 /* How much to display */
273 write_reg(((ivtv_window->top+ivtv_window->height) << 16) | (ivtv_window->left+ivtv_window->width), 0x02a08);
274
275 /* Pass this info back the yuv handler */
276 itv->yuv_info.osd_vis_w = ivtv_window->width;
277 itv->yuv_info.osd_vis_h = ivtv_window->height;
278 itv->yuv_info.osd_x_offset = ivtv_window->left;
279 itv->yuv_info.osd_y_offset = ivtv_window->top;
280
281 return 0;
282}
283
284static int ivtvfb_prep_dec_dma_to_device(struct ivtv *itv,
285 unsigned long ivtv_dest_addr, void __user *userbuf,
286 int size_in_bytes)
287{
288 DEFINE_WAIT(wait);
289 int ret = 0;
290 int got_sig = 0;
291
292 mutex_lock(&itv->udma.lock);
293 /* Map User DMA */
294 if (ivtv_udma_setup(itv, ivtv_dest_addr, userbuf, size_in_bytes) <= 0) {
295 mutex_unlock(&itv->udma.lock);
296 IVTVFB_WARN("ivtvfb_prep_dec_dma_to_device, "
297 "Error with get_user_pages: %d bytes, %d pages returned\n",
298 size_in_bytes, itv->udma.page_count);
299
300 /* get_user_pages must have failed completely */
301 return -EIO;
302 }
303
304 IVTVFB_DEBUG_INFO("ivtvfb_prep_dec_dma_to_device, %d bytes, %d pages\n",
305 size_in_bytes, itv->udma.page_count);
306
307 ivtv_udma_prepare(itv);
308 prepare_to_wait(&itv->dma_waitq, &wait, TASK_INTERRUPTIBLE);
309 /* if no UDMA is pending and no UDMA is in progress, then the DMA
310 is finished */
311 while (itv->i_flags & (IVTV_F_I_UDMA_PENDING | IVTV_F_I_UDMA)) {
312 /* don't interrupt if the DMA is in progress but break off
313 a still pending DMA. */
314 got_sig = signal_pending(current);
315 if (got_sig && test_and_clear_bit(IVTV_F_I_UDMA_PENDING, &itv->i_flags))
316 break;
317 got_sig = 0;
318 schedule();
319 }
320 finish_wait(&itv->dma_waitq, &wait);
321
322 /* Unmap Last DMA Xfer */
323 ivtv_udma_unmap(itv);
324 mutex_unlock(&itv->udma.lock);
325 if (got_sig) {
326 IVTV_DEBUG_INFO("User stopped OSD\n");
327 return -EINTR;
328 }
329
330 return ret;
331}
332
333static int ivtvfb_prep_frame(struct ivtv *itv, int cmd, void __user *source,
334 unsigned long dest_offset, int count)
335{
336 DEFINE_WAIT(wait);
337 struct osd_info *oi = itv->osd_info;
338
339 /* Nothing to do */
340 if (count == 0) {
341 IVTVFB_DEBUG_WARN("ivtvfb_prep_frame: Nothing to do. count = 0\n");
342 return -EINVAL;
343 }
344
345 /* Check Total FB Size */
346 if ((dest_offset + count) > oi->video_buffer_size) {
347 IVTVFB_WARN("ivtvfb_prep_frame: Overflowing the framebuffer %ld, only %d available\n",
348 dest_offset + count, oi->video_buffer_size);
349 return -E2BIG;
350 }
351
352 /* Not fatal, but will have undesirable results */
353 if ((unsigned long)source & 3)
354 IVTVFB_WARN("ivtvfb_prep_frame: Source address not 32 bit aligned (0x%08lx)\n",
355 (unsigned long)source);
356
357 if (dest_offset & 3)
358 IVTVFB_WARN("ivtvfb_prep_frame: Dest offset not 32 bit aligned (%ld)\n", dest_offset);
359
360 if (count & 3)
361 IVTVFB_WARN("ivtvfb_prep_frame: Count not a multiple of 4 (%d)\n", count);
362
363 /* Check Source */
364 if (!access_ok(VERIFY_READ, source + dest_offset, count)) {
365 IVTVFB_WARN("Invalid userspace pointer 0x%08lx\n",
366 (unsigned long)source);
367
368 IVTVFB_DEBUG_WARN("access_ok() failed for offset 0x%08lx source 0x%08lx count %d\n",
369 dest_offset, (unsigned long)source,
370 count);
371 return -EINVAL;
372 }
373
374 /* OSD Address to send DMA to */
375 dest_offset += IVTV_DECODER_OFFSET + oi->video_rbase;
376
377 /* Fill Buffers */
378 return ivtvfb_prep_dec_dma_to_device(itv, dest_offset, source, count);
379}
380
381static int ivtvfb_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
382{
383 DEFINE_WAIT(wait);
384 struct ivtv *itv = (struct ivtv *)info->par;
385 int rc = 0;
386
387 switch (cmd) {
388 case FBIOGET_VBLANK: {
389 struct fb_vblank vblank;
390 u32 trace;
391
392 vblank.flags = FB_VBLANK_HAVE_COUNT |FB_VBLANK_HAVE_VCOUNT |
393 FB_VBLANK_HAVE_VSYNC;
394 trace = read_reg(0x028c0) >> 16;
395 if (itv->is_50hz && trace > 312) trace -= 312;
396 else if (itv->is_60hz && trace > 262) trace -= 262;
397 if (trace == 1) vblank.flags |= FB_VBLANK_VSYNCING;
398 vblank.count = itv->last_vsync_field;
399 vblank.vcount = trace;
400 vblank.hcount = 0;
401 if (copy_to_user((void __user *)arg, &vblank, sizeof(vblank)))
402 return -EFAULT;
403 return 0;
404 }
405
406 case FBIO_WAITFORVSYNC:
407 prepare_to_wait(&itv->vsync_waitq, &wait, TASK_INTERRUPTIBLE);
408 if (!schedule_timeout(msecs_to_jiffies(50))) rc = -ETIMEDOUT;
409 finish_wait(&itv->vsync_waitq, &wait);
410 return rc;
411
412 case IVTVFB_IOC_DMA_FRAME: {
413 struct ivtvfb_dma_frame args;
414
415 IVTVFB_DEBUG_INFO("IVTVFB_IOC_DMA_FRAME\n");
416 if (copy_from_user(&args, (void __user *)arg, sizeof(args)))
417 return -EFAULT;
418
419 return ivtvfb_prep_frame(itv, cmd, args.source, args.dest_offset, args.count);
420 }
421
422 default:
423 IVTVFB_DEBUG_INFO("Unknown ioctl %08x\n", cmd);
424 return -EINVAL;
425 }
426 return 0;
427}
428
429/* Framebuffer device handling */
430
431static int ivtvfb_set_var(struct ivtv *itv, struct fb_var_screeninfo *var)
432{
433 struct osd_info *oi = itv->osd_info;
434 struct ivtv_osd_coords ivtv_osd;
435 struct v4l2_rect ivtv_window;
436 int osd_mode = -1;
437
438 IVTVFB_DEBUG_INFO("ivtvfb_set_var\n");
439
440 /* Select color space */
441 if (var->nonstd) /* YUV */
442 write_reg(read_reg(0x02a00) | 0x0002000, 0x02a00);
443 else /* RGB */
444 write_reg(read_reg(0x02a00) & ~0x0002000, 0x02a00);
445
446 /* Set the color mode */
447 switch (var->bits_per_pixel) {
448 case 8:
449 osd_mode = IVTV_OSD_BPP_8;
450 break;
451 case 32:
452 osd_mode = IVTV_OSD_BPP_32;
453 break;
454 case 16:
455 switch (var->green.length) {
456 case 4:
457 osd_mode = IVTV_OSD_BPP_16_444;
458 break;
459 case 5:
460 osd_mode = IVTV_OSD_BPP_16_555;
461 break;
462 case 6:
463 osd_mode = IVTV_OSD_BPP_16_565;
464 break;
465 default:
466 IVTVFB_DEBUG_WARN("ivtvfb_set_var - Invalid bpp\n");
467 }
468 break;
469 default:
470 IVTVFB_DEBUG_WARN("ivtvfb_set_var - Invalid bpp\n");
471 }
472
473 /* Change osd mode if needed.
474 Although rare, things can go wrong. The extra mode
475 change seems to help... */
476 if (osd_mode != -1 && osd_mode != oi->osd_mode) {
477 ivtv_vapi(itv, CX2341X_OSD_SET_PIXEL_FORMAT, 1, 0);
478 ivtv_vapi(itv, CX2341X_OSD_SET_PIXEL_FORMAT, 1, osd_mode);
479 oi->osd_mode = osd_mode;
480 }
481
482 oi->bits_per_pixel = var->bits_per_pixel;
483 oi->bytes_per_pixel = var->bits_per_pixel / 8;
484
485 /* Set the flicker filter */
486 switch (var->vmode & FB_VMODE_MASK) {
487 case FB_VMODE_NONINTERLACED: /* Filter on */
488 ivtv_vapi(itv, CX2341X_OSD_SET_FLICKER_STATE, 1, 1);
489 break;
490 case FB_VMODE_INTERLACED: /* Filter off */
491 ivtv_vapi(itv, CX2341X_OSD_SET_FLICKER_STATE, 1, 0);
492 break;
493 default:
494 IVTVFB_DEBUG_WARN("ivtvfb_set_var - Invalid video mode\n");
495 }
496
497 /* Read the current osd info */
498 ivtvfb_get_osd_coords(itv, &ivtv_osd);
499
500 /* Now set the OSD to the size we want */
501 ivtv_osd.pixel_stride = var->xres_virtual;
502 ivtv_osd.lines = var->yres_virtual;
503 ivtv_osd.x = 0;
504 ivtv_osd.y = 0;
505 ivtvfb_set_osd_coords(itv, &ivtv_osd);
506
507 /* Can't seem to find the right API combo for this.
508 Use another function which does what we need through direct register access. */
509 ivtv_window.width = var->xres;
510 ivtv_window.height = var->yres;
511
512 /* Minimum margin cannot be 0, as X won't allow such a mode */
513 if (!var->upper_margin) var->upper_margin++;
514 if (!var->left_margin) var->left_margin++;
515 ivtv_window.top = var->upper_margin - 1;
516 ivtv_window.left = var->left_margin - 1;
517
518 ivtvfb_set_display_window(itv, &ivtv_window);
519
520 /* Force update of yuv registers */
521 itv->yuv_info.yuv_forced_update = 1;
522
523 IVTVFB_DEBUG_INFO("Display size: %dx%d (virtual %dx%d) @ %dbpp\n",
524 var->xres, var->yres,
525 var->xres_virtual, var->yres_virtual,
526 var->bits_per_pixel);
527
528 IVTVFB_DEBUG_INFO("Display position: %d, %d\n",
529 var->left_margin, var->upper_margin);
530
531 IVTVFB_DEBUG_INFO("Display filter: %s\n",
532 (var->vmode & FB_VMODE_MASK) == FB_VMODE_NONINTERLACED ? "on" : "off");
533 IVTVFB_DEBUG_INFO("Color space: %s\n", var->nonstd ? "YUV" : "RGB");
534
535 return 0;
536}
537
538static int ivtvfb_get_fix(struct ivtv *itv, struct fb_fix_screeninfo *fix)
539{
540 struct osd_info *oi = itv->osd_info;
541
542 IVTVFB_DEBUG_INFO("ivtvfb_get_fix\n");
543 memset(fix, 0, sizeof(struct fb_fix_screeninfo));
544 strcpy(fix->id, "cx23415 TV out");
545 fix->smem_start = oi->video_pbase;
546 fix->smem_len = oi->video_buffer_size;
547 fix->type = FB_TYPE_PACKED_PIXELS;
548 fix->visual = (oi->bits_per_pixel == 8) ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
549 fix->xpanstep = 1;
550 fix->ypanstep = 1;
551 fix->ywrapstep = 0;
552 fix->line_length = oi->display_byte_stride;
553 fix->accel = FB_ACCEL_NONE;
554 return 0;
555}
556
557/* Check the requested display mode, returning -EINVAL if we can't
558 handle it. */
559
560static int _ivtvfb_check_var(struct fb_var_screeninfo *var, struct ivtv *itv)
561{
562 struct osd_info *oi = itv->osd_info;
563 int osd_height_limit;
564 u32 pixclock, hlimit, vlimit;
565
566 IVTVFB_DEBUG_INFO("ivtvfb_check_var\n");
567
568 /* Set base references for mode calcs. */
569 if (itv->is_50hz) {
570 pixclock = 84316;
571 hlimit = 776;
572 vlimit = 591;
573 osd_height_limit = 576;
574 }
575 else {
576 pixclock = 83926;
577 hlimit = 776;
578 vlimit = 495;
579 osd_height_limit = 480;
580 }
581
582 /* Check the bits per pixel */
583 if (osd_compat) {
584 if (var->bits_per_pixel != 32) {
585 IVTVFB_DEBUG_WARN("Invalid colour mode: %d\n", var->bits_per_pixel);
586 return -EINVAL;
587 }
588 }
589
590 if (var->bits_per_pixel == 8 || var->bits_per_pixel == 32) {
591 var->transp.offset = 24;
592 var->transp.length = 8;
593 var->red.offset = 16;
594 var->red.length = 8;
595 var->green.offset = 8;
596 var->green.length = 8;
597 var->blue.offset = 0;
598 var->blue.length = 8;
599 }
600 else if (var->bits_per_pixel == 16) {
601 /* To find out the true mode, check green length */
602 switch (var->green.length) {
603 case 4:
604 var->red.offset = 8;
605 var->red.length = 4;
606 var->green.offset = 4;
607 var->green.length = 4;
608 var->blue.offset = 0;
609 var->blue.length = 4;
610 var->transp.offset = 12;
611 var->transp.length = 1;
612 break;
613 case 5:
614 var->red.offset = 10;
615 var->red.length = 5;
616 var->green.offset = 5;
617 var->green.length = 5;
618 var->blue.offset = 0;
619 var->blue.length = 5;
620 var->transp.offset = 15;
621 var->transp.length = 1;
622 break;
623 default:
624 var->red.offset = 11;
625 var->red.length = 5;
626 var->green.offset = 5;
627 var->green.length = 6;
628 var->blue.offset = 0;
629 var->blue.length = 5;
630 var->transp.offset = 0;
631 var->transp.length = 0;
632 break;
633 }
634 }
635 else {
636 IVTVFB_DEBUG_WARN("Invalid colour mode: %d\n", var->bits_per_pixel);
637 return -EINVAL;
638 }
639
640 /* Check the resolution */
641 if (osd_compat) {
642 if (var->xres != oi->ivtvfb_defined.xres ||
643 var->yres != oi->ivtvfb_defined.yres ||
644 var->xres_virtual != oi->ivtvfb_defined.xres_virtual ||
645 var->yres_virtual != oi->ivtvfb_defined.yres_virtual) {
646 IVTVFB_DEBUG_WARN("Invalid resolution: %dx%d (virtual %dx%d)\n",
647 var->xres, var->yres, var->xres_virtual, var->yres_virtual);
648 return -EINVAL;
649 }
650 }
651 else {
652 if (var->xres > IVTV_OSD_MAX_WIDTH || var->yres > osd_height_limit) {
653 IVTVFB_DEBUG_WARN("Invalid resolution: %dx%d\n",
654 var->xres, var->yres);
655 return -EINVAL;
656 }
657
658 /* Max horizontal size is 1023 @ 32bpp, 2046 & 16bpp, 4092 @ 8bpp */
659 if (var->xres_virtual > 4095 / (var->bits_per_pixel / 8) ||
660 var->xres_virtual * var->yres_virtual * (var->bits_per_pixel / 8) > oi->video_buffer_size ||
661 var->xres_virtual < var->xres ||
662 var->yres_virtual < var->yres) {
663 IVTVFB_DEBUG_WARN("Invalid virtual resolution: %dx%d\n",
664 var->xres_virtual, var->yres_virtual);
665 return -EINVAL;
666 }
667 }
668
669 /* Some extra checks if in 8 bit mode */
670 if (var->bits_per_pixel == 8) {
671 /* Width must be a multiple of 4 */
672 if (var->xres & 3) {
673 IVTVFB_DEBUG_WARN("Invalid resolution for 8bpp: %d\n", var->xres);
674 return -EINVAL;
675 }
676 if (var->xres_virtual & 3) {
677 IVTVFB_DEBUG_WARN("Invalid virtual resolution for 8bpp: %d)\n", var->xres_virtual);
678 return -EINVAL;
679 }
680 }
681 else if (var->bits_per_pixel == 16) {
682 /* Width must be a multiple of 2 */
683 if (var->xres & 1) {
684 IVTVFB_DEBUG_WARN("Invalid resolution for 16bpp: %d\n", var->xres);
685 return -EINVAL;
686 }
687 if (var->xres_virtual & 1) {
688 IVTVFB_DEBUG_WARN("Invalid virtual resolution for 16bpp: %d)\n", var->xres_virtual);
689 return -EINVAL;
690 }
691 }
692
693 /* Now check the offsets */
694 if (var->xoffset >= var->xres_virtual || var->yoffset >= var->yres_virtual) {
695 IVTVFB_DEBUG_WARN("Invalid offset: %d (%d) %d (%d)\n",
696 var->xoffset, var->xres_virtual, var->yoffset, var->yres_virtual);
697 return -EINVAL;
698 }
699
700 /* Check pixel format */
701 if (var->nonstd > 1) {
702 IVTVFB_DEBUG_WARN("Invalid nonstd % d\n", var->nonstd);
703 return -EINVAL;
704 }
705
706 /* Check video mode */
707 if (((var->vmode & FB_VMODE_MASK) != FB_VMODE_NONINTERLACED) &&
708 ((var->vmode & FB_VMODE_MASK) != FB_VMODE_INTERLACED)) {
709 IVTVFB_DEBUG_WARN("Invalid video mode: %d\n", var->vmode & FB_VMODE_MASK);
710 return -EINVAL;
711 }
712
713 /* Check the left & upper margins
714 If the margins are too large, just center the screen
715 (enforcing margins causes too many problems) */
716
717 if (var->left_margin + var->xres > IVTV_OSD_MAX_WIDTH + 1) {
718 var->left_margin = 1 + ((IVTV_OSD_MAX_WIDTH - var->xres) / 2);
719 }
720 if (var->upper_margin + var->yres > (itv->is_50hz ? 577 : 481)) {
721 var->upper_margin = 1 + (((itv->is_50hz ? 576 : 480) - var->yres) / 2);
722 }
723
724 /* Maintain overall 'size' for a constant refresh rate */
725 var->right_margin = hlimit - var->left_margin - var->xres;
726 var->lower_margin = vlimit - var->upper_margin - var->yres;
727
728 /* Fixed sync times */
729 var->hsync_len = 24;
730 var->vsync_len = 2;
731
732 /* Non-interlaced / interlaced mode is used to switch the OSD filter
733 on or off. Adjust the clock timings to maintain a constant
734 vertical refresh rate. */
735 if ((var->vmode & FB_VMODE_MASK) == FB_VMODE_NONINTERLACED)
736 var->pixclock = pixclock / 2;
737 else
738 var->pixclock = pixclock;
739
740 IVTVFB_DEBUG_INFO("Display size: %dx%d (virtual %dx%d) @ %dbpp\n",
741 var->xres, var->yres,
742 var->xres_virtual, var->yres_virtual,
743 var->bits_per_pixel);
744
745 IVTVFB_DEBUG_INFO("Display position: %d, %d\n",
746 var->left_margin, var->upper_margin);
747
748 IVTVFB_DEBUG_INFO("Display filter: %s\n",
749 (var->vmode & FB_VMODE_MASK) == FB_VMODE_NONINTERLACED ? "on" : "off");
750 IVTVFB_DEBUG_INFO("Color space: %s\n", var->nonstd ? "YUV" : "RGB");
751 return 0;
752}
753
754static int ivtvfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
755{
756 struct ivtv *itv = (struct ivtv *) info->par;
757 IVTVFB_DEBUG_INFO("ivtvfb_check_var\n");
758 return _ivtvfb_check_var(var, itv);
759}
760
761static int ivtvfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
762{
763 u32 osd_pan_index;
764 struct ivtv *itv = (struct ivtv *) info->par;
765
766 osd_pan_index = (var->xoffset + (var->yoffset * var->xres_virtual))*var->bits_per_pixel/8;
767 write_reg(osd_pan_index, 0x02A0C);
768
769 /* Pass this info back the yuv handler */
770 itv->yuv_info.osd_x_pan = var->xoffset;
771 itv->yuv_info.osd_y_pan = var->yoffset;
772 /* Force update of yuv registers */
773 itv->yuv_info.yuv_forced_update = 1;
774 return 0;
775}
776
777static int ivtvfb_set_par(struct fb_info *info)
778{
779 int rc = 0;
780 struct ivtv *itv = (struct ivtv *) info->par;
781
782 IVTVFB_DEBUG_INFO("ivtvfb_set_par\n");
783
784 rc = ivtvfb_set_var(itv, &info->var);
785 ivtvfb_pan_display(&info->var, info);
786 ivtvfb_get_fix(itv, &info->fix);
787 return rc;
788}
789
790static int ivtvfb_setcolreg(unsigned regno, unsigned red, unsigned green,
791 unsigned blue, unsigned transp,
792 struct fb_info *info)
793{
794 u32 color, *palette;
795 struct ivtv *itv = (struct ivtv *)info->par;
796
797 if (regno >= info->cmap.len)
798 return -EINVAL;
799
800 color = ((transp & 0xFF00) << 16) |((red & 0xFF00) << 8) | (green & 0xFF00) | ((blue & 0xFF00) >> 8);
801 if (info->var.bits_per_pixel <= 8) {
802 write_reg(regno, 0x02a30);
803 write_reg(color, 0x02a34);
804 return 0;
805 }
806 if (regno >= 16)
807 return -EINVAL;
808
809 palette = info->pseudo_palette;
810 if (info->var.bits_per_pixel == 16) {
811 switch (info->var.green.length) {
812 case 4:
813 color = ((red & 0xf000) >> 4) |
814 ((green & 0xf000) >> 8) |
815 ((blue & 0xf000) >> 12);
816 break;
817 case 5:
818 color = ((red & 0xf800) >> 1) |
819 ((green & 0xf800) >> 6) |
820 ((blue & 0xf800) >> 11);
821 break;
822 case 6:
823 color = (red & 0xf800 ) |
824 ((green & 0xfc00) >> 5) |
825 ((blue & 0xf800) >> 11);
826 break;
827 }
828 }
829 palette[regno] = color;
830 return 0;
831}
832
833/* We don't really support blanking. All this does is enable or
834 disable the OSD. */
835static int ivtvfb_blank(int blank_mode, struct fb_info *info)
836{
837 struct ivtv *itv = (struct ivtv *)info->par;
838
839 IVTVFB_DEBUG_INFO("Set blanking mode : %d\n", blank_mode);
840 switch (blank_mode) {
841 case FB_BLANK_UNBLANK:
842 ivtv_vapi(itv, CX2341X_OSD_SET_STATE, 1, 1);
843 break;
844 case FB_BLANK_NORMAL:
845 case FB_BLANK_HSYNC_SUSPEND:
846 case FB_BLANK_VSYNC_SUSPEND:
847 case FB_BLANK_POWERDOWN:
848 ivtv_vapi(itv, CX2341X_OSD_SET_STATE, 1, 0);
849 break;
850 }
851 return 0;
852}
853
854static struct fb_ops ivtvfb_ops = {
855 .owner = THIS_MODULE,
856 .fb_check_var = ivtvfb_check_var,
857 .fb_set_par = ivtvfb_set_par,
858 .fb_setcolreg = ivtvfb_setcolreg,
859 .fb_fillrect = cfb_fillrect,
860 .fb_copyarea = cfb_copyarea,
861 .fb_imageblit = cfb_imageblit,
862 .fb_cursor = NULL,
863 .fb_ioctl = ivtvfb_ioctl,
864 .fb_pan_display = ivtvfb_pan_display,
865 .fb_blank = ivtvfb_blank,
866};
867
868/* Initialization */
869
870
871/* Setup our initial video mode */
872static int ivtvfb_init_vidmode(struct ivtv *itv)
873{
874 struct osd_info *oi = itv->osd_info;
875 struct v4l2_rect start_window;
876 int max_height;
877
878 /* Color mode */
879
880 if (osd_compat) osd_depth = 32;
881 if (osd_depth != 8 && osd_depth != 16 && osd_depth != 32) osd_depth = 8;
882 oi->bits_per_pixel = osd_depth;
883 oi->bytes_per_pixel = oi->bits_per_pixel / 8;
884
885 /* Invalidate current osd mode to force a mode switch later */
886 oi->osd_mode = -1;
887
888 /* Horizontal size & position */
889
890 if (osd_xres > 720) osd_xres = 720;
891
892 /* Must be a multiple of 4 for 8bpp & 2 for 16bpp */
893 if (osd_depth == 8)
894 osd_xres &= ~3;
895 else if (osd_depth == 16)
896 osd_xres &= ~1;
897
898 if (osd_xres)
899 start_window.width = osd_xres;
900 else
901 start_window.width = osd_compat ? 720: 640;
902
903 /* Check horizontal start (osd_left). */
904 if (osd_left && osd_left + start_window.width > 721) {
905 IVTVFB_ERR("Invalid osd_left - assuming default\n");
906 osd_left = 0;
907 }
908
909 /* Hardware coords start at 0, user coords start at 1. */
910 osd_left--;
911
912 start_window.left = osd_left >= 0 ? osd_left : ((IVTV_OSD_MAX_WIDTH - start_window.width) / 2);
913
914 oi->display_byte_stride =
915 start_window.width * oi->bytes_per_pixel;
916
917 /* Vertical size & position */
918
919 max_height = itv->is_50hz ? 576 : 480;
920
921 if (osd_yres > max_height)
922 osd_yres = max_height;
923
924 if (osd_yres)
925 start_window.height = osd_yres;
926 else
927 start_window.height = osd_compat ? max_height : (itv->is_50hz ? 480 : 400);
928
929 /* Check vertical start (osd_upper). */
930 if (osd_upper + start_window.height > max_height + 1) {
931 IVTVFB_ERR("Invalid osd_upper - assuming default\n");
932 osd_upper = 0;
933 }
934
935 /* Hardware coords start at 0, user coords start at 1. */
936 osd_upper--;
937
938 start_window.top = osd_upper >= 0 ? osd_upper : ((max_height - start_window.height) / 2);
939
940 oi->display_width = start_window.width;
941 oi->display_height = start_window.height;
942
943 /* Generate a valid fb_var_screeninfo */
944
945 oi->ivtvfb_defined.xres = oi->display_width;
946 oi->ivtvfb_defined.yres = oi->display_height;
947 oi->ivtvfb_defined.xres_virtual = oi->display_width;
948 oi->ivtvfb_defined.yres_virtual = oi->display_height;
949 oi->ivtvfb_defined.bits_per_pixel = oi->bits_per_pixel;
950 oi->ivtvfb_defined.vmode = (osd_laced ? FB_VMODE_INTERLACED : FB_VMODE_NONINTERLACED);
951 oi->ivtvfb_defined.left_margin = start_window.left + 1;
952 oi->ivtvfb_defined.upper_margin = start_window.top + 1;
953 oi->ivtvfb_defined.accel_flags = FB_ACCEL_NONE;
954 oi->ivtvfb_defined.nonstd = 0;
955
956 /* We've filled in the most data, let the usual mode check
957 routine fill in the rest. */
958 _ivtvfb_check_var(&oi->ivtvfb_defined, itv);
959
960 /* Generate valid fb_fix_screeninfo */
961
962 ivtvfb_get_fix(itv, &oi->ivtvfb_fix);
963
964 /* Generate valid fb_info */
965
966 oi->ivtvfb_info.node = -1;
967 oi->ivtvfb_info.flags = FBINFO_FLAG_DEFAULT;
968 oi->ivtvfb_info.fbops = &ivtvfb_ops;
969 oi->ivtvfb_info.par = itv;
970 oi->ivtvfb_info.var = oi->ivtvfb_defined;
971 oi->ivtvfb_info.fix = oi->ivtvfb_fix;
972 oi->ivtvfb_info.screen_base = (u8 __iomem *)oi->video_vbase;
973 oi->ivtvfb_info.fbops = &ivtvfb_ops;
974
975 /* Supply some monitor specs. Bogus values will do for now */
976 oi->ivtvfb_info.monspecs.hfmin = 8000;
977 oi->ivtvfb_info.monspecs.hfmax = 70000;
978 oi->ivtvfb_info.monspecs.vfmin = 10;
979 oi->ivtvfb_info.monspecs.vfmax = 100;
980
981 /* Allocate color map */
982 if (fb_alloc_cmap(&oi->ivtvfb_info.cmap, 256, 1)) {
983 IVTVFB_ERR("abort, unable to alloc cmap\n");
984 return -ENOMEM;
985 }
986
987 /* Allocate the pseudo palette */
988 oi->ivtvfb_info.pseudo_palette = kmalloc(sizeof(u32) * 16, GFP_KERNEL);
989
990 if (!oi->ivtvfb_info.pseudo_palette) {
991 IVTVFB_ERR("abort, unable to alloc pseudo pallete\n");
992 return -ENOMEM;
993 }
994
995 return 0;
996}
997
998/* Find OSD buffer base & size. Add to mtrr. Zero osd buffer. */
999
1000static int ivtvfb_init_io(struct ivtv *itv)
1001{
1002 struct osd_info *oi = itv->osd_info;
1003
1004 mutex_lock(&itv->serialize_lock);
1005 if (ivtv_init_on_first_open(itv)) {
1006 mutex_unlock(&itv->serialize_lock);
1007 IVTVFB_ERR("Failed to initialize ivtv\n");
1008 return -ENXIO;
1009 }
1010 mutex_unlock(&itv->serialize_lock);
1011
1012 ivtvfb_get_framebuffer(itv, &oi->video_rbase, &oi->video_buffer_size);
1013
1014 /* The osd buffer size depends on the number of video buffers allocated
1015 on the PVR350 itself. For now we'll hardcode the smallest osd buffer
1016 size to prevent any overlap. */
1017 oi->video_buffer_size = 1704960;
1018
1019 oi->video_pbase = itv->base_addr + IVTV_DECODER_OFFSET + oi->video_rbase;
1020 oi->video_vbase = itv->dec_mem + oi->video_rbase;
1021
1022 if (!oi->video_vbase) {
1023 IVTVFB_ERR("abort, video memory 0x%x @ 0x%lx isn't mapped!\n",
1024 oi->video_buffer_size, oi->video_pbase);
1025 return -EIO;
1026 }
1027
1028 IVTVFB_INFO("Framebuffer at 0x%lx, mapped to 0x%p, size %dk\n",
1029 oi->video_pbase, oi->video_vbase,
1030 oi->video_buffer_size / 1024);
1031
1032#ifdef CONFIG_MTRR
1033 {
1034 /* Find the largest power of two that maps the whole buffer */
1035 int size_shift = 31;
1036
1037 while (!(oi->video_buffer_size & (1 << size_shift))) {
1038 size_shift--;
1039 }
1040 size_shift++;
1041 oi->fb_start_aligned_physaddr = oi->video_pbase & ~((1 << size_shift) - 1);
1042 oi->fb_end_aligned_physaddr = oi->video_pbase + oi->video_buffer_size;
1043 oi->fb_end_aligned_physaddr += (1 << size_shift) - 1;
1044 oi->fb_end_aligned_physaddr &= ~((1 << size_shift) - 1);
1045 if (mtrr_add(oi->fb_start_aligned_physaddr,
1046 oi->fb_end_aligned_physaddr - oi->fb_start_aligned_physaddr,
1047 MTRR_TYPE_WRCOMB, 1) < 0) {
1048 IVTVFB_INFO("disabled mttr\n");
1049 oi->fb_start_aligned_physaddr = 0;
1050 oi->fb_end_aligned_physaddr = 0;
1051 }
1052 }
1053#endif
1054
1055 /* Blank the entire osd. */
1056 memset_io(oi->video_vbase, 0, oi->video_buffer_size);
1057
1058 return 0;
1059}
1060
1061/* Release any memory we've grabbed & remove mtrr entry */
1062static void ivtvfb_release_buffers (struct ivtv *itv)
1063{
1064 struct osd_info *oi = itv->osd_info;
1065
1066 /* Release cmap */
1067 if (oi->ivtvfb_info.cmap.len)
1068 fb_dealloc_cmap(&oi->ivtvfb_info.cmap);
1069
1070 /* Release pseudo palette */
1071 if (oi->ivtvfb_info.pseudo_palette)
1072 kfree(oi->ivtvfb_info.pseudo_palette);
1073
1074#ifdef CONFIG_MTRR
1075 if (oi->fb_end_aligned_physaddr) {
1076 mtrr_del(-1, oi->fb_start_aligned_physaddr,
1077 oi->fb_end_aligned_physaddr - oi->fb_start_aligned_physaddr);
1078 }
1079#endif
1080
1081 kfree(oi);
1082 itv->osd_info = NULL;
1083}
1084
1085/* Initialize the specified card */
1086
1087static int ivtvfb_init_card(struct ivtv *itv)
1088{
1089 int rc;
1090
1091 if (itv->osd_info) {
1092 IVTVFB_ERR("Card %d already initialised\n", ivtvfb_card_id);
1093 return -EBUSY;
1094 }
1095
1096 itv->osd_info = kzalloc(sizeof(struct osd_info), GFP_ATOMIC);
1097 if (itv->osd_info == 0) {
1098 IVTVFB_ERR("Failed to allocate memory for osd_info\n");
1099 return -ENOMEM;
1100 }
1101
1102 /* Find & setup the OSD buffer */
1103 if ((rc = ivtvfb_init_io(itv)))
1104 return rc;
1105
1106 /* Set the startup video mode information */
1107 if ((rc = ivtvfb_init_vidmode(itv))) {
1108 ivtvfb_release_buffers(itv);
1109 return rc;
1110 }
1111
1112 /* Register the framebuffer */
1113 if (register_framebuffer(&itv->osd_info->ivtvfb_info) < 0) {
1114 ivtvfb_release_buffers(itv);
1115 return -EINVAL;
1116 }
1117
1118 itv->osd_video_pbase = itv->osd_info->video_pbase;
1119
1120 /* Set the card to the requested mode */
1121 ivtvfb_set_par(&itv->osd_info->ivtvfb_info);
1122
1123 /* Set color 0 to black */
1124 write_reg(0, 0x02a30);
1125 write_reg(0, 0x02a34);
1126
1127 /* Enable the osd */
1128 ivtvfb_blank(FB_BLANK_UNBLANK, &itv->osd_info->ivtvfb_info);
1129
1130 /* Note if we're running in compatibility mode */
1131 if (osd_compat)
1132 IVTVFB_INFO("Running in compatibility mode. Display resize & mode change disabled\n");
1133
1134 /* Allocate DMA */
1135 ivtv_udma_alloc(itv);
1136 return 0;
1137
1138}
1139
1140static int __init ivtvfb_init(void)
1141{
1142 struct ivtv *itv;
1143 int i, registered = 0;
1144
1145 if (ivtvfb_card_id < -1 || ivtvfb_card_id >= IVTV_MAX_CARDS) {
1146 printk(KERN_ERR "ivtvfb: ivtvfb_card_id parameter is out of range (valid range: -1 - %d)\n",
1147 IVTV_MAX_CARDS - 1);
1148 return -EINVAL;
1149 }
1150
1151 /* Locate & initialise all cards supporting an OSD. */
1152 for (i = 0; i < ivtv_cards_active; i++) {
1153 if (ivtvfb_card_id != -1 && i != ivtvfb_card_id)
1154 continue;
1155 itv = ivtv_cards[i];
1156 if (itv && (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT)) {
1157 if (ivtvfb_init_card(itv) == 0) {
1158 IVTVFB_INFO("Framebuffer registered on ivtv card id %d\n", i);
1159 registered++;
1160 }
1161 }
1162 }
1163 if (!registered) {
1164 printk(KERN_ERR "ivtvfb: no cards found");
1165 return -ENODEV;
1166 }
1167 return 0;
1168}
1169
1170static void ivtvfb_cleanup(void)
1171{
1172 struct ivtv *itv;
1173 int i;
1174
1175 printk(KERN_INFO "ivtvfb: Unloading framebuffer module\n");
1176
1177 for (i = 0; i < ivtv_cards_active; i++) {
1178 itv = ivtv_cards[i];
1179 if (itv && (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT) && itv->osd_info) {
1180 IVTVFB_DEBUG_INFO("Unregister framebuffer %d\n", i);
1181 ivtvfb_blank(FB_BLANK_POWERDOWN, &itv->osd_info->ivtvfb_info);
1182 unregister_framebuffer(&itv->osd_info->ivtvfb_info);
1183 ivtvfb_release_buffers(itv);
1184 itv->osd_video_pbase = 0;
1185 }
1186 }
1187}
1188
1189module_init(ivtvfb_init);
1190module_exit(ivtvfb_cleanup);
diff --git a/drivers/media/video/msp3400-driver.c b/drivers/media/video/msp3400-driver.c
index 11cfcf18ec34..c0c87e06259b 100644
--- a/drivers/media/video/msp3400-driver.c
+++ b/drivers/media/video/msp3400-driver.c
@@ -244,17 +244,17 @@ int msp_write_dsp(struct i2c_client *client, int addr, int val)
244 * ----------------------------------------------------------------------- */ 244 * ----------------------------------------------------------------------- */
245 245
246static int scarts[3][9] = { 246static int scarts[3][9] = {
247 /* MASK IN1 IN2 IN3 IN4 IN1_DA IN2_DA MONO MUTE */ 247 /* MASK IN1 IN2 IN3 IN4 IN1_DA IN2_DA MONO MUTE */
248 /* SCART DSP Input select */ 248 /* SCART DSP Input select */
249 { 0x0320, 0x0000, 0x0200, 0x0300, 0x0020, -1, -1, 0x0100, 0x0320 }, 249 { 0x0320, 0x0000, 0x0200, 0x0300, 0x0020, -1, -1, 0x0100, 0x0320 },
250 /* SCART1 Output select */ 250 /* SCART1 Output select */
251 { 0x0c40, 0x0440, 0x0400, 0x0000, 0x0840, 0x0c00, 0x0040, 0x0800, 0x0c40 }, 251 { 0x0c40, 0x0440, 0x0400, 0x0000, 0x0840, 0x0c00, 0x0040, 0x0800, 0x0c40 },
252 /* SCART2 Output select */ 252 /* SCART2 Output select */
253 { 0x3080, 0x1000, 0x1080, 0x2080, 0x3080, 0x0000, 0x0080, 0x2000, 0x3000 }, 253 { 0x3080, 0x1000, 0x1080, 0x2080, 0x3080, 0x0000, 0x0080, 0x2000, 0x3000 },
254}; 254};
255 255
256static char *scart_names[] = { 256static char *scart_names[] = {
257 "in1", "in2", "in3", "in4", "in1 da", "in2 da", "mono", "mute" 257 "in1", "in2", "in3", "in4", "in1 da", "in2 da", "mono", "mute"
258}; 258};
259 259
260void msp_set_scart(struct i2c_client *client, int in, int out) 260void msp_set_scart(struct i2c_client *client, int in, int out)
@@ -813,8 +813,9 @@ static int msp_attach(struct i2c_adapter *adapter, int address, int kind)
813 int msp_rom; 813 int msp_rom;
814 814
815 client = kzalloc(sizeof(*client), GFP_KERNEL); 815 client = kzalloc(sizeof(*client), GFP_KERNEL);
816 if (client == NULL) 816 if (!client)
817 return -ENOMEM; 817 return -ENOMEM;
818
818 client->addr = address; 819 client->addr = address;
819 client->adapter = adapter; 820 client->adapter = adapter;
820 client->driver = &i2c_driver; 821 client->driver = &i2c_driver;
@@ -826,14 +827,14 @@ static int msp_attach(struct i2c_adapter *adapter, int address, int kind)
826 return 0; 827 return 0;
827 } 828 }
828 829
829 state = kmalloc(sizeof(*state), GFP_KERNEL); 830 state = kzalloc(sizeof(*state), GFP_KERNEL);
830 if (state == NULL) { 831 if (!state) {
831 kfree(client); 832 kfree(client);
832 return -ENOMEM; 833 return -ENOMEM;
833 } 834 }
835
834 i2c_set_clientdata(client, state); 836 i2c_set_clientdata(client, state);
835 837
836 memset(state, 0, sizeof(*state));
837 state->v4l2_std = V4L2_STD_NTSC; 838 state->v4l2_std = V4L2_STD_NTSC;
838 state->audmode = V4L2_TUNER_MODE_STEREO; 839 state->audmode = V4L2_TUNER_MODE_STEREO;
839 state->volume = 58880; /* 0db gain */ 840 state->volume = 58880; /* 0db gain */
diff --git a/drivers/media/video/mt20xx.c b/drivers/media/video/mt20xx.c
index 7549114aaaca..f49d1f4c40db 100644
--- a/drivers/media/video/mt20xx.c
+++ b/drivers/media/video/mt20xx.c
@@ -1,13 +1,20 @@
1/* 1/*
2 *
3 * i2c tv tuner chip device driver 2 * i2c tv tuner chip device driver
4 * controls microtune tuners, mt2032 + mt2050 at the moment. 3 * controls microtune tuners, mt2032 + mt2050 at the moment.
4 *
5 * This "mt20xx" module was split apart from the original "tuner" module.
5 */ 6 */
6#include <linux/delay.h> 7#include <linux/delay.h>
7#include <linux/i2c.h> 8#include <linux/i2c.h>
8#include <linux/videodev.h> 9#include <linux/videodev.h>
9#include <linux/moduleparam.h> 10#include "tuner-i2c.h"
10#include "tuner-driver.h" 11#include "mt20xx.h"
12
13static int debug = 0;
14module_param(debug, int, 0644);
15MODULE_PARM_DESC(debug, "enable verbose debug messages");
16
17#define PREFIX "mt20xx "
11 18
12/* ---------------------------------------------------------------------- */ 19/* ---------------------------------------------------------------------- */
13 20
@@ -20,9 +27,6 @@ module_param(tv_antenna, int, 0644);
20static unsigned int radio_antenna = 0; 27static unsigned int radio_antenna = 0;
21module_param(radio_antenna, int, 0644); 28module_param(radio_antenna, int, 0644);
22 29
23/* from tuner-core.c */
24extern int tuner_debug;
25
26/* ---------------------------------------------------------------------- */ 30/* ---------------------------------------------------------------------- */
27 31
28#define MT2032 0x04 32#define MT2032 0x04
@@ -38,23 +42,34 @@ static char *microtune_part[] = {
38}; 42};
39 43
40struct microtune_priv { 44struct microtune_priv {
45 struct tuner_i2c_props i2c_props;
46
41 unsigned int xogc; 47 unsigned int xogc;
42 unsigned int radio_if2; 48 //unsigned int radio_if2;
49
50 u32 frequency;
43}; 51};
44 52
45static void microtune_release(struct i2c_client *c) 53static int microtune_release(struct dvb_frontend *fe)
46{ 54{
47 struct tuner *t = i2c_get_clientdata(c); 55 kfree(fe->tuner_priv);
56 fe->tuner_priv = NULL;
48 57
49 kfree(t->priv); 58 return 0;
50 t->priv = NULL; 59}
60
61static int microtune_get_frequency(struct dvb_frontend *fe, u32 *frequency)
62{
63 struct microtune_priv *priv = fe->tuner_priv;
64 *frequency = priv->frequency;
65 return 0;
51} 66}
52 67
53// IsSpurInBand()? 68// IsSpurInBand()?
54static int mt2032_spurcheck(struct i2c_client *c, 69static int mt2032_spurcheck(struct dvb_frontend *fe,
55 int f1, int f2, int spectrum_from,int spectrum_to) 70 int f1, int f2, int spectrum_from,int spectrum_to)
56{ 71{
57 struct tuner *t = i2c_get_clientdata(c); 72 struct microtune_priv *priv = fe->tuner_priv;
58 int n1=1,n2,f; 73 int n1=1,n2,f;
59 74
60 f1=f1/1000; //scale to kHz to avoid 32bit overflows 75 f1=f1/1000; //scale to kHz to avoid 32bit overflows
@@ -82,7 +97,7 @@ static int mt2032_spurcheck(struct i2c_client *c,
82 return 1; 97 return 1;
83} 98}
84 99
85static int mt2032_compute_freq(struct i2c_client *c, 100static int mt2032_compute_freq(struct dvb_frontend *fe,
86 unsigned int rfin, 101 unsigned int rfin,
87 unsigned int if1, unsigned int if2, 102 unsigned int if1, unsigned int if2,
88 unsigned int spectrum_from, 103 unsigned int spectrum_from,
@@ -91,7 +106,7 @@ static int mt2032_compute_freq(struct i2c_client *c,
91 int *ret_sel, 106 int *ret_sel,
92 unsigned int xogc) //all in Hz 107 unsigned int xogc) //all in Hz
93{ 108{
94 struct tuner *t = i2c_get_clientdata(c); 109 struct microtune_priv *priv = fe->tuner_priv;
95 unsigned int fref,lo1,lo1n,lo1a,s,sel,lo1freq, desired_lo1, 110 unsigned int fref,lo1,lo1n,lo1a,s,sel,lo1freq, desired_lo1,
96 desired_lo2,lo2,lo2n,lo2a,lo2num,lo2freq; 111 desired_lo2,lo2,lo2n,lo2a,lo2num,lo2freq;
97 112
@@ -141,7 +156,7 @@ static int mt2032_compute_freq(struct i2c_client *c,
141 return(-1); 156 return(-1);
142 } 157 }
143 158
144 mt2032_spurcheck(c, lo1freq, desired_lo2, spectrum_from, spectrum_to); 159 mt2032_spurcheck(fe, lo1freq, desired_lo2, spectrum_from, spectrum_to);
145 // should recalculate lo1 (one step up/down) 160 // should recalculate lo1 (one step up/down)
146 161
147 // set up MT2032 register map for transfer over i2c 162 // set up MT2032 register map for transfer over i2c
@@ -165,16 +180,16 @@ static int mt2032_compute_freq(struct i2c_client *c,
165 return 0; 180 return 0;
166} 181}
167 182
168static int mt2032_check_lo_lock(struct i2c_client *c) 183static int mt2032_check_lo_lock(struct dvb_frontend *fe)
169{ 184{
170 struct tuner *t = i2c_get_clientdata(c); 185 struct microtune_priv *priv = fe->tuner_priv;
171 int try,lock=0; 186 int try,lock=0;
172 unsigned char buf[2]; 187 unsigned char buf[2];
173 188
174 for(try=0;try<10;try++) { 189 for(try=0;try<10;try++) {
175 buf[0]=0x0e; 190 buf[0]=0x0e;
176 i2c_master_send(c,buf,1); 191 tuner_i2c_xfer_send(&priv->i2c_props,buf,1);
177 i2c_master_recv(c,buf,1); 192 tuner_i2c_xfer_recv(&priv->i2c_props,buf,1);
178 tuner_dbg("mt2032 Reg.E=0x%02x\n",buf[0]); 193 tuner_dbg("mt2032 Reg.E=0x%02x\n",buf[0]);
179 lock=buf[0] &0x06; 194 lock=buf[0] &0x06;
180 195
@@ -187,15 +202,15 @@ static int mt2032_check_lo_lock(struct i2c_client *c)
187 return lock; 202 return lock;
188} 203}
189 204
190static int mt2032_optimize_vco(struct i2c_client *c,int sel,int lock) 205static int mt2032_optimize_vco(struct dvb_frontend *fe,int sel,int lock)
191{ 206{
192 struct tuner *t = i2c_get_clientdata(c); 207 struct microtune_priv *priv = fe->tuner_priv;
193 unsigned char buf[2]; 208 unsigned char buf[2];
194 int tad1; 209 int tad1;
195 210
196 buf[0]=0x0f; 211 buf[0]=0x0f;
197 i2c_master_send(c,buf,1); 212 tuner_i2c_xfer_send(&priv->i2c_props,buf,1);
198 i2c_master_recv(c,buf,1); 213 tuner_i2c_xfer_recv(&priv->i2c_props,buf,1);
199 tuner_dbg("mt2032 Reg.F=0x%02x\n",buf[0]); 214 tuner_dbg("mt2032 Reg.F=0x%02x\n",buf[0]);
200 tad1=buf[0]&0x07; 215 tad1=buf[0]&0x07;
201 216
@@ -218,58 +233,57 @@ static int mt2032_optimize_vco(struct i2c_client *c,int sel,int lock)
218 233
219 buf[0]=0x0f; 234 buf[0]=0x0f;
220 buf[1]=sel; 235 buf[1]=sel;
221 i2c_master_send(c,buf,2); 236 tuner_i2c_xfer_send(&priv->i2c_props,buf,2);
222 lock=mt2032_check_lo_lock(c); 237 lock=mt2032_check_lo_lock(fe);
223 return lock; 238 return lock;
224} 239}
225 240
226 241
227static void mt2032_set_if_freq(struct i2c_client *c, unsigned int rfin, 242static void mt2032_set_if_freq(struct dvb_frontend *fe, unsigned int rfin,
228 unsigned int if1, unsigned int if2, 243 unsigned int if1, unsigned int if2,
229 unsigned int from, unsigned int to) 244 unsigned int from, unsigned int to)
230{ 245{
231 unsigned char buf[21]; 246 unsigned char buf[21];
232 int lint_try,ret,sel,lock=0; 247 int lint_try,ret,sel,lock=0;
233 struct tuner *t = i2c_get_clientdata(c); 248 struct microtune_priv *priv = fe->tuner_priv;
234 struct microtune_priv *priv = t->priv;
235 249
236 tuner_dbg("mt2032_set_if_freq rfin=%d if1=%d if2=%d from=%d to=%d\n", 250 tuner_dbg("mt2032_set_if_freq rfin=%d if1=%d if2=%d from=%d to=%d\n",
237 rfin,if1,if2,from,to); 251 rfin,if1,if2,from,to);
238 252
239 buf[0]=0; 253 buf[0]=0;
240 ret=i2c_master_send(c,buf,1); 254 ret=tuner_i2c_xfer_send(&priv->i2c_props,buf,1);
241 i2c_master_recv(c,buf,21); 255 tuner_i2c_xfer_recv(&priv->i2c_props,buf,21);
242 256
243 buf[0]=0; 257 buf[0]=0;
244 ret=mt2032_compute_freq(c,rfin,if1,if2,from,to,&buf[1],&sel,priv->xogc); 258 ret=mt2032_compute_freq(fe,rfin,if1,if2,from,to,&buf[1],&sel,priv->xogc);
245 if (ret<0) 259 if (ret<0)
246 return; 260 return;
247 261
248 // send only the relevant registers per Rev. 1.2 262 // send only the relevant registers per Rev. 1.2
249 buf[0]=0; 263 buf[0]=0;
250 ret=i2c_master_send(c,buf,4); 264 ret=tuner_i2c_xfer_send(&priv->i2c_props,buf,4);
251 buf[5]=5; 265 buf[5]=5;
252 ret=i2c_master_send(c,buf+5,4); 266 ret=tuner_i2c_xfer_send(&priv->i2c_props,buf+5,4);
253 buf[11]=11; 267 buf[11]=11;
254 ret=i2c_master_send(c,buf+11,3); 268 ret=tuner_i2c_xfer_send(&priv->i2c_props,buf+11,3);
255 if(ret!=3) 269 if(ret!=3)
256 tuner_warn("i2c i/o error: rc == %d (should be 3)\n",ret); 270 tuner_warn("i2c i/o error: rc == %d (should be 3)\n",ret);
257 271
258 // wait for PLLs to lock (per manual), retry LINT if not. 272 // wait for PLLs to lock (per manual), retry LINT if not.
259 for(lint_try=0; lint_try<2; lint_try++) { 273 for(lint_try=0; lint_try<2; lint_try++) {
260 lock=mt2032_check_lo_lock(c); 274 lock=mt2032_check_lo_lock(fe);
261 275
262 if(optimize_vco) 276 if(optimize_vco)
263 lock=mt2032_optimize_vco(c,sel,lock); 277 lock=mt2032_optimize_vco(fe,sel,lock);
264 if(lock==6) break; 278 if(lock==6) break;
265 279
266 tuner_dbg("mt2032: re-init PLLs by LINT\n"); 280 tuner_dbg("mt2032: re-init PLLs by LINT\n");
267 buf[0]=7; 281 buf[0]=7;
268 buf[1]=0x80 +8+priv->xogc; // set LINT to re-init PLLs 282 buf[1]=0x80 +8+priv->xogc; // set LINT to re-init PLLs
269 i2c_master_send(c,buf,2); 283 tuner_i2c_xfer_send(&priv->i2c_props,buf,2);
270 mdelay(10); 284 mdelay(10);
271 buf[1]=8+priv->xogc; 285 buf[1]=8+priv->xogc;
272 i2c_master_send(c,buf,2); 286 tuner_i2c_xfer_send(&priv->i2c_props,buf,2);
273 } 287 }
274 288
275 if (lock!=6) 289 if (lock!=6)
@@ -277,19 +291,19 @@ static void mt2032_set_if_freq(struct i2c_client *c, unsigned int rfin,
277 291
278 buf[0]=2; 292 buf[0]=2;
279 buf[1]=0x20; // LOGC for optimal phase noise 293 buf[1]=0x20; // LOGC for optimal phase noise
280 ret=i2c_master_send(c,buf,2); 294 ret=tuner_i2c_xfer_send(&priv->i2c_props,buf,2);
281 if (ret!=2) 295 if (ret!=2)
282 tuner_warn("i2c i/o error: rc == %d (should be 2)\n",ret); 296 tuner_warn("i2c i/o error: rc == %d (should be 2)\n",ret);
283} 297}
284 298
285 299
286static void mt2032_set_tv_freq(struct i2c_client *c, unsigned int freq) 300static int mt2032_set_tv_freq(struct dvb_frontend *fe,
301 struct analog_parameters *params)
287{ 302{
288 struct tuner *t = i2c_get_clientdata(c);
289 int if2,from,to; 303 int if2,from,to;
290 304
291 // signal bandwidth and picture carrier 305 // signal bandwidth and picture carrier
292 if (t->std & V4L2_STD_525_60) { 306 if (params->std & V4L2_STD_525_60) {
293 // NTSC 307 // NTSC
294 from = 40750*1000; 308 from = 40750*1000;
295 to = 46750*1000; 309 to = 46750*1000;
@@ -301,32 +315,64 @@ static void mt2032_set_tv_freq(struct i2c_client *c, unsigned int freq)
301 if2 = 38900*1000; 315 if2 = 38900*1000;
302 } 316 }
303 317
304 mt2032_set_if_freq(c, freq*62500 /* freq*1000*1000/16 */, 318 mt2032_set_if_freq(fe, params->frequency*62500,
305 1090*1000*1000, if2, from, to); 319 1090*1000*1000, if2, from, to);
320
321 return 0;
306} 322}
307 323
308static void mt2032_set_radio_freq(struct i2c_client *c, unsigned int freq) 324static int mt2032_set_radio_freq(struct dvb_frontend *fe,
325 struct analog_parameters *params)
309{ 326{
310 struct tuner *t = i2c_get_clientdata(c); 327 struct microtune_priv *priv = fe->tuner_priv;
311 struct microtune_priv *priv = t->priv; 328 int if2;
312 int if2 = priv->radio_if2; 329
330 if (params->std & V4L2_STD_525_60) {
331 tuner_dbg("pinnacle ntsc\n");
332 if2 = 41300 * 1000;
333 } else {
334 tuner_dbg("pinnacle pal\n");
335 if2 = 33300 * 1000;
336 }
313 337
314 // per Manual for FM tuning: first if center freq. 1085 MHz 338 // per Manual for FM tuning: first if center freq. 1085 MHz
315 mt2032_set_if_freq(c, freq * 1000 / 16, 339 mt2032_set_if_freq(fe, params->frequency * 125 / 2,
316 1085*1000*1000,if2,if2,if2); 340 1085*1000*1000,if2,if2,if2);
341
342 return 0;
343}
344
345static int mt2032_set_params(struct dvb_frontend *fe,
346 struct analog_parameters *params)
347{
348 struct microtune_priv *priv = fe->tuner_priv;
349 int ret = -EINVAL;
350
351 switch (params->mode) {
352 case V4L2_TUNER_RADIO:
353 ret = mt2032_set_radio_freq(fe, params);
354 priv->frequency = params->frequency * 125 / 2;
355 break;
356 case V4L2_TUNER_ANALOG_TV:
357 case V4L2_TUNER_DIGITAL_TV:
358 ret = mt2032_set_tv_freq(fe, params);
359 priv->frequency = params->frequency * 62500;
360 break;
361 }
362
363 return ret;
317} 364}
318 365
319static struct tuner_operations mt2032_tuner_ops = { 366static struct dvb_tuner_ops mt2032_tuner_ops = {
320 .set_tv_freq = mt2032_set_tv_freq, 367 .set_analog_params = mt2032_set_params,
321 .set_radio_freq = mt2032_set_radio_freq, 368 .release = microtune_release,
322 .release = microtune_release, 369 .get_frequency = microtune_get_frequency,
323}; 370};
324 371
325// Initalization as described in "MT203x Programming Procedures", Rev 1.2, Feb.2001 372// Initalization as described in "MT203x Programming Procedures", Rev 1.2, Feb.2001
326static int mt2032_init(struct i2c_client *c) 373static int mt2032_init(struct dvb_frontend *fe)
327{ 374{
328 struct tuner *t = i2c_get_clientdata(c); 375 struct microtune_priv *priv = fe->tuner_priv;
329 struct microtune_priv *priv = t->priv;
330 unsigned char buf[21]; 376 unsigned char buf[21];
331 int ret,xogc,xok=0; 377 int ret,xogc,xok=0;
332 378
@@ -335,7 +381,7 @@ static int mt2032_init(struct i2c_client *c)
335 buf[2]=0xff; 381 buf[2]=0xff;
336 buf[3]=0x0f; 382 buf[3]=0x0f;
337 buf[4]=0x1f; 383 buf[4]=0x1f;
338 ret=i2c_master_send(c,buf+1,4); 384 ret=tuner_i2c_xfer_send(&priv->i2c_props,buf+1,4);
339 385
340 buf[5]=6; // Index register 6 386 buf[5]=6; // Index register 6
341 buf[6]=0xe4; 387 buf[6]=0xe4;
@@ -343,11 +389,11 @@ static int mt2032_init(struct i2c_client *c)
343 buf[8]=0xc3; 389 buf[8]=0xc3;
344 buf[9]=0x4e; 390 buf[9]=0x4e;
345 buf[10]=0xec; 391 buf[10]=0xec;
346 ret=i2c_master_send(c,buf+5,6); 392 ret=tuner_i2c_xfer_send(&priv->i2c_props,buf+5,6);
347 393
348 buf[12]=13; // Index register 13 394 buf[12]=13; // Index register 13
349 buf[13]=0x32; 395 buf[13]=0x32;
350 ret=i2c_master_send(c,buf+12,2); 396 ret=tuner_i2c_xfer_send(&priv->i2c_props,buf+12,2);
351 397
352 // Adjust XOGC (register 7), wait for XOK 398 // Adjust XOGC (register 7), wait for XOK
353 xogc=7; 399 xogc=7;
@@ -355,8 +401,8 @@ static int mt2032_init(struct i2c_client *c)
355 tuner_dbg("mt2032: xogc = 0x%02x\n",xogc&0x07); 401 tuner_dbg("mt2032: xogc = 0x%02x\n",xogc&0x07);
356 mdelay(10); 402 mdelay(10);
357 buf[0]=0x0e; 403 buf[0]=0x0e;
358 i2c_master_send(c,buf,1); 404 tuner_i2c_xfer_send(&priv->i2c_props,buf,1);
359 i2c_master_recv(c,buf,1); 405 tuner_i2c_xfer_recv(&priv->i2c_props,buf,1);
360 xok=buf[0]&0x01; 406 xok=buf[0]&0x01;
361 tuner_dbg("mt2032: xok = 0x%02x\n",xok); 407 tuner_dbg("mt2032: xok = 0x%02x\n",xok);
362 if (xok == 1) break; 408 if (xok == 1) break;
@@ -369,32 +415,32 @@ static int mt2032_init(struct i2c_client *c)
369 } 415 }
370 buf[0]=0x07; 416 buf[0]=0x07;
371 buf[1]=0x88 + xogc; 417 buf[1]=0x88 + xogc;
372 ret=i2c_master_send(c,buf,2); 418 ret=tuner_i2c_xfer_send(&priv->i2c_props,buf,2);
373 if (ret!=2) 419 if (ret!=2)
374 tuner_warn("i2c i/o error: rc == %d (should be 2)\n",ret); 420 tuner_warn("i2c i/o error: rc == %d (should be 2)\n",ret);
375 } while (xok != 1 ); 421 } while (xok != 1 );
376 priv->xogc=xogc; 422 priv->xogc=xogc;
377 423
378 memcpy(&t->ops, &mt2032_tuner_ops, sizeof(struct tuner_operations)); 424 memcpy(&fe->ops.tuner_ops, &mt2032_tuner_ops, sizeof(struct dvb_tuner_ops));
379 425
380 return(1); 426 return(1);
381} 427}
382 428
383static void mt2050_set_antenna(struct i2c_client *c, unsigned char antenna) 429static void mt2050_set_antenna(struct dvb_frontend *fe, unsigned char antenna)
384{ 430{
385 struct tuner *t = i2c_get_clientdata(c); 431 struct microtune_priv *priv = fe->tuner_priv;
386 unsigned char buf[2]; 432 unsigned char buf[2];
387 int ret; 433 int ret;
388 434
389 buf[0] = 6; 435 buf[0] = 6;
390 buf[1] = antenna ? 0x11 : 0x10; 436 buf[1] = antenna ? 0x11 : 0x10;
391 ret=i2c_master_send(c,buf,2); 437 ret=tuner_i2c_xfer_send(&priv->i2c_props,buf,2);
392 tuner_dbg("mt2050: enabled antenna connector %d\n", antenna); 438 tuner_dbg("mt2050: enabled antenna connector %d\n", antenna);
393} 439}
394 440
395static void mt2050_set_if_freq(struct i2c_client *c,unsigned int freq, unsigned int if2) 441static void mt2050_set_if_freq(struct dvb_frontend *fe,unsigned int freq, unsigned int if2)
396{ 442{
397 struct tuner *t = i2c_get_clientdata(c); 443 struct microtune_priv *priv = fe->tuner_priv;
398 unsigned int if1=1218*1000*1000; 444 unsigned int if1=1218*1000*1000;
399 unsigned int f_lo1,f_lo2,lo1,lo2,f_lo1_modulo,f_lo2_modulo,num1,num2,div1a,div1b,div2a,div2b; 445 unsigned int f_lo1,f_lo2,lo1,lo2,f_lo1_modulo,f_lo2_modulo,num1,num2,div1a,div1b,div2a,div2b;
400 int ret; 446 int ret;
@@ -426,7 +472,7 @@ static void mt2050_set_if_freq(struct i2c_client *c,unsigned int freq, unsigned
426 div2a=(lo2/8)-1; 472 div2a=(lo2/8)-1;
427 div2b=lo2-(div2a+1)*8; 473 div2b=lo2-(div2a+1)*8;
428 474
429 if (tuner_debug > 1) { 475 if (debug > 1) {
430 tuner_dbg("lo1 lo2 = %d %d\n", lo1, lo2); 476 tuner_dbg("lo1 lo2 = %d %d\n", lo1, lo2);
431 tuner_dbg("num1 num2 div1a div1b div2a div2b= %x %x %x %x %x %x\n", 477 tuner_dbg("num1 num2 div1a div1b div2a div2b= %x %x %x %x %x %x\n",
432 num1,num2,div1a,div1b,div2a,div2b); 478 num1,num2,div1a,div1b,div2a,div2b);
@@ -442,7 +488,7 @@ static void mt2050_set_if_freq(struct i2c_client *c,unsigned int freq, unsigned
442 buf[5]=div2a; 488 buf[5]=div2a;
443 if(num2!=0) buf[5]=buf[5]|0x40; 489 if(num2!=0) buf[5]=buf[5]|0x40;
444 490
445 if (tuner_debug > 1) { 491 if (debug > 1) {
446 int i; 492 int i;
447 tuner_dbg("bufs is: "); 493 tuner_dbg("bufs is: ");
448 for(i=0;i<6;i++) 494 for(i=0;i<6;i++)
@@ -450,101 +496,131 @@ static void mt2050_set_if_freq(struct i2c_client *c,unsigned int freq, unsigned
450 printk("\n"); 496 printk("\n");
451 } 497 }
452 498
453 ret=i2c_master_send(c,buf,6); 499 ret=tuner_i2c_xfer_send(&priv->i2c_props,buf,6);
454 if (ret!=6) 500 if (ret!=6)
455 tuner_warn("i2c i/o error: rc == %d (should be 6)\n",ret); 501 tuner_warn("i2c i/o error: rc == %d (should be 6)\n",ret);
456} 502}
457 503
458static void mt2050_set_tv_freq(struct i2c_client *c, unsigned int freq) 504static int mt2050_set_tv_freq(struct dvb_frontend *fe,
505 struct analog_parameters *params)
459{ 506{
460 struct tuner *t = i2c_get_clientdata(c);
461 unsigned int if2; 507 unsigned int if2;
462 508
463 if (t->std & V4L2_STD_525_60) { 509 if (params->std & V4L2_STD_525_60) {
464 // NTSC 510 // NTSC
465 if2 = 45750*1000; 511 if2 = 45750*1000;
466 } else { 512 } else {
467 // PAL 513 // PAL
468 if2 = 38900*1000; 514 if2 = 38900*1000;
469 } 515 }
470 if (V4L2_TUNER_DIGITAL_TV == t->mode) { 516 if (V4L2_TUNER_DIGITAL_TV == params->mode) {
471 // DVB (pinnacle 300i) 517 // DVB (pinnacle 300i)
472 if2 = 36150*1000; 518 if2 = 36150*1000;
473 } 519 }
474 mt2050_set_if_freq(c, freq*62500, if2); 520 mt2050_set_if_freq(fe, params->frequency*62500, if2);
475 mt2050_set_antenna(c, tv_antenna); 521 mt2050_set_antenna(fe, tv_antenna);
522
523 return 0;
476} 524}
477 525
478static void mt2050_set_radio_freq(struct i2c_client *c, unsigned int freq) 526static int mt2050_set_radio_freq(struct dvb_frontend *fe,
527 struct analog_parameters *params)
479{ 528{
480 struct tuner *t = i2c_get_clientdata(c); 529 struct microtune_priv *priv = fe->tuner_priv;
481 struct microtune_priv *priv = t->priv; 530 int if2;
482 int if2 = priv->radio_if2; 531
532 if (params->std & V4L2_STD_525_60) {
533 tuner_dbg("pinnacle ntsc\n");
534 if2 = 41300 * 1000;
535 } else {
536 tuner_dbg("pinnacle pal\n");
537 if2 = 33300 * 1000;
538 }
483 539
484 mt2050_set_if_freq(c, freq * 1000 / 16, if2); 540 mt2050_set_if_freq(fe, params->frequency * 125 / 2, if2);
485 mt2050_set_antenna(c, radio_antenna); 541 mt2050_set_antenna(fe, radio_antenna);
542
543 return 0;
486} 544}
487 545
488static struct tuner_operations mt2050_tuner_ops = { 546static int mt2050_set_params(struct dvb_frontend *fe,
489 .set_tv_freq = mt2050_set_tv_freq, 547 struct analog_parameters *params)
490 .set_radio_freq = mt2050_set_radio_freq, 548{
491 .release = microtune_release, 549 struct microtune_priv *priv = fe->tuner_priv;
550 int ret = -EINVAL;
551
552 switch (params->mode) {
553 case V4L2_TUNER_RADIO:
554 ret = mt2050_set_radio_freq(fe, params);
555 priv->frequency = params->frequency * 125 / 2;
556 break;
557 case V4L2_TUNER_ANALOG_TV:
558 case V4L2_TUNER_DIGITAL_TV:
559 ret = mt2050_set_tv_freq(fe, params);
560 priv->frequency = params->frequency * 62500;
561 break;
562 }
563
564 return ret;
565}
566
567static struct dvb_tuner_ops mt2050_tuner_ops = {
568 .set_analog_params = mt2050_set_params,
569 .release = microtune_release,
570 .get_frequency = microtune_get_frequency,
492}; 571};
493 572
494static int mt2050_init(struct i2c_client *c) 573static int mt2050_init(struct dvb_frontend *fe)
495{ 574{
496 struct tuner *t = i2c_get_clientdata(c); 575 struct microtune_priv *priv = fe->tuner_priv;
497 unsigned char buf[2]; 576 unsigned char buf[2];
498 int ret; 577 int ret;
499 578
500 buf[0]=6; 579 buf[0]=6;
501 buf[1]=0x10; 580 buf[1]=0x10;
502 ret=i2c_master_send(c,buf,2); // power 581 ret=tuner_i2c_xfer_send(&priv->i2c_props,buf,2); // power
503 582
504 buf[0]=0x0f; 583 buf[0]=0x0f;
505 buf[1]=0x0f; 584 buf[1]=0x0f;
506 ret=i2c_master_send(c,buf,2); // m1lo 585 ret=tuner_i2c_xfer_send(&priv->i2c_props,buf,2); // m1lo
507 586
508 buf[0]=0x0d; 587 buf[0]=0x0d;
509 ret=i2c_master_send(c,buf,1); 588 ret=tuner_i2c_xfer_send(&priv->i2c_props,buf,1);
510 i2c_master_recv(c,buf,1); 589 tuner_i2c_xfer_recv(&priv->i2c_props,buf,1);
511 590
512 tuner_dbg("mt2050: sro is %x\n",buf[0]); 591 tuner_dbg("mt2050: sro is %x\n",buf[0]);
513 592
514 memcpy(&t->ops, &mt2050_tuner_ops, sizeof(struct tuner_operations)); 593 memcpy(&fe->ops.tuner_ops, &mt2050_tuner_ops, sizeof(struct dvb_tuner_ops));
515 594
516 return 0; 595 return 0;
517} 596}
518 597
519int microtune_init(struct i2c_client *c) 598struct dvb_frontend *microtune_attach(struct dvb_frontend *fe,
599 struct i2c_adapter* i2c_adap,
600 u8 i2c_addr)
520{ 601{
521 struct microtune_priv *priv = NULL; 602 struct microtune_priv *priv = NULL;
522 struct tuner *t = i2c_get_clientdata(c);
523 char *name; 603 char *name;
524 unsigned char buf[21]; 604 unsigned char buf[21];
525 int company_code; 605 int company_code;
526 606
527 priv = kzalloc(sizeof(struct microtune_priv), GFP_KERNEL); 607 priv = kzalloc(sizeof(struct microtune_priv), GFP_KERNEL);
528 if (priv == NULL) 608 if (priv == NULL)
529 return -ENOMEM; 609 return NULL;
530 t->priv = priv; 610 fe->tuner_priv = priv;
611
612 priv->i2c_props.addr = i2c_addr;
613 priv->i2c_props.adap = i2c_adap;
531 614
532 priv->radio_if2 = 10700 * 1000; /* 10.7MHz - FM radio */ 615 //priv->radio_if2 = 10700 * 1000; /* 10.7MHz - FM radio */
533 616
534 memset(buf,0,sizeof(buf)); 617 memset(buf,0,sizeof(buf));
535 618
536 if (t->std & V4L2_STD_525_60) {
537 tuner_dbg("pinnacle ntsc\n");
538 priv->radio_if2 = 41300 * 1000;
539 } else {
540 tuner_dbg("pinnacle pal\n");
541 priv->radio_if2 = 33300 * 1000;
542 }
543 name = "unknown"; 619 name = "unknown";
544 620
545 i2c_master_send(c,buf,1); 621 tuner_i2c_xfer_send(&priv->i2c_props,buf,1);
546 i2c_master_recv(c,buf,21); 622 tuner_i2c_xfer_recv(&priv->i2c_props,buf,21);
547 if (tuner_debug) { 623 if (debug) {
548 int i; 624 int i;
549 tuner_dbg("MT20xx hexdump:"); 625 tuner_dbg("MT20xx hexdump:");
550 for(i=0;i<21;i++) { 626 for(i=0;i<21;i++) {
@@ -563,10 +639,10 @@ int microtune_init(struct i2c_client *c)
563 name = microtune_part[buf[0x13]]; 639 name = microtune_part[buf[0x13]];
564 switch (buf[0x13]) { 640 switch (buf[0x13]) {
565 case MT2032: 641 case MT2032:
566 mt2032_init(c); 642 mt2032_init(fe);
567 break; 643 break;
568 case MT2050: 644 case MT2050:
569 mt2050_init(c); 645 mt2050_init(fe);
570 break; 646 break;
571 default: 647 default:
572 tuner_info("microtune %s found, not (yet?) supported, sorry :-/\n", 648 tuner_info("microtune %s found, not (yet?) supported, sorry :-/\n",
@@ -574,11 +650,18 @@ int microtune_init(struct i2c_client *c)
574 return 0; 650 return 0;
575 } 651 }
576 652
577 strlcpy(c->name, name, sizeof(c->name)); 653 strlcpy(fe->ops.tuner_ops.info.name, name,
654 sizeof(fe->ops.tuner_ops.info.name));
578 tuner_info("microtune %s found, OK\n",name); 655 tuner_info("microtune %s found, OK\n",name);
579 return 0; 656 return fe;
580} 657}
581 658
659EXPORT_SYMBOL_GPL(microtune_attach);
660
661MODULE_DESCRIPTION("Microtune tuner driver");
662MODULE_AUTHOR("Ralph Metzler, Gerd Knorr, Gunther Mayer");
663MODULE_LICENSE("GPL");
664
582/* 665/*
583 * Overrides for Emacs so that we follow Linus's tabbing style. 666 * Overrides for Emacs so that we follow Linus's tabbing style.
584 * --------------------------------------------------------------------------- 667 * ---------------------------------------------------------------------------
diff --git a/drivers/media/video/mt20xx.h b/drivers/media/video/mt20xx.h
new file mode 100644
index 000000000000..5e9c825d2e91
--- /dev/null
+++ b/drivers/media/video/mt20xx.h
@@ -0,0 +1,37 @@
1/*
2 This program is free software; you can redistribute it and/or modify
3 it under the terms of the GNU General Public License as published by
4 the Free Software Foundation; either version 2 of the License, or
5 (at your option) any later version.
6
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
11
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
15*/
16
17#ifndef __MT20XX_H__
18#define __MT20XX_H__
19
20#include <linux/i2c.h>
21#include "dvb_frontend.h"
22
23#if defined(CONFIG_TUNER_MT20XX) || (defined(CONFIG_TUNER_MT20XX_MODULE) && defined(MODULE))
24extern struct dvb_frontend *microtune_attach(struct dvb_frontend *fe,
25 struct i2c_adapter* i2c_adap,
26 u8 i2c_addr);
27#else
28static inline struct dvb_frontend *microtune_attach(struct dvb_frontend *fe,
29 struct i2c_adapter* i2c_adap,
30 u8 i2c_addr)
31{
32 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
33 return NULL;
34}
35#endif
36
37#endif /* __MT20XX_H__ */
diff --git a/drivers/media/video/mxb.c b/drivers/media/video/mxb.c
index 152cc6b3e152..98ad3092a079 100644
--- a/drivers/media/video/mxb.c
+++ b/drivers/media/video/mxb.c
@@ -153,7 +153,6 @@ static int mxb_probe(struct saa7146_dev* dev)
153{ 153{
154 struct mxb* mxb = NULL; 154 struct mxb* mxb = NULL;
155 struct i2c_client *client; 155 struct i2c_client *client;
156 struct list_head *item;
157 int result; 156 int result;
158 157
159 if ((result = request_module("saa7111")) < 0) { 158 if ((result = request_module("saa7111")) < 0) {
@@ -196,8 +195,7 @@ static int mxb_probe(struct saa7146_dev* dev)
196 } 195 }
197 196
198 /* loop through all i2c-devices on the bus and look who is there */ 197 /* loop through all i2c-devices on the bus and look who is there */
199 list_for_each(item,&mxb->i2c_adapter.clients) { 198 list_for_each_entry(client, &mxb->i2c_adapter.clients, list) {
200 client = list_entry(item, struct i2c_client, list);
201 if( I2C_ADDR_TEA6420_1 == client->addr ) 199 if( I2C_ADDR_TEA6420_1 == client->addr )
202 mxb->tea6420_1 = client; 200 mxb->tea6420_1 = client;
203 if( I2C_ADDR_TEA6420_2 == client->addr ) 201 if( I2C_ADDR_TEA6420_2 == client->addr )
diff --git a/drivers/media/video/ov511.c b/drivers/media/video/ov511.c
index e5edff1059a2..9eb2562347a8 100644
--- a/drivers/media/video/ov511.c
+++ b/drivers/media/video/ov511.c
@@ -5554,41 +5554,46 @@ error:
5554 * sysfs 5554 * sysfs
5555 ***************************************************************************/ 5555 ***************************************************************************/
5556 5556
5557static inline struct usb_ov511 *cd_to_ov(struct class_device *cd) 5557static inline struct usb_ov511 *cd_to_ov(struct device *cd)
5558{ 5558{
5559 struct video_device *vdev = to_video_device(cd); 5559 struct video_device *vdev = to_video_device(cd);
5560 return video_get_drvdata(vdev); 5560 return video_get_drvdata(vdev);
5561} 5561}
5562 5562
5563static ssize_t show_custom_id(struct class_device *cd, char *buf) 5563static ssize_t show_custom_id(struct device *cd,
5564 struct device_attribute *attr, char *buf)
5564{ 5565{
5565 struct usb_ov511 *ov = cd_to_ov(cd); 5566 struct usb_ov511 *ov = cd_to_ov(cd);
5566 return sprintf(buf, "%d\n", ov->customid); 5567 return sprintf(buf, "%d\n", ov->customid);
5567} 5568}
5568static CLASS_DEVICE_ATTR(custom_id, S_IRUGO, show_custom_id, NULL); 5569static DEVICE_ATTR(custom_id, S_IRUGO, show_custom_id, NULL);
5569 5570
5570static ssize_t show_model(struct class_device *cd, char *buf) 5571static ssize_t show_model(struct device *cd,
5572 struct device_attribute *attr, char *buf)
5571{ 5573{
5572 struct usb_ov511 *ov = cd_to_ov(cd); 5574 struct usb_ov511 *ov = cd_to_ov(cd);
5573 return sprintf(buf, "%s\n", ov->desc); 5575 return sprintf(buf, "%s\n", ov->desc);
5574} 5576}
5575static CLASS_DEVICE_ATTR(model, S_IRUGO, show_model, NULL); 5577static DEVICE_ATTR(model, S_IRUGO, show_model, NULL);
5576 5578
5577static ssize_t show_bridge(struct class_device *cd, char *buf) 5579static ssize_t show_bridge(struct device *cd,
5580 struct device_attribute *attr, char *buf)
5578{ 5581{
5579 struct usb_ov511 *ov = cd_to_ov(cd); 5582 struct usb_ov511 *ov = cd_to_ov(cd);
5580 return sprintf(buf, "%s\n", symbolic(brglist, ov->bridge)); 5583 return sprintf(buf, "%s\n", symbolic(brglist, ov->bridge));
5581} 5584}
5582static CLASS_DEVICE_ATTR(bridge, S_IRUGO, show_bridge, NULL); 5585static DEVICE_ATTR(bridge, S_IRUGO, show_bridge, NULL);
5583 5586
5584static ssize_t show_sensor(struct class_device *cd, char *buf) 5587static ssize_t show_sensor(struct device *cd,
5588 struct device_attribute *attr, char *buf)
5585{ 5589{
5586 struct usb_ov511 *ov = cd_to_ov(cd); 5590 struct usb_ov511 *ov = cd_to_ov(cd);
5587 return sprintf(buf, "%s\n", symbolic(senlist, ov->sensor)); 5591 return sprintf(buf, "%s\n", symbolic(senlist, ov->sensor));
5588} 5592}
5589static CLASS_DEVICE_ATTR(sensor, S_IRUGO, show_sensor, NULL); 5593static DEVICE_ATTR(sensor, S_IRUGO, show_sensor, NULL);
5590 5594
5591static ssize_t show_brightness(struct class_device *cd, char *buf) 5595static ssize_t show_brightness(struct device *cd,
5596 struct device_attribute *attr, char *buf)
5592{ 5597{
5593 struct usb_ov511 *ov = cd_to_ov(cd); 5598 struct usb_ov511 *ov = cd_to_ov(cd);
5594 unsigned short x; 5599 unsigned short x;
@@ -5598,9 +5603,10 @@ static ssize_t show_brightness(struct class_device *cd, char *buf)
5598 sensor_get_brightness(ov, &x); 5603 sensor_get_brightness(ov, &x);
5599 return sprintf(buf, "%d\n", x >> 8); 5604 return sprintf(buf, "%d\n", x >> 8);
5600} 5605}
5601static CLASS_DEVICE_ATTR(brightness, S_IRUGO, show_brightness, NULL); 5606static DEVICE_ATTR(brightness, S_IRUGO, show_brightness, NULL);
5602 5607
5603static ssize_t show_saturation(struct class_device *cd, char *buf) 5608static ssize_t show_saturation(struct device *cd,
5609 struct device_attribute *attr, char *buf)
5604{ 5610{
5605 struct usb_ov511 *ov = cd_to_ov(cd); 5611 struct usb_ov511 *ov = cd_to_ov(cd);
5606 unsigned short x; 5612 unsigned short x;
@@ -5610,9 +5616,10 @@ static ssize_t show_saturation(struct class_device *cd, char *buf)
5610 sensor_get_saturation(ov, &x); 5616 sensor_get_saturation(ov, &x);
5611 return sprintf(buf, "%d\n", x >> 8); 5617 return sprintf(buf, "%d\n", x >> 8);
5612} 5618}
5613static CLASS_DEVICE_ATTR(saturation, S_IRUGO, show_saturation, NULL); 5619static DEVICE_ATTR(saturation, S_IRUGO, show_saturation, NULL);
5614 5620
5615static ssize_t show_contrast(struct class_device *cd, char *buf) 5621static ssize_t show_contrast(struct device *cd,
5622 struct device_attribute *attr, char *buf)
5616{ 5623{
5617 struct usb_ov511 *ov = cd_to_ov(cd); 5624 struct usb_ov511 *ov = cd_to_ov(cd);
5618 unsigned short x; 5625 unsigned short x;
@@ -5622,9 +5629,10 @@ static ssize_t show_contrast(struct class_device *cd, char *buf)
5622 sensor_get_contrast(ov, &x); 5629 sensor_get_contrast(ov, &x);
5623 return sprintf(buf, "%d\n", x >> 8); 5630 return sprintf(buf, "%d\n", x >> 8);
5624} 5631}
5625static CLASS_DEVICE_ATTR(contrast, S_IRUGO, show_contrast, NULL); 5632static DEVICE_ATTR(contrast, S_IRUGO, show_contrast, NULL);
5626 5633
5627static ssize_t show_hue(struct class_device *cd, char *buf) 5634static ssize_t show_hue(struct device *cd,
5635 struct device_attribute *attr, char *buf)
5628{ 5636{
5629 struct usb_ov511 *ov = cd_to_ov(cd); 5637 struct usb_ov511 *ov = cd_to_ov(cd);
5630 unsigned short x; 5638 unsigned short x;
@@ -5634,9 +5642,10 @@ static ssize_t show_hue(struct class_device *cd, char *buf)
5634 sensor_get_hue(ov, &x); 5642 sensor_get_hue(ov, &x);
5635 return sprintf(buf, "%d\n", x >> 8); 5643 return sprintf(buf, "%d\n", x >> 8);
5636} 5644}
5637static CLASS_DEVICE_ATTR(hue, S_IRUGO, show_hue, NULL); 5645static DEVICE_ATTR(hue, S_IRUGO, show_hue, NULL);
5638 5646
5639static ssize_t show_exposure(struct class_device *cd, char *buf) 5647static ssize_t show_exposure(struct device *cd,
5648 struct device_attribute *attr, char *buf)
5640{ 5649{
5641 struct usb_ov511 *ov = cd_to_ov(cd); 5650 struct usb_ov511 *ov = cd_to_ov(cd);
5642 unsigned char exp = 0; 5651 unsigned char exp = 0;
@@ -5646,49 +5655,49 @@ static ssize_t show_exposure(struct class_device *cd, char *buf)
5646 sensor_get_exposure(ov, &exp); 5655 sensor_get_exposure(ov, &exp);
5647 return sprintf(buf, "%d\n", exp >> 8); 5656 return sprintf(buf, "%d\n", exp >> 8);
5648} 5657}
5649static CLASS_DEVICE_ATTR(exposure, S_IRUGO, show_exposure, NULL); 5658static DEVICE_ATTR(exposure, S_IRUGO, show_exposure, NULL);
5650 5659
5651static int ov_create_sysfs(struct video_device *vdev) 5660static int ov_create_sysfs(struct video_device *vdev)
5652{ 5661{
5653 int rc; 5662 int rc;
5654 5663
5655 rc = video_device_create_file(vdev, &class_device_attr_custom_id); 5664 rc = video_device_create_file(vdev, &dev_attr_custom_id);
5656 if (rc) goto err; 5665 if (rc) goto err;
5657 rc = video_device_create_file(vdev, &class_device_attr_model); 5666 rc = video_device_create_file(vdev, &dev_attr_model);
5658 if (rc) goto err_id; 5667 if (rc) goto err_id;
5659 rc = video_device_create_file(vdev, &class_device_attr_bridge); 5668 rc = video_device_create_file(vdev, &dev_attr_bridge);
5660 if (rc) goto err_model; 5669 if (rc) goto err_model;
5661 rc = video_device_create_file(vdev, &class_device_attr_sensor); 5670 rc = video_device_create_file(vdev, &dev_attr_sensor);
5662 if (rc) goto err_bridge; 5671 if (rc) goto err_bridge;
5663 rc = video_device_create_file(vdev, &class_device_attr_brightness); 5672 rc = video_device_create_file(vdev, &dev_attr_brightness);
5664 if (rc) goto err_sensor; 5673 if (rc) goto err_sensor;
5665 rc = video_device_create_file(vdev, &class_device_attr_saturation); 5674 rc = video_device_create_file(vdev, &dev_attr_saturation);
5666 if (rc) goto err_bright; 5675 if (rc) goto err_bright;
5667 rc = video_device_create_file(vdev, &class_device_attr_contrast); 5676 rc = video_device_create_file(vdev, &dev_attr_contrast);
5668 if (rc) goto err_sat; 5677 if (rc) goto err_sat;
5669 rc = video_device_create_file(vdev, &class_device_attr_hue); 5678 rc = video_device_create_file(vdev, &dev_attr_hue);
5670 if (rc) goto err_contrast; 5679 if (rc) goto err_contrast;
5671 rc = video_device_create_file(vdev, &class_device_attr_exposure); 5680 rc = video_device_create_file(vdev, &dev_attr_exposure);
5672 if (rc) goto err_hue; 5681 if (rc) goto err_hue;
5673 5682
5674 return 0; 5683 return 0;
5675 5684
5676err_hue: 5685err_hue:
5677 video_device_remove_file(vdev, &class_device_attr_hue); 5686 video_device_remove_file(vdev, &dev_attr_hue);
5678err_contrast: 5687err_contrast:
5679 video_device_remove_file(vdev, &class_device_attr_contrast); 5688 video_device_remove_file(vdev, &dev_attr_contrast);
5680err_sat: 5689err_sat:
5681 video_device_remove_file(vdev, &class_device_attr_saturation); 5690 video_device_remove_file(vdev, &dev_attr_saturation);
5682err_bright: 5691err_bright:
5683 video_device_remove_file(vdev, &class_device_attr_brightness); 5692 video_device_remove_file(vdev, &dev_attr_brightness);
5684err_sensor: 5693err_sensor:
5685 video_device_remove_file(vdev, &class_device_attr_sensor); 5694 video_device_remove_file(vdev, &dev_attr_sensor);
5686err_bridge: 5695err_bridge:
5687 video_device_remove_file(vdev, &class_device_attr_bridge); 5696 video_device_remove_file(vdev, &dev_attr_bridge);
5688err_model: 5697err_model:
5689 video_device_remove_file(vdev, &class_device_attr_model); 5698 video_device_remove_file(vdev, &dev_attr_model);
5690err_id: 5699err_id:
5691 video_device_remove_file(vdev, &class_device_attr_custom_id); 5700 video_device_remove_file(vdev, &dev_attr_custom_id);
5692err: 5701err:
5693 return rc; 5702 return rc;
5694} 5703}
diff --git a/drivers/media/video/ov7670.c b/drivers/media/video/ov7670.c
index c4c5bd67f795..2bc6bdc9c1f2 100644
--- a/drivers/media/video/ov7670.c
+++ b/drivers/media/video/ov7670.c
@@ -12,7 +12,6 @@
12 */ 12 */
13#include <linux/init.h> 13#include <linux/init.h>
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/moduleparam.h>
16#include <linux/slab.h> 15#include <linux/slab.h>
17#include <linux/delay.h> 16#include <linux/delay.h>
18#include <linux/videodev.h> 17#include <linux/videodev.h>
diff --git a/drivers/media/video/ovcamchip/ovcamchip_core.c b/drivers/media/video/ovcamchip/ovcamchip_core.c
index 3fe9fa04cd84..8063e33f1c85 100644
--- a/drivers/media/video/ovcamchip/ovcamchip_core.c
+++ b/drivers/media/video/ovcamchip/ovcamchip_core.c
@@ -13,7 +13,6 @@
13 13
14#include <linux/init.h> 14#include <linux/init.h>
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/moduleparam.h>
17#include <linux/slab.h> 16#include <linux/slab.h>
18#include <linux/delay.h> 17#include <linux/delay.h>
19#include "ovcamchip_priv.h" 18#include "ovcamchip_priv.h"
diff --git a/drivers/media/video/planb.c b/drivers/media/video/planb.c
index 4ab1af74a970..0ef73d9d5848 100644
--- a/drivers/media/video/planb.c
+++ b/drivers/media/video/planb.c
@@ -844,21 +844,21 @@ cmd_tab_mask_end:
844/*********************************/ 844/*********************************/
845 845
846static int palette2fmt[] = { 846static int palette2fmt[] = {
847 0, 847 0,
848 PLANB_GRAY, 848 PLANB_GRAY,
849 0, 849 0,
850 0, 850 0,
851 0, 851 0,
852 PLANB_COLOUR32, 852 PLANB_COLOUR32,
853 PLANB_COLOUR15, 853 PLANB_COLOUR15,
854 0, 854 0,
855 0, 855 0,
856 0, 856 0,
857 0, 857 0,
858 0, 858 0,
859 0, 859 0,
860 0, 860 0,
861 0, 861 0,
862}; 862};
863 863
864#define PLANB_PALETTE_MAX 15 864#define PLANB_PALETTE_MAX 15
diff --git a/drivers/media/video/pvrusb2/pvrusb2-context.c b/drivers/media/video/pvrusb2/pvrusb2-context.c
index 6bbed88d7867..22719ba861ac 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-context.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-context.c
@@ -33,8 +33,10 @@ static void pvr2_context_destroy(struct pvr2_context *mp)
33{ 33{
34 if (mp->hdw) pvr2_hdw_destroy(mp->hdw); 34 if (mp->hdw) pvr2_hdw_destroy(mp->hdw);
35 pvr2_trace(PVR2_TRACE_STRUCT,"Destroying pvr_main id=%p",mp); 35 pvr2_trace(PVR2_TRACE_STRUCT,"Destroying pvr_main id=%p",mp);
36 flush_workqueue(mp->workqueue); 36 if (mp->workqueue) {
37 destroy_workqueue(mp->workqueue); 37 flush_workqueue(mp->workqueue);
38 destroy_workqueue(mp->workqueue);
39 }
38 kfree(mp); 40 kfree(mp);
39} 41}
40 42
diff --git a/drivers/media/video/pvrusb2/pvrusb2-debug.h b/drivers/media/video/pvrusb2/pvrusb2-debug.h
index d95a8588e4f8..da6441b88f31 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-debug.h
+++ b/drivers/media/video/pvrusb2/pvrusb2-debug.h
@@ -26,32 +26,33 @@ extern int pvrusb2_debug;
26 26
27/* These are listed in *rough* order of decreasing usefulness and 27/* These are listed in *rough* order of decreasing usefulness and
28 increasing noise level. */ 28 increasing noise level. */
29#define PVR2_TRACE_INFO (1 << 0) // Normal messages 29#define PVR2_TRACE_INFO (1 << 0) /* Normal messages */
30#define PVR2_TRACE_ERROR_LEGS (1 << 1) // error messages 30#define PVR2_TRACE_ERROR_LEGS (1 << 1) /* error messages */
31#define PVR2_TRACE_TOLERANCE (1 << 2) // track tolerance-affected errors 31#define PVR2_TRACE_TOLERANCE (1 << 2) /* track tolerance-affected errors */
32#define PVR2_TRACE_TRAP (1 << 3) // Trap & report misbehavior from app 32#define PVR2_TRACE_TRAP (1 << 3) /* Trap & report app misbehavior */
33#define PVR2_TRACE_INIT (1 << 4) // misc initialization steps 33#define PVR2_TRACE_STD (1 << 4) /* Log video standard stuff */
34#define PVR2_TRACE_START_STOP (1 << 5) // Streaming start / stop 34#define PVR2_TRACE_INIT (1 << 5) /* misc initialization steps */
35#define PVR2_TRACE_CTL (1 << 6) // commit of control changes 35#define PVR2_TRACE_START_STOP (1 << 6) /* Streaming start / stop */
36#define PVR2_TRACE_DEBUG (1 << 7) // Temporary debug code 36#define PVR2_TRACE_CTL (1 << 7) /* commit of control changes */
37#define PVR2_TRACE_EEPROM (1 << 8) // eeprom parsing / report 37#define PVR2_TRACE_DEBUG (1 << 8) /* Temporary debug code */
38#define PVR2_TRACE_STRUCT (1 << 9) // internal struct creation 38#define PVR2_TRACE_EEPROM (1 << 9) /* eeprom parsing / report */
39#define PVR2_TRACE_OPEN_CLOSE (1 << 10) // application open / close 39#define PVR2_TRACE_STRUCT (1 << 10) /* internal struct creation */
40#define PVR2_TRACE_CREG (1 << 11) // Main critical region entry / exit 40#define PVR2_TRACE_OPEN_CLOSE (1 << 11) /* application open / close */
41#define PVR2_TRACE_SYSFS (1 << 12) // Sysfs driven I/O 41#define PVR2_TRACE_CREG (1 << 12) /* Main critical region entry / exit */
42#define PVR2_TRACE_FIRMWARE (1 << 13) // firmware upload actions 42#define PVR2_TRACE_SYSFS (1 << 13) /* Sysfs driven I/O */
43#define PVR2_TRACE_CHIPS (1 << 14) // chip broadcast operation 43#define PVR2_TRACE_FIRMWARE (1 << 14) /* firmware upload actions */
44#define PVR2_TRACE_I2C (1 << 15) // I2C related stuff 44#define PVR2_TRACE_CHIPS (1 << 15) /* chip broadcast operation */
45#define PVR2_TRACE_I2C_CMD (1 << 16) // Software commands to I2C modules 45#define PVR2_TRACE_I2C (1 << 16) /* I2C related stuff */
46#define PVR2_TRACE_I2C_CORE (1 << 17) // I2C core debugging 46#define PVR2_TRACE_I2C_CMD (1 << 17) /* Software commands to I2C modules */
47#define PVR2_TRACE_I2C_TRAF (1 << 18) // I2C traffic through the adapter 47#define PVR2_TRACE_I2C_CORE (1 << 18) /* I2C core debugging */
48#define PVR2_TRACE_V4LIOCTL (1 << 19) // v4l ioctl details 48#define PVR2_TRACE_I2C_TRAF (1 << 19) /* I2C traffic through the adapter */
49#define PVR2_TRACE_ENCODER (1 << 20) // mpeg2 encoder operation 49#define PVR2_TRACE_V4LIOCTL (1 << 20) /* v4l ioctl details */
50#define PVR2_TRACE_BUF_POOL (1 << 21) // Track buffer pool management 50#define PVR2_TRACE_ENCODER (1 << 21) /* mpeg2 encoder operation */
51#define PVR2_TRACE_BUF_FLOW (1 << 22) // Track buffer flow in system 51#define PVR2_TRACE_BUF_POOL (1 << 22) /* Track buffer pool management */
52#define PVR2_TRACE_DATA_FLOW (1 << 23) // Track data flow 52#define PVR2_TRACE_BUF_FLOW (1 << 23) /* Track buffer flow in system */
53#define PVR2_TRACE_DEBUGIFC (1 << 24) // Debug interface actions 53#define PVR2_TRACE_DATA_FLOW (1 << 24) /* Track data flow */
54#define PVR2_TRACE_GPIO (1 << 25) // GPIO state bit changes 54#define PVR2_TRACE_DEBUGIFC (1 << 25) /* Debug interface actions */
55#define PVR2_TRACE_GPIO (1 << 26) /* GPIO state bit changes */
55 56
56 57
57#endif /* __PVRUSB2_HDW_INTERNAL_H */ 58#endif /* __PVRUSB2_HDW_INTERNAL_H */
diff --git a/drivers/media/video/pvrusb2/pvrusb2-debugifc.c b/drivers/media/video/pvrusb2/pvrusb2-debugifc.c
index e9da9bb8f8de..6f135f4a2497 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-debugifc.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-debugifc.c
@@ -397,10 +397,22 @@ static int pvr2_debugifc_do1cmd(struct pvr2_hdw *hdw,const char *buf,
397 count -= scnt; buf += scnt; 397 count -= scnt; buf += scnt;
398 if (!wptr) return -EINVAL; 398 if (!wptr) return -EINVAL;
399 if (debugifc_match_keyword(wptr,wlen,"fetch")) { 399 if (debugifc_match_keyword(wptr,wlen,"fetch")) {
400 pvr2_hdw_cpufw_set_enabled(hdw,!0); 400 scnt = debugifc_isolate_word(buf,count,&wptr,&wlen);
401 if (scnt && wptr) {
402 count -= scnt; buf += scnt;
403 if (debugifc_match_keyword(wptr,wlen,"prom")) {
404 pvr2_hdw_cpufw_set_enabled(hdw,!0,!0);
405 } else if (debugifc_match_keyword(wptr,wlen,
406 "ram")) {
407 pvr2_hdw_cpufw_set_enabled(hdw,0,!0);
408 } else {
409 return -EINVAL;
410 }
411 }
412 pvr2_hdw_cpufw_set_enabled(hdw,0,!0);
401 return 0; 413 return 0;
402 } else if (debugifc_match_keyword(wptr,wlen,"done")) { 414 } else if (debugifc_match_keyword(wptr,wlen,"done")) {
403 pvr2_hdw_cpufw_set_enabled(hdw,0); 415 pvr2_hdw_cpufw_set_enabled(hdw,0,0);
404 return 0; 416 return 0;
405 } else { 417 } else {
406 return -EINVAL; 418 return -EINVAL;
diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
index ce66ab8ff2d8..985d9ae7f5ee 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
@@ -238,6 +238,7 @@ struct pvr2_hdw {
238 // CPU firmware info (used to help find / save firmware data) 238 // CPU firmware info (used to help find / save firmware data)
239 char *fw_buffer; 239 char *fw_buffer;
240 unsigned int fw_size; 240 unsigned int fw_size;
241 int fw_cpu_flag; /* True if we are dealing with the CPU */
241 242
242 // Which subsystem pieces have been enabled / configured 243 // Which subsystem pieces have been enabled / configured
243 unsigned long subsys_enabled_mask; 244 unsigned long subsys_enabled_mask;
diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw.c b/drivers/media/video/pvrusb2/pvrusb2-hdw.c
index 1311891e7ee3..27b12b4b5c88 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-hdw.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw.c
@@ -492,7 +492,7 @@ static int ctrl_cx2341x_get(struct pvr2_ctrl *cptr,int *vp)
492 cs.controls = &c1; 492 cs.controls = &c1;
493 cs.count = 1; 493 cs.count = 1;
494 c1.id = cptr->info->v4l_id; 494 c1.id = cptr->info->v4l_id;
495 ret = cx2341x_ext_ctrls(&cptr->hdw->enc_ctl_state,&cs, 495 ret = cx2341x_ext_ctrls(&cptr->hdw->enc_ctl_state, 0, &cs,
496 VIDIOC_G_EXT_CTRLS); 496 VIDIOC_G_EXT_CTRLS);
497 if (ret) return ret; 497 if (ret) return ret;
498 *vp = c1.value; 498 *vp = c1.value;
@@ -510,7 +510,7 @@ static int ctrl_cx2341x_set(struct pvr2_ctrl *cptr,int m,int v)
510 cs.count = 1; 510 cs.count = 1;
511 c1.id = cptr->info->v4l_id; 511 c1.id = cptr->info->v4l_id;
512 c1.value = v; 512 c1.value = v;
513 ret = cx2341x_ext_ctrls(&cptr->hdw->enc_ctl_state,&cs, 513 ret = cx2341x_ext_ctrls(&cptr->hdw->enc_ctl_state, 0, &cs,
514 VIDIOC_S_EXT_CTRLS); 514 VIDIOC_S_EXT_CTRLS);
515 if (ret) return ret; 515 if (ret) return ret;
516 cptr->hdw->enc_stale = !0; 516 cptr->hdw->enc_stale = !0;
@@ -1143,6 +1143,13 @@ static int pvr2_upload_firmware1(struct pvr2_hdw *hdw)
1143 fw_files_24xxx, ARRAY_SIZE(fw_files_24xxx) 1143 fw_files_24xxx, ARRAY_SIZE(fw_files_24xxx)
1144 }, 1144 },
1145 }; 1145 };
1146
1147 if ((hdw->hdw_type >= ARRAY_SIZE(fw_file_defs)) ||
1148 (!fw_file_defs[hdw->hdw_type].lst)) {
1149 hdw->fw1_state = FW1_STATE_OK;
1150 return 0;
1151 }
1152
1146 hdw->fw1_state = FW1_STATE_FAILED; // default result 1153 hdw->fw1_state = FW1_STATE_FAILED; // default result
1147 1154
1148 trace_firmware("pvr2_upload_firmware1"); 1155 trace_firmware("pvr2_upload_firmware1");
@@ -1224,6 +1231,11 @@ int pvr2_upload_firmware2(struct pvr2_hdw *hdw)
1224 CX2341X_FIRM_ENC_FILENAME, 1231 CX2341X_FIRM_ENC_FILENAME,
1225 }; 1232 };
1226 1233
1234 if ((hdw->hdw_type != PVR2_HDW_TYPE_29XXX) &&
1235 (hdw->hdw_type != PVR2_HDW_TYPE_24XXX)) {
1236 return 0;
1237 }
1238
1227 trace_firmware("pvr2_upload_firmware2"); 1239 trace_firmware("pvr2_upload_firmware2");
1228 1240
1229 ret = pvr2_locate_firmware(hdw,&fw_entry,"encoder", 1241 ret = pvr2_locate_firmware(hdw,&fw_entry,"encoder",
@@ -1682,6 +1694,44 @@ static int pvr2_hdw_check_firmware(struct pvr2_hdw *hdw)
1682 return result == 0; 1694 return result == 0;
1683} 1695}
1684 1696
1697struct pvr2_std_hack {
1698 v4l2_std_id pat; /* Pattern to match */
1699 v4l2_std_id msk; /* Which bits we care about */
1700 v4l2_std_id std; /* What additional standards or default to set */
1701};
1702
1703/* This data structure labels specific combinations of standards from
1704 tveeprom that we'll try to recognize. If we recognize one, then assume
1705 a specified default standard to use. This is here because tveeprom only
1706 tells us about available standards not the intended default standard (if
1707 any) for the device in question. We guess the default based on what has
1708 been reported as available. Note that this is only for guessing a
1709 default - which can always be overridden explicitly - and if the user
1710 has otherwise named a default then that default will always be used in
1711 place of this table. */
1712const static struct pvr2_std_hack std_eeprom_maps[] = {
1713 { /* PAL(B/G) */
1714 .pat = V4L2_STD_B|V4L2_STD_GH,
1715 .std = V4L2_STD_PAL_B|V4L2_STD_PAL_B1|V4L2_STD_PAL_G,
1716 },
1717 { /* NTSC(M) */
1718 .pat = V4L2_STD_MN,
1719 .std = V4L2_STD_NTSC_M,
1720 },
1721 { /* PAL(I) */
1722 .pat = V4L2_STD_PAL_I,
1723 .std = V4L2_STD_PAL_I,
1724 },
1725 { /* SECAM(L/L') */
1726 .pat = V4L2_STD_SECAM_L|V4L2_STD_SECAM_LC,
1727 .std = V4L2_STD_SECAM_L|V4L2_STD_SECAM_LC,
1728 },
1729 { /* PAL(D/D1/K) */
1730 .pat = V4L2_STD_DK,
1731 .std = V4L2_STD_PAL_D/V4L2_STD_PAL_D1|V4L2_STD_PAL_K,
1732 },
1733};
1734
1685static void pvr2_hdw_setup_std(struct pvr2_hdw *hdw) 1735static void pvr2_hdw_setup_std(struct pvr2_hdw *hdw)
1686{ 1736{
1687 char buf[40]; 1737 char buf[40];
@@ -1691,7 +1741,7 @@ static void pvr2_hdw_setup_std(struct pvr2_hdw *hdw)
1691 std1 = get_default_standard(hdw); 1741 std1 = get_default_standard(hdw);
1692 1742
1693 bcnt = pvr2_std_id_to_str(buf,sizeof(buf),hdw->std_mask_eeprom); 1743 bcnt = pvr2_std_id_to_str(buf,sizeof(buf),hdw->std_mask_eeprom);
1694 pvr2_trace(PVR2_TRACE_INIT, 1744 pvr2_trace(PVR2_TRACE_STD,
1695 "Supported video standard(s) reported by eeprom: %.*s", 1745 "Supported video standard(s) reported by eeprom: %.*s",
1696 bcnt,buf); 1746 bcnt,buf);
1697 1747
@@ -1700,7 +1750,7 @@ static void pvr2_hdw_setup_std(struct pvr2_hdw *hdw)
1700 std2 = std1 & ~hdw->std_mask_avail; 1750 std2 = std1 & ~hdw->std_mask_avail;
1701 if (std2) { 1751 if (std2) {
1702 bcnt = pvr2_std_id_to_str(buf,sizeof(buf),std2); 1752 bcnt = pvr2_std_id_to_str(buf,sizeof(buf),std2);
1703 pvr2_trace(PVR2_TRACE_INIT, 1753 pvr2_trace(PVR2_TRACE_STD,
1704 "Expanding supported video standards" 1754 "Expanding supported video standards"
1705 " to include: %.*s", 1755 " to include: %.*s",
1706 bcnt,buf); 1756 bcnt,buf);
@@ -1711,7 +1761,7 @@ static void pvr2_hdw_setup_std(struct pvr2_hdw *hdw)
1711 1761
1712 if (std1) { 1762 if (std1) {
1713 bcnt = pvr2_std_id_to_str(buf,sizeof(buf),std1); 1763 bcnt = pvr2_std_id_to_str(buf,sizeof(buf),std1);
1714 pvr2_trace(PVR2_TRACE_INIT, 1764 pvr2_trace(PVR2_TRACE_STD,
1715 "Initial video standard forced to %.*s", 1765 "Initial video standard forced to %.*s",
1716 bcnt,buf); 1766 bcnt,buf);
1717 hdw->std_mask_cur = std1; 1767 hdw->std_mask_cur = std1;
@@ -1720,12 +1770,33 @@ static void pvr2_hdw_setup_std(struct pvr2_hdw *hdw)
1720 return; 1770 return;
1721 } 1771 }
1722 1772
1773 {
1774 unsigned int idx;
1775 for (idx = 0; idx < ARRAY_SIZE(std_eeprom_maps); idx++) {
1776 if (std_eeprom_maps[idx].msk ?
1777 ((std_eeprom_maps[idx].pat ^
1778 hdw->std_mask_eeprom) &
1779 std_eeprom_maps[idx].msk) :
1780 (std_eeprom_maps[idx].pat !=
1781 hdw->std_mask_eeprom)) continue;
1782 bcnt = pvr2_std_id_to_str(buf,sizeof(buf),
1783 std_eeprom_maps[idx].std);
1784 pvr2_trace(PVR2_TRACE_STD,
1785 "Initial video standard guessed as %.*s",
1786 bcnt,buf);
1787 hdw->std_mask_cur = std_eeprom_maps[idx].std;
1788 hdw->std_dirty = !0;
1789 pvr2_hdw_internal_find_stdenum(hdw);
1790 return;
1791 }
1792 }
1793
1723 if (hdw->std_enum_cnt > 1) { 1794 if (hdw->std_enum_cnt > 1) {
1724 // Autoselect the first listed standard 1795 // Autoselect the first listed standard
1725 hdw->std_enum_cur = 1; 1796 hdw->std_enum_cur = 1;
1726 hdw->std_mask_cur = hdw->std_defs[hdw->std_enum_cur-1].id; 1797 hdw->std_mask_cur = hdw->std_defs[hdw->std_enum_cur-1].id;
1727 hdw->std_dirty = !0; 1798 hdw->std_dirty = !0;
1728 pvr2_trace(PVR2_TRACE_INIT, 1799 pvr2_trace(PVR2_TRACE_STD,
1729 "Initial video standard auto-selected to %s", 1800 "Initial video standard auto-selected to %s",
1730 hdw->std_defs[hdw->std_enum_cur-1].name); 1801 hdw->std_defs[hdw->std_enum_cur-1].name);
1731 return; 1802 return;
@@ -1742,29 +1813,35 @@ static void pvr2_hdw_setup_low(struct pvr2_hdw *hdw)
1742 unsigned int idx; 1813 unsigned int idx;
1743 struct pvr2_ctrl *cptr; 1814 struct pvr2_ctrl *cptr;
1744 int reloadFl = 0; 1815 int reloadFl = 0;
1745 if (!reloadFl) { 1816 if ((hdw->hdw_type == PVR2_HDW_TYPE_29XXX) ||
1746 reloadFl = (hdw->usb_intf->cur_altsetting->desc.bNumEndpoints 1817 (hdw->hdw_type == PVR2_HDW_TYPE_24XXX)) {
1747 == 0); 1818 if (!reloadFl) {
1748 if (reloadFl) { 1819 reloadFl =
1749 pvr2_trace(PVR2_TRACE_INIT, 1820 (hdw->usb_intf->cur_altsetting->desc.bNumEndpoints
1750 "USB endpoint config looks strange" 1821 == 0);
1751 "; possibly firmware needs to be loaded"); 1822 if (reloadFl) {
1823 pvr2_trace(PVR2_TRACE_INIT,
1824 "USB endpoint config looks strange"
1825 "; possibly firmware needs to be"
1826 " loaded");
1827 }
1752 } 1828 }
1753 } 1829 if (!reloadFl) {
1754 if (!reloadFl) { 1830 reloadFl = !pvr2_hdw_check_firmware(hdw);
1755 reloadFl = !pvr2_hdw_check_firmware(hdw); 1831 if (reloadFl) {
1756 if (reloadFl) { 1832 pvr2_trace(PVR2_TRACE_INIT,
1757 pvr2_trace(PVR2_TRACE_INIT, 1833 "Check for FX2 firmware failed"
1758 "Check for FX2 firmware failed" 1834 "; possibly firmware needs to be"
1759 "; possibly firmware needs to be loaded"); 1835 " loaded");
1836 }
1760 } 1837 }
1761 } 1838 if (reloadFl) {
1762 if (reloadFl) { 1839 if (pvr2_upload_firmware1(hdw) != 0) {
1763 if (pvr2_upload_firmware1(hdw) != 0) { 1840 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
1764 pvr2_trace(PVR2_TRACE_ERROR_LEGS, 1841 "Failure uploading firmware1");
1765 "Failure uploading firmware1"); 1842 }
1843 return;
1766 } 1844 }
1767 return;
1768 } 1845 }
1769 hdw->fw1_state = FW1_STATE_OK; 1846 hdw->fw1_state = FW1_STATE_OK;
1770 1847
@@ -1773,17 +1850,25 @@ static void pvr2_hdw_setup_low(struct pvr2_hdw *hdw)
1773 } 1850 }
1774 if (!pvr2_hdw_dev_ok(hdw)) return; 1851 if (!pvr2_hdw_dev_ok(hdw)) return;
1775 1852
1776 for (idx = 0; idx < pvr2_client_lists[hdw->hdw_type].cnt; idx++) { 1853 if (hdw->hdw_type < ARRAY_SIZE(pvr2_client_lists)) {
1777 request_module(pvr2_client_lists[hdw->hdw_type].lst[idx]); 1854 for (idx = 0;
1855 idx < pvr2_client_lists[hdw->hdw_type].cnt;
1856 idx++) {
1857 request_module(
1858 pvr2_client_lists[hdw->hdw_type].lst[idx]);
1859 }
1778 } 1860 }
1779 1861
1780 pvr2_hdw_cmd_powerup(hdw); 1862 if ((hdw->hdw_type == PVR2_HDW_TYPE_29XXX) ||
1781 if (!pvr2_hdw_dev_ok(hdw)) return; 1863 (hdw->hdw_type == PVR2_HDW_TYPE_24XXX)) {
1864 pvr2_hdw_cmd_powerup(hdw);
1865 if (!pvr2_hdw_dev_ok(hdw)) return;
1782 1866
1783 if (pvr2_upload_firmware2(hdw)){ 1867 if (pvr2_upload_firmware2(hdw)){
1784 pvr2_trace(PVR2_TRACE_ERROR_LEGS,"device unstable!!"); 1868 pvr2_trace(PVR2_TRACE_ERROR_LEGS,"device unstable!!");
1785 pvr2_hdw_render_useless(hdw); 1869 pvr2_hdw_render_useless(hdw);
1786 return; 1870 return;
1871 }
1787 } 1872 }
1788 1873
1789 // This step MUST happen after the earlier powerup step. 1874 // This step MUST happen after the earlier powerup step.
@@ -2172,6 +2257,7 @@ static void pvr2_hdw_remove_usb_stuff(struct pvr2_hdw *hdw)
2172/* Destroy hardware interaction structure */ 2257/* Destroy hardware interaction structure */
2173void pvr2_hdw_destroy(struct pvr2_hdw *hdw) 2258void pvr2_hdw_destroy(struct pvr2_hdw *hdw)
2174{ 2259{
2260 if (!hdw) return;
2175 pvr2_trace(PVR2_TRACE_INIT,"pvr2_hdw_destroy: hdw=%p",hdw); 2261 pvr2_trace(PVR2_TRACE_INIT,"pvr2_hdw_destroy: hdw=%p",hdw);
2176 if (hdw->fw_buffer) { 2262 if (hdw->fw_buffer) {
2177 kfree(hdw->fw_buffer); 2263 kfree(hdw->fw_buffer);
@@ -2478,7 +2564,7 @@ static int pvr2_hdw_commit_ctl_internal(struct pvr2_hdw *hdw)
2478 cs.count = 1; 2564 cs.count = 1;
2479 c1.id = V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ; 2565 c1.id = V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ;
2480 c1.value = hdw->srate_val; 2566 c1.value = hdw->srate_val;
2481 cx2341x_ext_ctrls(&hdw->enc_ctl_state,&cs,VIDIOC_S_EXT_CTRLS); 2567 cx2341x_ext_ctrls(&hdw->enc_ctl_state, 0, &cs,VIDIOC_S_EXT_CTRLS);
2482 } 2568 }
2483 2569
2484 /* Scan i2c core at this point - before we clear all the dirty 2570 /* Scan i2c core at this point - before we clear all the dirty
@@ -2604,7 +2690,85 @@ void pvr2_hdw_trigger_module_log(struct pvr2_hdw *hdw)
2604 } while (0); LOCK_GIVE(hdw->big_lock); 2690 } while (0); LOCK_GIVE(hdw->big_lock);
2605} 2691}
2606 2692
2607void pvr2_hdw_cpufw_set_enabled(struct pvr2_hdw *hdw, int enable_flag) 2693
2694/* Grab EEPROM contents, needed for direct method. */
2695#define EEPROM_SIZE 8192
2696#define trace_eeprom(...) pvr2_trace(PVR2_TRACE_EEPROM,__VA_ARGS__)
2697static u8 *pvr2_full_eeprom_fetch(struct pvr2_hdw *hdw)
2698{
2699 struct i2c_msg msg[2];
2700 u8 *eeprom;
2701 u8 iadd[2];
2702 u8 addr;
2703 u16 eepromSize;
2704 unsigned int offs;
2705 int ret;
2706 int mode16 = 0;
2707 unsigned pcnt,tcnt;
2708 eeprom = kmalloc(EEPROM_SIZE,GFP_KERNEL);
2709 if (!eeprom) {
2710 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
2711 "Failed to allocate memory"
2712 " required to read eeprom");
2713 return NULL;
2714 }
2715
2716 trace_eeprom("Value for eeprom addr from controller was 0x%x",
2717 hdw->eeprom_addr);
2718 addr = hdw->eeprom_addr;
2719 /* Seems that if the high bit is set, then the *real* eeprom
2720 address is shifted right now bit position (noticed this in
2721 newer PVR USB2 hardware) */
2722 if (addr & 0x80) addr >>= 1;
2723
2724 /* FX2 documentation states that a 16bit-addressed eeprom is
2725 expected if the I2C address is an odd number (yeah, this is
2726 strange but it's what they do) */
2727 mode16 = (addr & 1);
2728 eepromSize = (mode16 ? EEPROM_SIZE : 256);
2729 trace_eeprom("Examining %d byte eeprom at location 0x%x"
2730 " using %d bit addressing",eepromSize,addr,
2731 mode16 ? 16 : 8);
2732
2733 msg[0].addr = addr;
2734 msg[0].flags = 0;
2735 msg[0].len = mode16 ? 2 : 1;
2736 msg[0].buf = iadd;
2737 msg[1].addr = addr;
2738 msg[1].flags = I2C_M_RD;
2739
2740 /* We have to do the actual eeprom data fetch ourselves, because
2741 (1) we're only fetching part of the eeprom, and (2) if we were
2742 getting the whole thing our I2C driver can't grab it in one
2743 pass - which is what tveeprom is otherwise going to attempt */
2744 memset(eeprom,0,EEPROM_SIZE);
2745 for (tcnt = 0; tcnt < EEPROM_SIZE; tcnt += pcnt) {
2746 pcnt = 16;
2747 if (pcnt + tcnt > EEPROM_SIZE) pcnt = EEPROM_SIZE-tcnt;
2748 offs = tcnt + (eepromSize - EEPROM_SIZE);
2749 if (mode16) {
2750 iadd[0] = offs >> 8;
2751 iadd[1] = offs;
2752 } else {
2753 iadd[0] = offs;
2754 }
2755 msg[1].len = pcnt;
2756 msg[1].buf = eeprom+tcnt;
2757 if ((ret = i2c_transfer(&hdw->i2c_adap,
2758 msg,ARRAY_SIZE(msg))) != 2) {
2759 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
2760 "eeprom fetch set offs err=%d",ret);
2761 kfree(eeprom);
2762 return NULL;
2763 }
2764 }
2765 return eeprom;
2766}
2767
2768
2769void pvr2_hdw_cpufw_set_enabled(struct pvr2_hdw *hdw,
2770 int prom_flag,
2771 int enable_flag)
2608{ 2772{
2609 int ret; 2773 int ret;
2610 u16 address; 2774 u16 address;
@@ -2618,37 +2782,59 @@ void pvr2_hdw_cpufw_set_enabled(struct pvr2_hdw *hdw, int enable_flag)
2618 kfree(hdw->fw_buffer); 2782 kfree(hdw->fw_buffer);
2619 hdw->fw_buffer = NULL; 2783 hdw->fw_buffer = NULL;
2620 hdw->fw_size = 0; 2784 hdw->fw_size = 0;
2621 /* Now release the CPU. It will disconnect and 2785 if (hdw->fw_cpu_flag) {
2622 reconnect later. */ 2786 /* Now release the CPU. It will disconnect
2623 pvr2_hdw_cpureset_assert(hdw,0); 2787 and reconnect later. */
2788 pvr2_hdw_cpureset_assert(hdw,0);
2789 }
2624 break; 2790 break;
2625 } 2791 }
2626 2792
2627 pvr2_trace(PVR2_TRACE_FIRMWARE, 2793 hdw->fw_cpu_flag = (prom_flag == 0);
2628 "Preparing to suck out CPU firmware"); 2794 if (hdw->fw_cpu_flag) {
2629 hdw->fw_size = 0x2000; 2795 pvr2_trace(PVR2_TRACE_FIRMWARE,
2630 hdw->fw_buffer = kzalloc(hdw->fw_size,GFP_KERNEL); 2796 "Preparing to suck out CPU firmware");
2631 if (!hdw->fw_buffer) { 2797 hdw->fw_size = 0x2000;
2632 hdw->fw_size = 0; 2798 hdw->fw_buffer = kzalloc(hdw->fw_size,GFP_KERNEL);
2633 break; 2799 if (!hdw->fw_buffer) {
2634 } 2800 hdw->fw_size = 0;
2801 break;
2802 }
2635 2803
2636 /* We have to hold the CPU during firmware upload. */ 2804 /* We have to hold the CPU during firmware upload. */
2637 pvr2_hdw_cpureset_assert(hdw,1); 2805 pvr2_hdw_cpureset_assert(hdw,1);
2638 2806
2639 /* download the firmware from address 0000-1fff in 2048 2807 /* download the firmware from address 0000-1fff in 2048
2640 (=0x800) bytes chunk. */ 2808 (=0x800) bytes chunk. */
2641 2809
2642 pvr2_trace(PVR2_TRACE_FIRMWARE,"Grabbing CPU firmware"); 2810 pvr2_trace(PVR2_TRACE_FIRMWARE,
2643 pipe = usb_rcvctrlpipe(hdw->usb_dev, 0); 2811 "Grabbing CPU firmware");
2644 for(address = 0; address < hdw->fw_size; address += 0x800) { 2812 pipe = usb_rcvctrlpipe(hdw->usb_dev, 0);
2645 ret = usb_control_msg(hdw->usb_dev,pipe,0xa0,0xc0, 2813 for(address = 0; address < hdw->fw_size;
2646 address,0, 2814 address += 0x800) {
2647 hdw->fw_buffer+address,0x800,HZ); 2815 ret = usb_control_msg(hdw->usb_dev,pipe,
2648 if (ret < 0) break; 2816 0xa0,0xc0,
2649 } 2817 address,0,
2818 hdw->fw_buffer+address,
2819 0x800,HZ);
2820 if (ret < 0) break;
2821 }
2650 2822
2651 pvr2_trace(PVR2_TRACE_FIRMWARE,"Done grabbing CPU firmware"); 2823 pvr2_trace(PVR2_TRACE_FIRMWARE,
2824 "Done grabbing CPU firmware");
2825 } else {
2826 pvr2_trace(PVR2_TRACE_FIRMWARE,
2827 "Sucking down EEPROM contents");
2828 hdw->fw_buffer = pvr2_full_eeprom_fetch(hdw);
2829 if (!hdw->fw_buffer) {
2830 pvr2_trace(PVR2_TRACE_FIRMWARE,
2831 "EEPROM content suck failed.");
2832 break;
2833 }
2834 hdw->fw_size = EEPROM_SIZE;
2835 pvr2_trace(PVR2_TRACE_FIRMWARE,
2836 "Done sucking down EEPROM contents");
2837 }
2652 2838
2653 } while (0); LOCK_GIVE(hdw->big_lock); 2839 } while (0); LOCK_GIVE(hdw->big_lock);
2654} 2840}
@@ -3272,7 +3458,6 @@ int pvr2_hdw_register_access(struct pvr2_hdw *hdw,
3272 int setFl,u64 *val_ptr) 3458 int setFl,u64 *val_ptr)
3273{ 3459{
3274#ifdef CONFIG_VIDEO_ADV_DEBUG 3460#ifdef CONFIG_VIDEO_ADV_DEBUG
3275 struct list_head *item;
3276 struct pvr2_i2c_client *cp; 3461 struct pvr2_i2c_client *cp;
3277 struct v4l2_register req; 3462 struct v4l2_register req;
3278 int stat = 0; 3463 int stat = 0;
@@ -3285,8 +3470,7 @@ int pvr2_hdw_register_access(struct pvr2_hdw *hdw,
3285 req.reg = reg_id; 3470 req.reg = reg_id;
3286 if (setFl) req.val = *val_ptr; 3471 if (setFl) req.val = *val_ptr;
3287 mutex_lock(&hdw->i2c_list_lock); do { 3472 mutex_lock(&hdw->i2c_list_lock); do {
3288 list_for_each(item,&hdw->i2c_clients) { 3473 list_for_each_entry(cp, &hdw->i2c_clients, list) {
3289 cp = list_entry(item,struct pvr2_i2c_client,list);
3290 if (!v4l2_chip_match_i2c_client( 3474 if (!v4l2_chip_match_i2c_client(
3291 cp->client, 3475 cp->client,
3292 req.match_type, req.match_chip)) { 3476 req.match_type, req.match_chip)) {
diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw.h b/drivers/media/video/pvrusb2/pvrusb2-hdw.h
index 4dba8d006324..e2f9d5e4cb65 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-hdw.h
+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw.h
@@ -197,11 +197,13 @@ void pvr2_hdw_subsys_stream_bit_chg(struct pvr2_hdw *hdw,
197unsigned long pvr2_hdw_subsys_stream_get(struct pvr2_hdw *); 197unsigned long pvr2_hdw_subsys_stream_get(struct pvr2_hdw *);
198 198
199 199
200/* Enable / disable retrieval of CPU firmware. This must be enabled before 200/* Enable / disable retrieval of CPU firmware or prom contents. This must
201 pvr2_hdw_cpufw_get() will function. Note that doing this may prevent 201 be enabled before pvr2_hdw_cpufw_get() will function. Note that doing
202 the device from running (and leaving this mode may imply a device 202 this may prevent the device from running (and leaving this mode may
203 reset). */ 203 imply a device reset). */
204void pvr2_hdw_cpufw_set_enabled(struct pvr2_hdw *, int enable_flag); 204void pvr2_hdw_cpufw_set_enabled(struct pvr2_hdw *,
205 int prom_flag,
206 int enable_flag);
205 207
206/* Return true if we're in a mode for retrieval CPU firmware */ 208/* Return true if we're in a mode for retrieval CPU firmware */
207int pvr2_hdw_cpufw_get_enabled(struct pvr2_hdw *); 209int pvr2_hdw_cpufw_get_enabled(struct pvr2_hdw *);
diff --git a/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c b/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
index 6786d3c0c98b..898c9d2e4cdf 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
@@ -389,10 +389,6 @@ static int pvr2_i2c_xfer(struct i2c_adapter *i2c_adap,
389 ret = -EINVAL; 389 ret = -EINVAL;
390 goto done; 390 goto done;
391 } 391 }
392 if ((msgs[0].flags & I2C_M_NOSTART)) {
393 trace_i2c("i2c refusing I2C_M_NOSTART");
394 goto done;
395 }
396 if (msgs[0].addr < PVR2_I2C_FUNC_CNT) { 392 if (msgs[0].addr < PVR2_I2C_FUNC_CNT) {
397 funcp = hdw->i2c_func[msgs[0].addr]; 393 funcp = hdw->i2c_func[msgs[0].addr];
398 } 394 }
@@ -494,14 +490,12 @@ static int pvr2_i2c_xfer(struct i2c_adapter *i2c_adap,
494 cnt = msgs[idx].len; 490 cnt = msgs[idx].len;
495 printk(KERN_INFO 491 printk(KERN_INFO
496 "pvrusb2 i2c xfer %u/%u:" 492 "pvrusb2 i2c xfer %u/%u:"
497 " addr=0x%x len=%d %s%s", 493 " addr=0x%x len=%d %s",
498 idx+1,num, 494 idx+1,num,
499 msgs[idx].addr, 495 msgs[idx].addr,
500 cnt, 496 cnt,
501 (msgs[idx].flags & I2C_M_RD ? 497 (msgs[idx].flags & I2C_M_RD ?
502 "read" : "write"), 498 "read" : "write"));
503 (msgs[idx].flags & I2C_M_NOSTART ?
504 " nostart" : ""));
505 if ((ret > 0) || !(msgs[idx].flags & I2C_M_RD)) { 499 if ((ret > 0) || !(msgs[idx].flags & I2C_M_RD)) {
506 if (cnt > 8) cnt = 8; 500 if (cnt > 8) cnt = 8;
507 printk(" ["); 501 printk(" [");
@@ -534,7 +528,7 @@ static int pvr2_i2c_control(struct i2c_adapter *adapter,
534 528
535static u32 pvr2_i2c_functionality(struct i2c_adapter *adap) 529static u32 pvr2_i2c_functionality(struct i2c_adapter *adap)
536{ 530{
537 return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_I2C | I2C_FUNC_SMBUS_BYTE_DATA; 531 return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_I2C;
538} 532}
539 533
540static int pvr2_i2c_core_singleton(struct i2c_client *cp, 534static int pvr2_i2c_core_singleton(struct i2c_client *cp,
@@ -576,15 +570,13 @@ int pvr2_i2c_client_cmd(struct pvr2_i2c_client *cp,unsigned int cmd,void *arg)
576 570
577int pvr2_i2c_core_cmd(struct pvr2_hdw *hdw,unsigned int cmd,void *arg) 571int pvr2_i2c_core_cmd(struct pvr2_hdw *hdw,unsigned int cmd,void *arg)
578{ 572{
579 struct list_head *item,*nc; 573 struct pvr2_i2c_client *cp, *ncp;
580 struct pvr2_i2c_client *cp;
581 int stat = -EINVAL; 574 int stat = -EINVAL;
582 575
583 if (!hdw) return stat; 576 if (!hdw) return stat;
584 577
585 mutex_lock(&hdw->i2c_list_lock); 578 mutex_lock(&hdw->i2c_list_lock);
586 list_for_each_safe(item,nc,&hdw->i2c_clients) { 579 list_for_each_entry_safe(cp, ncp, &hdw->i2c_clients, list) {
587 cp = list_entry(item,struct pvr2_i2c_client,list);
588 if (!cp->recv_enable) continue; 580 if (!cp->recv_enable) continue;
589 mutex_unlock(&hdw->i2c_list_lock); 581 mutex_unlock(&hdw->i2c_list_lock);
590 stat = pvr2_i2c_client_cmd(cp,cmd,arg); 582 stat = pvr2_i2c_client_cmd(cp,cmd,arg);
@@ -608,13 +600,11 @@ static int handler_check(struct pvr2_i2c_client *cp)
608 600
609void pvr2_i2c_core_status_poll(struct pvr2_hdw *hdw) 601void pvr2_i2c_core_status_poll(struct pvr2_hdw *hdw)
610{ 602{
611 struct list_head *item;
612 struct pvr2_i2c_client *cp; 603 struct pvr2_i2c_client *cp;
613 mutex_lock(&hdw->i2c_list_lock); do { 604 mutex_lock(&hdw->i2c_list_lock); do {
614 struct v4l2_tuner *vtp = &hdw->tuner_signal_info; 605 struct v4l2_tuner *vtp = &hdw->tuner_signal_info;
615 memset(vtp,0,sizeof(*vtp)); 606 memset(vtp,0,sizeof(*vtp));
616 list_for_each(item,&hdw->i2c_clients) { 607 list_for_each_entry(cp, &hdw->i2c_clients, list) {
617 cp = list_entry(item,struct pvr2_i2c_client,list);
618 if (!cp->detected_flag) continue; 608 if (!cp->detected_flag) continue;
619 if (!cp->status_poll) continue; 609 if (!cp->status_poll) continue;
620 cp->status_poll(cp); 610 cp->status_poll(cp);
@@ -636,8 +626,7 @@ void pvr2_i2c_core_sync(struct pvr2_hdw *hdw)
636{ 626{
637 unsigned long msk; 627 unsigned long msk;
638 unsigned int idx; 628 unsigned int idx;
639 struct list_head *item,*nc; 629 struct pvr2_i2c_client *cp, *ncp;
640 struct pvr2_i2c_client *cp;
641 630
642 if (!hdw->i2c_linked) return; 631 if (!hdw->i2c_linked) return;
643 if (!(hdw->i2c_pend_types & PVR2_I2C_PEND_ALL)) { 632 if (!(hdw->i2c_pend_types & PVR2_I2C_PEND_ALL)) {
@@ -655,9 +644,7 @@ void pvr2_i2c_core_sync(struct pvr2_hdw *hdw)
655 buf = kmalloc(BUFSIZE,GFP_KERNEL); 644 buf = kmalloc(BUFSIZE,GFP_KERNEL);
656 pvr2_trace(PVR2_TRACE_I2C_CORE,"i2c: PEND_DETECT"); 645 pvr2_trace(PVR2_TRACE_I2C_CORE,"i2c: PEND_DETECT");
657 hdw->i2c_pend_types &= ~PVR2_I2C_PEND_DETECT; 646 hdw->i2c_pend_types &= ~PVR2_I2C_PEND_DETECT;
658 list_for_each(item,&hdw->i2c_clients) { 647 list_for_each_entry(cp, &hdw->i2c_clients, list) {
659 cp = list_entry(item,struct pvr2_i2c_client,
660 list);
661 if (!cp->detected_flag) { 648 if (!cp->detected_flag) {
662 cp->ctl_mask = 0; 649 cp->ctl_mask = 0;
663 pvr2_i2c_probe(hdw,cp); 650 pvr2_i2c_probe(hdw,cp);
@@ -693,9 +680,7 @@ void pvr2_i2c_core_sync(struct pvr2_hdw *hdw)
693 "i2c: PEND_STALE (0x%lx)", 680 "i2c: PEND_STALE (0x%lx)",
694 hdw->i2c_stale_mask); 681 hdw->i2c_stale_mask);
695 hdw->i2c_pend_types &= ~PVR2_I2C_PEND_STALE; 682 hdw->i2c_pend_types &= ~PVR2_I2C_PEND_STALE;
696 list_for_each(item,&hdw->i2c_clients) { 683 list_for_each_entry(cp, &hdw->i2c_clients, list) {
697 cp = list_entry(item,struct pvr2_i2c_client,
698 list);
699 m2 = hdw->i2c_stale_mask; 684 m2 = hdw->i2c_stale_mask;
700 m2 &= cp->ctl_mask; 685 m2 &= cp->ctl_mask;
701 m2 &= ~cp->pend_mask; 686 m2 &= ~cp->pend_mask;
@@ -716,9 +701,8 @@ void pvr2_i2c_core_sync(struct pvr2_hdw *hdw)
716 and update each one. */ 701 and update each one. */
717 pvr2_trace(PVR2_TRACE_I2C_CORE,"i2c: PEND_CLIENT"); 702 pvr2_trace(PVR2_TRACE_I2C_CORE,"i2c: PEND_CLIENT");
718 hdw->i2c_pend_types &= ~PVR2_I2C_PEND_CLIENT; 703 hdw->i2c_pend_types &= ~PVR2_I2C_PEND_CLIENT;
719 list_for_each_safe(item,nc,&hdw->i2c_clients) { 704 list_for_each_entry_safe(cp, ncp, &hdw->i2c_clients,
720 cp = list_entry(item,struct pvr2_i2c_client, 705 list) {
721 list);
722 if (!cp->handler) continue; 706 if (!cp->handler) continue;
723 if (!cp->handler->func_table->update) continue; 707 if (!cp->handler->func_table->update) continue;
724 pvr2_trace(PVR2_TRACE_I2C_CORE, 708 pvr2_trace(PVR2_TRACE_I2C_CORE,
@@ -750,10 +734,8 @@ void pvr2_i2c_core_sync(struct pvr2_hdw *hdw)
750 for (idx = 0, msk = 1; pm; idx++, msk <<= 1) { 734 for (idx = 0, msk = 1; pm; idx++, msk <<= 1) {
751 if (!(pm & msk)) continue; 735 if (!(pm & msk)) continue;
752 pm &= ~msk; 736 pm &= ~msk;
753 list_for_each(item,&hdw->i2c_clients) { 737 list_for_each_entry(cp, &hdw->i2c_clients,
754 cp = list_entry(item, 738 list) {
755 struct pvr2_i2c_client,
756 list);
757 if (cp->pend_mask & msk) { 739 if (cp->pend_mask & msk) {
758 cp->pend_mask &= ~msk; 740 cp->pend_mask &= ~msk;
759 cp->recv_enable = !0; 741 cp->recv_enable = !0;
@@ -777,7 +759,6 @@ int pvr2_i2c_core_check_stale(struct pvr2_hdw *hdw)
777 unsigned long msk,sm,pm; 759 unsigned long msk,sm,pm;
778 unsigned int idx; 760 unsigned int idx;
779 const struct pvr2_i2c_op *opf; 761 const struct pvr2_i2c_op *opf;
780 struct list_head *item;
781 struct pvr2_i2c_client *cp; 762 struct pvr2_i2c_client *cp;
782 unsigned int pt = 0; 763 unsigned int pt = 0;
783 764
@@ -796,11 +777,9 @@ int pvr2_i2c_core_check_stale(struct pvr2_hdw *hdw)
796 } 777 }
797 if (sm) pt |= PVR2_I2C_PEND_STALE; 778 if (sm) pt |= PVR2_I2C_PEND_STALE;
798 779
799 list_for_each(item,&hdw->i2c_clients) { 780 list_for_each_entry(cp, &hdw->i2c_clients, list)
800 cp = list_entry(item,struct pvr2_i2c_client,list); 781 if (handler_check(cp))
801 if (!handler_check(cp)) continue; 782 pt |= PVR2_I2C_PEND_CLIENT;
802 pt |= PVR2_I2C_PEND_CLIENT;
803 }
804 783
805 if (pt) { 784 if (pt) {
806 mutex_lock(&hdw->i2c_list_lock); do { 785 mutex_lock(&hdw->i2c_list_lock); do {
@@ -888,12 +867,10 @@ unsigned int pvr2_i2c_report(struct pvr2_hdw *hdw,
888 char *buf,unsigned int maxlen) 867 char *buf,unsigned int maxlen)
889{ 868{
890 unsigned int ccnt,bcnt; 869 unsigned int ccnt,bcnt;
891 struct list_head *item;
892 struct pvr2_i2c_client *cp; 870 struct pvr2_i2c_client *cp;
893 ccnt = 0; 871 ccnt = 0;
894 mutex_lock(&hdw->i2c_list_lock); do { 872 mutex_lock(&hdw->i2c_list_lock); do {
895 list_for_each(item,&hdw->i2c_clients) { 873 list_for_each_entry(cp, &hdw->i2c_clients, list) {
896 cp = list_entry(item,struct pvr2_i2c_client,list);
897 bcnt = pvr2_i2c_client_describe( 874 bcnt = pvr2_i2c_client_describe(
898 cp, 875 cp,
899 (PVR2_I2C_DETAIL_HANDLER| 876 (PVR2_I2C_DETAIL_HANDLER|
@@ -931,13 +908,11 @@ static int pvr2_i2c_attach_inform(struct i2c_client *client)
931static int pvr2_i2c_detach_inform(struct i2c_client *client) 908static int pvr2_i2c_detach_inform(struct i2c_client *client)
932{ 909{
933 struct pvr2_hdw *hdw = (struct pvr2_hdw *)(client->adapter->algo_data); 910 struct pvr2_hdw *hdw = (struct pvr2_hdw *)(client->adapter->algo_data);
934 struct pvr2_i2c_client *cp; 911 struct pvr2_i2c_client *cp, *ncp;
935 struct list_head *item,*nc;
936 unsigned long amask = 0; 912 unsigned long amask = 0;
937 int foundfl = 0; 913 int foundfl = 0;
938 mutex_lock(&hdw->i2c_list_lock); do { 914 mutex_lock(&hdw->i2c_list_lock); do {
939 list_for_each_safe(item,nc,&hdw->i2c_clients) { 915 list_for_each_entry_safe(cp, ncp, &hdw->i2c_clients, list) {
940 cp = list_entry(item,struct pvr2_i2c_client,list);
941 if (cp->client == client) { 916 if (cp->client == client) {
942 trace_i2c("pvr2_i2c_detach" 917 trace_i2c("pvr2_i2c_detach"
943 " [client=%s @ 0x%x ctxt=%p]", 918 " [client=%s @ 0x%x ctxt=%p]",
diff --git a/drivers/media/video/pvrusb2/pvrusb2-main.c b/drivers/media/video/pvrusb2/pvrusb2-main.c
index 9ea41c6699bb..ca9e2789c8ca 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-main.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-main.c
@@ -24,7 +24,6 @@
24#include <linux/errno.h> 24#include <linux/errno.h>
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/module.h> 26#include <linux/module.h>
27#include <linux/moduleparam.h>
28#include <linux/usb.h> 27#include <linux/usb.h>
29#include <linux/videodev2.h> 28#include <linux/videodev2.h>
30 29
@@ -42,6 +41,7 @@
42 41
43#define DEFAULT_DEBUG_MASK (PVR2_TRACE_ERROR_LEGS| \ 42#define DEFAULT_DEBUG_MASK (PVR2_TRACE_ERROR_LEGS| \
44 PVR2_TRACE_INFO| \ 43 PVR2_TRACE_INFO| \
44 PVR2_TRACE_STD| \
45 PVR2_TRACE_TOLERANCE| \ 45 PVR2_TRACE_TOLERANCE| \
46 PVR2_TRACE_TRAP| \ 46 PVR2_TRACE_TRAP| \
47 0) 47 0)
diff --git a/drivers/media/video/pvrusb2/pvrusb2-std.c b/drivers/media/video/pvrusb2/pvrusb2-std.c
index 81de26ba41d9..63e55bb59fcb 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-std.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-std.c
@@ -298,7 +298,7 @@ static int pvr2_std_fill(struct v4l2_standard *std,v4l2_std_id id)
298 std->id = id; 298 std->id = id;
299 bcnt = pvr2_std_id_to_str(std->name,sizeof(std->name)-1,id); 299 bcnt = pvr2_std_id_to_str(std->name,sizeof(std->name)-1,id);
300 std->name[bcnt] = 0; 300 std->name[bcnt] = 0;
301 pvr2_trace(PVR2_TRACE_INIT,"Set up standard idx=%u name=%s", 301 pvr2_trace(PVR2_TRACE_STD,"Set up standard idx=%u name=%s",
302 std->index,std->name); 302 std->index,std->name);
303 return !0; 303 return !0;
304} 304}
@@ -320,11 +320,11 @@ struct v4l2_standard *pvr2_std_create_enum(unsigned int *countptr,
320 v4l2_std_id idmsk,cmsk,fmsk; 320 v4l2_std_id idmsk,cmsk,fmsk;
321 struct v4l2_standard *stddefs; 321 struct v4l2_standard *stddefs;
322 322
323 if (pvrusb2_debug & PVR2_TRACE_INIT) { 323 if (pvrusb2_debug & PVR2_TRACE_STD) {
324 char buf[50]; 324 char buf[50];
325 bcnt = pvr2_std_id_to_str(buf,sizeof(buf),id); 325 bcnt = pvr2_std_id_to_str(buf,sizeof(buf),id);
326 pvr2_trace( 326 pvr2_trace(
327 PVR2_TRACE_INIT,"Mapping standards mask=0x%x (%.*s)", 327 PVR2_TRACE_STD,"Mapping standards mask=0x%x (%.*s)",
328 (int)id,bcnt,buf); 328 (int)id,bcnt,buf);
329 } 329 }
330 330
@@ -355,7 +355,7 @@ struct v4l2_standard *pvr2_std_create_enum(unsigned int *countptr,
355 bcnt,buf); 355 bcnt,buf);
356 } 356 }
357 357
358 pvr2_trace(PVR2_TRACE_INIT,"Setting up %u unique standard(s)", 358 pvr2_trace(PVR2_TRACE_STD,"Setting up %u unique standard(s)",
359 std_cnt); 359 std_cnt);
360 if (!std_cnt) return NULL; // paranoia 360 if (!std_cnt) return NULL; // paranoia
361 361
diff --git a/drivers/media/video/pvrusb2/pvrusb2-sysfs.c b/drivers/media/video/pvrusb2/pvrusb2-sysfs.c
index 7ab79baa1c8c..7a78d6b34738 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-sysfs.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-sysfs.c
@@ -33,16 +33,16 @@
33 33
34struct pvr2_sysfs { 34struct pvr2_sysfs {
35 struct pvr2_channel channel; 35 struct pvr2_channel channel;
36 struct class_device *class_dev; 36 struct device *class_dev;
37#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC 37#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
38 struct pvr2_sysfs_debugifc *debugifc; 38 struct pvr2_sysfs_debugifc *debugifc;
39#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */ 39#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
40 struct pvr2_sysfs_ctl_item *item_first; 40 struct pvr2_sysfs_ctl_item *item_first;
41 struct pvr2_sysfs_ctl_item *item_last; 41 struct pvr2_sysfs_ctl_item *item_last;
42 struct class_device_attribute attr_v4l_minor_number; 42 struct device_attribute attr_v4l_minor_number;
43 struct class_device_attribute attr_v4l_radio_minor_number; 43 struct device_attribute attr_v4l_radio_minor_number;
44 struct class_device_attribute attr_unit_number; 44 struct device_attribute attr_unit_number;
45 struct class_device_attribute attr_bus_info; 45 struct device_attribute attr_bus_info;
46 int v4l_minor_number_created_ok; 46 int v4l_minor_number_created_ok;
47 int v4l_radio_minor_number_created_ok; 47 int v4l_radio_minor_number_created_ok;
48 int unit_number_created_ok; 48 int unit_number_created_ok;
@@ -51,22 +51,22 @@ struct pvr2_sysfs {
51 51
52#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC 52#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
53struct pvr2_sysfs_debugifc { 53struct pvr2_sysfs_debugifc {
54 struct class_device_attribute attr_debugcmd; 54 struct device_attribute attr_debugcmd;
55 struct class_device_attribute attr_debuginfo; 55 struct device_attribute attr_debuginfo;
56 int debugcmd_created_ok; 56 int debugcmd_created_ok;
57 int debuginfo_created_ok; 57 int debuginfo_created_ok;
58}; 58};
59#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */ 59#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
60 60
61struct pvr2_sysfs_ctl_item { 61struct pvr2_sysfs_ctl_item {
62 struct class_device_attribute attr_name; 62 struct device_attribute attr_name;
63 struct class_device_attribute attr_type; 63 struct device_attribute attr_type;
64 struct class_device_attribute attr_min; 64 struct device_attribute attr_min;
65 struct class_device_attribute attr_max; 65 struct device_attribute attr_max;
66 struct class_device_attribute attr_enum; 66 struct device_attribute attr_enum;
67 struct class_device_attribute attr_bits; 67 struct device_attribute attr_bits;
68 struct class_device_attribute attr_val; 68 struct device_attribute attr_val;
69 struct class_device_attribute attr_custom; 69 struct device_attribute attr_custom;
70 struct pvr2_ctrl *cptr; 70 struct pvr2_ctrl *cptr;
71 struct pvr2_sysfs *chptr; 71 struct pvr2_sysfs *chptr;
72 struct pvr2_sysfs_ctl_item *item_next; 72 struct pvr2_sysfs_ctl_item *item_next;
@@ -80,13 +80,13 @@ struct pvr2_sysfs_class {
80 struct class class; 80 struct class class;
81}; 81};
82 82
83static ssize_t show_name(int id,struct class_device *class_dev,char *buf) 83static ssize_t show_name(int id,struct device *class_dev,char *buf)
84{ 84{
85 struct pvr2_ctrl *cptr; 85 struct pvr2_ctrl *cptr;
86 struct pvr2_sysfs *sfp; 86 struct pvr2_sysfs *sfp;
87 const char *name; 87 const char *name;
88 88
89 sfp = (struct pvr2_sysfs *)class_dev->class_data; 89 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
90 if (!sfp) return -EINVAL; 90 if (!sfp) return -EINVAL;
91 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id); 91 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
92 if (!cptr) return -EINVAL; 92 if (!cptr) return -EINVAL;
@@ -99,14 +99,14 @@ static ssize_t show_name(int id,struct class_device *class_dev,char *buf)
99 return scnprintf(buf,PAGE_SIZE,"%s\n",name); 99 return scnprintf(buf,PAGE_SIZE,"%s\n",name);
100} 100}
101 101
102static ssize_t show_type(int id,struct class_device *class_dev,char *buf) 102static ssize_t show_type(int id,struct device *class_dev,char *buf)
103{ 103{
104 struct pvr2_ctrl *cptr; 104 struct pvr2_ctrl *cptr;
105 struct pvr2_sysfs *sfp; 105 struct pvr2_sysfs *sfp;
106 const char *name; 106 const char *name;
107 enum pvr2_ctl_type tp; 107 enum pvr2_ctl_type tp;
108 108
109 sfp = (struct pvr2_sysfs *)class_dev->class_data; 109 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
110 if (!sfp) return -EINVAL; 110 if (!sfp) return -EINVAL;
111 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id); 111 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
112 if (!cptr) return -EINVAL; 112 if (!cptr) return -EINVAL;
@@ -126,13 +126,13 @@ static ssize_t show_type(int id,struct class_device *class_dev,char *buf)
126 return scnprintf(buf,PAGE_SIZE,"%s\n",name); 126 return scnprintf(buf,PAGE_SIZE,"%s\n",name);
127} 127}
128 128
129static ssize_t show_min(int id,struct class_device *class_dev,char *buf) 129static ssize_t show_min(int id,struct device *class_dev,char *buf)
130{ 130{
131 struct pvr2_ctrl *cptr; 131 struct pvr2_ctrl *cptr;
132 struct pvr2_sysfs *sfp; 132 struct pvr2_sysfs *sfp;
133 long val; 133 long val;
134 134
135 sfp = (struct pvr2_sysfs *)class_dev->class_data; 135 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
136 if (!sfp) return -EINVAL; 136 if (!sfp) return -EINVAL;
137 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id); 137 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
138 if (!cptr) return -EINVAL; 138 if (!cptr) return -EINVAL;
@@ -143,13 +143,13 @@ static ssize_t show_min(int id,struct class_device *class_dev,char *buf)
143 return scnprintf(buf,PAGE_SIZE,"%ld\n",val); 143 return scnprintf(buf,PAGE_SIZE,"%ld\n",val);
144} 144}
145 145
146static ssize_t show_max(int id,struct class_device *class_dev,char *buf) 146static ssize_t show_max(int id,struct device *class_dev,char *buf)
147{ 147{
148 struct pvr2_ctrl *cptr; 148 struct pvr2_ctrl *cptr;
149 struct pvr2_sysfs *sfp; 149 struct pvr2_sysfs *sfp;
150 long val; 150 long val;
151 151
152 sfp = (struct pvr2_sysfs *)class_dev->class_data; 152 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
153 if (!sfp) return -EINVAL; 153 if (!sfp) return -EINVAL;
154 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id); 154 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
155 if (!cptr) return -EINVAL; 155 if (!cptr) return -EINVAL;
@@ -160,14 +160,14 @@ static ssize_t show_max(int id,struct class_device *class_dev,char *buf)
160 return scnprintf(buf,PAGE_SIZE,"%ld\n",val); 160 return scnprintf(buf,PAGE_SIZE,"%ld\n",val);
161} 161}
162 162
163static ssize_t show_val_norm(int id,struct class_device *class_dev,char *buf) 163static ssize_t show_val_norm(int id,struct device *class_dev,char *buf)
164{ 164{
165 struct pvr2_ctrl *cptr; 165 struct pvr2_ctrl *cptr;
166 struct pvr2_sysfs *sfp; 166 struct pvr2_sysfs *sfp;
167 int val,ret; 167 int val,ret;
168 unsigned int cnt = 0; 168 unsigned int cnt = 0;
169 169
170 sfp = (struct pvr2_sysfs *)class_dev->class_data; 170 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
171 if (!sfp) return -EINVAL; 171 if (!sfp) return -EINVAL;
172 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id); 172 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
173 if (!cptr) return -EINVAL; 173 if (!cptr) return -EINVAL;
@@ -184,14 +184,14 @@ static ssize_t show_val_norm(int id,struct class_device *class_dev,char *buf)
184 return cnt+1; 184 return cnt+1;
185} 185}
186 186
187static ssize_t show_val_custom(int id,struct class_device *class_dev,char *buf) 187static ssize_t show_val_custom(int id,struct device *class_dev,char *buf)
188{ 188{
189 struct pvr2_ctrl *cptr; 189 struct pvr2_ctrl *cptr;
190 struct pvr2_sysfs *sfp; 190 struct pvr2_sysfs *sfp;
191 int val,ret; 191 int val,ret;
192 unsigned int cnt = 0; 192 unsigned int cnt = 0;
193 193
194 sfp = (struct pvr2_sysfs *)class_dev->class_data; 194 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
195 if (!sfp) return -EINVAL; 195 if (!sfp) return -EINVAL;
196 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id); 196 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
197 if (!cptr) return -EINVAL; 197 if (!cptr) return -EINVAL;
@@ -208,14 +208,14 @@ static ssize_t show_val_custom(int id,struct class_device *class_dev,char *buf)
208 return cnt+1; 208 return cnt+1;
209} 209}
210 210
211static ssize_t show_enum(int id,struct class_device *class_dev,char *buf) 211static ssize_t show_enum(int id,struct device *class_dev,char *buf)
212{ 212{
213 struct pvr2_ctrl *cptr; 213 struct pvr2_ctrl *cptr;
214 struct pvr2_sysfs *sfp; 214 struct pvr2_sysfs *sfp;
215 long val; 215 long val;
216 unsigned int bcnt,ccnt,ecnt; 216 unsigned int bcnt,ccnt,ecnt;
217 217
218 sfp = (struct pvr2_sysfs *)class_dev->class_data; 218 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
219 if (!sfp) return -EINVAL; 219 if (!sfp) return -EINVAL;
220 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id); 220 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
221 if (!cptr) return -EINVAL; 221 if (!cptr) return -EINVAL;
@@ -233,14 +233,14 @@ static ssize_t show_enum(int id,struct class_device *class_dev,char *buf)
233 return bcnt; 233 return bcnt;
234} 234}
235 235
236static ssize_t show_bits(int id,struct class_device *class_dev,char *buf) 236static ssize_t show_bits(int id,struct device *class_dev,char *buf)
237{ 237{
238 struct pvr2_ctrl *cptr; 238 struct pvr2_ctrl *cptr;
239 struct pvr2_sysfs *sfp; 239 struct pvr2_sysfs *sfp;
240 int valid_bits,msk; 240 int valid_bits,msk;
241 unsigned int bcnt,ccnt; 241 unsigned int bcnt,ccnt;
242 242
243 sfp = (struct pvr2_sysfs *)class_dev->class_data; 243 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
244 if (!sfp) return -EINVAL; 244 if (!sfp) return -EINVAL;
245 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id); 245 cptr = pvr2_hdw_get_ctrl_by_index(sfp->channel.hdw,id);
246 if (!cptr) return -EINVAL; 246 if (!cptr) return -EINVAL;
@@ -278,23 +278,23 @@ static int store_val_any(int id,int customfl,struct pvr2_sysfs *sfp,
278 return ret; 278 return ret;
279} 279}
280 280
281static ssize_t store_val_norm(int id,struct class_device *class_dev, 281static ssize_t store_val_norm(int id,struct device *class_dev,
282 const char *buf,size_t count) 282 const char *buf,size_t count)
283{ 283{
284 struct pvr2_sysfs *sfp; 284 struct pvr2_sysfs *sfp;
285 int ret; 285 int ret;
286 sfp = (struct pvr2_sysfs *)class_dev->class_data; 286 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
287 ret = store_val_any(id,0,sfp,buf,count); 287 ret = store_val_any(id,0,sfp,buf,count);
288 if (!ret) ret = count; 288 if (!ret) ret = count;
289 return ret; 289 return ret;
290} 290}
291 291
292static ssize_t store_val_custom(int id,struct class_device *class_dev, 292static ssize_t store_val_custom(int id,struct device *class_dev,
293 const char *buf,size_t count) 293 const char *buf,size_t count)
294{ 294{
295 struct pvr2_sysfs *sfp; 295 struct pvr2_sysfs *sfp;
296 int ret; 296 int ret;
297 sfp = (struct pvr2_sysfs *)class_dev->class_data; 297 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
298 ret = store_val_any(id,1,sfp,buf,count); 298 ret = store_val_any(id,1,sfp,buf,count);
299 if (!ret) ret = count; 299 if (!ret) ret = count;
300 return ret; 300 return ret;
@@ -304,7 +304,7 @@ static ssize_t store_val_custom(int id,struct class_device *class_dev,
304 Mike Isely <isely@pobox.com> 30-April-2005 304 Mike Isely <isely@pobox.com> 30-April-2005
305 305
306 This next batch of horrible preprocessor hackery is needed because the 306 This next batch of horrible preprocessor hackery is needed because the
307 kernel's class_device_attribute mechanism fails to pass the actual 307 kernel's device_attribute mechanism fails to pass the actual
308 attribute through to the show / store functions, which means we have no 308 attribute through to the show / store functions, which means we have no
309 way to package up any attribute-specific parameters, like for example the 309 way to package up any attribute-specific parameters, like for example the
310 control id. So we work around this brain-damage by encoding the control 310 control id. So we work around this brain-damage by encoding the control
@@ -314,11 +314,13 @@ static ssize_t store_val_custom(int id,struct class_device *class_dev,
314*/ 314*/
315 315
316#define CREATE_SHOW_INSTANCE(sf_name,ctl_id) \ 316#define CREATE_SHOW_INSTANCE(sf_name,ctl_id) \
317static ssize_t sf_name##_##ctl_id(struct class_device *class_dev,char *buf) \ 317static ssize_t sf_name##_##ctl_id(struct device *class_dev, \
318struct device_attribute *attr, char *buf) \
318{ return sf_name(ctl_id,class_dev,buf); } 319{ return sf_name(ctl_id,class_dev,buf); }
319 320
320#define CREATE_STORE_INSTANCE(sf_name,ctl_id) \ 321#define CREATE_STORE_INSTANCE(sf_name,ctl_id) \
321static ssize_t sf_name##_##ctl_id(struct class_device *class_dev,const char *buf,size_t count) \ 322static ssize_t sf_name##_##ctl_id(struct device *class_dev, \
323struct device_attribute *attr, const char *buf, size_t count) \
322{ return sf_name(ctl_id,class_dev,buf,count); } 324{ return sf_name(ctl_id,class_dev,buf,count); }
323 325
324#define CREATE_BATCH(ctl_id) \ 326#define CREATE_BATCH(ctl_id) \
@@ -395,17 +397,27 @@ CREATE_BATCH(58)
395CREATE_BATCH(59) 397CREATE_BATCH(59)
396 398
397struct pvr2_sysfs_func_set { 399struct pvr2_sysfs_func_set {
398 ssize_t (*show_name)(struct class_device *,char *); 400 ssize_t (*show_name)(struct device *,
399 ssize_t (*show_type)(struct class_device *,char *); 401 struct device_attribute *attr, char *);
400 ssize_t (*show_min)(struct class_device *,char *); 402 ssize_t (*show_type)(struct device *,
401 ssize_t (*show_max)(struct class_device *,char *); 403 struct device_attribute *attr, char *);
402 ssize_t (*show_enum)(struct class_device *,char *); 404 ssize_t (*show_min)(struct device *,
403 ssize_t (*show_bits)(struct class_device *,char *); 405 struct device_attribute *attr, char *);
404 ssize_t (*show_val_norm)(struct class_device *,char *); 406 ssize_t (*show_max)(struct device *,
405 ssize_t (*store_val_norm)(struct class_device *, 407 struct device_attribute *attr, char *);
408 ssize_t (*show_enum)(struct device *,
409 struct device_attribute *attr, char *);
410 ssize_t (*show_bits)(struct device *,
411 struct device_attribute *attr, char *);
412 ssize_t (*show_val_norm)(struct device *,
413 struct device_attribute *attr, char *);
414 ssize_t (*store_val_norm)(struct device *,
415 struct device_attribute *attr,
406 const char *,size_t); 416 const char *,size_t);
407 ssize_t (*show_val_custom)(struct class_device *,char *); 417 ssize_t (*show_val_custom)(struct device *,
408 ssize_t (*store_val_custom)(struct class_device *, 418 struct device_attribute *attr, char *);
419 ssize_t (*store_val_custom)(struct device *,
420 struct device_attribute *attr,
409 const char *,size_t); 421 const char *,size_t);
410}; 422};
411 423
@@ -597,9 +609,12 @@ static void pvr2_sysfs_add_control(struct pvr2_sysfs *sfp,int ctl_id)
597} 609}
598 610
599#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC 611#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
600static ssize_t debuginfo_show(struct class_device *,char *); 612static ssize_t debuginfo_show(struct device *, struct device_attribute *,
601static ssize_t debugcmd_show(struct class_device *,char *); 613 char *);
602static ssize_t debugcmd_store(struct class_device *,const char *,size_t count); 614static ssize_t debugcmd_show(struct device *, struct device_attribute *,
615 char *);
616static ssize_t debugcmd_store(struct device *, struct device_attribute *,
617 const char *, size_t count);
603 618
604static void pvr2_sysfs_add_debugifc(struct pvr2_sysfs *sfp) 619static void pvr2_sysfs_add_debugifc(struct pvr2_sysfs *sfp)
605{ 620{
@@ -616,16 +631,16 @@ static void pvr2_sysfs_add_debugifc(struct pvr2_sysfs *sfp)
616 dip->attr_debuginfo.attr.mode = S_IRUGO; 631 dip->attr_debuginfo.attr.mode = S_IRUGO;
617 dip->attr_debuginfo.show = debuginfo_show; 632 dip->attr_debuginfo.show = debuginfo_show;
618 sfp->debugifc = dip; 633 sfp->debugifc = dip;
619 ret = class_device_create_file(sfp->class_dev,&dip->attr_debugcmd); 634 ret = device_create_file(sfp->class_dev,&dip->attr_debugcmd);
620 if (ret < 0) { 635 if (ret < 0) {
621 printk(KERN_WARNING "%s: class_device_create_file error: %d\n", 636 printk(KERN_WARNING "%s: device_create_file error: %d\n",
622 __FUNCTION__, ret); 637 __FUNCTION__, ret);
623 } else { 638 } else {
624 dip->debugcmd_created_ok = !0; 639 dip->debugcmd_created_ok = !0;
625 } 640 }
626 ret = class_device_create_file(sfp->class_dev,&dip->attr_debuginfo); 641 ret = device_create_file(sfp->class_dev,&dip->attr_debuginfo);
627 if (ret < 0) { 642 if (ret < 0) {
628 printk(KERN_WARNING "%s: class_device_create_file error: %d\n", 643 printk(KERN_WARNING "%s: device_create_file error: %d\n",
629 __FUNCTION__, ret); 644 __FUNCTION__, ret);
630 } else { 645 } else {
631 dip->debuginfo_created_ok = !0; 646 dip->debuginfo_created_ok = !0;
@@ -637,11 +652,11 @@ static void pvr2_sysfs_tear_down_debugifc(struct pvr2_sysfs *sfp)
637{ 652{
638 if (!sfp->debugifc) return; 653 if (!sfp->debugifc) return;
639 if (sfp->debugifc->debuginfo_created_ok) { 654 if (sfp->debugifc->debuginfo_created_ok) {
640 class_device_remove_file(sfp->class_dev, 655 device_remove_file(sfp->class_dev,
641 &sfp->debugifc->attr_debuginfo); 656 &sfp->debugifc->attr_debuginfo);
642 } 657 }
643 if (sfp->debugifc->debugcmd_created_ok) { 658 if (sfp->debugifc->debugcmd_created_ok) {
644 class_device_remove_file(sfp->class_dev, 659 device_remove_file(sfp->class_dev,
645 &sfp->debugifc->attr_debugcmd); 660 &sfp->debugifc->attr_debugcmd);
646 } 661 }
647 kfree(sfp->debugifc); 662 kfree(sfp->debugifc);
@@ -683,7 +698,7 @@ static void pvr2_sysfs_class_release(struct class *class)
683} 698}
684 699
685 700
686static void pvr2_sysfs_release(struct class_device *class_dev) 701static void pvr2_sysfs_release(struct device *class_dev)
687{ 702{
688 pvr2_sysfs_trace("Releasing class_dev id=%p",class_dev); 703 pvr2_sysfs_trace("Releasing class_dev id=%p",class_dev);
689 kfree(class_dev); 704 kfree(class_dev);
@@ -698,32 +713,33 @@ static void class_dev_destroy(struct pvr2_sysfs *sfp)
698#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */ 713#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
699 pvr2_sysfs_tear_down_controls(sfp); 714 pvr2_sysfs_tear_down_controls(sfp);
700 if (sfp->bus_info_created_ok) { 715 if (sfp->bus_info_created_ok) {
701 class_device_remove_file(sfp->class_dev, 716 device_remove_file(sfp->class_dev,
702 &sfp->attr_bus_info); 717 &sfp->attr_bus_info);
703 } 718 }
704 if (sfp->v4l_minor_number_created_ok) { 719 if (sfp->v4l_minor_number_created_ok) {
705 class_device_remove_file(sfp->class_dev, 720 device_remove_file(sfp->class_dev,
706 &sfp->attr_v4l_minor_number); 721 &sfp->attr_v4l_minor_number);
707 } 722 }
708 if (sfp->v4l_radio_minor_number_created_ok) { 723 if (sfp->v4l_radio_minor_number_created_ok) {
709 class_device_remove_file(sfp->class_dev, 724 device_remove_file(sfp->class_dev,
710 &sfp->attr_v4l_radio_minor_number); 725 &sfp->attr_v4l_radio_minor_number);
711 } 726 }
712 if (sfp->unit_number_created_ok) { 727 if (sfp->unit_number_created_ok) {
713 class_device_remove_file(sfp->class_dev, 728 device_remove_file(sfp->class_dev,
714 &sfp->attr_unit_number); 729 &sfp->attr_unit_number);
715 } 730 }
716 pvr2_sysfs_trace("Destroying class_dev id=%p",sfp->class_dev); 731 pvr2_sysfs_trace("Destroying class_dev id=%p",sfp->class_dev);
717 sfp->class_dev->class_data = NULL; 732 sfp->class_dev->driver_data = NULL;
718 class_device_unregister(sfp->class_dev); 733 device_unregister(sfp->class_dev);
719 sfp->class_dev = NULL; 734 sfp->class_dev = NULL;
720} 735}
721 736
722 737
723static ssize_t v4l_minor_number_show(struct class_device *class_dev,char *buf) 738static ssize_t v4l_minor_number_show(struct device *class_dev,
739 struct device_attribute *attr, char *buf)
724{ 740{
725 struct pvr2_sysfs *sfp; 741 struct pvr2_sysfs *sfp;
726 sfp = (struct pvr2_sysfs *)class_dev->class_data; 742 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
727 if (!sfp) return -EINVAL; 743 if (!sfp) return -EINVAL;
728 return scnprintf(buf,PAGE_SIZE,"%d\n", 744 return scnprintf(buf,PAGE_SIZE,"%d\n",
729 pvr2_hdw_v4l_get_minor_number(sfp->channel.hdw, 745 pvr2_hdw_v4l_get_minor_number(sfp->channel.hdw,
@@ -731,21 +747,23 @@ static ssize_t v4l_minor_number_show(struct class_device *class_dev,char *buf)
731} 747}
732 748
733 749
734static ssize_t bus_info_show(struct class_device *class_dev,char *buf) 750static ssize_t bus_info_show(struct device *class_dev,
751 struct device_attribute *attr, char *buf)
735{ 752{
736 struct pvr2_sysfs *sfp; 753 struct pvr2_sysfs *sfp;
737 sfp = (struct pvr2_sysfs *)class_dev->class_data; 754 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
738 if (!sfp) return -EINVAL; 755 if (!sfp) return -EINVAL;
739 return scnprintf(buf,PAGE_SIZE,"%s\n", 756 return scnprintf(buf,PAGE_SIZE,"%s\n",
740 pvr2_hdw_get_bus_info(sfp->channel.hdw)); 757 pvr2_hdw_get_bus_info(sfp->channel.hdw));
741} 758}
742 759
743 760
744static ssize_t v4l_radio_minor_number_show(struct class_device *class_dev, 761static ssize_t v4l_radio_minor_number_show(struct device *class_dev,
762 struct device_attribute *attr,
745 char *buf) 763 char *buf)
746{ 764{
747 struct pvr2_sysfs *sfp; 765 struct pvr2_sysfs *sfp;
748 sfp = (struct pvr2_sysfs *)class_dev->class_data; 766 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
749 if (!sfp) return -EINVAL; 767 if (!sfp) return -EINVAL;
750 return scnprintf(buf,PAGE_SIZE,"%d\n", 768 return scnprintf(buf,PAGE_SIZE,"%d\n",
751 pvr2_hdw_v4l_get_minor_number(sfp->channel.hdw, 769 pvr2_hdw_v4l_get_minor_number(sfp->channel.hdw,
@@ -753,10 +771,11 @@ static ssize_t v4l_radio_minor_number_show(struct class_device *class_dev,
753} 771}
754 772
755 773
756static ssize_t unit_number_show(struct class_device *class_dev,char *buf) 774static ssize_t unit_number_show(struct device *class_dev,
775 struct device_attribute *attr, char *buf)
757{ 776{
758 struct pvr2_sysfs *sfp; 777 struct pvr2_sysfs *sfp;
759 sfp = (struct pvr2_sysfs *)class_dev->class_data; 778 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
760 if (!sfp) return -EINVAL; 779 if (!sfp) return -EINVAL;
761 return scnprintf(buf,PAGE_SIZE,"%d\n", 780 return scnprintf(buf,PAGE_SIZE,"%d\n",
762 pvr2_hdw_get_unit_number(sfp->channel.hdw)); 781 pvr2_hdw_get_unit_number(sfp->channel.hdw));
@@ -767,7 +786,7 @@ static void class_dev_create(struct pvr2_sysfs *sfp,
767 struct pvr2_sysfs_class *class_ptr) 786 struct pvr2_sysfs_class *class_ptr)
768{ 787{
769 struct usb_device *usb_dev; 788 struct usb_device *usb_dev;
770 struct class_device *class_dev; 789 struct device *class_dev;
771 int ret; 790 int ret;
772 791
773 usb_dev = pvr2_hdw_get_dev(sfp->channel.hdw); 792 usb_dev = pvr2_hdw_get_dev(sfp->channel.hdw);
@@ -779,23 +798,23 @@ static void class_dev_create(struct pvr2_sysfs *sfp,
779 798
780 class_dev->class = &class_ptr->class; 799 class_dev->class = &class_ptr->class;
781 if (pvr2_hdw_get_sn(sfp->channel.hdw)) { 800 if (pvr2_hdw_get_sn(sfp->channel.hdw)) {
782 snprintf(class_dev->class_id,BUS_ID_SIZE,"sn-%lu", 801 snprintf(class_dev->bus_id, BUS_ID_SIZE, "sn-%lu",
783 pvr2_hdw_get_sn(sfp->channel.hdw)); 802 pvr2_hdw_get_sn(sfp->channel.hdw));
784 } else if (pvr2_hdw_get_unit_number(sfp->channel.hdw) >= 0) { 803 } else if (pvr2_hdw_get_unit_number(sfp->channel.hdw) >= 0) {
785 snprintf(class_dev->class_id,BUS_ID_SIZE,"unit-%c", 804 snprintf(class_dev->bus_id, BUS_ID_SIZE, "unit-%c",
786 pvr2_hdw_get_unit_number(sfp->channel.hdw) + 'a'); 805 pvr2_hdw_get_unit_number(sfp->channel.hdw) + 'a');
787 } else { 806 } else {
788 kfree(class_dev); 807 kfree(class_dev);
789 return; 808 return;
790 } 809 }
791 810
792 class_dev->dev = &usb_dev->dev; 811 class_dev->parent = &usb_dev->dev;
793 812
794 sfp->class_dev = class_dev; 813 sfp->class_dev = class_dev;
795 class_dev->class_data = sfp; 814 class_dev->driver_data = sfp;
796 ret = class_device_register(class_dev); 815 ret = device_register(class_dev);
797 if (ret) { 816 if (ret) {
798 printk(KERN_ERR "%s: class_device_register failed\n", 817 printk(KERN_ERR "%s: device_register failed\n",
799 __FUNCTION__); 818 __FUNCTION__);
800 kfree(class_dev); 819 kfree(class_dev);
801 return; 820 return;
@@ -805,10 +824,10 @@ static void class_dev_create(struct pvr2_sysfs *sfp,
805 sfp->attr_v4l_minor_number.attr.mode = S_IRUGO; 824 sfp->attr_v4l_minor_number.attr.mode = S_IRUGO;
806 sfp->attr_v4l_minor_number.show = v4l_minor_number_show; 825 sfp->attr_v4l_minor_number.show = v4l_minor_number_show;
807 sfp->attr_v4l_minor_number.store = NULL; 826 sfp->attr_v4l_minor_number.store = NULL;
808 ret = class_device_create_file(sfp->class_dev, 827 ret = device_create_file(sfp->class_dev,
809 &sfp->attr_v4l_minor_number); 828 &sfp->attr_v4l_minor_number);
810 if (ret < 0) { 829 if (ret < 0) {
811 printk(KERN_WARNING "%s: class_device_create_file error: %d\n", 830 printk(KERN_WARNING "%s: device_create_file error: %d\n",
812 __FUNCTION__, ret); 831 __FUNCTION__, ret);
813 } else { 832 } else {
814 sfp->v4l_minor_number_created_ok = !0; 833 sfp->v4l_minor_number_created_ok = !0;
@@ -818,10 +837,10 @@ static void class_dev_create(struct pvr2_sysfs *sfp,
818 sfp->attr_v4l_radio_minor_number.attr.mode = S_IRUGO; 837 sfp->attr_v4l_radio_minor_number.attr.mode = S_IRUGO;
819 sfp->attr_v4l_radio_minor_number.show = v4l_radio_minor_number_show; 838 sfp->attr_v4l_radio_minor_number.show = v4l_radio_minor_number_show;
820 sfp->attr_v4l_radio_minor_number.store = NULL; 839 sfp->attr_v4l_radio_minor_number.store = NULL;
821 ret = class_device_create_file(sfp->class_dev, 840 ret = device_create_file(sfp->class_dev,
822 &sfp->attr_v4l_radio_minor_number); 841 &sfp->attr_v4l_radio_minor_number);
823 if (ret < 0) { 842 if (ret < 0) {
824 printk(KERN_WARNING "%s: class_device_create_file error: %d\n", 843 printk(KERN_WARNING "%s: device_create_file error: %d\n",
825 __FUNCTION__, ret); 844 __FUNCTION__, ret);
826 } else { 845 } else {
827 sfp->v4l_radio_minor_number_created_ok = !0; 846 sfp->v4l_radio_minor_number_created_ok = !0;
@@ -831,9 +850,9 @@ static void class_dev_create(struct pvr2_sysfs *sfp,
831 sfp->attr_unit_number.attr.mode = S_IRUGO; 850 sfp->attr_unit_number.attr.mode = S_IRUGO;
832 sfp->attr_unit_number.show = unit_number_show; 851 sfp->attr_unit_number.show = unit_number_show;
833 sfp->attr_unit_number.store = NULL; 852 sfp->attr_unit_number.store = NULL;
834 ret = class_device_create_file(sfp->class_dev,&sfp->attr_unit_number); 853 ret = device_create_file(sfp->class_dev,&sfp->attr_unit_number);
835 if (ret < 0) { 854 if (ret < 0) {
836 printk(KERN_WARNING "%s: class_device_create_file error: %d\n", 855 printk(KERN_WARNING "%s: device_create_file error: %d\n",
837 __FUNCTION__, ret); 856 __FUNCTION__, ret);
838 } else { 857 } else {
839 sfp->unit_number_created_ok = !0; 858 sfp->unit_number_created_ok = !0;
@@ -843,10 +862,10 @@ static void class_dev_create(struct pvr2_sysfs *sfp,
843 sfp->attr_bus_info.attr.mode = S_IRUGO; 862 sfp->attr_bus_info.attr.mode = S_IRUGO;
844 sfp->attr_bus_info.show = bus_info_show; 863 sfp->attr_bus_info.show = bus_info_show;
845 sfp->attr_bus_info.store = NULL; 864 sfp->attr_bus_info.store = NULL;
846 ret = class_device_create_file(sfp->class_dev, 865 ret = device_create_file(sfp->class_dev,
847 &sfp->attr_bus_info); 866 &sfp->attr_bus_info);
848 if (ret < 0) { 867 if (ret < 0) {
849 printk(KERN_WARNING "%s: class_device_create_file error: %d\n", 868 printk(KERN_WARNING "%s: device_create_file error: %d\n",
850 __FUNCTION__, ret); 869 __FUNCTION__, ret);
851 } else { 870 } else {
852 sfp->bus_info_created_ok = !0; 871 sfp->bus_info_created_ok = !0;
@@ -886,7 +905,7 @@ struct pvr2_sysfs *pvr2_sysfs_create(struct pvr2_context *mp,
886} 905}
887 906
888 907
889static int pvr2_sysfs_hotplug(struct class_device *cd,char **envp, 908static int pvr2_sysfs_hotplug(struct device *cd,char **envp,
890 int numenvp,char *buf,int size) 909 int numenvp,char *buf,int size)
891{ 910{
892 /* Even though we don't do anything here, we still need this function 911 /* Even though we don't do anything here, we still need this function
@@ -902,8 +921,8 @@ struct pvr2_sysfs_class *pvr2_sysfs_class_create(void)
902 pvr2_sysfs_trace("Creating pvr2_sysfs_class id=%p",clp); 921 pvr2_sysfs_trace("Creating pvr2_sysfs_class id=%p",clp);
903 clp->class.name = "pvrusb2"; 922 clp->class.name = "pvrusb2";
904 clp->class.class_release = pvr2_sysfs_class_release; 923 clp->class.class_release = pvr2_sysfs_class_release;
905 clp->class.release = pvr2_sysfs_release; 924 clp->class.dev_release = pvr2_sysfs_release;
906 clp->class.uevent = pvr2_sysfs_hotplug; 925 clp->class.dev_uevent = pvr2_sysfs_hotplug;
907 if (class_register(&clp->class)) { 926 if (class_register(&clp->class)) {
908 pvr2_sysfs_trace( 927 pvr2_sysfs_trace(
909 "Registration failed for pvr2_sysfs_class id=%p",clp); 928 "Registration failed for pvr2_sysfs_class id=%p",clp);
@@ -921,32 +940,35 @@ void pvr2_sysfs_class_destroy(struct pvr2_sysfs_class *clp)
921 940
922 941
923#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC 942#ifdef CONFIG_VIDEO_PVRUSB2_DEBUGIFC
924static ssize_t debuginfo_show(struct class_device *class_dev,char *buf) 943static ssize_t debuginfo_show(struct device *class_dev,
944 struct device_attribute *attr, char *buf)
925{ 945{
926 struct pvr2_sysfs *sfp; 946 struct pvr2_sysfs *sfp;
927 sfp = (struct pvr2_sysfs *)class_dev->class_data; 947 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
928 if (!sfp) return -EINVAL; 948 if (!sfp) return -EINVAL;
929 pvr2_hdw_trigger_module_log(sfp->channel.hdw); 949 pvr2_hdw_trigger_module_log(sfp->channel.hdw);
930 return pvr2_debugifc_print_info(sfp->channel.hdw,buf,PAGE_SIZE); 950 return pvr2_debugifc_print_info(sfp->channel.hdw,buf,PAGE_SIZE);
931} 951}
932 952
933 953
934static ssize_t debugcmd_show(struct class_device *class_dev,char *buf) 954static ssize_t debugcmd_show(struct device *class_dev,
955 struct device_attribute *attr, char *buf)
935{ 956{
936 struct pvr2_sysfs *sfp; 957 struct pvr2_sysfs *sfp;
937 sfp = (struct pvr2_sysfs *)class_dev->class_data; 958 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
938 if (!sfp) return -EINVAL; 959 if (!sfp) return -EINVAL;
939 return pvr2_debugifc_print_status(sfp->channel.hdw,buf,PAGE_SIZE); 960 return pvr2_debugifc_print_status(sfp->channel.hdw,buf,PAGE_SIZE);
940} 961}
941 962
942 963
943static ssize_t debugcmd_store(struct class_device *class_dev, 964static ssize_t debugcmd_store(struct device *class_dev,
944 const char *buf,size_t count) 965 struct device_attribute *attr,
966 const char *buf, size_t count)
945{ 967{
946 struct pvr2_sysfs *sfp; 968 struct pvr2_sysfs *sfp;
947 int ret; 969 int ret;
948 970
949 sfp = (struct pvr2_sysfs *)class_dev->class_data; 971 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
950 if (!sfp) return -EINVAL; 972 if (!sfp) return -EINVAL;
951 973
952 ret = pvr2_debugifc_docmd(sfp->channel.hdw,buf,count); 974 ret = pvr2_debugifc_docmd(sfp->channel.hdw,buf,count);
diff --git a/drivers/media/video/pwc/pwc-ctrl.c b/drivers/media/video/pwc/pwc-ctrl.c
index 338ced7188f2..ea53316d2111 100644
--- a/drivers/media/video/pwc/pwc-ctrl.c
+++ b/drivers/media/video/pwc/pwc-ctrl.c
@@ -1648,7 +1648,7 @@ int pwc_ioctl(struct pwc_device *pdev, unsigned int cmd, void *arg)
1648 ARG_OUT(cmd) 1648 ARG_OUT(cmd)
1649 break; 1649 break;
1650 } 1650 }
1651 /* 1651 /*
1652 case VIDIOCPWCGVIDTABLE: 1652 case VIDIOCPWCGVIDTABLE:
1653 { 1653 {
1654 ARG_DEF(struct pwc_table_init_buffer, table); 1654 ARG_DEF(struct pwc_table_init_buffer, table);
diff --git a/drivers/media/video/pwc/pwc-if.c b/drivers/media/video/pwc/pwc-if.c
index 931b274bffca..0b67d4ec0318 100644
--- a/drivers/media/video/pwc/pwc-if.c
+++ b/drivers/media/video/pwc/pwc-if.c
@@ -64,7 +64,6 @@
64#include <linux/vmalloc.h> 64#include <linux/vmalloc.h>
65#include <linux/version.h> 65#include <linux/version.h>
66#include <asm/io.h> 66#include <asm/io.h>
67#include <linux/moduleparam.h>
68 67
69#include "pwc.h" 68#include "pwc.h"
70#include "pwc-kiara.h" 69#include "pwc-kiara.h"
@@ -127,9 +126,9 @@ static struct usb_driver pwc_driver = {
127static int default_size = PSZ_QCIF; 126static int default_size = PSZ_QCIF;
128static int default_fps = 10; 127static int default_fps = 10;
129static int default_fbufs = 3; /* Default number of frame buffers */ 128static int default_fbufs = 3; /* Default number of frame buffers */
130 int pwc_mbufs = 2; /* Default number of mmap() buffers */ 129 int pwc_mbufs = 2; /* Default number of mmap() buffers */
131#ifdef CONFIG_USB_PWC_DEBUG 130#ifdef CONFIG_USB_PWC_DEBUG
132 int pwc_trace = PWC_DEBUG_LEVEL; 131 int pwc_trace = PWC_DEBUG_LEVEL;
133#endif 132#endif
134static int power_save = 0; 133static int power_save = 0;
135static int led_on = 100, led_off = 0; /* defaults to LED that is on while in use */ 134static int led_on = 100, led_off = 0; /* defaults to LED that is on while in use */
@@ -908,31 +907,49 @@ int pwc_isoc_init(struct pwc_device *pdev)
908 return 0; 907 return 0;
909} 908}
910 909
911void pwc_isoc_cleanup(struct pwc_device *pdev) 910static void pwc_iso_stop(struct pwc_device *pdev)
912{ 911{
913 int i; 912 int i;
914 913
915 PWC_DEBUG_OPEN(">> pwc_isoc_cleanup()\n");
916 if (pdev == NULL)
917 return;
918 if (pdev->iso_init == 0)
919 return;
920
921 /* Unlinking ISOC buffers one by one */ 914 /* Unlinking ISOC buffers one by one */
922 for (i = 0; i < MAX_ISO_BUFS; i++) { 915 for (i = 0; i < MAX_ISO_BUFS; i++) {
923 struct urb *urb; 916 struct urb *urb;
924 917
925 urb = pdev->sbuf[i].urb; 918 urb = pdev->sbuf[i].urb;
926 if (urb != 0) { 919 if (urb != 0) {
927 if (pdev->iso_init) { 920 PWC_DEBUG_MEMORY("Unlinking URB %p\n", urb);
928 PWC_DEBUG_MEMORY("Unlinking URB %p\n", urb); 921 usb_kill_urb(urb);
929 usb_kill_urb(urb); 922 }
930 } 923 }
924}
925
926static void pwc_iso_free(struct pwc_device *pdev)
927{
928 int i;
929
930 /* Freeing ISOC buffers one by one */
931 for (i = 0; i < MAX_ISO_BUFS; i++) {
932 struct urb *urb;
933
934 urb = pdev->sbuf[i].urb;
935 if (urb != 0) {
931 PWC_DEBUG_MEMORY("Freeing URB\n"); 936 PWC_DEBUG_MEMORY("Freeing URB\n");
932 usb_free_urb(urb); 937 usb_free_urb(urb);
933 pdev->sbuf[i].urb = NULL; 938 pdev->sbuf[i].urb = NULL;
934 } 939 }
935 } 940 }
941}
942
943void pwc_isoc_cleanup(struct pwc_device *pdev)
944{
945 PWC_DEBUG_OPEN(">> pwc_isoc_cleanup()\n");
946 if (pdev == NULL)
947 return;
948 if (pdev->iso_init == 0)
949 return;
950
951 pwc_iso_stop(pdev);
952 pwc_iso_free(pdev);
936 953
937 /* Stop camera, but only if we are sure the camera is still there (unplug 954 /* Stop camera, but only if we are sure the camera is still there (unplug
938 is signalled by EPIPE) 955 is signalled by EPIPE)
@@ -979,20 +996,22 @@ int pwc_try_video_mode(struct pwc_device *pdev, int width, int height, int new_f
979/********* 996/*********
980 * sysfs 997 * sysfs
981 *********/ 998 *********/
982static struct pwc_device *cd_to_pwc(struct class_device *cd) 999static struct pwc_device *cd_to_pwc(struct device *cd)
983{ 1000{
984 struct video_device *vdev = to_video_device(cd); 1001 struct video_device *vdev = to_video_device(cd);
985 return video_get_drvdata(vdev); 1002 return video_get_drvdata(vdev);
986} 1003}
987 1004
988static ssize_t show_pan_tilt(struct class_device *class_dev, char *buf) 1005static ssize_t show_pan_tilt(struct device *class_dev,
1006 struct device_attribute *attr, char *buf)
989{ 1007{
990 struct pwc_device *pdev = cd_to_pwc(class_dev); 1008 struct pwc_device *pdev = cd_to_pwc(class_dev);
991 return sprintf(buf, "%d %d\n", pdev->pan_angle, pdev->tilt_angle); 1009 return sprintf(buf, "%d %d\n", pdev->pan_angle, pdev->tilt_angle);
992} 1010}
993 1011
994static ssize_t store_pan_tilt(struct class_device *class_dev, const char *buf, 1012static ssize_t store_pan_tilt(struct device *class_dev,
995 size_t count) 1013 struct device_attribute *attr,
1014 const char *buf, size_t count)
996{ 1015{
997 struct pwc_device *pdev = cd_to_pwc(class_dev); 1016 struct pwc_device *pdev = cd_to_pwc(class_dev);
998 int pan, tilt; 1017 int pan, tilt;
@@ -1008,10 +1027,11 @@ static ssize_t store_pan_tilt(struct class_device *class_dev, const char *buf,
1008 return ret; 1027 return ret;
1009 return strlen(buf); 1028 return strlen(buf);
1010} 1029}
1011static CLASS_DEVICE_ATTR(pan_tilt, S_IRUGO | S_IWUSR, show_pan_tilt, 1030static DEVICE_ATTR(pan_tilt, S_IRUGO | S_IWUSR, show_pan_tilt,
1012 store_pan_tilt); 1031 store_pan_tilt);
1013 1032
1014static ssize_t show_snapshot_button_status(struct class_device *class_dev, char *buf) 1033static ssize_t show_snapshot_button_status(struct device *class_dev,
1034 struct device_attribute *attr, char *buf)
1015{ 1035{
1016 struct pwc_device *pdev = cd_to_pwc(class_dev); 1036 struct pwc_device *pdev = cd_to_pwc(class_dev);
1017 int status = pdev->snapshot_button_status; 1037 int status = pdev->snapshot_button_status;
@@ -1019,26 +1039,26 @@ static ssize_t show_snapshot_button_status(struct class_device *class_dev, char
1019 return sprintf(buf, "%d\n", status); 1039 return sprintf(buf, "%d\n", status);
1020} 1040}
1021 1041
1022static CLASS_DEVICE_ATTR(button, S_IRUGO | S_IWUSR, show_snapshot_button_status, 1042static DEVICE_ATTR(button, S_IRUGO | S_IWUSR, show_snapshot_button_status,
1023 NULL); 1043 NULL);
1024 1044
1025static int pwc_create_sysfs_files(struct video_device *vdev) 1045static int pwc_create_sysfs_files(struct video_device *vdev)
1026{ 1046{
1027 struct pwc_device *pdev = video_get_drvdata(vdev); 1047 struct pwc_device *pdev = video_get_drvdata(vdev);
1028 int rc; 1048 int rc;
1029 1049
1030 rc = video_device_create_file(vdev, &class_device_attr_button); 1050 rc = video_device_create_file(vdev, &dev_attr_button);
1031 if (rc) 1051 if (rc)
1032 goto err; 1052 goto err;
1033 if (pdev->features & FEATURE_MOTOR_PANTILT) { 1053 if (pdev->features & FEATURE_MOTOR_PANTILT) {
1034 rc = video_device_create_file(vdev,&class_device_attr_pan_tilt); 1054 rc = video_device_create_file(vdev, &dev_attr_pan_tilt);
1035 if (rc) goto err_button; 1055 if (rc) goto err_button;
1036 } 1056 }
1037 1057
1038 return 0; 1058 return 0;
1039 1059
1040err_button: 1060err_button:
1041 video_device_remove_file(vdev, &class_device_attr_button); 1061 video_device_remove_file(vdev, &dev_attr_button);
1042err: 1062err:
1043 return rc; 1063 return rc;
1044} 1064}
@@ -1047,8 +1067,8 @@ static void pwc_remove_sysfs_files(struct video_device *vdev)
1047{ 1067{
1048 struct pwc_device *pdev = video_get_drvdata(vdev); 1068 struct pwc_device *pdev = video_get_drvdata(vdev);
1049 if (pdev->features & FEATURE_MOTOR_PANTILT) 1069 if (pdev->features & FEATURE_MOTOR_PANTILT)
1050 video_device_remove_file(vdev, &class_device_attr_pan_tilt); 1070 video_device_remove_file(vdev, &dev_attr_pan_tilt);
1051 video_device_remove_file(vdev, &class_device_attr_button); 1071 video_device_remove_file(vdev, &dev_attr_button);
1052} 1072}
1053 1073
1054#ifdef CONFIG_USB_PWC_DEBUG 1074#ifdef CONFIG_USB_PWC_DEBUG
@@ -1212,6 +1232,7 @@ static int pwc_video_close(struct inode *inode, struct file *file)
1212 1232
1213 PWC_DEBUG_OPEN(">> video_close called(vdev = 0x%p).\n", vdev); 1233 PWC_DEBUG_OPEN(">> video_close called(vdev = 0x%p).\n", vdev);
1214 1234
1235 lock_kernel();
1215 pdev = (struct pwc_device *)vdev->priv; 1236 pdev = (struct pwc_device *)vdev->priv;
1216 if (pdev->vopen == 0) 1237 if (pdev->vopen == 0)
1217 PWC_DEBUG_MODULE("video_close() called on closed device?\n"); 1238 PWC_DEBUG_MODULE("video_close() called on closed device?\n");
@@ -1231,7 +1252,6 @@ static int pwc_video_close(struct inode *inode, struct file *file)
1231 pwc_isoc_cleanup(pdev); 1252 pwc_isoc_cleanup(pdev);
1232 pwc_free_buffers(pdev); 1253 pwc_free_buffers(pdev);
1233 1254
1234 lock_kernel();
1235 /* Turn off LEDS and power down camera, but only when not unplugged */ 1255 /* Turn off LEDS and power down camera, but only when not unplugged */
1236 if (!pdev->unplugged) { 1256 if (!pdev->unplugged) {
1237 /* Turn LEDs off */ 1257 /* Turn LEDs off */
@@ -1277,7 +1297,7 @@ static ssize_t pwc_video_read(struct file *file, char __user *buf,
1277 struct pwc_device *pdev; 1297 struct pwc_device *pdev;
1278 int noblock = file->f_flags & O_NONBLOCK; 1298 int noblock = file->f_flags & O_NONBLOCK;
1279 DECLARE_WAITQUEUE(wait, current); 1299 DECLARE_WAITQUEUE(wait, current);
1280 int bytes_to_read; 1300 int bytes_to_read, rv = 0;
1281 void *image_buffer_addr; 1301 void *image_buffer_addr;
1282 1302
1283 PWC_DEBUG_READ("pwc_video_read(vdev=0x%p, buf=%p, count=%zd) called.\n", 1303 PWC_DEBUG_READ("pwc_video_read(vdev=0x%p, buf=%p, count=%zd) called.\n",
@@ -1287,8 +1307,12 @@ static ssize_t pwc_video_read(struct file *file, char __user *buf,
1287 pdev = vdev->priv; 1307 pdev = vdev->priv;
1288 if (pdev == NULL) 1308 if (pdev == NULL)
1289 return -EFAULT; 1309 return -EFAULT;
1290 if (pdev->error_status) 1310
1291 return -pdev->error_status; /* Something happened, report what. */ 1311 mutex_lock(&pdev->modlock);
1312 if (pdev->error_status) {
1313 rv = -pdev->error_status; /* Something happened, report what. */
1314 goto err_out;
1315 }
1292 1316
1293 /* In case we're doing partial reads, we don't have to wait for a frame */ 1317 /* In case we're doing partial reads, we don't have to wait for a frame */
1294 if (pdev->image_read_pos == 0) { 1318 if (pdev->image_read_pos == 0) {
@@ -1299,17 +1323,20 @@ static ssize_t pwc_video_read(struct file *file, char __user *buf,
1299 if (pdev->error_status) { 1323 if (pdev->error_status) {
1300 remove_wait_queue(&pdev->frameq, &wait); 1324 remove_wait_queue(&pdev->frameq, &wait);
1301 set_current_state(TASK_RUNNING); 1325 set_current_state(TASK_RUNNING);
1302 return -pdev->error_status ; 1326 rv = -pdev->error_status ;
1327 goto err_out;
1303 } 1328 }
1304 if (noblock) { 1329 if (noblock) {
1305 remove_wait_queue(&pdev->frameq, &wait); 1330 remove_wait_queue(&pdev->frameq, &wait);
1306 set_current_state(TASK_RUNNING); 1331 set_current_state(TASK_RUNNING);
1307 return -EWOULDBLOCK; 1332 rv = -EWOULDBLOCK;
1333 goto err_out;
1308 } 1334 }
1309 if (signal_pending(current)) { 1335 if (signal_pending(current)) {
1310 remove_wait_queue(&pdev->frameq, &wait); 1336 remove_wait_queue(&pdev->frameq, &wait);
1311 set_current_state(TASK_RUNNING); 1337 set_current_state(TASK_RUNNING);
1312 return -ERESTARTSYS; 1338 rv = -ERESTARTSYS;
1339 goto err_out;
1313 } 1340 }
1314 schedule(); 1341 schedule();
1315 set_current_state(TASK_INTERRUPTIBLE); 1342 set_current_state(TASK_INTERRUPTIBLE);
@@ -1318,8 +1345,10 @@ static ssize_t pwc_video_read(struct file *file, char __user *buf,
1318 set_current_state(TASK_RUNNING); 1345 set_current_state(TASK_RUNNING);
1319 1346
1320 /* Decompress and release frame */ 1347 /* Decompress and release frame */
1321 if (pwc_handle_frame(pdev)) 1348 if (pwc_handle_frame(pdev)) {
1322 return -EFAULT; 1349 rv = -EFAULT;
1350 goto err_out;
1351 }
1323 } 1352 }
1324 1353
1325 PWC_DEBUG_READ("Copying data to user space.\n"); 1354 PWC_DEBUG_READ("Copying data to user space.\n");
@@ -1334,14 +1363,20 @@ static ssize_t pwc_video_read(struct file *file, char __user *buf,
1334 image_buffer_addr = pdev->image_data; 1363 image_buffer_addr = pdev->image_data;
1335 image_buffer_addr += pdev->images[pdev->fill_image].offset; 1364 image_buffer_addr += pdev->images[pdev->fill_image].offset;
1336 image_buffer_addr += pdev->image_read_pos; 1365 image_buffer_addr += pdev->image_read_pos;
1337 if (copy_to_user(buf, image_buffer_addr, count)) 1366 if (copy_to_user(buf, image_buffer_addr, count)) {
1338 return -EFAULT; 1367 rv = -EFAULT;
1368 goto err_out;
1369 }
1339 pdev->image_read_pos += count; 1370 pdev->image_read_pos += count;
1340 if (pdev->image_read_pos >= bytes_to_read) { /* All data has been read */ 1371 if (pdev->image_read_pos >= bytes_to_read) { /* All data has been read */
1341 pdev->image_read_pos = 0; 1372 pdev->image_read_pos = 0;
1342 pwc_next_image(pdev); 1373 pwc_next_image(pdev);
1343 } 1374 }
1375 mutex_unlock(&pdev->modlock);
1344 return count; 1376 return count;
1377err_out:
1378 mutex_unlock(&pdev->modlock);
1379 return rv;
1345} 1380}
1346 1381
1347static unsigned int pwc_video_poll(struct file *file, poll_table *wait) 1382static unsigned int pwc_video_poll(struct file *file, poll_table *wait)
@@ -1367,7 +1402,20 @@ static unsigned int pwc_video_poll(struct file *file, poll_table *wait)
1367static int pwc_video_ioctl(struct inode *inode, struct file *file, 1402static int pwc_video_ioctl(struct inode *inode, struct file *file,
1368 unsigned int cmd, unsigned long arg) 1403 unsigned int cmd, unsigned long arg)
1369{ 1404{
1370 return video_usercopy(inode, file, cmd, arg, pwc_video_do_ioctl); 1405 struct video_device *vdev = file->private_data;
1406 struct pwc_device *pdev;
1407 int r = -ENODEV;
1408
1409 if (!vdev)
1410 goto out;
1411 pdev = vdev->priv;
1412
1413 mutex_lock(&pdev->modlock);
1414 if (!pdev->unplugged)
1415 r = video_usercopy(inode, file, cmd, arg, pwc_video_do_ioctl);
1416 mutex_unlock(&pdev->modlock);
1417out:
1418 return r;
1371} 1419}
1372 1420
1373static int pwc_video_mmap(struct file *file, struct vm_area_struct *vma) 1421static int pwc_video_mmap(struct file *file, struct vm_area_struct *vma)
@@ -1810,7 +1858,10 @@ static void usb_pwc_disconnect(struct usb_interface *intf)
1810 wake_up_interruptible(&pdev->frameq); 1858 wake_up_interruptible(&pdev->frameq);
1811 /* Wait until device is closed */ 1859 /* Wait until device is closed */
1812 if(pdev->vopen) { 1860 if(pdev->vopen) {
1861 mutex_lock(&pdev->modlock);
1813 pdev->unplugged = 1; 1862 pdev->unplugged = 1;
1863 mutex_unlock(&pdev->modlock);
1864 pwc_iso_stop(pdev);
1814 } else { 1865 } else {
1815 /* Device is closed, so we can safely unregister it */ 1866 /* Device is closed, so we can safely unregister it */
1816 PWC_DEBUG_PROBE("Unregistering video device in disconnect().\n"); 1867 PWC_DEBUG_PROBE("Unregistering video device in disconnect().\n");
@@ -1828,7 +1879,6 @@ disconnect_out:
1828 unlock_kernel(); 1879 unlock_kernel();
1829} 1880}
1830 1881
1831
1832/* *grunt* We have to do atoi ourselves :-( */ 1882/* *grunt* We have to do atoi ourselves :-( */
1833static int pwc_atoi(const char *s) 1883static int pwc_atoi(const char *s)
1834{ 1884{
diff --git a/drivers/media/video/saa6588.c b/drivers/media/video/saa6588.c
index 92eabf88a09b..72e344a12c79 100644
--- a/drivers/media/video/saa6588.c
+++ b/drivers/media/video/saa6588.c
@@ -406,6 +406,7 @@ static int saa6588_attach(struct i2c_adapter *adap, int addr, int kind)
406 kfree(s); 406 kfree(s);
407 return -ENOMEM; 407 return -ENOMEM;
408 } 408 }
409 spin_lock_init(&s->lock);
409 s->client = client_template; 410 s->client = client_template;
410 s->block_count = 0; 411 s->block_count = 0;
411 s->wr_index = 0; 412 s->wr_index = 0;
diff --git a/drivers/media/video/saa7127.c b/drivers/media/video/saa7127.c
index 9f986930490f..e35ef321ec71 100644
--- a/drivers/media/video/saa7127.c
+++ b/drivers/media/video/saa7127.c
@@ -332,11 +332,11 @@ static int saa7127_set_vps(struct i2c_client *client, struct v4l2_sliced_vbi_dat
332 if (!enable) 332 if (!enable)
333 return 0; 333 return 0;
334 334
335 state->vps_data[0] = data->data[4]; 335 state->vps_data[0] = data->data[2];
336 state->vps_data[1] = data->data[10]; 336 state->vps_data[1] = data->data[8];
337 state->vps_data[2] = data->data[11]; 337 state->vps_data[2] = data->data[9];
338 state->vps_data[3] = data->data[12]; 338 state->vps_data[3] = data->data[10];
339 state->vps_data[4] = data->data[13]; 339 state->vps_data[4] = data->data[11];
340 v4l_dbg(1, debug, client, "Set VPS data %02x %02x %02x %02x %02x\n", 340 v4l_dbg(1, debug, client, "Set VPS data %02x %02x %02x %02x %02x\n",
341 state->vps_data[0], state->vps_data[1], 341 state->vps_data[0], state->vps_data[1],
342 state->vps_data[2], state->vps_data[3], 342 state->vps_data[2], state->vps_data[3],
diff --git a/drivers/media/video/saa7134/Kconfig b/drivers/media/video/saa7134/Kconfig
index 9f1417a4f7d2..d6d8d660196d 100644
--- a/drivers/media/video/saa7134/Kconfig
+++ b/drivers/media/video/saa7134/Kconfig
@@ -1,7 +1,7 @@
1config VIDEO_SAA7134 1config VIDEO_SAA7134
2 tristate "Philips SAA7134 support" 2 tristate "Philips SAA7134 support"
3 depends on VIDEO_DEV && PCI && I2C 3 depends on VIDEO_DEV && PCI && I2C
4 select VIDEO_BUF 4 select VIDEOBUF_DMA_SG
5 select VIDEO_IR 5 select VIDEO_IR
6 select VIDEO_TUNER 6 select VIDEO_TUNER
7 select CRC32 7 select CRC32
@@ -38,7 +38,7 @@ config VIDEO_SAA7134_OSS
38config VIDEO_SAA7134_DVB 38config VIDEO_SAA7134_DVB
39 tristate "DVB/ATSC Support for saa7134 based TV cards" 39 tristate "DVB/ATSC Support for saa7134 based TV cards"
40 depends on VIDEO_SAA7134 && DVB_CORE 40 depends on VIDEO_SAA7134 && DVB_CORE
41 select VIDEO_BUF_DVB 41 select VIDEOBUF_DVB
42 select FW_LOADER 42 select FW_LOADER
43 select DVB_PLL if !DVB_FE_CUSTOMISE 43 select DVB_PLL if !DVB_FE_CUSTOMISE
44 select DVB_MT352 if !DVB_FE_CUSTOMISE 44 select DVB_MT352 if !DVB_FE_CUSTOMISE
diff --git a/drivers/media/video/saa7134/saa7134-alsa.c b/drivers/media/video/saa7134/saa7134-alsa.c
index 3c0fc9027ad0..c6f7279669c1 100644
--- a/drivers/media/video/saa7134/saa7134-alsa.c
+++ b/drivers/media/video/saa7134/saa7134-alsa.c
@@ -20,7 +20,6 @@
20#include <linux/slab.h> 20#include <linux/slab.h>
21#include <linux/time.h> 21#include <linux/time.h>
22#include <linux/wait.h> 22#include <linux/wait.h>
23#include <linux/moduleparam.h>
24#include <linux/module.h> 23#include <linux/module.h>
25#include <sound/driver.h> 24#include <sound/driver.h>
26#include <sound/core.h> 25#include <sound/core.h>
@@ -313,7 +312,7 @@ static int dsp_buffer_free(struct saa7134_dev *dev)
313 dev->dmasound.blksize = 0; 312 dev->dmasound.blksize = 0;
314 dev->dmasound.bufsize = 0; 313 dev->dmasound.bufsize = 0;
315 314
316 return 0; 315 return 0;
317} 316}
318 317
319 318
diff --git a/drivers/media/video/saa7134/saa7134-cards.c b/drivers/media/video/saa7134/saa7134-cards.c
index 25ec16810818..a4c192fb4e41 100644
--- a/drivers/media/video/saa7134/saa7134-cards.c
+++ b/drivers/media/video/saa7134/saa7134-cards.c
@@ -32,6 +32,7 @@ static char name_mute[] = "mute";
32static char name_radio[] = "Radio"; 32static char name_radio[] = "Radio";
33static char name_tv[] = "Television"; 33static char name_tv[] = "Television";
34static char name_tv_mono[] = "TV (mono only)"; 34static char name_tv_mono[] = "TV (mono only)";
35static char name_comp[] = "Composite";
35static char name_comp1[] = "Composite1"; 36static char name_comp1[] = "Composite1";
36static char name_comp2[] = "Composite2"; 37static char name_comp2[] = "Composite2";
37static char name_comp3[] = "Composite3"; 38static char name_comp3[] = "Composite3";
@@ -1535,12 +1536,7 @@ struct saa7134_board saa7134_boards[] = {
1535 .tv = 1, 1536 .tv = 1,
1536 .gpio = 0x00, 1537 .gpio = 0x00,
1537 },{ 1538 },{
1538 .name = name_comp1, 1539 .name = name_comp,
1539 .vmux = 0,
1540 .amux = LINE1,
1541 .gpio = 0x02,
1542 },{
1543 .name = name_comp2,
1544 .vmux = 3, 1540 .vmux = 3,
1545 .amux = LINE1, 1541 .amux = LINE1,
1546 .gpio = 0x02, 1542 .gpio = 0x02,
@@ -2771,6 +2767,7 @@ struct saa7134_board saa7134_boards[] = {
2771 .tuner_addr = ADDR_UNSET, 2767 .tuner_addr = ADDR_UNSET,
2772 .radio_addr = ADDR_UNSET, 2768 .radio_addr = ADDR_UNSET,
2773 .mpeg = SAA7134_MPEG_DVB, 2769 .mpeg = SAA7134_MPEG_DVB,
2770 .gpiomask = 1 << 21,
2774 .inputs = {{ 2771 .inputs = {{
2775 .name = name_tv, 2772 .name = name_tv,
2776 .vmux = 1, 2773 .vmux = 1,
@@ -2781,13 +2778,18 @@ struct saa7134_board saa7134_boards[] = {
2781 .vmux = 3, 2778 .vmux = 3,
2782 .amux = LINE1, 2779 .amux = LINE1,
2783 },{ 2780 },{
2784 .name = name_svideo, 2781 .name = name_comp2,
2785 .vmux = 0, 2782 .vmux = 0,
2786 .amux = LINE1, 2783 .amux = LINE1,
2784 },{
2785 .name = name_svideo,
2786 .vmux = 8,
2787 .amux = LINE1,
2787 }}, 2788 }},
2788 .radio = { 2789 .radio = {
2789 .name = name_radio, 2790 .name = name_radio,
2790 .amux = LINE1, 2791 .amux = TV,
2792 .gpio = 0x0200000,
2791 }, 2793 },
2792 }, 2794 },
2793 [SAA7134_BOARD_KWORLD_DVBT_210] = { 2795 [SAA7134_BOARD_KWORLD_DVBT_210] = {
@@ -2820,7 +2822,7 @@ struct saa7134_board saa7134_boards[] = {
2820 }, 2822 },
2821 }, 2823 },
2822 [SAA7134_BOARD_KWORLD_ATSC110] = { 2824 [SAA7134_BOARD_KWORLD_ATSC110] = {
2823 .name = "Kworld ATSC110", 2825 .name = "Kworld ATSC110/115",
2824 .audio_clock = 0x00187de7, 2826 .audio_clock = 0x00187de7,
2825 .tuner_type = TUNER_PHILIPS_TUV1236D, 2827 .tuner_type = TUNER_PHILIPS_TUV1236D,
2826 .radio_type = UNSET, 2828 .radio_type = UNSET,
@@ -2896,7 +2898,7 @@ struct saa7134_board saa7134_boards[] = {
2896 .radio_addr = ADDR_UNSET, 2898 .radio_addr = ADDR_UNSET,
2897 }, 2899 },
2898 [SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS] = { 2900 [SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS] = {
2899 .name = "LifeView FlyDVB-T Hybrid Cardbus", 2901 .name = "LifeView FlyDVB-T Hybrid Cardbus/MSI TV @nywhere A/D NB",
2900 .audio_clock = 0x00200000, 2902 .audio_clock = 0x00200000,
2901 .tuner_type = TUNER_PHILIPS_TDA8290, 2903 .tuner_type = TUNER_PHILIPS_TDA8290,
2902 .radio_type = UNSET, 2904 .radio_type = UNSET,
@@ -3534,6 +3536,22 @@ struct saa7134_board saa7134_boards[] = {
3534 .gpio = 0x3000, 3536 .gpio = 0x3000,
3535 }, 3537 },
3536 }, 3538 },
3539 [SAA7134_BOARD_AVERMEDIA_SUPER_007] = {
3540 .name = "Avermedia Super 007",
3541 .audio_clock = 0x00187de7,
3542 .tuner_type = TUNER_PHILIPS_TDA8290,
3543 .radio_type = UNSET,
3544 .tuner_addr = ADDR_UNSET,
3545 .radio_addr = ADDR_UNSET,
3546 .tuner_config = 0,
3547 .mpeg = SAA7134_MPEG_DVB,
3548 .inputs = {{
3549 .name = name_tv, /* FIXME: analog tv untested */
3550 .vmux = 1,
3551 .amux = TV,
3552 .tv = 1,
3553 }},
3554 },
3537}; 3555};
3538 3556
3539const unsigned int saa7134_bcount = ARRAY_SIZE(saa7134_boards); 3557const unsigned int saa7134_bcount = ARRAY_SIZE(saa7134_boards);
@@ -4066,6 +4084,12 @@ struct pci_device_id saa7134_pci_tbl[] = {
4066 .driver_data = SAA7134_BOARD_KWORLD_ATSC110, 4084 .driver_data = SAA7134_BOARD_KWORLD_ATSC110,
4067 },{ 4085 },{
4068 .vendor = PCI_VENDOR_ID_PHILIPS, 4086 .vendor = PCI_VENDOR_ID_PHILIPS,
4087 .device = PCI_DEVICE_ID_PHILIPS_SAA7133, /* SAA7135HL */
4088 .subvendor = 0x17de,
4089 .subdevice = 0x7352,
4090 .driver_data = SAA7134_BOARD_KWORLD_ATSC110, /* ATSC 115 */
4091 },{
4092 .vendor = PCI_VENDOR_ID_PHILIPS,
4069 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 4093 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
4070 .subvendor = 0x1461, 4094 .subvendor = 0x1461,
4071 .subdevice = 0x7360, 4095 .subdevice = 0x7360,
@@ -4257,6 +4281,18 @@ struct pci_device_id saa7134_pci_tbl[] = {
4257 .subdevice = 0x2304, 4281 .subdevice = 0x2304,
4258 .driver_data = SAA7134_BOARD_10MOONSTVMASTER3, 4282 .driver_data = SAA7134_BOARD_10MOONSTVMASTER3,
4259 },{ 4283 },{
4284 .vendor = PCI_VENDOR_ID_PHILIPS,
4285 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
4286 .subvendor = 0x1461, /* Avermedia Technologies Inc */
4287 .subdevice = 0xf01d, /* AVerTV DVB-T Super 007 */
4288 .driver_data = SAA7134_BOARD_AVERMEDIA_SUPER_007,
4289 },{
4290 .vendor = PCI_VENDOR_ID_PHILIPS,
4291 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
4292 .subvendor = 0x4e42,
4293 .subdevice = 0x3502,
4294 .driver_data = SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS
4295 },{
4260 /* --- boards without eeprom + subsystem ID --- */ 4296 /* --- boards without eeprom + subsystem ID --- */
4261 .vendor = PCI_VENDOR_ID_PHILIPS, 4297 .vendor = PCI_VENDOR_ID_PHILIPS,
4262 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 4298 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
@@ -4564,6 +4600,7 @@ int saa7134_board_init2(struct saa7134_dev *dev)
4564 break; 4600 break;
4565 case SAA7134_BOARD_PHILIPS_TIGER: 4601 case SAA7134_BOARD_PHILIPS_TIGER:
4566 case SAA7134_BOARD_PHILIPS_TIGER_S: 4602 case SAA7134_BOARD_PHILIPS_TIGER_S:
4603 case SAA7134_BOARD_AVERMEDIA_SUPER_007:
4567 { 4604 {
4568 u8 data[] = { 0x3c, 0x33, 0x60}; 4605 u8 data[] = { 0x3c, 0x33, 0x60};
4569 struct i2c_msg msg = {.addr=0x08, .flags=0, .buf=data, .len = sizeof(data)}; 4606 struct i2c_msg msg = {.addr=0x08, .flags=0, .buf=data, .len = sizeof(data)};
diff --git a/drivers/media/video/saa7134/saa7134-core.c b/drivers/media/video/saa7134/saa7134-core.c
index 25f84701a8e8..1a4a24471f20 100644
--- a/drivers/media/video/saa7134/saa7134-core.c
+++ b/drivers/media/video/saa7134/saa7134-core.c
@@ -23,7 +23,6 @@
23#include <linux/init.h> 23#include <linux/init.h>
24#include <linux/list.h> 24#include <linux/list.h>
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/moduleparam.h>
27#include <linux/kernel.h> 26#include <linux/kernel.h>
28#include <linux/slab.h> 27#include <linux/slab.h>
29#include <linux/kmod.h> 28#include <linux/kmod.h>
@@ -32,6 +31,7 @@
32#include <linux/delay.h> 31#include <linux/delay.h>
33#include <linux/mutex.h> 32#include <linux/mutex.h>
34#include <linux/dma-mapping.h> 33#include <linux/dma-mapping.h>
34#include <linux/pm.h>
35 35
36#include "saa7134-reg.h" 36#include "saa7134-reg.h"
37#include "saa7134.h" 37#include "saa7134.h"
@@ -237,9 +237,10 @@ int saa7134_buffer_startpage(struct saa7134_buf *buf)
237unsigned long saa7134_buffer_base(struct saa7134_buf *buf) 237unsigned long saa7134_buffer_base(struct saa7134_buf *buf)
238{ 238{
239 unsigned long base; 239 unsigned long base;
240 struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb);
240 241
241 base = saa7134_buffer_startpage(buf) * 4096; 242 base = saa7134_buffer_startpage(buf) * 4096;
242 base += buf->vb.dma.sglist[0].offset; 243 base += dma->sglist[0].offset;
243 return base; 244 return base;
244} 245}
245 246
@@ -287,11 +288,12 @@ void saa7134_pgtable_free(struct pci_dev *pci, struct saa7134_pgtable *pt)
287 288
288void saa7134_dma_free(struct videobuf_queue *q,struct saa7134_buf *buf) 289void saa7134_dma_free(struct videobuf_queue *q,struct saa7134_buf *buf)
289{ 290{
291 struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb);
290 BUG_ON(in_interrupt()); 292 BUG_ON(in_interrupt());
291 293
292 videobuf_waiton(&buf->vb,0,0); 294 videobuf_waiton(&buf->vb,0,0);
293 videobuf_dma_unmap(q, &buf->vb.dma); 295 videobuf_dma_unmap(q, dma);
294 videobuf_dma_free(&buf->vb.dma); 296 videobuf_dma_free(dma);
295 buf->vb.state = STATE_NEEDS_INIT; 297 buf->vb.state = STATE_NEEDS_INIT;
296} 298}
297 299
@@ -391,6 +393,32 @@ void saa7134_buffer_timeout(unsigned long data)
391 spin_unlock_irqrestore(&dev->slock,flags); 393 spin_unlock_irqrestore(&dev->slock,flags);
392} 394}
393 395
396/* resends a current buffer in queue after resume */
397
398int saa7134_buffer_requeue(struct saa7134_dev *dev,
399 struct saa7134_dmaqueue *q)
400{
401 struct saa7134_buf *buf, *next;
402
403 assert_spin_locked(&dev->slock);
404
405 buf = q->curr;
406 next = buf;
407 dprintk("buffer_requeue\n");
408
409 if (!buf)
410 return 0;
411
412 dprintk("buffer_requeue : resending active buffers \n");
413
414 if (!list_empty(&q->queue))
415 next = list_entry(q->queue.next, struct saa7134_buf,
416 vb.queue);
417 buf->activate(dev, buf, next);
418
419 return 0;
420}
421
394/* ------------------------------------------------------------------ */ 422/* ------------------------------------------------------------------ */
395 423
396int saa7134_set_dmabits(struct saa7134_dev *dev) 424int saa7134_set_dmabits(struct saa7134_dev *dev)
@@ -401,6 +429,9 @@ int saa7134_set_dmabits(struct saa7134_dev *dev)
401 429
402 assert_spin_locked(&dev->slock); 430 assert_spin_locked(&dev->slock);
403 431
432 if (dev->inresume)
433 return 0;
434
404 /* video capture -- dma 0 + video task A */ 435 /* video capture -- dma 0 + video task A */
405 if (dev->video_q.curr) { 436 if (dev->video_q.curr) {
406 task |= 0x01; 437 task |= 0x01;
@@ -560,8 +591,10 @@ static irqreturn_t saa7134_irq(int irq, void *dev_id)
560 print_irqstatus(dev,loop,report,status); 591 print_irqstatus(dev,loop,report,status);
561 592
562 593
563 if (report & SAA7134_IRQ_REPORT_RDCAP /* _INTL */) 594 if ((report & SAA7134_IRQ_REPORT_RDCAP) ||
564 saa7134_irq_video_intl(dev); 595 (report & SAA7134_IRQ_REPORT_INTL))
596 saa7134_irq_video_signalchange(dev);
597
565 598
566 if ((report & SAA7134_IRQ_REPORT_DONE_RA0) && 599 if ((report & SAA7134_IRQ_REPORT_DONE_RA0) &&
567 (status & 0x60) == 0) 600 (status & 0x60) == 0)
@@ -646,6 +679,39 @@ static irqreturn_t saa7134_irq(int irq, void *dev_id)
646/* ------------------------------------------------------------------ */ 679/* ------------------------------------------------------------------ */
647 680
648/* early init (no i2c, no irq) */ 681/* early init (no i2c, no irq) */
682
683static int saa7134_hw_enable1(struct saa7134_dev *dev)
684{
685 /* RAM FIFO config */
686 saa_writel(SAA7134_FIFO_SIZE, 0x08070503);
687 saa_writel(SAA7134_THRESHOULD, 0x02020202);
688
689 /* enable audio + video processing */
690 saa_writel(SAA7134_MAIN_CTRL,
691 SAA7134_MAIN_CTRL_VPLLE |
692 SAA7134_MAIN_CTRL_APLLE |
693 SAA7134_MAIN_CTRL_EXOSC |
694 SAA7134_MAIN_CTRL_EVFE1 |
695 SAA7134_MAIN_CTRL_EVFE2 |
696 SAA7134_MAIN_CTRL_ESFE |
697 SAA7134_MAIN_CTRL_EBDAC);
698
699 /*
700 * Initialize OSS _after_ enabling audio clock PLL and audio processing.
701 * OSS initialization writes to registers via the audio DSP; these
702 * writes will fail unless the audio clock has been started. At worst,
703 * audio will not work.
704 */
705
706 /* enable peripheral devices */
707 saa_writeb(SAA7134_SPECIAL_MODE, 0x01);
708
709 /* set vertical line numbering start (vbi needs this) */
710 saa_writeb(SAA7134_SOURCE_TIMING2, 0x20);
711
712 return 0;
713}
714
649static int saa7134_hwinit1(struct saa7134_dev *dev) 715static int saa7134_hwinit1(struct saa7134_dev *dev)
650{ 716{
651 dprintk("hwinit1\n"); 717 dprintk("hwinit1\n");
@@ -662,44 +728,16 @@ static int saa7134_hwinit1(struct saa7134_dev *dev)
662 saa7134_ts_init1(dev); 728 saa7134_ts_init1(dev);
663 saa7134_input_init1(dev); 729 saa7134_input_init1(dev);
664 730
665 /* RAM FIFO config */ 731 saa7134_hw_enable1(dev);
666 saa_writel(SAA7134_FIFO_SIZE, 0x08070503);
667 saa_writel(SAA7134_THRESHOULD,0x02020202);
668
669 /* enable audio + video processing */
670 saa_writel(SAA7134_MAIN_CTRL,
671 SAA7134_MAIN_CTRL_VPLLE |
672 SAA7134_MAIN_CTRL_APLLE |
673 SAA7134_MAIN_CTRL_EXOSC |
674 SAA7134_MAIN_CTRL_EVFE1 |
675 SAA7134_MAIN_CTRL_EVFE2 |
676 SAA7134_MAIN_CTRL_ESFE |
677 SAA7134_MAIN_CTRL_EBDAC);
678
679 /*
680 * Initialize OSS _after_ enabling audio clock PLL and audio processing.
681 * OSS initialization writes to registers via the audio DSP; these
682 * writes will fail unless the audio clock has been started. At worst,
683 * audio will not work.
684 */
685
686 /* enable peripheral devices */
687 saa_writeb(SAA7134_SPECIAL_MODE, 0x01);
688
689 /* set vertical line numbering start (vbi needs this) */
690 saa_writeb(SAA7134_SOURCE_TIMING2, 0x20);
691 732
692 return 0; 733 return 0;
693} 734}
694 735
695/* late init (with i2c + irq) */ 736/* late init (with i2c + irq) */
696static int saa7134_hwinit2(struct saa7134_dev *dev) 737static int saa7134_hw_enable2(struct saa7134_dev *dev)
697{ 738{
698 unsigned int irq2_mask;
699 dprintk("hwinit2\n");
700 739
701 saa7134_video_init2(dev); 740 unsigned int irq2_mask;
702 saa7134_tvaudio_init2(dev);
703 741
704 /* enable IRQ's */ 742 /* enable IRQ's */
705 irq2_mask = 743 irq2_mask =
@@ -725,6 +763,20 @@ static int saa7134_hwinit2(struct saa7134_dev *dev)
725 return 0; 763 return 0;
726} 764}
727 765
766static int saa7134_hwinit2(struct saa7134_dev *dev)
767{
768
769 dprintk("hwinit2\n");
770
771 saa7134_video_init2(dev);
772 saa7134_tvaudio_init2(dev);
773
774 saa7134_hw_enable2(dev);
775
776 return 0;
777}
778
779
728/* shutdown */ 780/* shutdown */
729static int saa7134_hwfini(struct saa7134_dev *dev) 781static int saa7134_hwfini(struct saa7134_dev *dev)
730{ 782{
@@ -838,7 +890,6 @@ static int __devinit saa7134_initdev(struct pci_dev *pci_dev,
838 const struct pci_device_id *pci_id) 890 const struct pci_device_id *pci_id)
839{ 891{
840 struct saa7134_dev *dev; 892 struct saa7134_dev *dev;
841 struct list_head *item;
842 struct saa7134_mpeg_ops *mops; 893 struct saa7134_mpeg_ops *mops;
843 int err; 894 int err;
844 895
@@ -1020,15 +1071,13 @@ static int __devinit saa7134_initdev(struct pci_dev *pci_dev,
1020 saa7134_devcount++; 1071 saa7134_devcount++;
1021 1072
1022 mutex_lock(&devlist_lock); 1073 mutex_lock(&devlist_lock);
1023 list_for_each(item,&mops_list) { 1074 list_for_each_entry(mops, &mops_list, next)
1024 mops = list_entry(item, struct saa7134_mpeg_ops, next);
1025 mpeg_ops_attach(mops, dev); 1075 mpeg_ops_attach(mops, dev);
1026 }
1027 list_add_tail(&dev->devlist,&saa7134_devlist); 1076 list_add_tail(&dev->devlist,&saa7134_devlist);
1028 mutex_unlock(&devlist_lock); 1077 mutex_unlock(&devlist_lock);
1029 1078
1030 /* check for signal */ 1079 /* check for signal */
1031 saa7134_irq_video_intl(dev); 1080 saa7134_irq_video_signalchange(dev);
1032 1081
1033 if (saa7134_dmasound_init && !dev->dmasound.priv_data) { 1082 if (saa7134_dmasound_init && !dev->dmasound.priv_data) {
1034 saa7134_dmasound_init(dev); 1083 saa7134_dmasound_init(dev);
@@ -1057,7 +1106,6 @@ static int __devinit saa7134_initdev(struct pci_dev *pci_dev,
1057static void __devexit saa7134_finidev(struct pci_dev *pci_dev) 1106static void __devexit saa7134_finidev(struct pci_dev *pci_dev)
1058{ 1107{
1059 struct saa7134_dev *dev = pci_get_drvdata(pci_dev); 1108 struct saa7134_dev *dev = pci_get_drvdata(pci_dev);
1060 struct list_head *item;
1061 struct saa7134_mpeg_ops *mops; 1109 struct saa7134_mpeg_ops *mops;
1062 1110
1063 /* Release DMA sound modules if present */ 1111 /* Release DMA sound modules if present */
@@ -1086,10 +1134,8 @@ static void __devexit saa7134_finidev(struct pci_dev *pci_dev)
1086 /* unregister */ 1134 /* unregister */
1087 mutex_lock(&devlist_lock); 1135 mutex_lock(&devlist_lock);
1088 list_del(&dev->devlist); 1136 list_del(&dev->devlist);
1089 list_for_each(item,&mops_list) { 1137 list_for_each_entry(mops, &mops_list, next)
1090 mops = list_entry(item, struct saa7134_mpeg_ops, next);
1091 mpeg_ops_detach(mops, dev); 1138 mpeg_ops_detach(mops, dev);
1092 }
1093 mutex_unlock(&devlist_lock); 1139 mutex_unlock(&devlist_lock);
1094 saa7134_devcount--; 1140 saa7134_devcount--;
1095 1141
@@ -1117,18 +1163,79 @@ static void __devexit saa7134_finidev(struct pci_dev *pci_dev)
1117 kfree(dev); 1163 kfree(dev);
1118} 1164}
1119 1165
1166static int saa7134_suspend(struct pci_dev *pci_dev , pm_message_t state)
1167{
1168
1169 struct saa7134_dev *dev = pci_get_drvdata(pci_dev);
1170
1171 /* disable overlay - apps should enable it explicitly on resume*/
1172 dev->ovenable = 0;
1173
1174 /* Disable interrupts, DMA, and rest of the chip*/
1175 saa_writel(SAA7134_IRQ1, 0);
1176 saa_writel(SAA7134_IRQ2, 0);
1177 saa_writel(SAA7134_MAIN_CTRL, 0);
1178
1179 pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state));
1180 pci_save_state(pci_dev);
1181
1182 return 0;
1183}
1184
1185static int saa7134_resume(struct pci_dev *pci_dev)
1186{
1187
1188 struct saa7134_dev *dev = pci_get_drvdata(pci_dev);
1189 unsigned int flags;
1190
1191 pci_restore_state(pci_dev);
1192 pci_set_power_state(pci_dev, PCI_D0);
1193
1194 /* Do things that are done in saa7134_initdev ,
1195 except of initializing memory structures.*/
1196
1197 dev->inresume = 1;
1198 saa7134_board_init1(dev);
1199
1200 if (saa7134_boards[dev->board].video_out)
1201 saa7134_videoport_init(dev);
1202
1203 if (card_has_mpeg(dev))
1204 saa7134_ts_init_hw(dev);
1205
1206 saa7134_hw_enable1(dev);
1207 saa7134_set_decoder(dev);
1208 saa7134_i2c_call_clients(dev, VIDIOC_S_STD, &dev->tvnorm->id);
1209 saa7134_board_init2(dev);
1210 saa7134_hw_enable2(dev);
1211
1212 saa7134_tvaudio_setmute(dev);
1213 saa7134_tvaudio_setvolume(dev, dev->ctl_volume);
1214 saa7134_enable_i2s(dev);
1215
1216 /*resume unfinished buffer(s)*/
1217 spin_lock_irqsave(&dev->slock, flags);
1218 saa7134_buffer_requeue(dev, &dev->video_q);
1219 saa7134_buffer_requeue(dev, &dev->vbi_q);
1220 saa7134_buffer_requeue(dev, &dev->ts_q);
1221
1222 /* start DMA now*/
1223 dev->inresume = 0;
1224 saa7134_set_dmabits(dev);
1225 spin_unlock_irqrestore(&dev->slock, flags);
1226
1227 return 0;
1228}
1229
1120/* ----------------------------------------------------------- */ 1230/* ----------------------------------------------------------- */
1121 1231
1122int saa7134_ts_register(struct saa7134_mpeg_ops *ops) 1232int saa7134_ts_register(struct saa7134_mpeg_ops *ops)
1123{ 1233{
1124 struct list_head *item;
1125 struct saa7134_dev *dev; 1234 struct saa7134_dev *dev;
1126 1235
1127 mutex_lock(&devlist_lock); 1236 mutex_lock(&devlist_lock);
1128 list_for_each(item,&saa7134_devlist) { 1237 list_for_each_entry(dev, &saa7134_devlist, devlist)
1129 dev = list_entry(item, struct saa7134_dev, devlist);
1130 mpeg_ops_attach(ops, dev); 1238 mpeg_ops_attach(ops, dev);
1131 }
1132 list_add_tail(&ops->next,&mops_list); 1239 list_add_tail(&ops->next,&mops_list);
1133 mutex_unlock(&devlist_lock); 1240 mutex_unlock(&devlist_lock);
1134 return 0; 1241 return 0;
@@ -1136,15 +1243,12 @@ int saa7134_ts_register(struct saa7134_mpeg_ops *ops)
1136 1243
1137void saa7134_ts_unregister(struct saa7134_mpeg_ops *ops) 1244void saa7134_ts_unregister(struct saa7134_mpeg_ops *ops)
1138{ 1245{
1139 struct list_head *item;
1140 struct saa7134_dev *dev; 1246 struct saa7134_dev *dev;
1141 1247
1142 mutex_lock(&devlist_lock); 1248 mutex_lock(&devlist_lock);
1143 list_del(&ops->next); 1249 list_del(&ops->next);
1144 list_for_each(item,&saa7134_devlist) { 1250 list_for_each_entry(dev, &saa7134_devlist, devlist)
1145 dev = list_entry(item, struct saa7134_dev, devlist);
1146 mpeg_ops_detach(ops, dev); 1251 mpeg_ops_detach(ops, dev);
1147 }
1148 mutex_unlock(&devlist_lock); 1252 mutex_unlock(&devlist_lock);
1149} 1253}
1150 1254
@@ -1158,6 +1262,8 @@ static struct pci_driver saa7134_pci_driver = {
1158 .id_table = saa7134_pci_tbl, 1262 .id_table = saa7134_pci_tbl,
1159 .probe = saa7134_initdev, 1263 .probe = saa7134_initdev,
1160 .remove = __devexit_p(saa7134_finidev), 1264 .remove = __devexit_p(saa7134_finidev),
1265 .suspend = saa7134_suspend,
1266 .resume = saa7134_resume
1161}; 1267};
1162 1268
1163static int saa7134_init(void) 1269static int saa7134_init(void)
diff --git a/drivers/media/video/saa7134/saa7134-dvb.c b/drivers/media/video/saa7134/saa7134-dvb.c
index 1f6bd3300715..38d87332cc5d 100644
--- a/drivers/media/video/saa7134/saa7134-dvb.c
+++ b/drivers/media/video/saa7134/saa7134-dvb.c
@@ -567,6 +567,7 @@ static void configure_tda827x_fe(struct saa7134_dev *dev, struct tda1004x_config
567} 567}
568 568
569/* ------------------------------------------------------------------ */ 569/* ------------------------------------------------------------------ */
570
570static struct tda1004x_config tda827x_lifeview_config = { 571static struct tda1004x_config tda827x_lifeview_config = {
571 .demod_address = 0x08, 572 .demod_address = 0x08,
572 .invert = 1, 573 .invert = 1,
@@ -746,6 +747,7 @@ static struct tda1004x_config asus_p7131_hybrid_lna_config = {
746 .antenna_switch= 2, 747 .antenna_switch= 2,
747 .request_firmware = philips_tda1004x_request_firmware 748 .request_firmware = philips_tda1004x_request_firmware
748}; 749};
750
749static struct tda1004x_config kworld_dvb_t_210_config = { 751static struct tda1004x_config kworld_dvb_t_210_config = {
750 .demod_address = 0x08, 752 .demod_address = 0x08,
751 .invert = 1, 753 .invert = 1,
@@ -760,6 +762,22 @@ static struct tda1004x_config kworld_dvb_t_210_config = {
760 .antenna_switch= 1, 762 .antenna_switch= 1,
761 .request_firmware = philips_tda1004x_request_firmware 763 .request_firmware = philips_tda1004x_request_firmware
762}; 764};
765
766static struct tda1004x_config avermedia_super_007_config = {
767 .demod_address = 0x08,
768 .invert = 1,
769 .invert_oclk = 0,
770 .xtal_freq = TDA10046_XTAL_16M,
771 .agc_config = TDA10046_AGC_TDA827X,
772 .gpio_config = TDA10046_GP01_I,
773 .if_freq = TDA10046_FREQ_045,
774 .i2c_gate = 0x4b,
775 .tuner_address = 0x60,
776 .tuner_config = 0,
777 .antenna_switch= 1,
778 .request_firmware = philips_tda1004x_request_firmware
779};
780
763/* ------------------------------------------------------------------ 781/* ------------------------------------------------------------------
764 * special case: this card uses saa713x GPIO22 for the mode switch 782 * special case: this card uses saa713x GPIO22 for the mode switch
765 */ 783 */
@@ -832,7 +850,7 @@ static int dvb_init(struct saa7134_dev *dev)
832 dev->ts.nr_bufs = 32; 850 dev->ts.nr_bufs = 32;
833 dev->ts.nr_packets = 32*4; 851 dev->ts.nr_packets = 32*4;
834 dev->dvb.name = dev->name; 852 dev->dvb.name = dev->name;
835 videobuf_queue_init(&dev->dvb.dvbq, &saa7134_ts_qops, 853 videobuf_queue_pci_init(&dev->dvb.dvbq, &saa7134_ts_qops,
836 dev->pci, &dev->slock, 854 dev->pci, &dev->slock,
837 V4L2_BUF_TYPE_VIDEO_CAPTURE, 855 V4L2_BUF_TYPE_VIDEO_CAPTURE,
838 V4L2_FIELD_ALTERNATE, 856 V4L2_FIELD_ALTERNATE,
@@ -1022,6 +1040,9 @@ static int dvb_init(struct saa7134_dev *dev)
1022 case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA: 1040 case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA:
1023 configure_tda827x_fe(dev, &asus_p7131_hybrid_lna_config); 1041 configure_tda827x_fe(dev, &asus_p7131_hybrid_lna_config);
1024 break; 1042 break;
1043 case SAA7134_BOARD_AVERMEDIA_SUPER_007:
1044 configure_tda827x_fe(dev, &avermedia_super_007_config);
1045 break;
1025 default: 1046 default:
1026 wprintk("Huh? unknown DVB card?\n"); 1047 wprintk("Huh? unknown DVB card?\n");
1027 break; 1048 break;
diff --git a/drivers/media/video/saa7134/saa7134-empress.c b/drivers/media/video/saa7134/saa7134-empress.c
index fc260ec8fdc2..34ca874dd7fe 100644
--- a/drivers/media/video/saa7134/saa7134-empress.c
+++ b/drivers/media/video/saa7134/saa7134-empress.c
@@ -20,7 +20,6 @@
20#include <linux/init.h> 20#include <linux/init.h>
21#include <linux/list.h> 21#include <linux/list.h>
22#include <linux/module.h> 22#include <linux/module.h>
23#include <linux/moduleparam.h>
24#include <linux/kernel.h> 23#include <linux/kernel.h>
25#include <linux/slab.h> 24#include <linux/slab.h>
26#include <linux/delay.h> 25#include <linux/delay.h>
@@ -77,17 +76,14 @@ static int ts_init_encoder(struct saa7134_dev* dev)
77static int ts_open(struct inode *inode, struct file *file) 76static int ts_open(struct inode *inode, struct file *file)
78{ 77{
79 int minor = iminor(inode); 78 int minor = iminor(inode);
80 struct saa7134_dev *h,*dev = NULL; 79 struct saa7134_dev *dev;
81 struct list_head *list;
82 int err; 80 int err;
83 81
84 list_for_each(list,&saa7134_devlist) { 82 list_for_each_entry(dev, &saa7134_devlist, devlist)
85 h = list_entry(list, struct saa7134_dev, devlist); 83 if (dev->empress_dev && dev->empress_dev->minor == minor)
86 if (h->empress_dev && h->empress_dev->minor == minor) 84 goto found;
87 dev = h; 85 return -ENODEV;
88 } 86 found:
89 if (NULL == dev)
90 return -ENODEV;
91 87
92 dprintk("open minor=%d\n",minor); 88 dprintk("open minor=%d\n",minor);
93 err = -EBUSY; 89 err = -EBUSY;
@@ -401,7 +397,7 @@ static int empress_init(struct saa7134_dev *dev)
401 printk(KERN_INFO "%s: registered device video%d [mpeg]\n", 397 printk(KERN_INFO "%s: registered device video%d [mpeg]\n",
402 dev->name,dev->empress_dev->minor & 0x1f); 398 dev->name,dev->empress_dev->minor & 0x1f);
403 399
404 videobuf_queue_init(&dev->empress_tsq, &saa7134_ts_qops, 400 videobuf_queue_pci_init(&dev->empress_tsq, &saa7134_ts_qops,
405 dev->pci, &dev->slock, 401 dev->pci, &dev->slock,
406 V4L2_BUF_TYPE_VIDEO_CAPTURE, 402 V4L2_BUF_TYPE_VIDEO_CAPTURE,
407 V4L2_FIELD_ALTERNATE, 403 V4L2_FIELD_ALTERNATE,
diff --git a/drivers/media/video/saa7134/saa7134-i2c.c b/drivers/media/video/saa7134/saa7134-i2c.c
index 1cb8c709ca90..cc87f5855a21 100644
--- a/drivers/media/video/saa7134/saa7134-i2c.c
+++ b/drivers/media/video/saa7134/saa7134-i2c.c
@@ -23,7 +23,6 @@
23#include <linux/init.h> 23#include <linux/init.h>
24#include <linux/list.h> 24#include <linux/list.h>
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/moduleparam.h>
27#include <linux/kernel.h> 26#include <linux/kernel.h>
28#include <linux/slab.h> 27#include <linux/slab.h>
29#include <linux/delay.h> 28#include <linux/delay.h>
diff --git a/drivers/media/video/saa7134/saa7134-input.c b/drivers/media/video/saa7134/saa7134-input.c
index 1b6dfd801cc1..80d2644f765a 100644
--- a/drivers/media/video/saa7134/saa7134-input.c
+++ b/drivers/media/video/saa7134/saa7134-input.c
@@ -19,7 +19,6 @@
19 */ 19 */
20 20
21#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/moduleparam.h>
23#include <linux/init.h> 22#include <linux/init.h>
24#include <linux/delay.h> 23#include <linux/delay.h>
25#include <linux/interrupt.h> 24#include <linux/interrupt.h>
diff --git a/drivers/media/video/saa7134/saa7134-oss.c b/drivers/media/video/saa7134/saa7134-oss.c
index 72444f039e3d..aedf04653e0e 100644
--- a/drivers/media/video/saa7134/saa7134-oss.c
+++ b/drivers/media/video/saa7134/saa7134-oss.c
@@ -25,7 +25,6 @@
25#include <linux/init.h> 25#include <linux/init.h>
26#include <linux/list.h> 26#include <linux/list.h>
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/moduleparam.h>
29#include <linux/kernel.h> 28#include <linux/kernel.h>
30#include <linux/interrupt.h> 29#include <linux/interrupt.h>
31#include <linux/slab.h> 30#include <linux/slab.h>
@@ -240,17 +239,14 @@ static int dsp_rec_stop(struct saa7134_dev *dev)
240static int dsp_open(struct inode *inode, struct file *file) 239static int dsp_open(struct inode *inode, struct file *file)
241{ 240{
242 int minor = iminor(inode); 241 int minor = iminor(inode);
243 struct saa7134_dev *h,*dev = NULL; 242 struct saa7134_dev *dev;
244 struct list_head *list;
245 int err; 243 int err;
246 244
247 list_for_each(list,&saa7134_devlist) { 245 list_for_each_entry(dev, &saa7134_devlist, devlist)
248 h = list_entry(list, struct saa7134_dev, devlist); 246 if (dev->dmasound.minor_dsp == minor)
249 if (h->dmasound.minor_dsp == minor) 247 goto found;
250 dev = h; 248 return -ENODEV;
251 } 249 found:
252 if (NULL == dev)
253 return -ENODEV;
254 250
255 mutex_lock(&dev->dmasound.lock); 251 mutex_lock(&dev->dmasound.lock);
256 err = -EBUSY; 252 err = -EBUSY;
@@ -681,19 +677,14 @@ mixer_level(struct saa7134_dev *dev, enum saa7134_audio_in src, int level)
681static int mixer_open(struct inode *inode, struct file *file) 677static int mixer_open(struct inode *inode, struct file *file)
682{ 678{
683 int minor = iminor(inode); 679 int minor = iminor(inode);
684 struct saa7134_dev *h,*dev = NULL; 680 struct saa7134_dev *dev;
685 struct list_head *list;
686 681
687 list_for_each(list,&saa7134_devlist) { 682 list_for_each_entry(dev, &saa7134_devlist, devlist)
688 h = list_entry(list, struct saa7134_dev, devlist); 683 if (dev->dmasound.minor_mixer == minor) {
689 if (h->dmasound.minor_mixer == minor) 684 file->private_data = dev;
690 dev = h; 685 return 0;
691 } 686 }
692 if (NULL == dev) 687 return -ENODEV;
693 return -ENODEV;
694
695 file->private_data = dev;
696 return 0;
697} 688}
698 689
699static int mixer_release(struct inode *inode, struct file *file) 690static int mixer_release(struct inode *inode, struct file *file)
@@ -1023,18 +1014,14 @@ static int saa7134_oss_init(void)
1023 1014
1024static void saa7134_oss_exit(void) 1015static void saa7134_oss_exit(void)
1025{ 1016{
1026 struct saa7134_dev *dev = NULL; 1017 struct saa7134_dev *dev;
1027 struct list_head *list;
1028
1029 list_for_each(list,&saa7134_devlist) {
1030 dev = list_entry(list, struct saa7134_dev, devlist);
1031 1018
1019 list_for_each_entry(dev, &saa7134_devlist, devlist) {
1032 /* Device isn't registered by OSS, probably ALSA's */ 1020 /* Device isn't registered by OSS, probably ALSA's */
1033 if (!dev->dmasound.minor_dsp) 1021 if (!dev->dmasound.minor_dsp)
1034 continue; 1022 continue;
1035 1023
1036 oss_device_exit(dev); 1024 oss_device_exit(dev);
1037
1038 } 1025 }
1039 1026
1040 saa7134_dmasound_init = NULL; 1027 saa7134_dmasound_init = NULL;
diff --git a/drivers/media/video/saa7134/saa7134-ts.c b/drivers/media/video/saa7134/saa7134-ts.c
index 60a90a2617ae..4b63ad3e8466 100644
--- a/drivers/media/video/saa7134/saa7134-ts.c
+++ b/drivers/media/video/saa7134/saa7134-ts.c
@@ -23,7 +23,6 @@
23#include <linux/init.h> 23#include <linux/init.h>
24#include <linux/list.h> 24#include <linux/list.h>
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/moduleparam.h>
27#include <linux/kernel.h> 26#include <linux/kernel.h>
28#include <linux/slab.h> 27#include <linux/slab.h>
29#include <linux/delay.h> 28#include <linux/delay.h>
@@ -93,6 +92,8 @@ static int buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
93 } 92 }
94 93
95 if (STATE_NEEDS_INIT == buf->vb.state) { 94 if (STATE_NEEDS_INIT == buf->vb.state) {
95 struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb);
96
96 buf->vb.width = llength; 97 buf->vb.width = llength;
97 buf->vb.height = lines; 98 buf->vb.height = lines;
98 buf->vb.size = size; 99 buf->vb.size = size;
@@ -102,8 +103,8 @@ static int buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
102 if (err) 103 if (err)
103 goto oops; 104 goto oops;
104 err = saa7134_pgtable_build(dev->pci,buf->pt, 105 err = saa7134_pgtable_build(dev->pci,buf->pt,
105 buf->vb.dma.sglist, 106 dma->sglist,
106 buf->vb.dma.sglen, 107 dma->sglen,
107 saa7134_buffer_startpage(buf)); 108 saa7134_buffer_startpage(buf));
108 if (err) 109 if (err)
109 goto oops; 110 goto oops;
@@ -176,6 +177,22 @@ static unsigned int ts_nr_packets = 64;
176module_param(ts_nr_packets, int, 0444); 177module_param(ts_nr_packets, int, 0444);
177MODULE_PARM_DESC(ts_nr_packets,"size of a ts buffers (in ts packets)"); 178MODULE_PARM_DESC(ts_nr_packets,"size of a ts buffers (in ts packets)");
178 179
180int saa7134_ts_init_hw(struct saa7134_dev *dev)
181{
182 /* deactivate TS softreset */
183 saa_writeb(SAA7134_TS_SERIAL1, 0x00);
184 /* TSSOP high active, TSVAL high active, TSLOCK ignored */
185 saa_writeb(SAA7134_TS_PARALLEL, 0xec);
186 saa_writeb(SAA7134_TS_PARALLEL_SERIAL, (TS_PACKET_SIZE-1));
187 saa_writeb(SAA7134_TS_DMA0, ((dev->ts.nr_packets-1)&0xff));
188 saa_writeb(SAA7134_TS_DMA1, (((dev->ts.nr_packets-1)>>8)&0xff));
189 /* TSNOPIT=0, TSCOLAP=0 */
190 saa_writeb(SAA7134_TS_DMA2,
191 ((((dev->ts.nr_packets-1)>>16)&0x3f) | 0x00));
192
193 return 0;
194}
195
179int saa7134_ts_init1(struct saa7134_dev *dev) 196int saa7134_ts_init1(struct saa7134_dev *dev)
180{ 197{
181 /* sanitycheck insmod options */ 198 /* sanitycheck insmod options */
@@ -199,12 +216,7 @@ int saa7134_ts_init1(struct saa7134_dev *dev)
199 saa7134_pgtable_alloc(dev->pci,&dev->ts.pt_ts); 216 saa7134_pgtable_alloc(dev->pci,&dev->ts.pt_ts);
200 217
201 /* init TS hw */ 218 /* init TS hw */
202 saa_writeb(SAA7134_TS_SERIAL1, 0x00); /* deactivate TS softreset */ 219 saa7134_ts_init_hw(dev);
203 saa_writeb(SAA7134_TS_PARALLEL, 0xec); /* TSSOP high active, TSVAL high active, TSLOCK ignored */
204 saa_writeb(SAA7134_TS_PARALLEL_SERIAL, (TS_PACKET_SIZE-1));
205 saa_writeb(SAA7134_TS_DMA0, ((dev->ts.nr_packets-1)&0xff));
206 saa_writeb(SAA7134_TS_DMA1, (((dev->ts.nr_packets-1)>>8)&0xff));
207 saa_writeb(SAA7134_TS_DMA2, ((((dev->ts.nr_packets-1)>>16)&0x3f) | 0x00)); /* TSNOPIT=0, TSCOLAP=0 */
208 220
209 return 0; 221 return 0;
210} 222}
diff --git a/drivers/media/video/saa7134/saa7134-tvaudio.c b/drivers/media/video/saa7134/saa7134-tvaudio.c
index 18b4817b4aac..1b9e39a5ea47 100644
--- a/drivers/media/video/saa7134/saa7134-tvaudio.c
+++ b/drivers/media/video/saa7134/saa7134-tvaudio.c
@@ -23,7 +23,6 @@
23#include <linux/init.h> 23#include <linux/init.h>
24#include <linux/list.h> 24#include <linux/list.h>
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/moduleparam.h>
27#include <linux/kernel.h> 26#include <linux/kernel.h>
28#include <linux/kthread.h> 27#include <linux/kthread.h>
29#include <linux/slab.h> 28#include <linux/slab.h>
@@ -232,7 +231,7 @@ static void mute_input_7134(struct saa7134_dev *dev)
232 } 231 }
233 232
234 if (dev->hw_mute == mute && 233 if (dev->hw_mute == mute &&
235 dev->hw_input == in) { 234 dev->hw_input == in && !dev->inresume) {
236 dprintk("mute/input: nothing to do [mute=%d,input=%s]\n", 235 dprintk("mute/input: nothing to do [mute=%d,input=%s]\n",
237 mute,in->name); 236 mute,in->name);
238 return; 237 return;
@@ -877,7 +876,7 @@ static int tvaudio_thread_ddep(void *data)
877/* ------------------------------------------------------------------ */ 876/* ------------------------------------------------------------------ */
878/* common stuff + external entry points */ 877/* common stuff + external entry points */
879 878
880static void saa7134_enable_i2s(struct saa7134_dev *dev) 879void saa7134_enable_i2s(struct saa7134_dev *dev)
881{ 880{
882 int i2s_format; 881 int i2s_format;
883 882
diff --git a/drivers/media/video/saa7134/saa7134-vbi.c b/drivers/media/video/saa7134/saa7134-vbi.c
index f38366a470fa..81a2aedeff5c 100644
--- a/drivers/media/video/saa7134/saa7134-vbi.c
+++ b/drivers/media/video/saa7134/saa7134-vbi.c
@@ -23,7 +23,6 @@
23#include <linux/init.h> 23#include <linux/init.h>
24#include <linux/list.h> 24#include <linux/list.h>
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/moduleparam.h>
27#include <linux/kernel.h> 26#include <linux/kernel.h>
28#include <linux/slab.h> 27#include <linux/slab.h>
29 28
@@ -138,6 +137,8 @@ static int buffer_prepare(struct videobuf_queue *q,
138 saa7134_dma_free(q,buf); 137 saa7134_dma_free(q,buf);
139 138
140 if (STATE_NEEDS_INIT == buf->vb.state) { 139 if (STATE_NEEDS_INIT == buf->vb.state) {
140 struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb);
141
141 buf->vb.width = llength; 142 buf->vb.width = llength;
142 buf->vb.height = lines; 143 buf->vb.height = lines;
143 buf->vb.size = size; 144 buf->vb.size = size;
@@ -147,8 +148,8 @@ static int buffer_prepare(struct videobuf_queue *q,
147 if (err) 148 if (err)
148 goto oops; 149 goto oops;
149 err = saa7134_pgtable_build(dev->pci,buf->pt, 150 err = saa7134_pgtable_build(dev->pci,buf->pt,
150 buf->vb.dma.sglist, 151 dma->sglist,
151 buf->vb.dma.sglen, 152 dma->sglen,
152 saa7134_buffer_startpage(buf)); 153 saa7134_buffer_startpage(buf));
153 if (err) 154 if (err)
154 goto oops; 155 goto oops;
diff --git a/drivers/media/video/saa7134/saa7134-video.c b/drivers/media/video/saa7134/saa7134-video.c
index 9985ded20950..471b92793c12 100644
--- a/drivers/media/video/saa7134/saa7134-video.c
+++ b/drivers/media/video/saa7134/saa7134-video.c
@@ -23,7 +23,6 @@
23#include <linux/init.h> 23#include <linux/init.h>
24#include <linux/list.h> 24#include <linux/list.h>
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/moduleparam.h>
27#include <linux/kernel.h> 26#include <linux/kernel.h>
28#include <linux/slab.h> 27#include <linux/slab.h>
29#include <linux/sort.h> 28#include <linux/sort.h>
@@ -41,7 +40,7 @@
41 40
42static unsigned int video_debug = 0; 41static unsigned int video_debug = 0;
43static unsigned int gbuffers = 8; 42static unsigned int gbuffers = 8;
44static unsigned int noninterlaced = 1; 43static unsigned int noninterlaced = 0;
45static unsigned int gbufsize = 720*576*4; 44static unsigned int gbufsize = 720*576*4;
46static unsigned int gbufsize_max = 720*576*4; 45static unsigned int gbufsize_max = 720*576*4;
47static char secam[] = "--"; 46static char secam[] = "--";
@@ -541,22 +540,12 @@ void res_free(struct saa7134_dev *dev, struct saa7134_fh *fh, unsigned int bits)
541 540
542/* ------------------------------------------------------------------ */ 541/* ------------------------------------------------------------------ */
543 542
544static void set_tvnorm(struct saa7134_dev *dev, struct saa7134_tvnorm *norm) 543void set_tvnorm(struct saa7134_dev *dev, struct saa7134_tvnorm *norm)
545{ 544{
546 int luma_control,sync_control,mux;
547 545
548 dprintk("set tv norm = %s\n",norm->name); 546 dprintk("set tv norm = %s\n",norm->name);
549 dev->tvnorm = norm; 547 dev->tvnorm = norm;
550 548
551 mux = card_in(dev,dev->ctl_input).vmux;
552 luma_control = norm->luma_control;
553 sync_control = norm->sync_control;
554
555 if (mux > 5)
556 luma_control |= 0x80; /* svideo */
557 if (noninterlaced || dev->nosignal)
558 sync_control |= 0x20;
559
560 /* setup cropping */ 549 /* setup cropping */
561 dev->crop_bounds.left = norm->h_start; 550 dev->crop_bounds.left = norm->h_start;
562 dev->crop_defrect.left = norm->h_start; 551 dev->crop_defrect.left = norm->h_start;
@@ -571,6 +560,40 @@ static void set_tvnorm(struct saa7134_dev *dev, struct saa7134_tvnorm *norm)
571 560
572 dev->crop_current = dev->crop_defrect; 561 dev->crop_current = dev->crop_defrect;
573 562
563 saa7134_set_decoder(dev);
564
565 if (card_in(dev, dev->ctl_input).tv) {
566 if ((card(dev).tuner_type == TUNER_PHILIPS_TDA8290)
567 && ((card(dev).tuner_config == 1)
568 || (card(dev).tuner_config == 2)))
569 saa7134_set_gpio(dev, 22, 5);
570 saa7134_i2c_call_clients(dev, VIDIOC_S_STD, &norm->id);
571 }
572}
573
574static void video_mux(struct saa7134_dev *dev, int input)
575{
576 dprintk("video input = %d [%s]\n", input, card_in(dev, input).name);
577 dev->ctl_input = input;
578 set_tvnorm(dev, dev->tvnorm);
579 saa7134_tvaudio_setinput(dev, &card_in(dev, input));
580}
581
582void saa7134_set_decoder(struct saa7134_dev *dev)
583{
584 int luma_control, sync_control, mux;
585
586 struct saa7134_tvnorm *norm = dev->tvnorm;
587 mux = card_in(dev, dev->ctl_input).vmux;
588
589 luma_control = norm->luma_control;
590 sync_control = norm->sync_control;
591
592 if (mux > 5)
593 luma_control |= 0x80; /* svideo */
594 if (noninterlaced || dev->nosignal)
595 sync_control |= 0x20;
596
574 /* setup video decoder */ 597 /* setup video decoder */
575 saa_writeb(SAA7134_INCR_DELAY, 0x08); 598 saa_writeb(SAA7134_INCR_DELAY, 0x08);
576 saa_writeb(SAA7134_ANALOG_IN_CTRL1, 0xc0 | mux); 599 saa_writeb(SAA7134_ANALOG_IN_CTRL1, 0xc0 | mux);
@@ -585,9 +608,13 @@ static void set_tvnorm(struct saa7134_dev *dev, struct saa7134_tvnorm *norm)
585 saa_writeb(SAA7134_SYNC_CTRL, sync_control); 608 saa_writeb(SAA7134_SYNC_CTRL, sync_control);
586 saa_writeb(SAA7134_LUMA_CTRL, luma_control); 609 saa_writeb(SAA7134_LUMA_CTRL, luma_control);
587 saa_writeb(SAA7134_DEC_LUMA_BRIGHT, dev->ctl_bright); 610 saa_writeb(SAA7134_DEC_LUMA_BRIGHT, dev->ctl_bright);
588 saa_writeb(SAA7134_DEC_LUMA_CONTRAST, dev->ctl_contrast);
589 611
590 saa_writeb(SAA7134_DEC_CHROMA_SATURATION, dev->ctl_saturation); 612 saa_writeb(SAA7134_DEC_LUMA_CONTRAST,
613 dev->ctl_invert ? -dev->ctl_contrast : dev->ctl_contrast);
614
615 saa_writeb(SAA7134_DEC_CHROMA_SATURATION,
616 dev->ctl_invert ? -dev->ctl_saturation : dev->ctl_saturation);
617
591 saa_writeb(SAA7134_DEC_CHROMA_HUE, dev->ctl_hue); 618 saa_writeb(SAA7134_DEC_CHROMA_HUE, dev->ctl_hue);
592 saa_writeb(SAA7134_CHROMA_CTRL1, norm->chroma_ctrl1); 619 saa_writeb(SAA7134_CHROMA_CTRL1, norm->chroma_ctrl1);
593 saa_writeb(SAA7134_CHROMA_GAIN, norm->chroma_gain); 620 saa_writeb(SAA7134_CHROMA_GAIN, norm->chroma_gain);
@@ -601,23 +628,6 @@ static void set_tvnorm(struct saa7134_dev *dev, struct saa7134_tvnorm *norm)
601 saa_writeb(SAA7134_MISC_VGATE_MSB, norm->vgate_misc); 628 saa_writeb(SAA7134_MISC_VGATE_MSB, norm->vgate_misc);
602 saa_writeb(SAA7134_RAW_DATA_GAIN, 0x40); 629 saa_writeb(SAA7134_RAW_DATA_GAIN, 0x40);
603 saa_writeb(SAA7134_RAW_DATA_OFFSET, 0x80); 630 saa_writeb(SAA7134_RAW_DATA_OFFSET, 0x80);
604
605 /* only tell the tuner if this is a tv input */
606 if (card_in(dev,dev->ctl_input).tv) {
607 if ((card(dev).tuner_type == TUNER_PHILIPS_TDA8290)
608 && ((card(dev).tuner_config == 1)
609 || (card(dev).tuner_config == 2)))
610 saa7134_set_gpio(dev, 22, 5);
611 saa7134_i2c_call_clients(dev,VIDIOC_S_STD,&norm->id);
612 }
613}
614
615static void video_mux(struct saa7134_dev *dev, int input)
616{
617 dprintk("video input = %d [%s]\n",input,card_in(dev,input).name);
618 dev->ctl_input = input;
619 set_tvnorm(dev,dev->tvnorm);
620 saa7134_tvaudio_setinput(dev,&card_in(dev,input));
621} 631}
622 632
623static 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)
@@ -1038,6 +1048,8 @@ static int buffer_prepare(struct videobuf_queue *q,
1038 } 1048 }
1039 1049
1040 if (STATE_NEEDS_INIT == buf->vb.state) { 1050 if (STATE_NEEDS_INIT == buf->vb.state) {
1051 struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb);
1052
1041 buf->vb.width = fh->width; 1053 buf->vb.width = fh->width;
1042 buf->vb.height = fh->height; 1054 buf->vb.height = fh->height;
1043 buf->vb.size = size; 1055 buf->vb.size = size;
@@ -1049,8 +1061,8 @@ static int buffer_prepare(struct videobuf_queue *q,
1049 if (err) 1061 if (err)
1050 goto oops; 1062 goto oops;
1051 err = saa7134_pgtable_build(dev->pci,buf->pt, 1063 err = saa7134_pgtable_build(dev->pci,buf->pt,
1052 buf->vb.dma.sglist, 1064 dma->sglist,
1053 buf->vb.dma.sglen, 1065 dma->sglen,
1054 saa7134_buffer_startpage(buf)); 1066 saa7134_buffer_startpage(buf));
1055 if (err) 1067 if (err)
1056 goto oops; 1068 goto oops;
@@ -1273,26 +1285,24 @@ static int saa7134_resource(struct saa7134_fh *fh)
1273static int video_open(struct inode *inode, struct file *file) 1285static int video_open(struct inode *inode, struct file *file)
1274{ 1286{
1275 int minor = iminor(inode); 1287 int minor = iminor(inode);
1276 struct saa7134_dev *h,*dev = NULL; 1288 struct saa7134_dev *dev;
1277 struct saa7134_fh *fh; 1289 struct saa7134_fh *fh;
1278 struct list_head *list;
1279 enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 1290 enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1280 int radio = 0; 1291 int radio = 0;
1281 list_for_each(list,&saa7134_devlist) { 1292 list_for_each_entry(dev, &saa7134_devlist, devlist) {
1282 h = list_entry(list, struct saa7134_dev, devlist); 1293 if (dev->video_dev && (dev->video_dev->minor == minor))
1283 if (h->video_dev && (h->video_dev->minor == minor)) 1294 goto found;
1284 dev = h; 1295 if (dev->radio_dev && (dev->radio_dev->minor == minor)) {
1285 if (h->radio_dev && (h->radio_dev->minor == minor)) {
1286 radio = 1; 1296 radio = 1;
1287 dev = h; 1297 goto found;
1288 } 1298 }
1289 if (h->vbi_dev && (h->vbi_dev->minor == minor)) { 1299 if (dev->vbi_dev && (dev->vbi_dev->minor == minor)) {
1290 type = V4L2_BUF_TYPE_VBI_CAPTURE; 1300 type = V4L2_BUF_TYPE_VBI_CAPTURE;
1291 dev = h; 1301 goto found;
1292 } 1302 }
1293 } 1303 }
1294 if (NULL == dev) 1304 return -ENODEV;
1295 return -ENODEV; 1305 found:
1296 1306
1297 dprintk("open minor=%d radio=%d type=%s\n",minor,radio, 1307 dprintk("open minor=%d radio=%d type=%s\n",minor,radio,
1298 v4l2_type_names[type]); 1308 v4l2_type_names[type]);
@@ -1310,13 +1320,13 @@ static int video_open(struct inode *inode, struct file *file)
1310 fh->height = 576; 1320 fh->height = 576;
1311 v4l2_prio_open(&dev->prio,&fh->prio); 1321 v4l2_prio_open(&dev->prio,&fh->prio);
1312 1322
1313 videobuf_queue_init(&fh->cap, &video_qops, 1323 videobuf_queue_pci_init(&fh->cap, &video_qops,
1314 dev->pci, &dev->slock, 1324 dev->pci, &dev->slock,
1315 V4L2_BUF_TYPE_VIDEO_CAPTURE, 1325 V4L2_BUF_TYPE_VIDEO_CAPTURE,
1316 V4L2_FIELD_INTERLACED, 1326 V4L2_FIELD_INTERLACED,
1317 sizeof(struct saa7134_buf), 1327 sizeof(struct saa7134_buf),
1318 fh); 1328 fh);
1319 videobuf_queue_init(&fh->vbi, &saa7134_vbi_qops, 1329 videobuf_queue_pci_init(&fh->vbi, &saa7134_vbi_qops,
1320 dev->pci, &dev->slock, 1330 dev->pci, &dev->slock,
1321 V4L2_BUF_TYPE_VBI_CAPTURE, 1331 V4L2_BUF_TYPE_VBI_CAPTURE,
1322 V4L2_FIELD_SEQ_TB, 1332 V4L2_FIELD_SEQ_TB,
@@ -1833,7 +1843,11 @@ static int video_do_ioctl(struct inode *inode, struct file *file,
1833 if (res_check(fh, RESOURCE_OVERLAY)) { 1843 if (res_check(fh, RESOURCE_OVERLAY)) {
1834 spin_lock_irqsave(&dev->slock,flags); 1844 spin_lock_irqsave(&dev->slock,flags);
1835 stop_preview(dev,fh); 1845 stop_preview(dev,fh);
1846 spin_unlock_irqrestore(&dev->slock, flags);
1847
1836 set_tvnorm(dev,&tvnorms[i]); 1848 set_tvnorm(dev,&tvnorms[i]);
1849
1850 spin_lock_irqsave(&dev->slock, flags);
1837 start_preview(dev,fh); 1851 start_preview(dev,fh);
1838 spin_unlock_irqrestore(&dev->slock,flags); 1852 spin_unlock_irqrestore(&dev->slock,flags);
1839 } else 1853 } else
@@ -2138,29 +2152,7 @@ static int video_do_ioctl(struct inode *inode, struct file *file,
2138 } 2152 }
2139#ifdef CONFIG_VIDEO_V4L1_COMPAT 2153#ifdef CONFIG_VIDEO_V4L1_COMPAT
2140 case VIDIOCGMBUF: 2154 case VIDIOCGMBUF:
2141 { 2155 return videobuf_cgmbuf(saa7134_queue(fh), arg, gbuffers);
2142 struct video_mbuf *mbuf = arg;
2143 struct videobuf_queue *q;
2144 struct v4l2_requestbuffers req;
2145 unsigned int i;
2146
2147 q = saa7134_queue(fh);
2148 memset(&req,0,sizeof(req));
2149 req.type = q->type;
2150 req.count = gbuffers;
2151 req.memory = V4L2_MEMORY_MMAP;
2152 err = videobuf_reqbufs(q,&req);
2153 if (err < 0)
2154 return err;
2155 memset(mbuf,0,sizeof(*mbuf));
2156 mbuf->frames = req.count;
2157 mbuf->size = 0;
2158 for (i = 0; i < mbuf->frames; i++) {
2159 mbuf->offsets[i] = q->bufs[i]->boff;
2160 mbuf->size += q->bufs[i]->bsize;
2161 }
2162 return 0;
2163 }
2164#endif 2156#endif
2165 case VIDIOC_REQBUFS: 2157 case VIDIOC_REQBUFS:
2166 return videobuf_reqbufs(saa7134_queue(fh),arg); 2158 return videobuf_reqbufs(saa7134_queue(fh),arg);
@@ -2412,34 +2404,40 @@ int saa7134_video_init1(struct saa7134_dev *dev)
2412 dev->video_q.timeout.data = (unsigned long)(&dev->video_q); 2404 dev->video_q.timeout.data = (unsigned long)(&dev->video_q);
2413 dev->video_q.dev = dev; 2405 dev->video_q.dev = dev;
2414 2406
2415 if (saa7134_boards[dev->board].video_out) { 2407 if (saa7134_boards[dev->board].video_out)
2416 /* enable video output */ 2408 saa7134_videoport_init(dev);
2417 int vo = saa7134_boards[dev->board].video_out; 2409
2418 int video_reg; 2410 return 0;
2419 unsigned int vid_port_opts = saa7134_boards[dev->board].vid_port_opts; 2411}
2420 saa_writeb(SAA7134_VIDEO_PORT_CTRL0, video_out[vo][0]); 2412
2421 video_reg = video_out[vo][1]; 2413int saa7134_videoport_init(struct saa7134_dev *dev)
2422 if (vid_port_opts & SET_T_CODE_POLARITY_NON_INVERTED) 2414{
2423 video_reg &= ~VP_T_CODE_P_INVERTED; 2415 /* enable video output */
2424 saa_writeb(SAA7134_VIDEO_PORT_CTRL1, video_reg); 2416 int vo = saa7134_boards[dev->board].video_out;
2425 saa_writeb(SAA7134_VIDEO_PORT_CTRL2, video_out[vo][2]); 2417 int video_reg;
2426 saa_writeb(SAA7134_VIDEO_PORT_CTRL3, video_out[vo][3]); 2418 unsigned int vid_port_opts = saa7134_boards[dev->board].vid_port_opts;
2427 saa_writeb(SAA7134_VIDEO_PORT_CTRL4, video_out[vo][4]); 2419 saa_writeb(SAA7134_VIDEO_PORT_CTRL0, video_out[vo][0]);
2428 video_reg = video_out[vo][5]; 2420 video_reg = video_out[vo][1];
2429 if (vid_port_opts & SET_CLOCK_NOT_DELAYED) 2421 if (vid_port_opts & SET_T_CODE_POLARITY_NON_INVERTED)
2430 video_reg &= ~VP_CLK_CTRL2_DELAYED; 2422 video_reg &= ~VP_T_CODE_P_INVERTED;
2431 if (vid_port_opts & SET_CLOCK_INVERTED) 2423 saa_writeb(SAA7134_VIDEO_PORT_CTRL1, video_reg);
2432 video_reg |= VP_CLK_CTRL1_INVERTED; 2424 saa_writeb(SAA7134_VIDEO_PORT_CTRL2, video_out[vo][2]);
2433 saa_writeb(SAA7134_VIDEO_PORT_CTRL5, video_reg); 2425 saa_writeb(SAA7134_VIDEO_PORT_CTRL3, video_out[vo][3]);
2434 video_reg = video_out[vo][6]; 2426 saa_writeb(SAA7134_VIDEO_PORT_CTRL4, video_out[vo][4]);
2435 if (vid_port_opts & SET_VSYNC_OFF) { 2427 video_reg = video_out[vo][5];
2436 video_reg &= ~VP_VS_TYPE_MASK; 2428 if (vid_port_opts & SET_CLOCK_NOT_DELAYED)
2437 video_reg |= VP_VS_TYPE_OFF; 2429 video_reg &= ~VP_CLK_CTRL2_DELAYED;
2438 } 2430 if (vid_port_opts & SET_CLOCK_INVERTED)
2439 saa_writeb(SAA7134_VIDEO_PORT_CTRL6, video_reg); 2431 video_reg |= VP_CLK_CTRL1_INVERTED;
2440 saa_writeb(SAA7134_VIDEO_PORT_CTRL7, video_out[vo][7]); 2432 saa_writeb(SAA7134_VIDEO_PORT_CTRL5, video_reg);
2441 saa_writeb(SAA7134_VIDEO_PORT_CTRL8, video_out[vo][8]); 2433 video_reg = video_out[vo][6];
2442 } 2434 if (vid_port_opts & SET_VSYNC_OFF) {
2435 video_reg &= ~VP_VS_TYPE_MASK;
2436 video_reg |= VP_VS_TYPE_OFF;
2437 }
2438 saa_writeb(SAA7134_VIDEO_PORT_CTRL6, video_reg);
2439 saa_writeb(SAA7134_VIDEO_PORT_CTRL7, video_out[vo][7]);
2440 saa_writeb(SAA7134_VIDEO_PORT_CTRL8, video_out[vo][8]);
2443 2441
2444 return 0; 2442 return 0;
2445} 2443}
@@ -2454,7 +2452,7 @@ int saa7134_video_init2(struct saa7134_dev *dev)
2454 return 0; 2452 return 0;
2455} 2453}
2456 2454
2457void saa7134_irq_video_intl(struct saa7134_dev *dev) 2455void saa7134_irq_video_signalchange(struct saa7134_dev *dev)
2458{ 2456{
2459 static const char *st[] = { 2457 static const char *st[] = {
2460 "(no signal)", "NTSC", "PAL", "SECAM" }; 2458 "(no signal)", "NTSC", "PAL", "SECAM" };
@@ -2466,24 +2464,28 @@ void saa7134_irq_video_intl(struct saa7134_dev *dev)
2466 (st1 & 0x40) ? "not locked" : "locked", 2464 (st1 & 0x40) ? "not locked" : "locked",
2467 (st2 & 0x40) ? "no" : "yes", 2465 (st2 & 0x40) ? "no" : "yes",
2468 st[st1 & 0x03]); 2466 st[st1 & 0x03]);
2469 dev->nosignal = (st1 & 0x40) || (st2 & 0x40); 2467 dev->nosignal = (st1 & 0x40) || (st2 & 0x40) || !(st2 & 0x1);
2470 2468
2471 if (dev->nosignal) { 2469 if (dev->nosignal) {
2472 /* no video signal -> mute audio */ 2470 /* no video signal -> mute audio */
2473 if (dev->ctl_automute) 2471 if (dev->ctl_automute)
2474 dev->automute = 1; 2472 dev->automute = 1;
2475 saa7134_tvaudio_setmute(dev); 2473 saa7134_tvaudio_setmute(dev);
2476 saa_setb(SAA7134_SYNC_CTRL, 0x20);
2477 } else { 2474 } else {
2478 /* wake up tvaudio audio carrier scan thread */ 2475 /* wake up tvaudio audio carrier scan thread */
2479 saa7134_tvaudio_do_scan(dev); 2476 saa7134_tvaudio_do_scan(dev);
2480 if (!noninterlaced)
2481 saa_clearb(SAA7134_SYNC_CTRL, 0x20);
2482 } 2477 }
2478
2479 if ((st2 & 0x80) && !noninterlaced && !dev->nosignal)
2480 saa_clearb(SAA7134_SYNC_CTRL, 0x20);
2481 else
2482 saa_setb(SAA7134_SYNC_CTRL, 0x20);
2483
2483 if (dev->mops && dev->mops->signal_change) 2484 if (dev->mops && dev->mops->signal_change)
2484 dev->mops->signal_change(dev); 2485 dev->mops->signal_change(dev);
2485} 2486}
2486 2487
2488
2487void saa7134_irq_video_done(struct saa7134_dev *dev, unsigned long status) 2489void saa7134_irq_video_done(struct saa7134_dev *dev, unsigned long status)
2488{ 2490{
2489 enum v4l2_field field; 2491 enum v4l2_field field;
diff --git a/drivers/media/video/saa7134/saa7134.h b/drivers/media/video/saa7134/saa7134.h
index 346255468dad..28ec6804bd5d 100644
--- a/drivers/media/video/saa7134/saa7134.h
+++ b/drivers/media/video/saa7134/saa7134.h
@@ -37,12 +37,12 @@
37#include <media/tuner.h> 37#include <media/tuner.h>
38#include <media/ir-common.h> 38#include <media/ir-common.h>
39#include <media/ir-kbd-i2c.h> 39#include <media/ir-kbd-i2c.h>
40#include <media/video-buf.h> 40#include <media/videobuf-dma-sg.h>
41#include <sound/driver.h> 41#include <sound/driver.h>
42#include <sound/core.h> 42#include <sound/core.h>
43#include <sound/pcm.h> 43#include <sound/pcm.h>
44#if defined(CONFIG_VIDEO_BUF_DVB) || defined(CONFIG_VIDEO_BUF_DVB_MODULE) 44#if defined(CONFIG_VIDEO_SAA7134_DVB) || defined(CONFIG_VIDEO_SAA7134_DVB_MODULE)
45#include <media/video-buf-dvb.h> 45#include <media/videobuf-dvb.h>
46#endif 46#endif
47 47
48#define UNSET (-1U) 48#define UNSET (-1U)
@@ -239,6 +239,7 @@ struct saa7134_format {
239#define SAA7134_BOARD_KWORLD_DVBT_210 114 239#define SAA7134_BOARD_KWORLD_DVBT_210 114
240#define SAA7134_BOARD_SABRENT_TV_PCB05 115 240#define SAA7134_BOARD_SABRENT_TV_PCB05 115
241#define SAA7134_BOARD_10MOONSTVMASTER3 116 241#define SAA7134_BOARD_10MOONSTVMASTER3 116
242#define SAA7134_BOARD_AVERMEDIA_SUPER_007 117
242 243
243#define SAA7134_MAXBOARDS 8 244#define SAA7134_MAXBOARDS 8
244#define SAA7134_INPUT_MAX 8 245#define SAA7134_INPUT_MAX 8
@@ -523,6 +524,7 @@ struct saa7134_dev {
523 unsigned int hw_mute; 524 unsigned int hw_mute;
524 int last_carrier; 525 int last_carrier;
525 int nosignal; 526 int nosignal;
527 unsigned int inresume;
526 528
527 /* SAA7134_MPEG_* */ 529 /* SAA7134_MPEG_* */
528 struct saa7134_ts ts; 530 struct saa7134_ts ts;
@@ -536,7 +538,7 @@ struct saa7134_dev {
536 struct work_struct empress_workqueue; 538 struct work_struct empress_workqueue;
537 int empress_started; 539 int empress_started;
538 540
539#if defined(CONFIG_VIDEO_BUF_DVB) || defined(CONFIG_VIDEO_BUF_DVB_MODULE) 541#if defined(CONFIG_VIDEO_SAA7134_DVB) || defined(CONFIG_VIDEO_SAA7134_DVB_MODULE)
540 /* SAA7134_MPEG_DVB only */ 542 /* SAA7134_MPEG_DVB only */
541 struct videobuf_dvb dvb; 543 struct videobuf_dvb dvb;
542 int (*original_demod_sleep)(struct dvb_frontend* fe); 544 int (*original_demod_sleep)(struct dvb_frontend* fe);
@@ -593,6 +595,9 @@ void saa7134_buffer_next(struct saa7134_dev *dev, struct saa7134_dmaqueue *q);
593void saa7134_buffer_timeout(unsigned long data); 595void saa7134_buffer_timeout(unsigned long data);
594void saa7134_dma_free(struct videobuf_queue *q,struct saa7134_buf *buf); 596void saa7134_dma_free(struct videobuf_queue *q,struct saa7134_buf *buf);
595 597
598int saa7134_buffer_requeue(struct saa7134_dev *dev,
599 struct saa7134_dmaqueue *q);
600
596int saa7134_set_dmabits(struct saa7134_dev *dev); 601int saa7134_set_dmabits(struct saa7134_dev *dev);
597 602
598extern int (*saa7134_dmasound_init)(struct saa7134_dev *dev); 603extern int (*saa7134_dmasound_init)(struct saa7134_dev *dev);
@@ -625,12 +630,16 @@ void saa7134_i2c_call_clients(struct saa7134_dev *dev,
625extern struct video_device saa7134_video_template; 630extern struct video_device saa7134_video_template;
626extern struct video_device saa7134_radio_template; 631extern struct video_device saa7134_radio_template;
627 632
633void set_tvnorm(struct saa7134_dev *dev, struct saa7134_tvnorm *norm);
634int saa7134_videoport_init(struct saa7134_dev *dev);
635void saa7134_set_decoder(struct saa7134_dev *dev);
636
628int saa7134_common_ioctl(struct saa7134_dev *dev, 637int saa7134_common_ioctl(struct saa7134_dev *dev,
629 unsigned int cmd, void *arg); 638 unsigned int cmd, void *arg);
630 639
631int saa7134_video_init1(struct saa7134_dev *dev); 640int saa7134_video_init1(struct saa7134_dev *dev);
632int saa7134_video_init2(struct saa7134_dev *dev); 641int saa7134_video_init2(struct saa7134_dev *dev);
633void saa7134_irq_video_intl(struct saa7134_dev *dev); 642void saa7134_irq_video_signalchange(struct saa7134_dev *dev);
634void saa7134_irq_video_done(struct saa7134_dev *dev, unsigned long status); 643void saa7134_irq_video_done(struct saa7134_dev *dev, unsigned long status);
635 644
636 645
@@ -648,6 +657,8 @@ void saa7134_irq_ts_done(struct saa7134_dev *dev, unsigned long status);
648int saa7134_ts_register(struct saa7134_mpeg_ops *ops); 657int saa7134_ts_register(struct saa7134_mpeg_ops *ops);
649void saa7134_ts_unregister(struct saa7134_mpeg_ops *ops); 658void saa7134_ts_unregister(struct saa7134_mpeg_ops *ops);
650 659
660int saa7134_ts_init_hw(struct saa7134_dev *dev);
661
651/* ----------------------------------------------------------- */ 662/* ----------------------------------------------------------- */
652/* saa7134-vbi.c */ 663/* saa7134-vbi.c */
653 664
@@ -676,6 +687,8 @@ int saa7134_tvaudio_do_scan(struct saa7134_dev *dev);
676 687
677int saa_dsp_writel(struct saa7134_dev *dev, int reg, u32 value); 688int saa_dsp_writel(struct saa7134_dev *dev, int reg, u32 value);
678 689
690void saa7134_enable_i2s(struct saa7134_dev *dev);
691
679/* ----------------------------------------------------------- */ 692/* ----------------------------------------------------------- */
680/* saa7134-oss.c */ 693/* saa7134-oss.c */
681 694
diff --git a/drivers/media/video/sn9c102/sn9c102_core.c b/drivers/media/video/sn9c102/sn9c102_core.c
index 36d8a455e0ec..6991e06f7651 100644
--- a/drivers/media/video/sn9c102/sn9c102_core.c
+++ b/drivers/media/video/sn9c102/sn9c102_core.c
@@ -22,7 +22,6 @@
22#include <linux/init.h> 22#include <linux/init.h>
23#include <linux/kernel.h> 23#include <linux/kernel.h>
24#include <linux/param.h> 24#include <linux/param.h>
25#include <linux/moduleparam.h>
26#include <linux/errno.h> 25#include <linux/errno.h>
27#include <linux/slab.h> 26#include <linux/slab.h>
28#include <linux/device.h> 27#include <linux/device.h>
@@ -1030,7 +1029,8 @@ static u16 sn9c102_strtou16(const char* buff, size_t len, ssize_t* count)
1030 NOTE 2: buffers are PAGE_SIZE long 1029 NOTE 2: buffers are PAGE_SIZE long
1031*/ 1030*/
1032 1031
1033static ssize_t sn9c102_show_reg(struct class_device* cd, char* buf) 1032static ssize_t sn9c102_show_reg(struct device* cd,
1033 struct device_attribute *attr, char* buf)
1034{ 1034{
1035 struct sn9c102_device* cam; 1035 struct sn9c102_device* cam;
1036 ssize_t count; 1036 ssize_t count;
@@ -1054,7 +1054,8 @@ static ssize_t sn9c102_show_reg(struct class_device* cd, char* buf)
1054 1054
1055 1055
1056static ssize_t 1056static ssize_t
1057sn9c102_store_reg(struct class_device* cd, const char* buf, size_t len) 1057sn9c102_store_reg(struct device* cd, struct device_attribute *attr,
1058 const char* buf, size_t len)
1058{ 1059{
1059 struct sn9c102_device* cam; 1060 struct sn9c102_device* cam;
1060 u16 index; 1061 u16 index;
@@ -1087,7 +1088,8 @@ sn9c102_store_reg(struct class_device* cd, const char* buf, size_t len)
1087} 1088}
1088 1089
1089 1090
1090static ssize_t sn9c102_show_val(struct class_device* cd, char* buf) 1091static ssize_t sn9c102_show_val(struct device* cd,
1092 struct device_attribute *attr, char* buf)
1091{ 1093{
1092 struct sn9c102_device* cam; 1094 struct sn9c102_device* cam;
1093 ssize_t count; 1095 ssize_t count;
@@ -1119,7 +1121,8 @@ static ssize_t sn9c102_show_val(struct class_device* cd, char* buf)
1119 1121
1120 1122
1121static ssize_t 1123static ssize_t
1122sn9c102_store_val(struct class_device* cd, const char* buf, size_t len) 1124sn9c102_store_val(struct device* cd, struct device_attribute *attr,
1125 const char* buf, size_t len)
1123{ 1126{
1124 struct sn9c102_device* cam; 1127 struct sn9c102_device* cam;
1125 u16 value; 1128 u16 value;
@@ -1158,7 +1161,8 @@ sn9c102_store_val(struct class_device* cd, const char* buf, size_t len)
1158} 1161}
1159 1162
1160 1163
1161static ssize_t sn9c102_show_i2c_reg(struct class_device* cd, char* buf) 1164static ssize_t sn9c102_show_i2c_reg(struct device* cd,
1165 struct device_attribute *attr, char* buf)
1162{ 1166{
1163 struct sn9c102_device* cam; 1167 struct sn9c102_device* cam;
1164 ssize_t count; 1168 ssize_t count;
@@ -1184,7 +1188,8 @@ static ssize_t sn9c102_show_i2c_reg(struct class_device* cd, char* buf)
1184 1188
1185 1189
1186static ssize_t 1190static ssize_t
1187sn9c102_store_i2c_reg(struct class_device* cd, const char* buf, size_t len) 1191sn9c102_store_i2c_reg(struct device* cd, struct device_attribute *attr,
1192 const char* buf, size_t len)
1188{ 1193{
1189 struct sn9c102_device* cam; 1194 struct sn9c102_device* cam;
1190 u16 index; 1195 u16 index;
@@ -1217,7 +1222,8 @@ sn9c102_store_i2c_reg(struct class_device* cd, const char* buf, size_t len)
1217} 1222}
1218 1223
1219 1224
1220static ssize_t sn9c102_show_i2c_val(struct class_device* cd, char* buf) 1225static ssize_t sn9c102_show_i2c_val(struct device* cd,
1226 struct device_attribute *attr, char* buf)
1221{ 1227{
1222 struct sn9c102_device* cam; 1228 struct sn9c102_device* cam;
1223 ssize_t count; 1229 ssize_t count;
@@ -1254,7 +1260,8 @@ static ssize_t sn9c102_show_i2c_val(struct class_device* cd, char* buf)
1254 1260
1255 1261
1256static ssize_t 1262static ssize_t
1257sn9c102_store_i2c_val(struct class_device* cd, const char* buf, size_t len) 1263sn9c102_store_i2c_val(struct device* cd, struct device_attribute *attr,
1264 const char* buf, size_t len)
1258{ 1265{
1259 struct sn9c102_device* cam; 1266 struct sn9c102_device* cam;
1260 u16 value; 1267 u16 value;
@@ -1299,7 +1306,8 @@ sn9c102_store_i2c_val(struct class_device* cd, const char* buf, size_t len)
1299 1306
1300 1307
1301static ssize_t 1308static ssize_t
1302sn9c102_store_green(struct class_device* cd, const char* buf, size_t len) 1309sn9c102_store_green(struct device* cd, struct device_attribute *attr,
1310 const char* buf, size_t len)
1303{ 1311{
1304 struct sn9c102_device* cam; 1312 struct sn9c102_device* cam;
1305 enum sn9c102_bridge bridge; 1313 enum sn9c102_bridge bridge;
@@ -1330,16 +1338,16 @@ sn9c102_store_green(struct class_device* cd, const char* buf, size_t len)
1330 case BRIDGE_SN9C102: 1338 case BRIDGE_SN9C102:
1331 if (value > 0x0f) 1339 if (value > 0x0f)
1332 return -EINVAL; 1340 return -EINVAL;
1333 if ((res = sn9c102_store_reg(cd, "0x11", 4)) >= 0) 1341 if ((res = sn9c102_store_reg(cd, attr, "0x11", 4)) >= 0)
1334 res = sn9c102_store_val(cd, buf, len); 1342 res = sn9c102_store_val(cd, attr, buf, len);
1335 break; 1343 break;
1336 case BRIDGE_SN9C103: 1344 case BRIDGE_SN9C103:
1337 case BRIDGE_SN9C105: 1345 case BRIDGE_SN9C105:
1338 case BRIDGE_SN9C120: 1346 case BRIDGE_SN9C120:
1339 if (value > 0x7f) 1347 if (value > 0x7f)
1340 return -EINVAL; 1348 return -EINVAL;
1341 if ((res = sn9c102_store_reg(cd, "0x07", 4)) >= 0) 1349 if ((res = sn9c102_store_reg(cd, attr, "0x07", 4)) >= 0)
1342 res = sn9c102_store_val(cd, buf, len); 1350 res = sn9c102_store_val(cd, attr, buf, len);
1343 break; 1351 break;
1344 } 1352 }
1345 1353
@@ -1348,7 +1356,8 @@ sn9c102_store_green(struct class_device* cd, const char* buf, size_t len)
1348 1356
1349 1357
1350static ssize_t 1358static ssize_t
1351sn9c102_store_blue(struct class_device* cd, const char* buf, size_t len) 1359sn9c102_store_blue(struct device* cd, struct device_attribute *attr,
1360 const char* buf, size_t len)
1352{ 1361{
1353 ssize_t res = 0; 1362 ssize_t res = 0;
1354 u16 value; 1363 u16 value;
@@ -1358,15 +1367,16 @@ sn9c102_store_blue(struct class_device* cd, const char* buf, size_t len)
1358 if (!count || value > 0x7f) 1367 if (!count || value > 0x7f)
1359 return -EINVAL; 1368 return -EINVAL;
1360 1369
1361 if ((res = sn9c102_store_reg(cd, "0x06", 4)) >= 0) 1370 if ((res = sn9c102_store_reg(cd, attr, "0x06", 4)) >= 0)
1362 res = sn9c102_store_val(cd, buf, len); 1371 res = sn9c102_store_val(cd, attr, buf, len);
1363 1372
1364 return res; 1373 return res;
1365} 1374}
1366 1375
1367 1376
1368static ssize_t 1377static ssize_t
1369sn9c102_store_red(struct class_device* cd, const char* buf, size_t len) 1378sn9c102_store_red(struct device* cd, struct device_attribute *attr,
1379 const char* buf, size_t len)
1370{ 1380{
1371 ssize_t res = 0; 1381 ssize_t res = 0;
1372 u16 value; 1382 u16 value;
@@ -1376,14 +1386,16 @@ sn9c102_store_red(struct class_device* cd, const char* buf, size_t len)
1376 if (!count || value > 0x7f) 1386 if (!count || value > 0x7f)
1377 return -EINVAL; 1387 return -EINVAL;
1378 1388
1379 if ((res = sn9c102_store_reg(cd, "0x05", 4)) >= 0) 1389 if ((res = sn9c102_store_reg(cd, attr, "0x05", 4)) >= 0)
1380 res = sn9c102_store_val(cd, buf, len); 1390 res = sn9c102_store_val(cd, attr, buf, len);
1381 1391
1382 return res; 1392 return res;
1383} 1393}
1384 1394
1385 1395
1386static ssize_t sn9c102_show_frame_header(struct class_device* cd, char* buf) 1396static ssize_t sn9c102_show_frame_header(struct device* cd,
1397 struct device_attribute *attr,
1398 char* buf)
1387{ 1399{
1388 struct sn9c102_device* cam; 1400 struct sn9c102_device* cam;
1389 ssize_t count; 1401 ssize_t count;
@@ -1402,72 +1414,63 @@ static ssize_t sn9c102_show_frame_header(struct class_device* cd, char* buf)
1402} 1414}
1403 1415
1404 1416
1405static CLASS_DEVICE_ATTR(reg, S_IRUGO | S_IWUSR, 1417static DEVICE_ATTR(reg, S_IRUGO | S_IWUSR, sn9c102_show_reg, sn9c102_store_reg);
1406 sn9c102_show_reg, sn9c102_store_reg); 1418static DEVICE_ATTR(val, S_IRUGO | S_IWUSR, sn9c102_show_val, sn9c102_store_val);
1407static CLASS_DEVICE_ATTR(val, S_IRUGO | S_IWUSR, 1419static DEVICE_ATTR(i2c_reg, S_IRUGO | S_IWUSR,
1408 sn9c102_show_val, sn9c102_store_val); 1420 sn9c102_show_i2c_reg, sn9c102_store_i2c_reg);
1409static CLASS_DEVICE_ATTR(i2c_reg, S_IRUGO | S_IWUSR, 1421static DEVICE_ATTR(i2c_val, S_IRUGO | S_IWUSR,
1410 sn9c102_show_i2c_reg, sn9c102_store_i2c_reg); 1422 sn9c102_show_i2c_val, sn9c102_store_i2c_val);
1411static CLASS_DEVICE_ATTR(i2c_val, S_IRUGO | S_IWUSR, 1423static DEVICE_ATTR(green, S_IWUGO, NULL, sn9c102_store_green);
1412 sn9c102_show_i2c_val, sn9c102_store_i2c_val); 1424static DEVICE_ATTR(blue, S_IWUGO, NULL, sn9c102_store_blue);
1413static CLASS_DEVICE_ATTR(green, S_IWUGO, NULL, sn9c102_store_green); 1425static DEVICE_ATTR(red, S_IWUGO, NULL, sn9c102_store_red);
1414static CLASS_DEVICE_ATTR(blue, S_IWUGO, NULL, sn9c102_store_blue); 1426static DEVICE_ATTR(frame_header, S_IRUGO, sn9c102_show_frame_header, NULL);
1415static CLASS_DEVICE_ATTR(red, S_IWUGO, NULL, sn9c102_store_red);
1416static CLASS_DEVICE_ATTR(frame_header, S_IRUGO,
1417 sn9c102_show_frame_header, NULL);
1418 1427
1419 1428
1420static int sn9c102_create_sysfs(struct sn9c102_device* cam) 1429static int sn9c102_create_sysfs(struct sn9c102_device* cam)
1421{ 1430{
1422 struct class_device *classdev = &(cam->v4ldev->class_dev); 1431 struct device *classdev = &(cam->v4ldev->class_dev);
1423 int err = 0; 1432 int err = 0;
1424 1433
1425 if ((err = class_device_create_file(classdev, &class_device_attr_reg))) 1434 if ((err = device_create_file(classdev, &dev_attr_reg)))
1426 goto err_out; 1435 goto err_out;
1427 if ((err = class_device_create_file(classdev, &class_device_attr_val))) 1436 if ((err = device_create_file(classdev, &dev_attr_val)))
1428 goto err_reg; 1437 goto err_reg;
1429 if ((err = class_device_create_file(classdev, 1438 if ((err = device_create_file(classdev, &dev_attr_frame_header)))
1430 &class_device_attr_frame_header)))
1431 goto err_val; 1439 goto err_val;
1432 1440
1433 if (cam->sensor.sysfs_ops) { 1441 if (cam->sensor.sysfs_ops) {
1434 if ((err = class_device_create_file(classdev, 1442 if ((err = device_create_file(classdev, &dev_attr_i2c_reg)))
1435 &class_device_attr_i2c_reg)))
1436 goto err_frame_header; 1443 goto err_frame_header;
1437 if ((err = class_device_create_file(classdev, 1444 if ((err = device_create_file(classdev, &dev_attr_i2c_val)))
1438 &class_device_attr_i2c_val)))
1439 goto err_i2c_reg; 1445 goto err_i2c_reg;
1440 } 1446 }
1441 1447
1442 if (cam->bridge == BRIDGE_SN9C101 || cam->bridge == BRIDGE_SN9C102) { 1448 if (cam->bridge == BRIDGE_SN9C101 || cam->bridge == BRIDGE_SN9C102) {
1443 if ((err = class_device_create_file(classdev, 1449 if ((err = device_create_file(classdev, &dev_attr_green)))
1444 &class_device_attr_green)))
1445 goto err_i2c_val; 1450 goto err_i2c_val;
1446 } else { 1451 } else {
1447 if ((err = class_device_create_file(classdev, 1452 if ((err = device_create_file(classdev, &dev_attr_blue)))
1448 &class_device_attr_blue)))
1449 goto err_i2c_val; 1453 goto err_i2c_val;
1450 if ((err = class_device_create_file(classdev, 1454 if ((err = device_create_file(classdev, &dev_attr_red)))
1451 &class_device_attr_red)))
1452 goto err_blue; 1455 goto err_blue;
1453 } 1456 }
1454 1457
1455 return 0; 1458 return 0;
1456 1459
1457err_blue: 1460err_blue:
1458 class_device_remove_file(classdev, &class_device_attr_blue); 1461 device_remove_file(classdev, &dev_attr_blue);
1459err_i2c_val: 1462err_i2c_val:
1460 if (cam->sensor.sysfs_ops) 1463 if (cam->sensor.sysfs_ops)
1461 class_device_remove_file(classdev, &class_device_attr_i2c_val); 1464 device_remove_file(classdev, &dev_attr_i2c_val);
1462err_i2c_reg: 1465err_i2c_reg:
1463 if (cam->sensor.sysfs_ops) 1466 if (cam->sensor.sysfs_ops)
1464 class_device_remove_file(classdev, &class_device_attr_i2c_reg); 1467 device_remove_file(classdev, &dev_attr_i2c_reg);
1465err_frame_header: 1468err_frame_header:
1466 class_device_remove_file(classdev, &class_device_attr_frame_header); 1469 device_remove_file(classdev, &dev_attr_frame_header);
1467err_val: 1470err_val:
1468 class_device_remove_file(classdev, &class_device_attr_val); 1471 device_remove_file(classdev, &dev_attr_val);
1469err_reg: 1472err_reg:
1470 class_device_remove_file(classdev, &class_device_attr_reg); 1473 device_remove_file(classdev, &dev_attr_reg);
1471err_out: 1474err_out:
1472 return err; 1475 return err;
1473} 1476}
diff --git a/drivers/media/video/stv680.c b/drivers/media/video/stv680.c
index 4dc5bc714b95..9e009a7ab863 100644
--- a/drivers/media/video/stv680.c
+++ b/drivers/media/video/stv680.c
@@ -499,13 +499,14 @@ exit:
499 * sysfs 499 * sysfs
500 ***************************************************************************/ 500 ***************************************************************************/
501#define stv680_file(name, variable, field) \ 501#define stv680_file(name, variable, field) \
502static ssize_t show_##name(struct class_device *class_dev, char *buf) \ 502static ssize_t show_##name(struct device *class_dev, \
503 struct device_attribute *attr, char *buf) \
503{ \ 504{ \
504 struct video_device *vdev = to_video_device(class_dev); \ 505 struct video_device *vdev = to_video_device(class_dev); \
505 struct usb_stv *stv = video_get_drvdata(vdev); \ 506 struct usb_stv *stv = video_get_drvdata(vdev); \
506 return sprintf(buf, field, stv->variable); \ 507 return sprintf(buf, field, stv->variable); \
507} \ 508} \
508static CLASS_DEVICE_ATTR(name, S_IRUGO, show_##name, NULL); 509static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL);
509 510
510stv680_file(model, camera_name, "%s\n"); 511stv680_file(model, camera_name, "%s\n");
511stv680_file(in_use, user, "%d\n"); 512stv680_file(in_use, user, "%d\n");
@@ -520,53 +521,53 @@ static int stv680_create_sysfs_files(struct video_device *vdev)
520{ 521{
521 int rc; 522 int rc;
522 523
523 rc = video_device_create_file(vdev, &class_device_attr_model); 524 rc = video_device_create_file(vdev, &dev_attr_model);
524 if (rc) goto err; 525 if (rc) goto err;
525 rc = video_device_create_file(vdev, &class_device_attr_in_use); 526 rc = video_device_create_file(vdev, &dev_attr_in_use);
526 if (rc) goto err_model; 527 if (rc) goto err_model;
527 rc = video_device_create_file(vdev, &class_device_attr_streaming); 528 rc = video_device_create_file(vdev, &dev_attr_streaming);
528 if (rc) goto err_inuse; 529 if (rc) goto err_inuse;
529 rc = video_device_create_file(vdev, &class_device_attr_palette); 530 rc = video_device_create_file(vdev, &dev_attr_palette);
530 if (rc) goto err_stream; 531 if (rc) goto err_stream;
531 rc = video_device_create_file(vdev, &class_device_attr_frames_total); 532 rc = video_device_create_file(vdev, &dev_attr_frames_total);
532 if (rc) goto err_pal; 533 if (rc) goto err_pal;
533 rc = video_device_create_file(vdev, &class_device_attr_frames_read); 534 rc = video_device_create_file(vdev, &dev_attr_frames_read);
534 if (rc) goto err_framtot; 535 if (rc) goto err_framtot;
535 rc = video_device_create_file(vdev, &class_device_attr_packets_dropped); 536 rc = video_device_create_file(vdev, &dev_attr_packets_dropped);
536 if (rc) goto err_framread; 537 if (rc) goto err_framread;
537 rc = video_device_create_file(vdev, &class_device_attr_decoding_errors); 538 rc = video_device_create_file(vdev, &dev_attr_decoding_errors);
538 if (rc) goto err_dropped; 539 if (rc) goto err_dropped;
539 540
540 return 0; 541 return 0;
541 542
542err_dropped: 543err_dropped:
543 video_device_remove_file(vdev, &class_device_attr_packets_dropped); 544 video_device_remove_file(vdev, &dev_attr_packets_dropped);
544err_framread: 545err_framread:
545 video_device_remove_file(vdev, &class_device_attr_frames_read); 546 video_device_remove_file(vdev, &dev_attr_frames_read);
546err_framtot: 547err_framtot:
547 video_device_remove_file(vdev, &class_device_attr_frames_total); 548 video_device_remove_file(vdev, &dev_attr_frames_total);
548err_pal: 549err_pal:
549 video_device_remove_file(vdev, &class_device_attr_palette); 550 video_device_remove_file(vdev, &dev_attr_palette);
550err_stream: 551err_stream:
551 video_device_remove_file(vdev, &class_device_attr_streaming); 552 video_device_remove_file(vdev, &dev_attr_streaming);
552err_inuse: 553err_inuse:
553 video_device_remove_file(vdev, &class_device_attr_in_use); 554 video_device_remove_file(vdev, &dev_attr_in_use);
554err_model: 555err_model:
555 video_device_remove_file(vdev, &class_device_attr_model); 556 video_device_remove_file(vdev, &dev_attr_model);
556err: 557err:
557 return rc; 558 return rc;
558} 559}
559 560
560static void stv680_remove_sysfs_files(struct video_device *vdev) 561static void stv680_remove_sysfs_files(struct video_device *vdev)
561{ 562{
562 video_device_remove_file(vdev, &class_device_attr_model); 563 video_device_remove_file(vdev, &dev_attr_model);
563 video_device_remove_file(vdev, &class_device_attr_in_use); 564 video_device_remove_file(vdev, &dev_attr_in_use);
564 video_device_remove_file(vdev, &class_device_attr_streaming); 565 video_device_remove_file(vdev, &dev_attr_streaming);
565 video_device_remove_file(vdev, &class_device_attr_palette); 566 video_device_remove_file(vdev, &dev_attr_palette);
566 video_device_remove_file(vdev, &class_device_attr_frames_total); 567 video_device_remove_file(vdev, &dev_attr_frames_total);
567 video_device_remove_file(vdev, &class_device_attr_frames_read); 568 video_device_remove_file(vdev, &dev_attr_frames_read);
568 video_device_remove_file(vdev, &class_device_attr_packets_dropped); 569 video_device_remove_file(vdev, &dev_attr_packets_dropped);
569 video_device_remove_file(vdev, &class_device_attr_decoding_errors); 570 video_device_remove_file(vdev, &dev_attr_decoding_errors);
570} 571}
571 572
572/******************************************************************** 573/********************************************************************
diff --git a/drivers/media/video/tcm825x.c b/drivers/media/video/tcm825x.c
new file mode 100644
index 000000000000..41cd6a0b0485
--- /dev/null
+++ b/drivers/media/video/tcm825x.c
@@ -0,0 +1,928 @@
1/*
2 * drivers/media/video/tcm825x.c
3 *
4 * TCM825X camera sensor driver.
5 *
6 * Copyright (C) 2007 Nokia Corporation.
7 *
8 * Contact: Sakari Ailus <sakari.ailus@nokia.com>
9 *
10 * Based on code from David Cohen <david.cohen@indt.org.br>
11 *
12 * This driver was based on ov9640 sensor driver from MontaVista
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * version 2 as published by the Free Software Foundation.
17 *
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
26 * 02110-1301 USA
27 */
28
29#include <linux/i2c.h>
30#include <media/v4l2-int-device.h>
31
32#include "tcm825x.h"
33
34/*
35 * The sensor has two fps modes: the lower one just gives half the fps
36 * at the same xclk than the high one.
37 */
38#define MAX_FPS 30
39#define MIN_FPS 8
40#define MAX_HALF_FPS (MAX_FPS / 2)
41#define HIGH_FPS_MODE_LOWER_LIMIT 14
42#define DEFAULT_FPS MAX_HALF_FPS
43
44struct tcm825x_sensor {
45 const struct tcm825x_platform_data *platform_data;
46 struct v4l2_int_device *v4l2_int_device;
47 struct i2c_client *i2c_client;
48 struct v4l2_pix_format pix;
49 struct v4l2_fract timeperframe;
50};
51
52/* list of image formats supported by TCM825X sensor */
53const static struct v4l2_fmtdesc tcm825x_formats[] = {
54 {
55 .description = "YUYV (YUV 4:2:2), packed",
56 .pixelformat = V4L2_PIX_FMT_UYVY,
57 }, {
58 /* Note: V4L2 defines RGB565 as:
59 *
60 * Byte 0 Byte 1
61 * g2 g1 g0 r4 r3 r2 r1 r0 b4 b3 b2 b1 b0 g5 g4 g3
62 *
63 * We interpret RGB565 as:
64 *
65 * Byte 0 Byte 1
66 * g2 g1 g0 b4 b3 b2 b1 b0 r4 r3 r2 r1 r0 g5 g4 g3
67 */
68 .description = "RGB565, le",
69 .pixelformat = V4L2_PIX_FMT_RGB565,
70 },
71};
72
73#define TCM825X_NUM_CAPTURE_FORMATS ARRAY_SIZE(tcm825x_formats)
74
75/*
76 * TCM825X register configuration for all combinations of pixel format and
77 * image size
78 */
79const static struct tcm825x_reg subqcif = { 0x20, TCM825X_PICSIZ };
80const static struct tcm825x_reg qcif = { 0x18, TCM825X_PICSIZ };
81const static struct tcm825x_reg cif = { 0x14, TCM825X_PICSIZ };
82const static struct tcm825x_reg qqvga = { 0x0c, TCM825X_PICSIZ };
83const static struct tcm825x_reg qvga = { 0x04, TCM825X_PICSIZ };
84const static struct tcm825x_reg vga = { 0x00, TCM825X_PICSIZ };
85
86const static struct tcm825x_reg yuv422 = { 0x00, TCM825X_PICFMT };
87const static struct tcm825x_reg rgb565 = { 0x02, TCM825X_PICFMT };
88
89/* Our own specific controls */
90#define V4L2_CID_ALC V4L2_CID_PRIVATE_BASE
91#define V4L2_CID_H_EDGE_EN V4L2_CID_PRIVATE_BASE + 1
92#define V4L2_CID_V_EDGE_EN V4L2_CID_PRIVATE_BASE + 2
93#define V4L2_CID_LENS V4L2_CID_PRIVATE_BASE + 3
94#define V4L2_CID_MAX_EXPOSURE_TIME V4L2_CID_PRIVATE_BASE + 4
95#define V4L2_CID_LAST_PRIV V4L2_CID_MAX_EXPOSURE_TIME
96
97/* Video controls */
98static struct vcontrol {
99 struct v4l2_queryctrl qc;
100 u16 reg;
101 u16 start_bit;
102} video_control[] = {
103 {
104 {
105 .id = V4L2_CID_GAIN,
106 .type = V4L2_CTRL_TYPE_INTEGER,
107 .name = "Gain",
108 .minimum = 0,
109 .maximum = 63,
110 .step = 1,
111 },
112 .reg = TCM825X_AG,
113 .start_bit = 0,
114 },
115 {
116 {
117 .id = V4L2_CID_RED_BALANCE,
118 .type = V4L2_CTRL_TYPE_INTEGER,
119 .name = "Red Balance",
120 .minimum = 0,
121 .maximum = 255,
122 .step = 1,
123 },
124 .reg = TCM825X_MRG,
125 .start_bit = 0,
126 },
127 {
128 {
129 .id = V4L2_CID_BLUE_BALANCE,
130 .type = V4L2_CTRL_TYPE_INTEGER,
131 .name = "Blue Balance",
132 .minimum = 0,
133 .maximum = 255,
134 .step = 1,
135 },
136 .reg = TCM825X_MBG,
137 .start_bit = 0,
138 },
139 {
140 {
141 .id = V4L2_CID_AUTO_WHITE_BALANCE,
142 .type = V4L2_CTRL_TYPE_BOOLEAN,
143 .name = "Auto White Balance",
144 .minimum = 0,
145 .maximum = 1,
146 .step = 0,
147 },
148 .reg = TCM825X_AWBSW,
149 .start_bit = 7,
150 },
151 {
152 {
153 .id = V4L2_CID_EXPOSURE,
154 .type = V4L2_CTRL_TYPE_INTEGER,
155 .name = "Exposure Time",
156 .minimum = 0,
157 .maximum = 0x1fff,
158 .step = 1,
159 },
160 .reg = TCM825X_ESRSPD_U,
161 .start_bit = 0,
162 },
163 {
164 {
165 .id = V4L2_CID_HFLIP,
166 .type = V4L2_CTRL_TYPE_BOOLEAN,
167 .name = "Mirror Image",
168 .minimum = 0,
169 .maximum = 1,
170 .step = 0,
171 },
172 .reg = TCM825X_H_INV,
173 .start_bit = 6,
174 },
175 {
176 {
177 .id = V4L2_CID_VFLIP,
178 .type = V4L2_CTRL_TYPE_BOOLEAN,
179 .name = "Vertical Flip",
180 .minimum = 0,
181 .maximum = 1,
182 .step = 0,
183 },
184 .reg = TCM825X_V_INV,
185 .start_bit = 7,
186 },
187 /* Private controls */
188 {
189 {
190 .id = V4L2_CID_ALC,
191 .type = V4L2_CTRL_TYPE_BOOLEAN,
192 .name = "Auto Luminance Control",
193 .minimum = 0,
194 .maximum = 1,
195 .step = 0,
196 },
197 .reg = TCM825X_ALCSW,
198 .start_bit = 7,
199 },
200 {
201 {
202 .id = V4L2_CID_H_EDGE_EN,
203 .type = V4L2_CTRL_TYPE_INTEGER,
204 .name = "Horizontal Edge Enhancement",
205 .minimum = 0,
206 .maximum = 0xff,
207 .step = 1,
208 },
209 .reg = TCM825X_HDTG,
210 .start_bit = 0,
211 },
212 {
213 {
214 .id = V4L2_CID_V_EDGE_EN,
215 .type = V4L2_CTRL_TYPE_INTEGER,
216 .name = "Vertical Edge Enhancement",
217 .minimum = 0,
218 .maximum = 0xff,
219 .step = 1,
220 },
221 .reg = TCM825X_VDTG,
222 .start_bit = 0,
223 },
224 {
225 {
226 .id = V4L2_CID_LENS,
227 .type = V4L2_CTRL_TYPE_INTEGER,
228 .name = "Lens Shading Compensation",
229 .minimum = 0,
230 .maximum = 0x3f,
231 .step = 1,
232 },
233 .reg = TCM825X_LENS,
234 .start_bit = 0,
235 },
236 {
237 {
238 .id = V4L2_CID_MAX_EXPOSURE_TIME,
239 .type = V4L2_CTRL_TYPE_INTEGER,
240 .name = "Maximum Exposure Time",
241 .minimum = 0,
242 .maximum = 0x3,
243 .step = 1,
244 },
245 .reg = TCM825X_ESRLIM,
246 .start_bit = 5,
247 },
248};
249
250
251const static struct tcm825x_reg *tcm825x_siz_reg[NUM_IMAGE_SIZES] =
252{ &subqcif, &qqvga, &qcif, &qvga, &cif, &vga };
253
254const static struct tcm825x_reg *tcm825x_fmt_reg[NUM_PIXEL_FORMATS] =
255{ &yuv422, &rgb565 };
256
257/*
258 * Read a value from a register in an TCM825X sensor device. The value is
259 * returned in 'val'.
260 * Returns zero if successful, or non-zero otherwise.
261 */
262static int tcm825x_read_reg(struct i2c_client *client, int reg)
263{
264 int err;
265 struct i2c_msg msg[2];
266 u8 reg_buf, data_buf = 0;
267
268 if (!client->adapter)
269 return -ENODEV;
270
271 msg[0].addr = client->addr;
272 msg[0].flags = 0;
273 msg[0].len = 1;
274 msg[0].buf = &reg_buf;
275 msg[1].addr = client->addr;
276 msg[1].flags = I2C_M_RD;
277 msg[1].len = 1;
278 msg[1].buf = &data_buf;
279
280 reg_buf = reg;
281
282 err = i2c_transfer(client->adapter, msg, 2);
283 if (err < 0)
284 return err;
285 return data_buf;
286}
287
288/*
289 * Write a value to a register in an TCM825X sensor device.
290 * Returns zero if successful, or non-zero otherwise.
291 */
292static int tcm825x_write_reg(struct i2c_client *client, u8 reg, u8 val)
293{
294 int err;
295 struct i2c_msg msg[1];
296 unsigned char data[2];
297
298 if (!client->adapter)
299 return -ENODEV;
300
301 msg->addr = client->addr;
302 msg->flags = 0;
303 msg->len = 2;
304 msg->buf = data;
305 data[0] = reg;
306 data[1] = val;
307 err = i2c_transfer(client->adapter, msg, 1);
308 if (err >= 0)
309 return 0;
310 return err;
311}
312
313static int __tcm825x_write_reg_mask(struct i2c_client *client,
314 u8 reg, u8 val, u8 mask)
315{
316 int rc;
317
318 /* need to do read - modify - write */
319 rc = tcm825x_read_reg(client, reg);
320 if (rc < 0)
321 return rc;
322
323 rc &= (~mask); /* Clear the masked bits */
324 val &= mask; /* Enforce mask on value */
325 val |= rc;
326
327 /* write the new value to the register */
328 rc = tcm825x_write_reg(client, reg, val);
329 if (rc)
330 return rc;
331
332 return 0;
333}
334
335#define tcm825x_write_reg_mask(client, regmask, val) \
336 __tcm825x_write_reg_mask(client, TCM825X_ADDR((regmask)), val, \
337 TCM825X_MASK((regmask)))
338
339
340/*
341 * Initialize a list of TCM825X registers.
342 * The list of registers is terminated by the pair of values
343 * { TCM825X_REG_TERM, TCM825X_VAL_TERM }.
344 * Returns zero if successful, or non-zero otherwise.
345 */
346static int tcm825x_write_default_regs(struct i2c_client *client,
347 const struct tcm825x_reg *reglist)
348{
349 int err;
350 const struct tcm825x_reg *next = reglist;
351
352 while (!((next->reg == TCM825X_REG_TERM)
353 && (next->val == TCM825X_VAL_TERM))) {
354 err = tcm825x_write_reg(client, next->reg, next->val);
355 if (err) {
356 dev_err(&client->dev, "register writing failed\n");
357 return err;
358 }
359 next++;
360 }
361
362 return 0;
363}
364
365static struct vcontrol *find_vctrl(int id)
366{
367 int i;
368
369 if (id < V4L2_CID_BASE)
370 return NULL;
371
372 for (i = 0; i < ARRAY_SIZE(video_control); i++)
373 if (video_control[i].qc.id == id)
374 return &video_control[i];
375
376 return NULL;
377}
378
379/*
380 * Find the best match for a requested image capture size. The best match
381 * is chosen as the nearest match that has the same number or fewer pixels
382 * as the requested size, or the smallest image size if the requested size
383 * has fewer pixels than the smallest image.
384 */
385static enum image_size tcm825x_find_size(struct v4l2_int_device *s,
386 unsigned int width,
387 unsigned int height)
388{
389 enum image_size isize;
390 unsigned long pixels = width * height;
391 struct tcm825x_sensor *sensor = s->priv;
392
393 for (isize = subQCIF; isize < VGA; isize++) {
394 if (tcm825x_sizes[isize + 1].height
395 * tcm825x_sizes[isize + 1].width > pixels) {
396 dev_dbg(&sensor->i2c_client->dev, "size %d\n", isize);
397
398 return isize;
399 }
400 }
401
402 dev_dbg(&sensor->i2c_client->dev, "format default VGA\n");
403
404 return VGA;
405}
406
407/*
408 * Configure the TCM825X for current image size, pixel format, and
409 * frame period. fper is the frame period (in seconds) expressed as a
410 * fraction. Returns zero if successful, or non-zero otherwise. The
411 * actual frame period is returned in fper.
412 */
413static int tcm825x_configure(struct v4l2_int_device *s)
414{
415 struct tcm825x_sensor *sensor = s->priv;
416 struct v4l2_pix_format *pix = &sensor->pix;
417 enum image_size isize = tcm825x_find_size(s, pix->width, pix->height);
418 struct v4l2_fract *fper = &sensor->timeperframe;
419 enum pixel_format pfmt;
420 int err;
421 u32 tgt_fps;
422 u8 val;
423
424 /* common register initialization */
425 err = tcm825x_write_default_regs(
426 sensor->i2c_client, sensor->platform_data->default_regs());
427 if (err)
428 return err;
429
430 /* configure image size */
431 val = tcm825x_siz_reg[isize]->val;
432 dev_dbg(&sensor->i2c_client->dev,
433 "configuring image size %d\n", isize);
434 err = tcm825x_write_reg_mask(sensor->i2c_client,
435 tcm825x_siz_reg[isize]->reg, val);
436 if (err)
437 return err;
438
439 /* configure pixel format */
440 switch (pix->pixelformat) {
441 default:
442 case V4L2_PIX_FMT_RGB565:
443 pfmt = RGB565;
444 break;
445 case V4L2_PIX_FMT_UYVY:
446 pfmt = YUV422;
447 break;
448 }
449
450 dev_dbg(&sensor->i2c_client->dev,
451 "configuring pixel format %d\n", pfmt);
452 val = tcm825x_fmt_reg[pfmt]->val;
453
454 err = tcm825x_write_reg_mask(sensor->i2c_client,
455 tcm825x_fmt_reg[pfmt]->reg, val);
456 if (err)
457 return err;
458
459 /*
460 * For frame rate < 15, the FPS reg (addr 0x02, bit 7) must be
461 * set. Frame rate will be halved from the normal.
462 */
463 tgt_fps = fper->denominator / fper->numerator;
464 if (tgt_fps <= HIGH_FPS_MODE_LOWER_LIMIT) {
465 val = tcm825x_read_reg(sensor->i2c_client, 0x02);
466 val |= 0x80;
467 tcm825x_write_reg(sensor->i2c_client, 0x02, val);
468 }
469
470 return 0;
471}
472
473static int ioctl_queryctrl(struct v4l2_int_device *s,
474 struct v4l2_queryctrl *qc)
475{
476 struct vcontrol *control;
477
478 control = find_vctrl(qc->id);
479
480 if (control == NULL)
481 return -EINVAL;
482
483 *qc = control->qc;
484
485 return 0;
486}
487
488static int ioctl_g_ctrl(struct v4l2_int_device *s,
489 struct v4l2_control *vc)
490{
491 struct tcm825x_sensor *sensor = s->priv;
492 struct i2c_client *client = sensor->i2c_client;
493 int val, r;
494 struct vcontrol *lvc;
495
496 /* exposure time is special, spread accross 2 registers */
497 if (vc->id == V4L2_CID_EXPOSURE) {
498 int val_lower, val_upper;
499
500 val_upper = tcm825x_read_reg(client,
501 TCM825X_ADDR(TCM825X_ESRSPD_U));
502 if (val_upper < 0)
503 return val_upper;
504 val_lower = tcm825x_read_reg(client,
505 TCM825X_ADDR(TCM825X_ESRSPD_L));
506 if (val_lower < 0)
507 return val_lower;
508
509 vc->value = ((val_upper & 0x1f) << 8) | (val_lower);
510 return 0;
511 }
512
513 lvc = find_vctrl(vc->id);
514 if (lvc == NULL)
515 return -EINVAL;
516
517 r = tcm825x_read_reg(client, TCM825X_ADDR(lvc->reg));
518 if (r < 0)
519 return r;
520 val = r & TCM825X_MASK(lvc->reg);
521 val >>= lvc->start_bit;
522
523 if (val < 0)
524 return val;
525
526 vc->value = val;
527 return 0;
528}
529
530static int ioctl_s_ctrl(struct v4l2_int_device *s,
531 struct v4l2_control *vc)
532{
533 struct tcm825x_sensor *sensor = s->priv;
534 struct i2c_client *client = sensor->i2c_client;
535 struct vcontrol *lvc;
536 int val = vc->value;
537
538 /* exposure time is special, spread accross 2 registers */
539 if (vc->id == V4L2_CID_EXPOSURE) {
540 int val_lower, val_upper;
541 val_lower = val & TCM825X_MASK(TCM825X_ESRSPD_L);
542 val_upper = (val >> 8) & TCM825X_MASK(TCM825X_ESRSPD_U);
543
544 if (tcm825x_write_reg_mask(client,
545 TCM825X_ESRSPD_U, val_upper))
546 return -EIO;
547
548 if (tcm825x_write_reg_mask(client,
549 TCM825X_ESRSPD_L, val_lower))
550 return -EIO;
551
552 return 0;
553 }
554
555 lvc = find_vctrl(vc->id);
556 if (lvc == NULL)
557 return -EINVAL;
558
559 val = val << lvc->start_bit;
560 if (tcm825x_write_reg_mask(client, lvc->reg, val))
561 return -EIO;
562
563 return 0;
564}
565
566static int ioctl_enum_fmt_cap(struct v4l2_int_device *s,
567 struct v4l2_fmtdesc *fmt)
568{
569 int index = fmt->index;
570
571 switch (fmt->type) {
572 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
573 if (index >= TCM825X_NUM_CAPTURE_FORMATS)
574 return -EINVAL;
575 break;
576
577 default:
578 return -EINVAL;
579 }
580
581 fmt->flags = tcm825x_formats[index].flags;
582 strlcpy(fmt->description, tcm825x_formats[index].description,
583 sizeof(fmt->description));
584 fmt->pixelformat = tcm825x_formats[index].pixelformat;
585
586 return 0;
587}
588
589static int ioctl_try_fmt_cap(struct v4l2_int_device *s,
590 struct v4l2_format *f)
591{
592 struct tcm825x_sensor *sensor = s->priv;
593 enum image_size isize;
594 int ifmt;
595 struct v4l2_pix_format *pix = &f->fmt.pix;
596
597 isize = tcm825x_find_size(s, pix->width, pix->height);
598 dev_dbg(&sensor->i2c_client->dev, "isize = %d num_capture = %lu\n",
599 isize, (unsigned long)TCM825X_NUM_CAPTURE_FORMATS);
600
601 pix->width = tcm825x_sizes[isize].width;
602 pix->height = tcm825x_sizes[isize].height;
603
604 for (ifmt = 0; ifmt < TCM825X_NUM_CAPTURE_FORMATS; ifmt++)
605 if (pix->pixelformat == tcm825x_formats[ifmt].pixelformat)
606 break;
607
608 if (ifmt == TCM825X_NUM_CAPTURE_FORMATS)
609 ifmt = 0; /* Default = YUV 4:2:2 */
610
611 pix->pixelformat = tcm825x_formats[ifmt].pixelformat;
612 pix->field = V4L2_FIELD_NONE;
613 pix->bytesperline = pix->width * TCM825X_BYTES_PER_PIXEL;
614 pix->sizeimage = pix->bytesperline * pix->height;
615 pix->priv = 0;
616 dev_dbg(&sensor->i2c_client->dev, "format = 0x%08x\n",
617 pix->pixelformat);
618
619 switch (pix->pixelformat) {
620 case V4L2_PIX_FMT_UYVY:
621 default:
622 pix->colorspace = V4L2_COLORSPACE_JPEG;
623 break;
624 case V4L2_PIX_FMT_RGB565:
625 pix->colorspace = V4L2_COLORSPACE_SRGB;
626 break;
627 }
628
629 return 0;
630}
631
632static int ioctl_s_fmt_cap(struct v4l2_int_device *s,
633 struct v4l2_format *f)
634{
635 struct tcm825x_sensor *sensor = s->priv;
636 struct v4l2_pix_format *pix = &f->fmt.pix;
637 int rval;
638
639 rval = ioctl_try_fmt_cap(s, f);
640 if (rval)
641 return rval;
642
643 rval = tcm825x_configure(s);
644
645 sensor->pix = *pix;
646
647 return rval;
648}
649
650static int ioctl_g_fmt_cap(struct v4l2_int_device *s,
651 struct v4l2_format *f)
652{
653 struct tcm825x_sensor *sensor = s->priv;
654
655 f->fmt.pix = sensor->pix;
656
657 return 0;
658}
659
660static int ioctl_g_parm(struct v4l2_int_device *s,
661 struct v4l2_streamparm *a)
662{
663 struct tcm825x_sensor *sensor = s->priv;
664 struct v4l2_captureparm *cparm = &a->parm.capture;
665
666 if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
667 return -EINVAL;
668
669 memset(a, 0, sizeof(*a));
670 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
671
672 cparm->capability = V4L2_CAP_TIMEPERFRAME;
673 cparm->timeperframe = sensor->timeperframe;
674
675 return 0;
676}
677
678static int ioctl_s_parm(struct v4l2_int_device *s,
679 struct v4l2_streamparm *a)
680{
681 struct tcm825x_sensor *sensor = s->priv;
682 struct v4l2_fract *timeperframe = &a->parm.capture.timeperframe;
683 u32 tgt_fps; /* target frames per secound */
684 int rval;
685
686 if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
687 return -EINVAL;
688
689 if ((timeperframe->numerator == 0)
690 || (timeperframe->denominator == 0)) {
691 timeperframe->denominator = DEFAULT_FPS;
692 timeperframe->numerator = 1;
693 }
694
695 tgt_fps = timeperframe->denominator / timeperframe->numerator;
696
697 if (tgt_fps > MAX_FPS) {
698 timeperframe->denominator = MAX_FPS;
699 timeperframe->numerator = 1;
700 } else if (tgt_fps < MIN_FPS) {
701 timeperframe->denominator = MIN_FPS;
702 timeperframe->numerator = 1;
703 }
704
705 sensor->timeperframe = *timeperframe;
706
707 rval = tcm825x_configure(s);
708
709 return rval;
710}
711
712static int ioctl_s_power(struct v4l2_int_device *s, int on)
713{
714 struct tcm825x_sensor *sensor = s->priv;
715
716 return sensor->platform_data->power_set(on);
717}
718
719/*
720 * Given the image capture format in pix, the nominal frame period in
721 * timeperframe, calculate the required xclk frequency.
722 *
723 * TCM825X input frequency characteristics are:
724 * Minimum 11.9 MHz, Typical 24.57 MHz and maximum 25/27 MHz
725 */
726
727static int ioctl_g_ifparm(struct v4l2_int_device *s, struct v4l2_ifparm *p)
728{
729 struct tcm825x_sensor *sensor = s->priv;
730 struct v4l2_fract *timeperframe = &sensor->timeperframe;
731 u32 tgt_xclk; /* target xclk */
732 u32 tgt_fps; /* target frames per secound */
733 int rval;
734
735 rval = sensor->platform_data->ifparm(p);
736 if (rval)
737 return rval;
738
739 tgt_fps = timeperframe->denominator / timeperframe->numerator;
740
741 tgt_xclk = (tgt_fps <= HIGH_FPS_MODE_LOWER_LIMIT) ?
742 (2457 * tgt_fps) / MAX_HALF_FPS :
743 (2457 * tgt_fps) / MAX_FPS;
744 tgt_xclk *= 10000;
745
746 tgt_xclk = min(tgt_xclk, (u32)TCM825X_XCLK_MAX);
747 tgt_xclk = max(tgt_xclk, (u32)TCM825X_XCLK_MIN);
748
749 p->u.bt656.clock_curr = tgt_xclk;
750
751 return 0;
752}
753
754static int ioctl_g_needs_reset(struct v4l2_int_device *s, void *buf)
755{
756 struct tcm825x_sensor *sensor = s->priv;
757
758 return sensor->platform_data->needs_reset(s, buf, &sensor->pix);
759}
760
761static int ioctl_reset(struct v4l2_int_device *s)
762{
763 return -EBUSY;
764}
765
766static int ioctl_init(struct v4l2_int_device *s)
767{
768 return tcm825x_configure(s);
769}
770
771static int ioctl_dev_exit(struct v4l2_int_device *s)
772{
773 return 0;
774}
775
776static int ioctl_dev_init(struct v4l2_int_device *s)
777{
778 struct tcm825x_sensor *sensor = s->priv;
779 int r;
780
781 r = tcm825x_read_reg(sensor->i2c_client, 0x01);
782 if (r < 0)
783 return r;
784 if (r == 0) {
785 dev_err(&sensor->i2c_client->dev, "device not detected\n");
786 return -EIO;
787 }
788 return 0;
789}
790
791static struct v4l2_int_ioctl_desc tcm825x_ioctl_desc[] = {
792 { vidioc_int_dev_init_num,
793 (v4l2_int_ioctl_func *)ioctl_dev_init },
794 { vidioc_int_dev_exit_num,
795 (v4l2_int_ioctl_func *)ioctl_dev_exit },
796 { vidioc_int_s_power_num,
797 (v4l2_int_ioctl_func *)ioctl_s_power },
798 { vidioc_int_g_ifparm_num,
799 (v4l2_int_ioctl_func *)ioctl_g_ifparm },
800 { vidioc_int_g_needs_reset_num,
801 (v4l2_int_ioctl_func *)ioctl_g_needs_reset },
802 { vidioc_int_reset_num,
803 (v4l2_int_ioctl_func *)ioctl_reset },
804 { vidioc_int_init_num,
805 (v4l2_int_ioctl_func *)ioctl_init },
806 { vidioc_int_enum_fmt_cap_num,
807 (v4l2_int_ioctl_func *)ioctl_enum_fmt_cap },
808 { vidioc_int_try_fmt_cap_num,
809 (v4l2_int_ioctl_func *)ioctl_try_fmt_cap },
810 { vidioc_int_g_fmt_cap_num,
811 (v4l2_int_ioctl_func *)ioctl_g_fmt_cap },
812 { vidioc_int_s_fmt_cap_num,
813 (v4l2_int_ioctl_func *)ioctl_s_fmt_cap },
814 { vidioc_int_g_parm_num,
815 (v4l2_int_ioctl_func *)ioctl_g_parm },
816 { vidioc_int_s_parm_num,
817 (v4l2_int_ioctl_func *)ioctl_s_parm },
818 { vidioc_int_queryctrl_num,
819 (v4l2_int_ioctl_func *)ioctl_queryctrl },
820 { vidioc_int_g_ctrl_num,
821 (v4l2_int_ioctl_func *)ioctl_g_ctrl },
822 { vidioc_int_s_ctrl_num,
823 (v4l2_int_ioctl_func *)ioctl_s_ctrl },
824};
825
826static struct v4l2_int_slave tcm825x_slave = {
827 .ioctls = tcm825x_ioctl_desc,
828 .num_ioctls = ARRAY_SIZE(tcm825x_ioctl_desc),
829};
830
831static struct tcm825x_sensor tcm825x;
832
833static struct v4l2_int_device tcm825x_int_device = {
834 .module = THIS_MODULE,
835 .name = TCM825X_NAME,
836 .priv = &tcm825x,
837 .type = v4l2_int_type_slave,
838 .u = {
839 .slave = &tcm825x_slave,
840 },
841};
842
843static int tcm825x_probe(struct i2c_client *client)
844{
845 struct tcm825x_sensor *sensor = &tcm825x;
846 int rval;
847
848 if (i2c_get_clientdata(client))
849 return -EBUSY;
850
851 sensor->platform_data = client->dev.platform_data;
852
853 if (sensor->platform_data == NULL
854 && !sensor->platform_data->is_okay())
855 return -ENODEV;
856
857 sensor->v4l2_int_device = &tcm825x_int_device;
858
859 sensor->i2c_client = client;
860 i2c_set_clientdata(client, sensor);
861
862 /* Make the default capture format QVGA RGB565 */
863 sensor->pix.width = tcm825x_sizes[QVGA].width;
864 sensor->pix.height = tcm825x_sizes[QVGA].height;
865 sensor->pix.pixelformat = V4L2_PIX_FMT_RGB565;
866
867 rval = v4l2_int_device_register(sensor->v4l2_int_device);
868 if (rval)
869 i2c_set_clientdata(client, NULL);
870
871 return rval;
872}
873
874static int __exit tcm825x_remove(struct i2c_client *client)
875{
876 struct tcm825x_sensor *sensor = i2c_get_clientdata(client);
877
878 if (!client->adapter)
879 return -ENODEV; /* our client isn't attached */
880
881 v4l2_int_device_unregister(sensor->v4l2_int_device);
882 i2c_set_clientdata(client, NULL);
883
884 return 0;
885}
886
887static struct i2c_driver tcm825x_i2c_driver = {
888 .driver = {
889 .name = TCM825X_NAME,
890 },
891 .probe = tcm825x_probe,
892 .remove = __exit_p(tcm825x_remove),
893};
894
895static struct tcm825x_sensor tcm825x = {
896 .timeperframe = {
897 .numerator = 1,
898 .denominator = DEFAULT_FPS,
899 },
900};
901
902static int __init tcm825x_init(void)
903{
904 int rval;
905
906 rval = i2c_add_driver(&tcm825x_i2c_driver);
907 if (rval)
908 printk(KERN_INFO "%s: failed registering " TCM825X_NAME "\n",
909 __FUNCTION__);
910
911 return rval;
912}
913
914static void __exit tcm825x_exit(void)
915{
916 i2c_del_driver(&tcm825x_i2c_driver);
917}
918
919/*
920 * FIXME: Menelaus isn't ready (?) at module_init stage, so use
921 * late_initcall for now.
922 */
923late_initcall(tcm825x_init);
924module_exit(tcm825x_exit);
925
926MODULE_AUTHOR("Sakari Ailus <sakari.ailus@nokia.com>");
927MODULE_DESCRIPTION("TCM825x camera sensor driver");
928MODULE_LICENSE("GPL");
diff --git a/drivers/media/video/tcm825x.h b/drivers/media/video/tcm825x.h
new file mode 100644
index 000000000000..966765b66b3a
--- /dev/null
+++ b/drivers/media/video/tcm825x.h
@@ -0,0 +1,199 @@
1/*
2 * drivers/media/video/tcm825x.h
3 *
4 * Register definitions for the TCM825X CameraChip.
5 *
6 * Author: David Cohen (david.cohen@indt.org.br)
7 *
8 * This file is licensed under the terms of the GNU General Public License
9 * version 2. This program is licensed "as is" without any warranty of any
10 * kind, whether express or implied.
11 *
12 * This file was based on ov9640.h from MontaVista
13 */
14
15#ifndef TCM825X_H
16#define TCM825X_H
17
18#include <linux/videodev2.h>
19
20#include <media/v4l2-int-device.h>
21
22#define TCM825X_NAME "tcm825x"
23
24#define TCM825X_MASK(x) x & 0x00ff
25#define TCM825X_ADDR(x) (x & 0xff00) >> 8
26
27/* The TCM825X I2C sensor chip has a fixed slave address of 0x3d. */
28#define TCM825X_I2C_ADDR 0x3d
29
30/*
31 * define register offsets for the TCM825X sensor chip
32 * OFFSET(8 bits) + MASK(8 bits)
33 * MASK bit 4 and 3 are used when the register uses more than one address
34 */
35#define TCM825X_FPS 0x0280
36#define TCM825X_ACF 0x0240
37#define TCM825X_DOUTBUF 0x020C
38#define TCM825X_DCLKP 0x0202
39#define TCM825X_ACFDET 0x0201
40#define TCM825X_DOUTSW 0x0380
41#define TCM825X_DATAHZ 0x0340
42#define TCM825X_PICSIZ 0x033c
43#define TCM825X_PICFMT 0x0302
44#define TCM825X_V_INV 0x0480
45#define TCM825X_H_INV 0x0440
46#define TCM825X_ESRLSW 0x0430
47#define TCM825X_V_LENGTH 0x040F
48#define TCM825X_ALCSW 0x0580
49#define TCM825X_ESRLIM 0x0560
50#define TCM825X_ESRSPD_U 0x051F
51#define TCM825X_ESRSPD_L 0x06FF
52#define TCM825X_AG 0x07FF
53#define TCM825X_ESRSPD2 0x06FF
54#define TCM825X_ALCMODE 0x0830
55#define TCM825X_ALCH 0x080F
56#define TCM825X_ALCL 0x09FF
57#define TCM825X_AWBSW 0x0A80
58#define TCM825X_MRG 0x0BFF
59#define TCM825X_MBG 0x0CFF
60#define TCM825X_GAMSW 0x0D80
61#define TCM825X_HDTG 0x0EFF
62#define TCM825X_VDTG 0x0FFF
63#define TCM825X_HDTCORE 0x10F0
64#define TCM825X_VDTCORE 0x100F
65#define TCM825X_CONT 0x11FF
66#define TCM825X_BRIGHT 0x12FF
67#define TCM825X_VHUE 0x137F
68#define TCM825X_UHUE 0x147F
69#define TCM825X_VGAIN 0x153F
70#define TCM825X_UGAIN 0x163F
71#define TCM825X_UVCORE 0x170F
72#define TCM825X_SATU 0x187F
73#define TCM825X_MHMODE 0x1980
74#define TCM825X_MHLPFSEL 0x1940
75#define TCM825X_YMODE 0x1930
76#define TCM825X_MIXHG 0x1907
77#define TCM825X_LENS 0x1A3F
78#define TCM825X_AGLIM 0x1BE0
79#define TCM825X_LENSRPOL 0x1B10
80#define TCM825X_LENSRGAIN 0x1B0F
81#define TCM825X_ES100S 0x1CFF
82#define TCM825X_ES120S 0x1DFF
83#define TCM825X_DMASK 0x1EC0
84#define TCM825X_CODESW 0x1E20
85#define TCM825X_CODESEL 0x1E10
86#define TCM825X_TESPIC 0x1E04
87#define TCM825X_PICSEL 0x1E03
88#define TCM825X_HNUM 0x20FF
89#define TCM825X_VOUTPH 0x287F
90#define TCM825X_ESROUT 0x327F
91#define TCM825X_ESROUT2 0x33FF
92#define TCM825X_AGOUT 0x34FF
93#define TCM825X_DGOUT 0x353F
94#define TCM825X_AGSLOW1 0x39C0
95#define TCM825X_FLLSMODE 0x3930
96#define TCM825X_FLLSLIM 0x390F
97#define TCM825X_DETSEL 0x3AF0
98#define TCM825X_ACDETNC 0x3A0F
99#define TCM825X_AGSLOW2 0x3BC0
100#define TCM825X_DG 0x3B3F
101#define TCM825X_REJHLEV 0x3CFF
102#define TCM825X_ALCLOCK 0x3D80
103#define TCM825X_FPSLNKSW 0x3D40
104#define TCM825X_ALCSPD 0x3D30
105#define TCM825X_REJH 0x3D03
106#define TCM825X_SHESRSW 0x3E80
107#define TCM825X_ESLIMSEL 0x3E40
108#define TCM825X_SHESRSPD 0x3E30
109#define TCM825X_ELSTEP 0x3E0C
110#define TCM825X_ELSTART 0x3E03
111#define TCM825X_AGMIN 0x3FFF
112#define TCM825X_PREGRG 0x423F
113#define TCM825X_PREGBG 0x433F
114#define TCM825X_PRERG 0x443F
115#define TCM825X_PREBG 0x453F
116#define TCM825X_MSKBR 0x477F
117#define TCM825X_MSKGR 0x487F
118#define TCM825X_MSKRB 0x497F
119#define TCM825X_MSKGB 0x4A7F
120#define TCM825X_MSKRG 0x4B7F
121#define TCM825X_MSKBG 0x4C7F
122#define TCM825X_HDTCSW 0x4D80
123#define TCM825X_VDTCSW 0x4D40
124#define TCM825X_DTCYL 0x4D3F
125#define TCM825X_HDTPSW 0x4E80
126#define TCM825X_VDTPSW 0x4E40
127#define TCM825X_DTCGAIN 0x4E3F
128#define TCM825X_DTLLIMSW 0x4F10
129#define TCM825X_DTLYLIM 0x4F0F
130#define TCM825X_YLCUTLMSK 0x5080
131#define TCM825X_YLCUTL 0x503F
132#define TCM825X_YLCUTHMSK 0x5180
133#define TCM825X_YLCUTH 0x513F
134#define TCM825X_UVSKNC 0x527F
135#define TCM825X_UVLJ 0x537F
136#define TCM825X_WBGMIN 0x54FF
137#define TCM825X_WBGMAX 0x55FF
138#define TCM825X_WBSPDUP 0x5603
139#define TCM825X_ALLAREA 0x5820
140#define TCM825X_WBLOCK 0x5810
141#define TCM825X_WB2SP 0x580F
142#define TCM825X_KIZUSW 0x5920
143#define TCM825X_PBRSW 0x5910
144#define TCM825X_ABCSW 0x5903
145#define TCM825X_PBDLV 0x5AFF
146#define TCM825X_PBC1LV 0x5BFF
147
148#define TCM825X_NUM_REGS (TCM825X_ADDR(TCM825X_PBC1LV) + 1)
149
150#define TCM825X_BYTES_PER_PIXEL 2
151
152#define TCM825X_REG_TERM 0xff /* terminating list entry for reg */
153#define TCM825X_VAL_TERM 0xff /* terminating list entry for val */
154
155/* define a structure for tcm825x register initialization values */
156struct tcm825x_reg {
157 u8 val;
158 u16 reg;
159};
160
161enum image_size { subQCIF = 0, QQVGA, QCIF, QVGA, CIF, VGA };
162enum pixel_format { YUV422 = 0, RGB565 };
163#define NUM_IMAGE_SIZES 6
164#define NUM_PIXEL_FORMATS 2
165
166#define TCM825X_XCLK_MIN 11900000
167#define TCM825X_XCLK_MAX 25000000
168
169struct capture_size {
170 unsigned long width;
171 unsigned long height;
172};
173
174struct tcm825x_platform_data {
175 /* Is the sensor usable? Doesn't yet mean it's there, but you
176 * can try! */
177 int (*is_okay)(void);
178 /* Set power state, zero is off, non-zero is on. */
179 int (*power_set)(int power);
180 /* Default registers written after power-on or reset. */
181 const struct tcm825x_reg *(*default_regs)(void);
182 int (*needs_reset)(struct v4l2_int_device *s, void *buf,
183 struct v4l2_pix_format *fmt);
184 int (*ifparm)(struct v4l2_ifparm *p);
185};
186
187/* Array of image sizes supported by TCM825X. These must be ordered from
188 * smallest image size to largest.
189 */
190const static struct capture_size tcm825x_sizes[] = {
191 { 128, 96 }, /* subQCIF */
192 { 160, 120 }, /* QQVGA */
193 { 176, 144 }, /* QCIF */
194 { 320, 240 }, /* QVGA */
195 { 352, 288 }, /* CIF */
196 { 640, 480 }, /* VGA */
197};
198
199#endif /* ifndef TCM825X_H */
diff --git a/drivers/media/video/tda8290.c b/drivers/media/video/tda8290.c
index 59cff5a3c59e..0e5cf459d3ed 100644
--- a/drivers/media/video/tda8290.c
+++ b/drivers/media/video/tda8290.c
@@ -16,21 +16,37 @@
16 You should have received a copy of the GNU General Public License 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 17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
20 This "tda8290" module was split apart from the original "tuner" module.
19*/ 21*/
20 22
21#include <linux/i2c.h> 23#include <linux/i2c.h>
22#include <linux/videodev.h>
23#include <linux/delay.h> 24#include <linux/delay.h>
24#include "tuner-driver.h" 25#include <linux/videodev.h>
26#include "tuner-i2c.h"
27#include "tda8290.h"
28
29static int debug = 0;
30module_param(debug, int, 0644);
31MODULE_PARM_DESC(debug, "enable verbose debug messages");
32
33#define PREFIX "tda8290 "
25 34
26/* ---------------------------------------------------------------------- */ 35/* ---------------------------------------------------------------------- */
27 36
28struct tda8290_priv { 37struct tda8290_priv {
38 struct tuner_i2c_props i2c_props;
39
29 unsigned char tda8290_easy_mode; 40 unsigned char tda8290_easy_mode;
30 unsigned char tda827x_lpsel; 41 unsigned char tda827x_lpsel;
31 unsigned char tda827x_addr; 42 unsigned char tda827x_addr;
32 unsigned char tda827x_ver; 43 unsigned char tda827x_ver;
33 unsigned int sgIF; 44 unsigned int sgIF;
45
46 u32 frequency;
47
48 unsigned int *lna_cfg;
49 int (*tuner_callback) (void *dev, int command,int arg);
34}; 50};
35 51
36/* ---------------------------------------------------------------------- */ 52/* ---------------------------------------------------------------------- */
@@ -79,20 +95,21 @@ static struct tda827x_data tda827x_analog[] = {
79 { .lomax = 0, .spd = 0, .bs = 0, .bp = 0, .cp = 0, .gc3 = 0, .div1p5 = 0} /* End */ 95 { .lomax = 0, .spd = 0, .bs = 0, .bp = 0, .cp = 0, .gc3 = 0, .div1p5 = 0} /* End */
80}; 96};
81 97
82static void tda827x_tune(struct i2c_client *c, u16 ifc, unsigned int freq) 98static void tda827x_set_analog_params(struct dvb_frontend *fe,
99 struct analog_parameters *params)
83{ 100{
84 unsigned char tuner_reg[8]; 101 unsigned char tuner_reg[8];
85 unsigned char reg2[2]; 102 unsigned char reg2[2];
86 u32 N; 103 u32 N;
87 int i; 104 int i;
88 struct tuner *t = i2c_get_clientdata(c); 105 struct tda8290_priv *priv = fe->tuner_priv;
89 struct tda8290_priv *priv = t->priv;
90 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags = 0}; 106 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags = 0};
107 unsigned int freq = params->frequency;
91 108
92 if (t->mode == V4L2_TUNER_RADIO) 109 if (params->mode == V4L2_TUNER_RADIO)
93 freq = freq / 1000; 110 freq = freq / 1000;
94 111
95 N = freq + ifc; 112 N = freq + priv->sgIF;
96 i = 0; 113 i = 0;
97 while (tda827x_analog[i].lomax < N) { 114 while (tda827x_analog[i].lomax < N) {
98 if(tda827x_analog[i + 1].lomax == 0) 115 if(tda827x_analog[i + 1].lomax == 0)
@@ -114,54 +131,53 @@ static void tda827x_tune(struct i2c_client *c, u16 ifc, unsigned int freq)
114 131
115 msg.buf = tuner_reg; 132 msg.buf = tuner_reg;
116 msg.len = 8; 133 msg.len = 8;
117 i2c_transfer(c->adapter, &msg, 1); 134 i2c_transfer(priv->i2c_props.adap, &msg, 1);
118 135
119 msg.buf= reg2; 136 msg.buf= reg2;
120 msg.len = 2; 137 msg.len = 2;
121 reg2[0] = 0x80; 138 reg2[0] = 0x80;
122 reg2[1] = 0; 139 reg2[1] = 0;
123 i2c_transfer(c->adapter, &msg, 1); 140 i2c_transfer(priv->i2c_props.adap, &msg, 1);
124 141
125 reg2[0] = 0x60; 142 reg2[0] = 0x60;
126 reg2[1] = 0xbf; 143 reg2[1] = 0xbf;
127 i2c_transfer(c->adapter, &msg, 1); 144 i2c_transfer(priv->i2c_props.adap, &msg, 1);
128 145
129 reg2[0] = 0x30; 146 reg2[0] = 0x30;
130 reg2[1] = tuner_reg[4] + 0x80; 147 reg2[1] = tuner_reg[4] + 0x80;
131 i2c_transfer(c->adapter, &msg, 1); 148 i2c_transfer(priv->i2c_props.adap, &msg, 1);
132 149
133 msleep(1); 150 msleep(1);
134 reg2[0] = 0x30; 151 reg2[0] = 0x30;
135 reg2[1] = tuner_reg[4] + 4; 152 reg2[1] = tuner_reg[4] + 4;
136 i2c_transfer(c->adapter, &msg, 1); 153 i2c_transfer(priv->i2c_props.adap, &msg, 1);
137 154
138 msleep(1); 155 msleep(1);
139 reg2[0] = 0x30; 156 reg2[0] = 0x30;
140 reg2[1] = tuner_reg[4]; 157 reg2[1] = tuner_reg[4];
141 i2c_transfer(c->adapter, &msg, 1); 158 i2c_transfer(priv->i2c_props.adap, &msg, 1);
142 159
143 msleep(550); 160 msleep(550);
144 reg2[0] = 0x30; 161 reg2[0] = 0x30;
145 reg2[1] = (tuner_reg[4] & 0xfc) + tda827x_analog[i].cp ; 162 reg2[1] = (tuner_reg[4] & 0xfc) + tda827x_analog[i].cp ;
146 i2c_transfer(c->adapter, &msg, 1); 163 i2c_transfer(priv->i2c_props.adap, &msg, 1);
147 164
148 reg2[0] = 0x60; 165 reg2[0] = 0x60;
149 reg2[1] = 0x3f; 166 reg2[1] = 0x3f;
150 i2c_transfer(c->adapter, &msg, 1); 167 i2c_transfer(priv->i2c_props.adap, &msg, 1);
151 168
152 reg2[0] = 0x80; 169 reg2[0] = 0x80;
153 reg2[1] = 0x08; // Vsync en 170 reg2[1] = 0x08; // Vsync en
154 i2c_transfer(c->adapter, &msg, 1); 171 i2c_transfer(priv->i2c_props.adap, &msg, 1);
155} 172}
156 173
157static void tda827x_agcf(struct i2c_client *c) 174static void tda827x_agcf(struct dvb_frontend *fe)
158{ 175{
159 struct tuner *t = i2c_get_clientdata(c); 176 struct tda8290_priv *priv = fe->tuner_priv;
160 struct tda8290_priv *priv = t->priv;
161 unsigned char data[] = {0x80, 0x0c}; 177 unsigned char data[] = {0x80, 0x0c};
162 struct i2c_msg msg = {.addr = priv->tda827x_addr, .buf = data, 178 struct i2c_msg msg = {.addr = priv->tda827x_addr, .buf = data,
163 .flags = 0, .len = 2}; 179 .flags = 0, .len = 2};
164 i2c_transfer(c->adapter, &msg, 1); 180 i2c_transfer(priv->i2c_props.adap, &msg, 1);
165} 181}
166 182
167/* ---------------------------------------------------------------------- */ 183/* ---------------------------------------------------------------------- */
@@ -204,58 +220,64 @@ static struct tda827xa_data tda827xa_analog[] = {
204 { .lomax = 0, .svco = 0, .spd = 0, .scr = 0, .sbs = 0, .gc3 = 0} /* End */ 220 { .lomax = 0, .svco = 0, .spd = 0, .scr = 0, .sbs = 0, .gc3 = 0} /* End */
205}; 221};
206 222
207static void tda827xa_lna_gain(struct i2c_client *c, int high) 223static void tda827xa_lna_gain(struct dvb_frontend *fe, int high,
224 struct analog_parameters *params)
208{ 225{
209 struct tuner *t = i2c_get_clientdata(c); 226 struct tda8290_priv *priv = fe->tuner_priv;
210 unsigned char buf[] = {0x22, 0x01}; 227 unsigned char buf[] = {0x22, 0x01};
211 int arg; 228 int arg;
212 struct i2c_msg msg = {.addr = c->addr, .flags = 0, .buf = buf, .len = sizeof(buf)}; 229 struct i2c_msg msg = {.addr = priv->i2c_props.addr, .flags = 0, .buf = buf, .len = sizeof(buf)};
213 if (t->config) { 230
231 if ((priv->lna_cfg == NULL) || (priv->tuner_callback == NULL))
232 return;
233
234 if (*priv->lna_cfg) {
214 if (high) 235 if (high)
215 tuner_dbg("setting LNA to high gain\n"); 236 tuner_dbg("setting LNA to high gain\n");
216 else 237 else
217 tuner_dbg("setting LNA to low gain\n"); 238 tuner_dbg("setting LNA to low gain\n");
218 } 239 }
219 switch (t->config) { 240 switch (*priv->lna_cfg) {
220 case 0: /* no LNA */ 241 case 0: /* no LNA */
221 break; 242 break;
222 case 1: /* switch is GPIO 0 of tda8290 */ 243 case 1: /* switch is GPIO 0 of tda8290 */
223 case 2: 244 case 2:
224 /* turn Vsync on */ 245 /* turn Vsync on */
225 if (t->std & V4L2_STD_MN) 246 if (params->std & V4L2_STD_MN)
226 arg = 1; 247 arg = 1;
227 else 248 else
228 arg = 0; 249 arg = 0;
229 if (t->tuner_callback) 250 if (priv->tuner_callback)
230 t->tuner_callback(c->adapter->algo_data, 1, arg); 251 priv->tuner_callback(priv->i2c_props.adap->algo_data, 1, arg);
231 buf[1] = high ? 0 : 1; 252 buf[1] = high ? 0 : 1;
232 if (t->config == 2) 253 if (*priv->lna_cfg == 2)
233 buf[1] = high ? 1 : 0; 254 buf[1] = high ? 1 : 0;
234 i2c_transfer(c->adapter, &msg, 1); 255 i2c_transfer(priv->i2c_props.adap, &msg, 1);
235 break; 256 break;
236 case 3: /* switch with GPIO of saa713x */ 257 case 3: /* switch with GPIO of saa713x */
237 if (t->tuner_callback) 258 if (priv->tuner_callback)
238 t->tuner_callback(c->adapter->algo_data, 0, high); 259 priv->tuner_callback(priv->i2c_props.adap->algo_data, 0, high);
239 break; 260 break;
240 } 261 }
241} 262}
242 263
243static void tda827xa_tune(struct i2c_client *c, u16 ifc, unsigned int freq) 264static void tda827xa_set_analog_params(struct dvb_frontend *fe,
265 struct analog_parameters *params)
244{ 266{
245 unsigned char tuner_reg[11]; 267 unsigned char tuner_reg[11];
246 u32 N; 268 u32 N;
247 int i; 269 int i;
248 struct tuner *t = i2c_get_clientdata(c); 270 struct tda8290_priv *priv = fe->tuner_priv;
249 struct tda8290_priv *priv = t->priv;
250 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags = 0, .buf = tuner_reg}; 271 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags = 0, .buf = tuner_reg};
272 unsigned int freq = params->frequency;
251 273
252 tda827xa_lna_gain( c, 1); 274 tda827xa_lna_gain(fe, 1, params);
253 msleep(10); 275 msleep(10);
254 276
255 if (t->mode == V4L2_TUNER_RADIO) 277 if (params->mode == V4L2_TUNER_RADIO)
256 freq = freq / 1000; 278 freq = freq / 1000;
257 279
258 N = freq + ifc; 280 N = freq + priv->sgIF;
259 i = 0; 281 i = 0;
260 while (tda827xa_analog[i].lomax < N) { 282 while (tda827xa_analog[i].lomax < N) {
261 if(tda827xa_analog[i + 1].lomax == 0) 283 if(tda827xa_analog[i + 1].lomax == 0)
@@ -278,7 +300,7 @@ static void tda827xa_tune(struct i2c_client *c, u16 ifc, unsigned int freq)
278 tuner_reg[9] = 0x20; 300 tuner_reg[9] = 0x20;
279 tuner_reg[10] = 0x00; 301 tuner_reg[10] = 0x00;
280 msg.len = 11; 302 msg.len = 11;
281 i2c_transfer(c->adapter, &msg, 1); 303 i2c_transfer(priv->i2c_props.adap, &msg, 1);
282 304
283 tuner_reg[0] = 0x90; 305 tuner_reg[0] = 0x90;
284 tuner_reg[1] = 0xff; 306 tuner_reg[1] = 0xff;
@@ -286,82 +308,131 @@ static void tda827xa_tune(struct i2c_client *c, u16 ifc, unsigned int freq)
286 tuner_reg[3] = 0; 308 tuner_reg[3] = 0;
287 tuner_reg[4] = 0x99 + (priv->tda827x_lpsel << 1); 309 tuner_reg[4] = 0x99 + (priv->tda827x_lpsel << 1);
288 msg.len = 5; 310 msg.len = 5;
289 i2c_transfer(c->adapter, &msg, 1); 311 i2c_transfer(priv->i2c_props.adap, &msg, 1);
290 312
291 tuner_reg[0] = 0xa0; 313 tuner_reg[0] = 0xa0;
292 tuner_reg[1] = 0xc0; 314 tuner_reg[1] = 0xc0;
293 msg.len = 2; 315 msg.len = 2;
294 i2c_transfer(c->adapter, &msg, 1); 316 i2c_transfer(priv->i2c_props.adap, &msg, 1);
295 317
296 tuner_reg[0] = 0x30; 318 tuner_reg[0] = 0x30;
297 tuner_reg[1] = 0x10 + tda827xa_analog[i].scr; 319 tuner_reg[1] = 0x10 + tda827xa_analog[i].scr;
298 i2c_transfer(c->adapter, &msg, 1); 320 i2c_transfer(priv->i2c_props.adap, &msg, 1);
299 321
300 msg.flags = I2C_M_RD; 322 msg.flags = I2C_M_RD;
301 i2c_transfer(c->adapter, &msg, 1); 323 i2c_transfer(priv->i2c_props.adap, &msg, 1);
302 msg.flags = 0; 324 msg.flags = 0;
303 tuner_reg[1] >>= 4; 325 tuner_reg[1] >>= 4;
304 tuner_dbg("AGC2 gain is: %d\n", tuner_reg[1]); 326 tuner_dbg("AGC2 gain is: %d\n", tuner_reg[1]);
305 if (tuner_reg[1] < 1) 327 if (tuner_reg[1] < 1)
306 tda827xa_lna_gain( c, 0); 328 tda827xa_lna_gain(fe, 0, params);
307 329
308 msleep(100); 330 msleep(100);
309 tuner_reg[0] = 0x60; 331 tuner_reg[0] = 0x60;
310 tuner_reg[1] = 0x3c; 332 tuner_reg[1] = 0x3c;
311 i2c_transfer(c->adapter, &msg, 1); 333 i2c_transfer(priv->i2c_props.adap, &msg, 1);
312 334
313 msleep(163); 335 msleep(163);
314 tuner_reg[0] = 0x50; 336 tuner_reg[0] = 0x50;
315 tuner_reg[1] = 0x8f + (tda827xa_analog[i].gc3 << 4); 337 tuner_reg[1] = 0x8f + (tda827xa_analog[i].gc3 << 4);
316 i2c_transfer(c->adapter, &msg, 1); 338 i2c_transfer(priv->i2c_props.adap, &msg, 1);
317 339
318 tuner_reg[0] = 0x80; 340 tuner_reg[0] = 0x80;
319 tuner_reg[1] = 0x28; 341 tuner_reg[1] = 0x28;
320 i2c_transfer(c->adapter, &msg, 1); 342 i2c_transfer(priv->i2c_props.adap, &msg, 1);
321 343
322 tuner_reg[0] = 0xb0; 344 tuner_reg[0] = 0xb0;
323 tuner_reg[1] = 0x01; 345 tuner_reg[1] = 0x01;
324 i2c_transfer(c->adapter, &msg, 1); 346 i2c_transfer(priv->i2c_props.adap, &msg, 1);
325 347
326 tuner_reg[0] = 0xc0; 348 tuner_reg[0] = 0xc0;
327 tuner_reg[1] = 0x19 + (priv->tda827x_lpsel << 1); 349 tuner_reg[1] = 0x19 + (priv->tda827x_lpsel << 1);
328 i2c_transfer(c->adapter, &msg, 1); 350 i2c_transfer(priv->i2c_props.adap, &msg, 1);
329} 351}
330 352
331static void tda827xa_agcf(struct i2c_client *c) 353static void tda827xa_agcf(struct dvb_frontend *fe)
332{ 354{
333 struct tuner *t = i2c_get_clientdata(c); 355 struct tda8290_priv *priv = fe->tuner_priv;
334 struct tda8290_priv *priv = t->priv;
335 unsigned char data[] = {0x80, 0x2c}; 356 unsigned char data[] = {0x80, 0x2c};
336 struct i2c_msg msg = {.addr = priv->tda827x_addr, .buf = data, 357 struct i2c_msg msg = {.addr = priv->tda827x_addr, .buf = data,
337 .flags = 0, .len = 2}; 358 .flags = 0, .len = 2};
338 i2c_transfer(c->adapter, &msg, 1); 359 i2c_transfer(priv->i2c_props.adap, &msg, 1);
339} 360}
340 361
341/*---------------------------------------------------------------------*/ 362/*---------------------------------------------------------------------*/
342 363
343static void tda8290_i2c_bridge(struct i2c_client *c, int close) 364static void tda8290_i2c_bridge(struct dvb_frontend *fe, int close)
344{ 365{
366 struct tda8290_priv *priv = fe->tuner_priv;
367
345 unsigned char enable[2] = { 0x21, 0xC0 }; 368 unsigned char enable[2] = { 0x21, 0xC0 };
346 unsigned char disable[2] = { 0x21, 0x00 }; 369 unsigned char disable[2] = { 0x21, 0x00 };
347 unsigned char *msg; 370 unsigned char *msg;
348 if(close) { 371 if(close) {
349 msg = enable; 372 msg = enable;
350 i2c_master_send(c, msg, 2); 373 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
351 /* let the bridge stabilize */ 374 /* let the bridge stabilize */
352 msleep(20); 375 msleep(20);
353 } else { 376 } else {
354 msg = disable; 377 msg = disable;
355 i2c_master_send(c, msg, 2); 378 tuner_i2c_xfer_send(&priv->i2c_props, msg, 2);
356 } 379 }
357} 380}
358 381
359/*---------------------------------------------------------------------*/ 382/*---------------------------------------------------------------------*/
360 383
361static int tda8290_tune(struct i2c_client *c, u16 ifc, unsigned int freq) 384static void set_audio(struct dvb_frontend *fe,
385 struct analog_parameters *params)
386{
387 struct tda8290_priv *priv = fe->tuner_priv;
388 char* mode;
389
390 priv->tda827x_lpsel = 0;
391 if (params->std & V4L2_STD_MN) {
392 priv->sgIF = 92;
393 priv->tda8290_easy_mode = 0x01;
394 priv->tda827x_lpsel = 1;
395 mode = "MN";
396 } else if (params->std & V4L2_STD_B) {
397 priv->sgIF = 108;
398 priv->tda8290_easy_mode = 0x02;
399 mode = "B";
400 } else if (params->std & V4L2_STD_GH) {
401 priv->sgIF = 124;
402 priv->tda8290_easy_mode = 0x04;
403 mode = "GH";
404 } else if (params->std & V4L2_STD_PAL_I) {
405 priv->sgIF = 124;
406 priv->tda8290_easy_mode = 0x08;
407 mode = "I";
408 } else if (params->std & V4L2_STD_DK) {
409 priv->sgIF = 124;
410 priv->tda8290_easy_mode = 0x10;
411 mode = "DK";
412 } else if (params->std & V4L2_STD_SECAM_L) {
413 priv->sgIF = 124;
414 priv->tda8290_easy_mode = 0x20;
415 mode = "L";
416 } else if (params->std & V4L2_STD_SECAM_LC) {
417 priv->sgIF = 20;
418 priv->tda8290_easy_mode = 0x40;
419 mode = "LC";
420 } else {
421 priv->sgIF = 124;
422 priv->tda8290_easy_mode = 0x10;
423 mode = "xx";
424 }
425
426 if (params->mode == V4L2_TUNER_RADIO)
427 priv->sgIF = 88; /* if frequency is 5.5 MHz */
428
429 tuner_dbg("setting tda8290 to system %s\n", mode);
430}
431
432static int tda8290_set_params(struct dvb_frontend *fe,
433 struct analog_parameters *params)
362{ 434{
363 struct tuner *t = i2c_get_clientdata(c); 435 struct tda8290_priv *priv = fe->tuner_priv;
364 struct tda8290_priv *priv = t->priv;
365 unsigned char soft_reset[] = { 0x00, 0x00 }; 436 unsigned char soft_reset[] = { 0x00, 0x00 };
366 unsigned char easy_mode[] = { 0x01, priv->tda8290_easy_mode }; 437 unsigned char easy_mode[] = { 0x01, priv->tda8290_easy_mode };
367 unsigned char expert_mode[] = { 0x01, 0x80 }; 438 unsigned char expert_mode[] = { 0x01, 0x80 };
@@ -384,35 +455,38 @@ static int tda8290_tune(struct i2c_client *c, u16 ifc, unsigned int freq)
384 pll_stat; 455 pll_stat;
385 int i; 456 int i;
386 457
387 tuner_dbg("tda827xa config is 0x%02x\n", t->config); 458 set_audio(fe, params);
388 i2c_master_send(c, easy_mode, 2); 459
389 i2c_master_send(c, agc_out_on, 2); 460 if (priv->lna_cfg)
390 i2c_master_send(c, soft_reset, 2); 461 tuner_dbg("tda827xa config is 0x%02x\n", *priv->lna_cfg);
462 tuner_i2c_xfer_send(&priv->i2c_props, easy_mode, 2);
463 tuner_i2c_xfer_send(&priv->i2c_props, agc_out_on, 2);
464 tuner_i2c_xfer_send(&priv->i2c_props, soft_reset, 2);
391 msleep(1); 465 msleep(1);
392 466
393 expert_mode[1] = priv->tda8290_easy_mode + 0x80; 467 expert_mode[1] = priv->tda8290_easy_mode + 0x80;
394 i2c_master_send(c, expert_mode, 2); 468 tuner_i2c_xfer_send(&priv->i2c_props, expert_mode, 2);
395 i2c_master_send(c, gainset_off, 2); 469 tuner_i2c_xfer_send(&priv->i2c_props, gainset_off, 2);
396 i2c_master_send(c, if_agc_spd, 2); 470 tuner_i2c_xfer_send(&priv->i2c_props, if_agc_spd, 2);
397 if (priv->tda8290_easy_mode & 0x60) 471 if (priv->tda8290_easy_mode & 0x60)
398 i2c_master_send(c, adc_head_9, 2); 472 tuner_i2c_xfer_send(&priv->i2c_props, adc_head_9, 2);
399 else 473 else
400 i2c_master_send(c, adc_head_6, 2); 474 tuner_i2c_xfer_send(&priv->i2c_props, adc_head_6, 2);
401 i2c_master_send(c, pll_bw_nom, 2); 475 tuner_i2c_xfer_send(&priv->i2c_props, pll_bw_nom, 2);
402 476
403 tda8290_i2c_bridge(c, 1); 477 tda8290_i2c_bridge(fe, 1);
404 if (priv->tda827x_ver != 0) 478 if (priv->tda827x_ver != 0)
405 tda827xa_tune(c, ifc, freq); 479 tda827xa_set_analog_params(fe, params);
406 else 480 else
407 tda827x_tune(c, ifc, freq); 481 tda827x_set_analog_params(fe, params);
408 for (i = 0; i < 3; i++) { 482 for (i = 0; i < 3; i++) {
409 i2c_master_send(c, &addr_pll_stat, 1); 483 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
410 i2c_master_recv(c, &pll_stat, 1); 484 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
411 if (pll_stat & 0x80) { 485 if (pll_stat & 0x80) {
412 i2c_master_send(c, &addr_adc_sat, 1); 486 tuner_i2c_xfer_send(&priv->i2c_props, &addr_adc_sat, 1);
413 i2c_master_recv(c, &adc_sat, 1); 487 tuner_i2c_xfer_recv(&priv->i2c_props, &adc_sat, 1);
414 i2c_master_send(c, &addr_agc_stat, 1); 488 tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1);
415 i2c_master_recv(c, &agc_stat, 1); 489 tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1);
416 tuner_dbg("tda8290 is locked, AGC: %d\n", agc_stat); 490 tuner_dbg("tda8290 is locked, AGC: %d\n", agc_stat);
417 break; 491 break;
418 } else { 492 } else {
@@ -424,28 +498,28 @@ static int tda8290_tune(struct i2c_client *c, u16 ifc, unsigned int freq)
424 if ((agc_stat > 115) || (!(pll_stat & 0x80) && (adc_sat < 20))) { 498 if ((agc_stat > 115) || (!(pll_stat & 0x80) && (adc_sat < 20))) {
425 tuner_dbg("adjust gain, step 1. Agc: %d, ADC stat: %d, lock: %d\n", 499 tuner_dbg("adjust gain, step 1. Agc: %d, ADC stat: %d, lock: %d\n",
426 agc_stat, adc_sat, pll_stat & 0x80); 500 agc_stat, adc_sat, pll_stat & 0x80);
427 i2c_master_send(c, gainset_2, 2); 501 tuner_i2c_xfer_send(&priv->i2c_props, gainset_2, 2);
428 msleep(100); 502 msleep(100);
429 i2c_master_send(c, &addr_agc_stat, 1); 503 tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1);
430 i2c_master_recv(c, &agc_stat, 1); 504 tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1);
431 i2c_master_send(c, &addr_pll_stat, 1); 505 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
432 i2c_master_recv(c, &pll_stat, 1); 506 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
433 if ((agc_stat > 115) || !(pll_stat & 0x80)) { 507 if ((agc_stat > 115) || !(pll_stat & 0x80)) {
434 tuner_dbg("adjust gain, step 2. Agc: %d, lock: %d\n", 508 tuner_dbg("adjust gain, step 2. Agc: %d, lock: %d\n",
435 agc_stat, pll_stat & 0x80); 509 agc_stat, pll_stat & 0x80);
436 if (priv->tda827x_ver != 0) 510 if (priv->tda827x_ver != 0)
437 tda827xa_agcf(c); 511 tda827xa_agcf(fe);
438 else 512 else
439 tda827x_agcf(c); 513 tda827x_agcf(fe);
440 msleep(100); 514 msleep(100);
441 i2c_master_send(c, &addr_agc_stat, 1); 515 tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1);
442 i2c_master_recv(c, &agc_stat, 1); 516 tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1);
443 i2c_master_send(c, &addr_pll_stat, 1); 517 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
444 i2c_master_recv(c, &pll_stat, 1); 518 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
445 if((agc_stat > 115) || !(pll_stat & 0x80)) { 519 if((agc_stat > 115) || !(pll_stat & 0x80)) {
446 tuner_dbg("adjust gain, step 3. Agc: %d\n", agc_stat); 520 tuner_dbg("adjust gain, step 3. Agc: %d\n", agc_stat);
447 i2c_master_send(c, adc_head_12, 2); 521 tuner_i2c_xfer_send(&priv->i2c_props, adc_head_12, 2);
448 i2c_master_send(c, pll_bw_low, 2); 522 tuner_i2c_xfer_send(&priv->i2c_props, pll_bw_low, 2);
449 msleep(100); 523 msleep(100);
450 } 524 }
451 } 525 }
@@ -453,132 +527,106 @@ static int tda8290_tune(struct i2c_client *c, u16 ifc, unsigned int freq)
453 527
454 /* l/ l' deadlock? */ 528 /* l/ l' deadlock? */
455 if(priv->tda8290_easy_mode & 0x60) { 529 if(priv->tda8290_easy_mode & 0x60) {
456 i2c_master_send(c, &addr_adc_sat, 1); 530 tuner_i2c_xfer_send(&priv->i2c_props, &addr_adc_sat, 1);
457 i2c_master_recv(c, &adc_sat, 1); 531 tuner_i2c_xfer_recv(&priv->i2c_props, &adc_sat, 1);
458 i2c_master_send(c, &addr_pll_stat, 1); 532 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
459 i2c_master_recv(c, &pll_stat, 1); 533 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
460 if ((adc_sat > 20) || !(pll_stat & 0x80)) { 534 if ((adc_sat > 20) || !(pll_stat & 0x80)) {
461 tuner_dbg("trying to resolve SECAM L deadlock\n"); 535 tuner_dbg("trying to resolve SECAM L deadlock\n");
462 i2c_master_send(c, agc_rst_on, 2); 536 tuner_i2c_xfer_send(&priv->i2c_props, agc_rst_on, 2);
463 msleep(40); 537 msleep(40);
464 i2c_master_send(c, agc_rst_off, 2); 538 tuner_i2c_xfer_send(&priv->i2c_props, agc_rst_off, 2);
465 } 539 }
466 } 540 }
467 541
468 tda8290_i2c_bridge(c, 0); 542 tda8290_i2c_bridge(fe, 0);
469 i2c_master_send(c, if_agc_set, 2); 543 tuner_i2c_xfer_send(&priv->i2c_props, if_agc_set, 2);
544
545 priv->frequency = (V4L2_TUNER_RADIO == params->mode) ?
546 params->frequency * 125 / 2 : params->frequency * 62500;
547
470 return 0; 548 return 0;
471} 549}
472 550
473/*---------------------------------------------------------------------*/ 551/*---------------------------------------------------------------------*/
474 552
475static void set_audio(struct tuner *t) 553static int tda8290_has_signal(struct dvb_frontend *fe)
476{ 554{
477 struct tda8290_priv *priv = t->priv; 555 struct tda8290_priv *priv = fe->tuner_priv;
478 char* mode; 556 int ret;
479 557
480 priv->tda827x_lpsel = 0; 558 unsigned char i2c_get_afc[1] = { 0x1B };
481 if (t->std & V4L2_STD_MN) { 559 unsigned char afc = 0;
482 priv->sgIF = 92;
483 priv->tda8290_easy_mode = 0x01;
484 priv->tda827x_lpsel = 1;
485 mode = "MN";
486 } else if (t->std & V4L2_STD_B) {
487 priv->sgIF = 108;
488 priv->tda8290_easy_mode = 0x02;
489 mode = "B";
490 } else if (t->std & V4L2_STD_GH) {
491 priv->sgIF = 124;
492 priv->tda8290_easy_mode = 0x04;
493 mode = "GH";
494 } else if (t->std & V4L2_STD_PAL_I) {
495 priv->sgIF = 124;
496 priv->tda8290_easy_mode = 0x08;
497 mode = "I";
498 } else if (t->std & V4L2_STD_DK) {
499 priv->sgIF = 124;
500 priv->tda8290_easy_mode = 0x10;
501 mode = "DK";
502 } else if (t->std & V4L2_STD_SECAM_L) {
503 priv->sgIF = 124;
504 priv->tda8290_easy_mode = 0x20;
505 mode = "L";
506 } else if (t->std & V4L2_STD_SECAM_LC) {
507 priv->sgIF = 20;
508 priv->tda8290_easy_mode = 0x40;
509 mode = "LC";
510 } else {
511 priv->sgIF = 124;
512 priv->tda8290_easy_mode = 0x10;
513 mode = "xx";
514 }
515 tuner_dbg("setting tda8290 to system %s\n", mode);
516}
517 560
518static void set_tv_freq(struct i2c_client *c, unsigned int freq) 561 /* for now, report based on afc status */
519{ 562 tuner_i2c_xfer_send(&priv->i2c_props, i2c_get_afc, ARRAY_SIZE(i2c_get_afc));
520 struct tuner *t = i2c_get_clientdata(c); 563 tuner_i2c_xfer_recv(&priv->i2c_props, &afc, 1);
521 struct tda8290_priv *priv = t->priv; 564
565 ret = (afc & 0x80) ? 65535 : 0;
522 566
523 set_audio(t); 567 tuner_dbg("AFC status: %d\n", ret);
524 tda8290_tune(c, priv->sgIF, freq); 568
569 return ret;
525} 570}
526 571
527static void set_radio_freq(struct i2c_client *c, unsigned int freq) 572static int tda8290_get_status(struct dvb_frontend *fe, u32 *status)
528{ 573{
529 /* if frequency is 5.5 MHz */ 574 *status = 0;
530 tda8290_tune(c, 88, freq); 575
576 if (tda8290_has_signal(fe))
577 *status = TUNER_STATUS_LOCKED;
578
579 return 0;
531} 580}
532 581
533static int has_signal(struct i2c_client *c) 582static int tda8290_get_rf_strength(struct dvb_frontend *fe, u16 *strength)
534{ 583{
535 unsigned char i2c_get_afc[1] = { 0x1B }; 584 *strength = tda8290_has_signal(fe);
536 unsigned char afc = 0;
537 585
538 i2c_master_send(c, i2c_get_afc, ARRAY_SIZE(i2c_get_afc)); 586 return 0;
539 i2c_master_recv(c, &afc, 1);
540 return (afc & 0x80)? 65535:0;
541} 587}
542 588
543/*---------------------------------------------------------------------*/ 589/*---------------------------------------------------------------------*/
544 590
545static void standby(struct i2c_client *c) 591static int tda8290_standby(struct dvb_frontend *fe)
546{ 592{
547 struct tuner *t = i2c_get_clientdata(c); 593 struct tda8290_priv *priv = fe->tuner_priv;
548 struct tda8290_priv *priv = t->priv;
549 unsigned char cb1[] = { 0x30, 0xD0 }; 594 unsigned char cb1[] = { 0x30, 0xD0 };
550 unsigned char tda8290_standby[] = { 0x00, 0x02 }; 595 unsigned char tda8290_standby[] = { 0x00, 0x02 };
551 unsigned char tda8290_agc_tri[] = { 0x02, 0x20 }; 596 unsigned char tda8290_agc_tri[] = { 0x02, 0x20 };
552 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0, .buf=cb1, .len = 2}; 597 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0, .buf=cb1, .len = 2};
553 598
554 tda8290_i2c_bridge(c, 1); 599 tda8290_i2c_bridge(fe, 1);
555 if (priv->tda827x_ver != 0) 600 if (priv->tda827x_ver != 0)
556 cb1[1] = 0x90; 601 cb1[1] = 0x90;
557 i2c_transfer(c->adapter, &msg, 1); 602 i2c_transfer(priv->i2c_props.adap, &msg, 1);
558 tda8290_i2c_bridge(c, 0); 603 tda8290_i2c_bridge(fe, 0);
559 i2c_master_send(c, tda8290_agc_tri, 2); 604 tuner_i2c_xfer_send(&priv->i2c_props, tda8290_agc_tri, 2);
560 i2c_master_send(c, tda8290_standby, 2); 605 tuner_i2c_xfer_send(&priv->i2c_props, tda8290_standby, 2);
606
607 return 0;
561} 608}
562 609
563 610
564static void tda8290_init_if(struct i2c_client *c) 611static void tda8290_init_if(struct dvb_frontend *fe)
565{ 612{
566 struct tuner *t = i2c_get_clientdata(c); 613 struct tda8290_priv *priv = fe->tuner_priv;
614
567 unsigned char set_VS[] = { 0x30, 0x6F }; 615 unsigned char set_VS[] = { 0x30, 0x6F };
568 unsigned char set_GP00_CF[] = { 0x20, 0x01 }; 616 unsigned char set_GP00_CF[] = { 0x20, 0x01 };
569 unsigned char set_GP01_CF[] = { 0x20, 0x0B }; 617 unsigned char set_GP01_CF[] = { 0x20, 0x0B };
570 618
571 if ((t->config == 1) || (t->config == 2)) 619 if ((priv->lna_cfg) &&
572 i2c_master_send(c, set_GP00_CF, 2); 620 ((*priv->lna_cfg == 1) || (*priv->lna_cfg == 2)))
621 tuner_i2c_xfer_send(&priv->i2c_props, set_GP00_CF, 2);
573 else 622 else
574 i2c_master_send(c, set_GP01_CF, 2); 623 tuner_i2c_xfer_send(&priv->i2c_props, set_GP01_CF, 2);
575 i2c_master_send(c, set_VS, 2); 624 tuner_i2c_xfer_send(&priv->i2c_props, set_VS, 2);
576} 625}
577 626
578static void tda8290_init_tuner(struct i2c_client *c) 627static void tda8290_init_tuner(struct dvb_frontend *fe)
579{ 628{
580 struct tuner *t = i2c_get_clientdata(c); 629 struct tda8290_priv *priv = fe->tuner_priv;
581 struct tda8290_priv *priv = t->priv;
582 unsigned char tda8275_init[] = { 0x00, 0x00, 0x00, 0x40, 0xdC, 0x04, 0xAf, 630 unsigned char tda8275_init[] = { 0x00, 0x00, 0x00, 0x40, 0xdC, 0x04, 0xAf,
583 0x3F, 0x2A, 0x04, 0xFF, 0x00, 0x00, 0x40 }; 631 0x3F, 0x2A, 0x04, 0xFF, 0x00, 0x00, 0x40 };
584 unsigned char tda8275a_init[] = { 0x00, 0x00, 0x00, 0x00, 0xdC, 0x05, 0x8b, 632 unsigned char tda8275a_init[] = { 0x00, 0x00, 0x00, 0x00, 0xdC, 0x05, 0x8b,
@@ -588,33 +636,43 @@ static void tda8290_init_tuner(struct i2c_client *c)
588 if (priv->tda827x_ver != 0) 636 if (priv->tda827x_ver != 0)
589 msg.buf = tda8275a_init; 637 msg.buf = tda8275a_init;
590 638
591 tda8290_i2c_bridge(c, 1); 639 tda8290_i2c_bridge(fe, 1);
592 i2c_transfer(c->adapter, &msg, 1); 640 i2c_transfer(priv->i2c_props.adap, &msg, 1);
593 tda8290_i2c_bridge(c, 0); 641 tda8290_i2c_bridge(fe, 0);
594} 642}
595 643
596/*---------------------------------------------------------------------*/ 644/*---------------------------------------------------------------------*/
597 645
598static void tda8290_release(struct i2c_client *c) 646static int tda8290_release(struct dvb_frontend *fe)
599{ 647{
600 struct tuner *t = i2c_get_clientdata(c); 648 kfree(fe->tuner_priv);
649 fe->tuner_priv = NULL;
601 650
602 kfree(t->priv); 651 return 0;
603 t->priv = NULL;
604} 652}
605 653
606static struct tuner_operations tda8290_tuner_ops = { 654static int tda8290_get_frequency(struct dvb_frontend *fe, u32 *frequency)
607 .set_tv_freq = set_tv_freq, 655{
608 .set_radio_freq = set_radio_freq, 656 struct tda8290_priv *priv = fe->tuner_priv;
609 .has_signal = has_signal, 657 *frequency = priv->frequency;
610 .standby = standby, 658 return 0;
611 .release = tda8290_release, 659}
660
661static struct dvb_tuner_ops tda8290_tuner_ops = {
662 .sleep = tda8290_standby,
663 .set_analog_params = tda8290_set_params,
664 .release = tda8290_release,
665 .get_frequency = tda8290_get_frequency,
666 .get_status = tda8290_get_status,
667 .get_rf_strength = tda8290_get_rf_strength,
612}; 668};
613 669
614int tda8290_init(struct i2c_client *c) 670struct dvb_frontend *tda8290_attach(struct dvb_frontend *fe,
671 struct i2c_adapter* i2c_adap,
672 u8 i2c_addr,
673 struct tda8290_config *cfg)
615{ 674{
616 struct tda8290_priv *priv = NULL; 675 struct tda8290_priv *priv = NULL;
617 struct tuner *t = i2c_get_clientdata(c);
618 u8 data; 676 u8 data;
619 int i, ret, tuners_found; 677 int i, ret, tuners_found;
620 u32 tuner_addrs; 678 u32 tuner_addrs;
@@ -622,16 +680,23 @@ int tda8290_init(struct i2c_client *c)
622 680
623 priv = kzalloc(sizeof(struct tda8290_priv), GFP_KERNEL); 681 priv = kzalloc(sizeof(struct tda8290_priv), GFP_KERNEL);
624 if (priv == NULL) 682 if (priv == NULL)
625 return -ENOMEM; 683 return NULL;
626 t->priv = priv; 684 fe->tuner_priv = priv;
685
686 priv->i2c_props.addr = i2c_addr;
687 priv->i2c_props.adap = i2c_adap;
688 if (cfg) {
689 priv->lna_cfg = cfg->lna_cfg;
690 priv->tuner_callback = cfg->tuner_callback;
691 }
627 692
628 tda8290_i2c_bridge(c, 1); 693 tda8290_i2c_bridge(fe, 1);
629 /* probe for tuner chip */ 694 /* probe for tuner chip */
630 tuners_found = 0; 695 tuners_found = 0;
631 tuner_addrs = 0; 696 tuner_addrs = 0;
632 for (i=0x60; i<= 0x63; i++) { 697 for (i=0x60; i<= 0x63; i++) {
633 msg.addr = i; 698 msg.addr = i;
634 ret = i2c_transfer(c->adapter, &msg, 1); 699 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
635 if (ret == 1) { 700 if (ret == 1) {
636 tuners_found++; 701 tuners_found++;
637 tuner_addrs = (tuner_addrs << 8) + i; 702 tuner_addrs = (tuner_addrs << 8) + i;
@@ -641,11 +706,11 @@ int tda8290_init(struct i2c_client *c)
641 behind the bridge and we choose the highest address that doesn't 706 behind the bridge and we choose the highest address that doesn't
642 give a response now 707 give a response now
643 */ 708 */
644 tda8290_i2c_bridge(c, 0); 709 tda8290_i2c_bridge(fe, 0);
645 if(tuners_found > 1) 710 if(tuners_found > 1)
646 for (i = 0; i < tuners_found; i++) { 711 for (i = 0; i < tuners_found; i++) {
647 msg.addr = tuner_addrs & 0xff; 712 msg.addr = tuner_addrs & 0xff;
648 ret = i2c_transfer(c->adapter, &msg, 1); 713 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
649 if(ret == 1) 714 if(ret == 1)
650 tuner_addrs = tuner_addrs >> 8; 715 tuner_addrs = tuner_addrs >> 8;
651 else 716 else
@@ -653,40 +718,53 @@ int tda8290_init(struct i2c_client *c)
653 } 718 }
654 if (tuner_addrs == 0) { 719 if (tuner_addrs == 0) {
655 tuner_addrs = 0x61; 720 tuner_addrs = 0x61;
656 tuner_info ("could not clearly identify tuner address, defaulting to %x\n", 721 tuner_info("could not clearly identify tuner address, defaulting to %x\n",
657 tuner_addrs); 722 tuner_addrs);
658 } else { 723 } else {
659 tuner_addrs = tuner_addrs & 0xff; 724 tuner_addrs = tuner_addrs & 0xff;
660 tuner_info ("setting tuner address to %x\n", tuner_addrs); 725 tuner_info("setting tuner address to %x\n", tuner_addrs);
661 } 726 }
662 priv->tda827x_addr = tuner_addrs; 727 priv->tda827x_addr = tuner_addrs;
663 msg.addr = tuner_addrs; 728 msg.addr = tuner_addrs;
664 729
665 tda8290_i2c_bridge(c, 1); 730 tda8290_i2c_bridge(fe, 1);
666 ret = i2c_transfer(c->adapter, &msg, 1); 731 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
667 if( ret != 1) 732 if( ret != 1)
668 tuner_warn ("TDA827x access failed!\n"); 733 tuner_warn("TDA827x access failed!\n");
734
735 memcpy(&fe->ops.tuner_ops, &tda8290_tuner_ops,
736 sizeof(struct dvb_tuner_ops));
737
669 if ((data & 0x3c) == 0) { 738 if ((data & 0x3c) == 0) {
670 strlcpy(c->name, "tda8290+75", sizeof(c->name)); 739 strlcpy(fe->ops.tuner_ops.info.name, "tda8290+75",
740 sizeof(fe->ops.tuner_ops.info.name));
741 fe->ops.tuner_ops.info.frequency_min = 55000000;
742 fe->ops.tuner_ops.info.frequency_max = 860000000;
743 fe->ops.tuner_ops.info.frequency_step = 250000;
671 priv->tda827x_ver = 0; 744 priv->tda827x_ver = 0;
672 } else { 745 } else {
673 strlcpy(c->name, "tda8290+75a", sizeof(c->name)); 746 strlcpy(fe->ops.tuner_ops.info.name, "tda8290+75a",
747 sizeof(fe->ops.tuner_ops.info.name));
748 fe->ops.tuner_ops.info.frequency_min = 44000000;
749 fe->ops.tuner_ops.info.frequency_max = 906000000;
750 fe->ops.tuner_ops.info.frequency_step = 62500;
674 priv->tda827x_ver = 2; 751 priv->tda827x_ver = 2;
675 } 752 }
676 tuner_info("type set to %s\n", c->name);
677
678 memcpy(&t->ops, &tda8290_tuner_ops, sizeof(struct tuner_operations));
679 753
680 priv->tda827x_lpsel = 0; 754 priv->tda827x_lpsel = 0;
681 t->mode = V4L2_TUNER_ANALOG_TV;
682 755
683 tda8290_init_tuner(c); 756 tda8290_init_tuner(fe);
684 tda8290_init_if(c); 757 tda8290_init_if(fe);
685 return 0; 758 return fe;
686} 759}
687 760
688int tda8290_probe(struct i2c_client *c) 761int tda8290_probe(struct i2c_adapter* i2c_adap, u8 i2c_addr)
689{ 762{
763 struct tuner_i2c_props i2c_props = {
764 .adap = i2c_adap,
765 .addr = i2c_addr
766 };
767
690 unsigned char soft_reset[] = { 0x00, 0x00 }; 768 unsigned char soft_reset[] = { 0x00, 0x00 };
691 unsigned char easy_mode_b[] = { 0x01, 0x02 }; 769 unsigned char easy_mode_b[] = { 0x01, 0x02 };
692 unsigned char easy_mode_g[] = { 0x01, 0x04 }; 770 unsigned char easy_mode_g[] = { 0x01, 0x04 };
@@ -694,23 +772,30 @@ int tda8290_probe(struct i2c_client *c)
694 unsigned char addr_dto_lsb = 0x07; 772 unsigned char addr_dto_lsb = 0x07;
695 unsigned char data; 773 unsigned char data;
696 774
697 i2c_master_send(c, easy_mode_b, 2); 775 tuner_i2c_xfer_send(&i2c_props, easy_mode_b, 2);
698 i2c_master_send(c, soft_reset, 2); 776 tuner_i2c_xfer_send(&i2c_props, soft_reset, 2);
699 i2c_master_send(c, &addr_dto_lsb, 1); 777 tuner_i2c_xfer_send(&i2c_props, &addr_dto_lsb, 1);
700 i2c_master_recv(c, &data, 1); 778 tuner_i2c_xfer_recv(&i2c_props, &data, 1);
701 if (data == 0) { 779 if (data == 0) {
702 i2c_master_send(c, easy_mode_g, 2); 780 tuner_i2c_xfer_send(&i2c_props, easy_mode_g, 2);
703 i2c_master_send(c, soft_reset, 2); 781 tuner_i2c_xfer_send(&i2c_props, soft_reset, 2);
704 i2c_master_send(c, &addr_dto_lsb, 1); 782 tuner_i2c_xfer_send(&i2c_props, &addr_dto_lsb, 1);
705 i2c_master_recv(c, &data, 1); 783 tuner_i2c_xfer_recv(&i2c_props, &data, 1);
706 if (data == 0x7b) { 784 if (data == 0x7b) {
707 return 0; 785 return 0;
708 } 786 }
709 } 787 }
710 i2c_master_send(c, restore_9886, 3); 788 tuner_i2c_xfer_send(&i2c_props, restore_9886, 3);
711 return -1; 789 return -1;
712} 790}
713 791
792EXPORT_SYMBOL_GPL(tda8290_probe);
793EXPORT_SYMBOL_GPL(tda8290_attach);
794
795MODULE_DESCRIPTION("Philips TDA8290 + TDA8275 / TDA8275a tuner driver");
796MODULE_AUTHOR("Gerd Knorr, Hartmut Hackmann");
797MODULE_LICENSE("GPL");
798
714/* 799/*
715 * Overrides for Emacs so that we follow Linus's tabbing style. 800 * Overrides for Emacs so that we follow Linus's tabbing style.
716 * --------------------------------------------------------------------------- 801 * ---------------------------------------------------------------------------
diff --git a/drivers/media/video/tda8290.h b/drivers/media/video/tda8290.h
new file mode 100644
index 000000000000..107b24b05aa1
--- /dev/null
+++ b/drivers/media/video/tda8290.h
@@ -0,0 +1,54 @@
1/*
2 This program is free software; you can redistribute it and/or modify
3 it under the terms of the GNU General Public License as published by
4 the Free Software Foundation; either version 2 of the License, or
5 (at your option) any later version.
6
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
11
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
15*/
16
17#ifndef __TDA8290_H__
18#define __TDA8290_H__
19
20#include <linux/i2c.h>
21#include "dvb_frontend.h"
22
23struct tda8290_config
24{
25 unsigned int *lna_cfg;
26 int (*tuner_callback) (void *dev, int command,int arg);
27};
28
29#if defined(CONFIG_TUNER_TDA8290) || (defined(CONFIG_TUNER_TDA8290_MODULE) && defined(MODULE))
30extern int tda8290_probe(struct i2c_adapter* i2c_adap, u8 i2c_addr);
31
32extern struct dvb_frontend *tda8290_attach(struct dvb_frontend *fe,
33 struct i2c_adapter* i2c_adap,
34 u8 i2c_addr,
35 struct tda8290_config *cfg);
36#else
37static inline int tda8290_probe(struct i2c_adapter* i2c_adap, u8 i2c_addr)
38{
39 printk(KERN_INFO "%s: not probed - driver disabled by Kconfig\n",
40 __FUNCTION__);
41 return -EINVAL;
42}
43
44static inline struct dvb_frontend *tda8290_attach(struct dvb_frontend *fe,
45 struct i2c_adapter* i2c_adap,
46 u8 i2c_addr,
47 struct tda8290_config *cfg)
48{
49 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
50 return NULL;
51}
52#endif
53
54#endif /* __TDA8290_H__ */
diff --git a/drivers/media/video/tda9887.c b/drivers/media/video/tda9887.c
index a8f773274fe3..be5387f11afb 100644
--- a/drivers/media/video/tda9887.c
+++ b/drivers/media/video/tda9887.c
@@ -1,14 +1,12 @@
1#include <linux/module.h> 1#include <linux/module.h>
2#include <linux/moduleparam.h>
3#include <linux/kernel.h> 2#include <linux/kernel.h>
4#include <linux/i2c.h> 3#include <linux/i2c.h>
5#include <linux/types.h> 4#include <linux/types.h>
6#include <linux/videodev.h>
7#include <linux/init.h> 5#include <linux/init.h>
8#include <linux/errno.h> 6#include <linux/errno.h>
9#include <linux/slab.h> 7#include <linux/slab.h>
10#include <linux/delay.h> 8#include <linux/delay.h>
11 9#include <linux/videodev.h>
12#include <media/v4l2-common.h> 10#include <media/v4l2-common.h>
13#include <media/tuner.h> 11#include <media/tuner.h>
14#include "tuner-driver.h" 12#include "tuner-driver.h"
@@ -31,6 +29,8 @@
31 i2c_adapter_id(t->i2c.adapter), t->i2c.addr , ##arg); } while (0) 29 i2c_adapter_id(t->i2c.adapter), t->i2c.addr , ##arg); } while (0)
32 30
33struct tda9887_priv { 31struct tda9887_priv {
32 struct tuner_i2c_props i2c_props;
33
34 unsigned char data[4]; 34 unsigned char data[4];
35}; 35};
36 36
@@ -97,6 +97,8 @@ struct tvnorm {
97#define cAudioIF_6_5 0x03 // bit e0:1 97#define cAudioIF_6_5 0x03 // bit e0:1
98 98
99 99
100#define cVideoIFMask 0x1c // bit e2:4
101/* Video IF selection in TV Mode (bit B3=0) */
100#define cVideoIF_58_75 0x00 // bit e2:4 102#define cVideoIF_58_75 0x00 // bit e2:4
101#define cVideoIF_45_75 0x04 // bit e2:4 103#define cVideoIF_45_75 0x04 // bit e2:4
102#define cVideoIF_38_90 0x08 // bit e2:4 104#define cVideoIF_38_90 0x08 // bit e2:4
@@ -106,6 +108,13 @@ struct tvnorm {
106#define cRadioIF_45_75 0x18 // bit e2:4 108#define cRadioIF_45_75 0x18 // bit e2:4
107#define cRadioIF_38_90 0x1C // bit e2:4 109#define cRadioIF_38_90 0x1C // bit e2:4
108 110
111/* IF1 selection in Radio Mode (bit B3=1) */
112#define cRadioIF_33_30 0x00 // bit e2,4 (also 0x10,0x14)
113#define cRadioIF_41_30 0x04 // bit e2,4
114
115/* Output of AFC pin in radio mode when bit E7=1 */
116#define cRadioAGC_SIF 0x00 // bit e3
117#define cRadioAGC_FM 0x08 // bit e3
109 118
110#define cTunerGainNormal 0x00 // bit e5 119#define cTunerGainNormal 0x00 // bit e5
111#define cTunerGainLow 0x20 // bit e5 120#define cTunerGainLow 0x20 // bit e5
@@ -487,9 +496,13 @@ static int tda9887_set_config(struct tuner *t, char *buf)
487 if (t->tda9887_config & TDA9887_GATING_18) 496 if (t->tda9887_config & TDA9887_GATING_18)
488 buf[3] &= ~cGating_36; 497 buf[3] &= ~cGating_36;
489 498
490 if (t->tda9887_config & TDA9887_GAIN_NORMAL) { 499 if (t->mode == V4L2_TUNER_RADIO) {
491 radio_stereo.e &= ~cTunerGainLow; 500 if (t->tda9887_config & TDA9887_RIF_41_3) {
492 radio_mono.e &= ~cTunerGainLow; 501 buf[3] &= ~cVideoIFMask;
502 buf[3] |= cRadioIF_41_30;
503 }
504 if (t->tda9887_config & TDA9887_GAIN_NORMAL)
505 buf[3] &= ~cTunerGainLow;
493 } 506 }
494 507
495 return 0; 508 return 0;
@@ -499,19 +512,19 @@ static int tda9887_set_config(struct tuner *t, char *buf)
499 512
500static int tda9887_status(struct tuner *t) 513static int tda9887_status(struct tuner *t)
501{ 514{
515 struct tda9887_priv *priv = t->priv;
502 unsigned char buf[1]; 516 unsigned char buf[1];
503 int rc; 517 int rc;
504 518
505 memset(buf,0,sizeof(buf)); 519 memset(buf,0,sizeof(buf));
506 if (1 != (rc = i2c_master_recv(&t->i2c,buf,1))) 520 if (1 != (rc = tuner_i2c_xfer_recv(&priv->i2c_props,buf,1)))
507 tda9887_info("i2c i/o error: rc == %d (should be 1)\n",rc); 521 tda9887_info("i2c i/o error: rc == %d (should be 1)\n",rc);
508 dump_read_message(t, buf); 522 dump_read_message(t, buf);
509 return 0; 523 return 0;
510} 524}
511 525
512static void tda9887_configure(struct i2c_client *client) 526static void tda9887_configure(struct tuner *t)
513{ 527{
514 struct tuner *t = i2c_get_clientdata(client);
515 struct tda9887_priv *priv = t->priv; 528 struct tda9887_priv *priv = t->priv;
516 int rc; 529 int rc;
517 530
@@ -546,7 +559,7 @@ static void tda9887_configure(struct i2c_client *client)
546 if (tuner_debug > 1) 559 if (tuner_debug > 1)
547 dump_write_message(t, priv->data); 560 dump_write_message(t, priv->data);
548 561
549 if (4 != (rc = i2c_master_send(&t->i2c,priv->data,4))) 562 if (4 != (rc = tuner_i2c_xfer_send(&priv->i2c_props,priv->data,4)))
550 tda9887_info("i2c i/o error: rc == %d (should be 4)\n",rc); 563 tda9887_info("i2c i/o error: rc == %d (should be 4)\n",rc);
551 564
552 if (tuner_debug > 2) { 565 if (tuner_debug > 2) {
@@ -557,16 +570,15 @@ static void tda9887_configure(struct i2c_client *client)
557 570
558/* ---------------------------------------------------------------------- */ 571/* ---------------------------------------------------------------------- */
559 572
560static void tda9887_tuner_status(struct i2c_client *client) 573static void tda9887_tuner_status(struct tuner *t)
561{ 574{
562 struct tuner *t = i2c_get_clientdata(client);
563 struct tda9887_priv *priv = t->priv; 575 struct tda9887_priv *priv = t->priv;
564 tda9887_info("Data bytes: b=0x%02x c=0x%02x e=0x%02x\n", priv->data[1], priv->data[2], priv->data[3]); 576 tda9887_info("Data bytes: b=0x%02x c=0x%02x e=0x%02x\n", priv->data[1], priv->data[2], priv->data[3]);
565} 577}
566 578
567static int tda9887_get_afc(struct i2c_client *client) 579static int tda9887_get_afc(struct tuner *t)
568{ 580{
569 struct tuner *t = i2c_get_clientdata(client); 581 struct tda9887_priv *priv = t->priv;
570 static int AFC_BITS_2_kHz[] = { 582 static int AFC_BITS_2_kHz[] = {
571 -12500, -37500, -62500, -97500, 583 -12500, -37500, -62500, -97500,
572 -112500, -137500, -162500, -187500, 584 -112500, -137500, -162500, -187500,
@@ -576,26 +588,24 @@ static int tda9887_get_afc(struct i2c_client *client)
576 int afc=0; 588 int afc=0;
577 __u8 reg = 0; 589 __u8 reg = 0;
578 590
579 if (1 == i2c_master_recv(&t->i2c,&reg,1)) 591 if (1 == tuner_i2c_xfer_recv(&priv->i2c_props,&reg,1))
580 afc = AFC_BITS_2_kHz[(reg>>1)&0x0f]; 592 afc = AFC_BITS_2_kHz[(reg>>1)&0x0f];
581 593
582 return afc; 594 return afc;
583} 595}
584 596
585static void tda9887_standby(struct i2c_client *client) 597static void tda9887_standby(struct tuner *t)
586{ 598{
587 tda9887_configure(client); 599 tda9887_configure(t);
588} 600}
589 601
590static void tda9887_set_freq(struct i2c_client *client, unsigned int freq) 602static void tda9887_set_freq(struct tuner *t, unsigned int freq)
591{ 603{
592 tda9887_configure(client); 604 tda9887_configure(t);
593} 605}
594 606
595static void tda9887_release(struct i2c_client *c) 607static void tda9887_release(struct tuner *t)
596{ 608{
597 struct tuner *t = i2c_get_clientdata(c);
598
599 kfree(t->priv); 609 kfree(t->priv);
600 t->priv = NULL; 610 t->priv = NULL;
601} 611}
@@ -609,17 +619,19 @@ static struct tuner_operations tda9887_tuner_ops = {
609 .release = tda9887_release, 619 .release = tda9887_release,
610}; 620};
611 621
612int tda9887_tuner_init(struct i2c_client *c) 622int tda9887_tuner_init(struct tuner *t)
613{ 623{
614 struct tda9887_priv *priv = NULL; 624 struct tda9887_priv *priv = NULL;
615 struct tuner *t = i2c_get_clientdata(c);
616 625
617 priv = kzalloc(sizeof(struct tda9887_priv), GFP_KERNEL); 626 priv = kzalloc(sizeof(struct tda9887_priv), GFP_KERNEL);
618 if (priv == NULL) 627 if (priv == NULL)
619 return -ENOMEM; 628 return -ENOMEM;
620 t->priv = priv; 629 t->priv = priv;
621 630
622 strlcpy(c->name, "tda9887", sizeof(c->name)); 631 priv->i2c_props.addr = t->i2c.addr;
632 priv->i2c_props.adap = t->i2c.adapter;
633
634 strlcpy(t->i2c.name, "tda9887", sizeof(t->i2c.name));
623 635
624 tda9887_info("tda988[5/6/7] found @ 0x%x (%s)\n", t->i2c.addr, 636 tda9887_info("tda988[5/6/7] found @ 0x%x (%s)\n", t->i2c.addr,
625 t->i2c.driver->driver.name); 637 t->i2c.driver->driver.name);
diff --git a/drivers/media/video/tea5761.c b/drivers/media/video/tea5761.c
index ae105c2cd0ac..2150222a3860 100644
--- a/drivers/media/video/tea5761.c
+++ b/drivers/media/video/tea5761.c
@@ -8,15 +8,23 @@
8 */ 8 */
9 9
10#include <linux/i2c.h> 10#include <linux/i2c.h>
11#include <linux/videodev.h>
12#include <linux/delay.h> 11#include <linux/delay.h>
12#include <linux/videodev.h>
13#include <media/tuner.h> 13#include <media/tuner.h>
14#include "tuner-driver.h" 14#include "tuner-i2c.h"
15#include "tea5761.h"
15 16
16#define PREFIX "TEA5761 " 17static int debug = 0;
18module_param(debug, int, 0644);
19MODULE_PARM_DESC(debug, "enable verbose debug messages");
17 20
18/* from tuner-core.c */ 21#define PREFIX "tea5761 "
19extern int tuner_debug; 22
23struct tea5761_priv {
24 struct tuner_i2c_props i2c_props;
25
26 u32 frequency;
27};
20 28
21/*****************************************************************************/ 29/*****************************************************************************/
22 30
@@ -114,13 +122,6 @@ extern int tuner_debug;
114 122
115/*****************************************************************************/ 123/*****************************************************************************/
116 124
117static void set_tv_freq(struct i2c_client *c, unsigned int freq)
118{
119 struct tuner *t = i2c_get_clientdata(c);
120
121 tuner_warn("This tuner doesn't support TV freq.\n");
122}
123
124#define FREQ_OFFSET 0 /* for TEA5767, it is 700 to give the right freq */ 125#define FREQ_OFFSET 0 /* for TEA5767, it is 700 to give the right freq */
125static void tea5761_status_dump(unsigned char *buffer) 126static void tea5761_status_dump(unsigned char *buffer)
126{ 127{
@@ -135,16 +136,18 @@ static void tea5761_status_dump(unsigned char *buffer)
135} 136}
136 137
137/* Freq should be specifyed at 62.5 Hz */ 138/* Freq should be specifyed at 62.5 Hz */
138static void set_radio_freq(struct i2c_client *c, unsigned int frq) 139static int set_radio_freq(struct dvb_frontend *fe,
140 struct analog_parameters *params)
139{ 141{
140 struct tuner *t = i2c_get_clientdata(c); 142 struct tea5761_priv *priv = fe->tuner_priv;
143 unsigned int frq = params->frequency;
141 unsigned char buffer[7] = {0, 0, 0, 0, 0, 0, 0 }; 144 unsigned char buffer[7] = {0, 0, 0, 0, 0, 0, 0 };
142 unsigned div; 145 unsigned div;
143 int rc; 146 int rc;
144 147
145 tuner_dbg (PREFIX "radio freq counter %d\n", frq); 148 tuner_dbg("radio freq counter %d\n", frq);
146 149
147 if (t->mode == T_STANDBY) { 150 if (params->mode == T_STANDBY) {
148 tuner_dbg("TEA5761 set to standby mode\n"); 151 tuner_dbg("TEA5761 set to standby mode\n");
149 buffer[5] |= TEA5761_TNCTRL_MU; 152 buffer[5] |= TEA5761_TNCTRL_MU;
150 } else { 153 } else {
@@ -152,10 +155,9 @@ static void set_radio_freq(struct i2c_client *c, unsigned int frq)
152 } 155 }
153 156
154 157
155 if (t->audmode == V4L2_TUNER_MODE_MONO) { 158 if (params->audmode == V4L2_TUNER_MODE_MONO) {
156 tuner_dbg("TEA5761 set to mono\n"); 159 tuner_dbg("TEA5761 set to mono\n");
157 buffer[5] |= TEA5761_TNCTRL_MST; 160 buffer[5] |= TEA5761_TNCTRL_MST;
158;
159 } else { 161 } else {
160 tuner_dbg("TEA5761 set to stereo\n"); 162 tuner_dbg("TEA5761 set to stereo\n");
161 } 163 }
@@ -164,80 +166,155 @@ static void set_radio_freq(struct i2c_client *c, unsigned int frq)
164 buffer[1] = (div >> 8) & 0x3f; 166 buffer[1] = (div >> 8) & 0x3f;
165 buffer[2] = div & 0xff; 167 buffer[2] = div & 0xff;
166 168
167 if (tuner_debug) 169 if (debug)
168 tea5761_status_dump(buffer); 170 tea5761_status_dump(buffer);
169 171
170 if (7 != (rc = i2c_master_send(c, buffer, 7))) 172 if (7 != (rc = tuner_i2c_xfer_send(&priv->i2c_props, buffer, 7)))
171 tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc); 173 tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc);
174
175 priv->frequency = frq * 125 / 2;
176
177 return 0;
172} 178}
173 179
174static int tea5761_signal(struct i2c_client *c) 180static int tea5761_read_status(struct dvb_frontend *fe, char *buffer)
175{ 181{
176 unsigned char buffer[16]; 182 struct tea5761_priv *priv = fe->tuner_priv;
177 int rc; 183 int rc;
178 struct tuner *t = i2c_get_clientdata(c);
179 184
180 memset(buffer, 0, sizeof(buffer)); 185 memset(buffer, 0, 16);
181 if (16 != (rc = i2c_master_recv(c, buffer, 16))) 186 if (16 != (rc = tuner_i2c_xfer_recv(&priv->i2c_props, buffer, 16))) {
182 tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc); 187 tuner_warn("i2c i/o error: rc == %d (should be 16)\n", rc);
188 return -EREMOTEIO;
189 }
190
191 return 0;
192}
193
194static inline int tea5761_signal(struct dvb_frontend *fe, const char *buffer)
195{
196 struct tea5761_priv *priv = fe->tuner_priv;
197
198 int signal = ((buffer[9] & TEA5761_TUNCHECK_LEV_MASK) << (13 - 4));
199
200 tuner_dbg("Signal strength: %d\n", signal);
201
202 return signal;
203}
204
205static inline int tea5761_stereo(struct dvb_frontend *fe, const char *buffer)
206{
207 struct tea5761_priv *priv = fe->tuner_priv;
208
209 int stereo = buffer[9] & TEA5761_TUNCHECK_STEREO;
183 210
184 return ((buffer[9] & TEA5761_TUNCHECK_LEV_MASK) << (13 - 4)); 211 tuner_dbg("Radio ST GET = %02x\n", stereo);
212
213 return (stereo ? V4L2_TUNER_SUB_STEREO : 0);
185} 214}
186 215
187static int tea5761_stereo(struct i2c_client *c) 216static int tea5761_get_status(struct dvb_frontend *fe, u32 *status)
188{ 217{
189 unsigned char buffer[16]; 218 unsigned char buffer[16];
190 int rc;
191 struct tuner *t = i2c_get_clientdata(c);
192 219
193 memset(buffer, 0, sizeof(buffer)); 220 *status = 0;
194 if (16 != (rc = i2c_master_recv(c, buffer, 16))) 221
195 tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc); 222 if (0 == tea5761_read_status(fe, buffer)) {
223 if (tea5761_signal(fe, buffer))
224 *status = TUNER_STATUS_LOCKED;
225 if (tea5761_stereo(fe, buffer))
226 *status |= TUNER_STATUS_STEREO;
227 }
228
229 return 0;
230}
231
232static int tea5761_get_rf_strength(struct dvb_frontend *fe, u16 *strength)
233{
234 unsigned char buffer[16];
196 235
197 rc = buffer[9] & TEA5761_TUNCHECK_STEREO; 236 *strength = 0;
198 237
199 tuner_dbg("TEA5761 radio ST GET = %02x\n", rc); 238 if (0 == tea5761_read_status(fe, buffer))
239 *strength = tea5761_signal(fe, buffer);
200 240
201 return (rc ? V4L2_TUNER_SUB_STEREO : 0); 241 return 0;
202} 242}
203 243
204int tea5761_autodetection(struct i2c_client *c) 244int tea5761_autodetection(struct i2c_adapter* i2c_adap, u8 i2c_addr)
205{ 245{
206 unsigned char buffer[16]; 246 unsigned char buffer[16];
207 int rc; 247 int rc;
208 struct tuner *t = i2c_get_clientdata(c); 248 struct tuner_i2c_props i2c = { .adap = i2c_adap, .addr = i2c_addr };
209 249
210 if (16 != (rc = i2c_master_recv(c, buffer, 16))) { 250 if (16 != (rc = tuner_i2c_xfer_recv(&i2c, buffer, 16))) {
211 tuner_warn("it is not a TEA5761. Received %i chars.\n", rc); 251 printk(KERN_WARNING "it is not a TEA5761. Received %i chars.\n", rc);
212 return EINVAL; 252 return EINVAL;
213 } 253 }
214 254
215 if (!((buffer[13] != 0x2b) || (buffer[14] != 0x57) || (buffer[15] != 0x061))) { 255 if (!((buffer[13] != 0x2b) || (buffer[14] != 0x57) || (buffer[15] != 0x061))) {
216 tuner_warn("Manufacturer ID= 0x%02x, Chip ID = %02x%02x. It is not a TEA5761\n",buffer[13],buffer[14],buffer[15]); 256 printk(KERN_WARNING "Manufacturer ID= 0x%02x, Chip ID = %02x%02x. It is not a TEA5761\n",buffer[13],buffer[14],buffer[15]);
217 return EINVAL; 257 return EINVAL;
218 } 258 }
219 tuner_warn("TEA5761 detected.\n"); 259 printk(KERN_WARNING "TEA5761 detected.\n");
220 return 0; 260 return 0;
221} 261}
222 262
223static struct tuner_operations tea5761_tuner_ops = { 263static int tea5761_release(struct dvb_frontend *fe)
224 .set_tv_freq = set_tv_freq, 264{
225 .set_radio_freq = set_radio_freq, 265 kfree(fe->tuner_priv);
226 .has_signal = tea5761_signal, 266 fe->tuner_priv = NULL;
227 .is_stereo = tea5761_stereo, 267
268 return 0;
269}
270
271static int tea5761_get_frequency(struct dvb_frontend *fe, u32 *frequency)
272{
273 struct tea5761_priv *priv = fe->tuner_priv;
274 *frequency = priv->frequency;
275 return 0;
276}
277
278static struct dvb_tuner_ops tea5761_tuner_ops = {
279 .info = {
280 .name = "tea5761", // Philips TEA5761HN FM Radio
281 },
282 .set_analog_params = set_radio_freq,
283 .release = tea5761_release,
284 .get_frequency = tea5761_get_frequency,
285 .get_status = tea5761_get_status,
286 .get_rf_strength = tea5761_get_rf_strength,
228}; 287};
229 288
230int tea5761_tuner_init(struct i2c_client *c) 289struct dvb_frontend *tea5761_attach(struct dvb_frontend *fe,
290 struct i2c_adapter* i2c_adap,
291 u8 i2c_addr)
231{ 292{
232 struct tuner *t = i2c_get_clientdata(c); 293 struct tea5761_priv *priv = NULL;
233 294
234 if (tea5761_autodetection(c) == EINVAL) 295 if (tea5761_autodetection(i2c_adap, i2c_addr) == EINVAL)
235 return EINVAL; 296 return NULL;
297
298 priv = kzalloc(sizeof(struct tea5761_priv), GFP_KERNEL);
299 if (priv == NULL)
300 return NULL;
301 fe->tuner_priv = priv;
302
303 priv->i2c_props.addr = i2c_addr;
304 priv->i2c_props.adap = i2c_adap;
236 305
237 tuner_info("type set to %d (%s)\n", t->type, "Philips TEA5761HN FM Radio"); 306 memcpy(&fe->ops.tuner_ops, &tea5761_tuner_ops,
238 strlcpy(c->name, "tea5761", sizeof(c->name)); 307 sizeof(struct dvb_tuner_ops));
239 308
240 memcpy(&t->ops, &tea5761_tuner_ops, sizeof(struct tuner_operations)); 309 tuner_info("type set to %s\n", "Philips TEA5761HN FM Radio");
241 310
242 return (0); 311 return fe;
243} 312}
313
314
315EXPORT_SYMBOL_GPL(tea5761_attach);
316EXPORT_SYMBOL_GPL(tea5761_autodetection);
317
318MODULE_DESCRIPTION("Philips TEA5761 FM tuner driver");
319MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
320MODULE_LICENSE("GPL");
diff --git a/drivers/media/video/tea5761.h b/drivers/media/video/tea5761.h
new file mode 100644
index 000000000000..73a03b427843
--- /dev/null
+++ b/drivers/media/video/tea5761.h
@@ -0,0 +1,47 @@
1/*
2 This program is free software; you can redistribute it and/or modify
3 it under the terms of the GNU General Public License as published by
4 the Free Software Foundation; either version 2 of the License, or
5 (at your option) any later version.
6
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
11
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
15*/
16
17#ifndef __TEA5761_H__
18#define __TEA5761_H__
19
20#include <linux/i2c.h>
21#include "dvb_frontend.h"
22
23#if defined(CONFIG_TUNER_TEA5761) || (defined(CONFIG_TUNER_TEA5761_MODULE) && defined(MODULE))
24extern int tea5761_autodetection(struct i2c_adapter* i2c_adap, u8 i2c_addr);
25
26extern struct dvb_frontend *tea5761_attach(struct dvb_frontend *fe,
27 struct i2c_adapter* i2c_adap,
28 u8 i2c_addr);
29#else
30static inline int tea5761_autodetection(struct i2c_adapter* i2c_adap,
31 u8 i2c_addr)
32{
33 printk(KERN_INFO "%s: not probed - driver disabled by Kconfig\n",
34 __FUNCTION__);
35 return -EINVAL;
36}
37
38static inline struct dvb_frontend *tea5761_attach(struct dvb_frontend *fe,
39 struct i2c_adapter* i2c_adap,
40 u8 i2c_addr)
41{
42 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
43 return NULL;
44}
45#endif
46
47#endif /* __TEA5761_H__ */
diff --git a/drivers/media/video/tea5767.c b/drivers/media/video/tea5767.c
index 4985d47a508f..71df419df7bc 100644
--- a/drivers/media/video/tea5767.c
+++ b/drivers/media/video/tea5767.c
@@ -11,14 +11,22 @@
11 */ 11 */
12 12
13#include <linux/i2c.h> 13#include <linux/i2c.h>
14#include <linux/videodev.h>
15#include <linux/delay.h> 14#include <linux/delay.h>
16#include "tuner-driver.h" 15#include <linux/videodev.h>
16#include "tuner-i2c.h"
17#include "tea5767.h"
17 18
18#define PREFIX "TEA5767 " 19static int debug = 0;
20module_param(debug, int, 0644);
21MODULE_PARM_DESC(debug, "enable verbose debug messages");
19 22
20/* from tuner-core.c */ 23#define PREFIX "tea5767 "
21extern int tuner_debug; 24
25struct tea5767_priv {
26 struct tuner_i2c_props i2c_props;
27
28 u32 frequency;
29};
22 30
23/*****************************************************************************/ 31/*****************************************************************************/
24 32
@@ -129,13 +137,6 @@ enum tea5767_xtal_freq {
129 137
130/*****************************************************************************/ 138/*****************************************************************************/
131 139
132static void set_tv_freq(struct i2c_client *c, unsigned int freq)
133{
134 struct tuner *t = i2c_get_clientdata(c);
135
136 tuner_warn("This tuner doesn't support TV freq.\n");
137}
138
139static void tea5767_status_dump(unsigned char *buffer) 140static void tea5767_status_dump(unsigned char *buffer)
140{ 141{
141 unsigned int div, frq; 142 unsigned int div, frq;
@@ -190,14 +191,16 @@ static void tea5767_status_dump(unsigned char *buffer)
190} 191}
191 192
192/* Freq should be specifyed at 62.5 Hz */ 193/* Freq should be specifyed at 62.5 Hz */
193static void set_radio_freq(struct i2c_client *c, unsigned int frq) 194static int set_radio_freq(struct dvb_frontend *fe,
195 struct analog_parameters *params)
194{ 196{
195 struct tuner *t = i2c_get_clientdata(c); 197 struct tea5767_priv *priv = fe->tuner_priv;
198 unsigned int frq = params->frequency;
196 unsigned char buffer[5]; 199 unsigned char buffer[5];
197 unsigned div; 200 unsigned div;
198 int rc; 201 int rc;
199 202
200 tuner_dbg (PREFIX "radio freq = %d.%03d MHz\n", frq/16000,(frq/16)%1000); 203 tuner_dbg("radio freq = %d.%03d MHz\n", frq/16000,(frq/16)%1000);
201 204
202 /* Rounds freq to next decimal value - for 62.5 KHz step */ 205 /* Rounds freq to next decimal value - for 62.5 KHz step */
203 /* frq = 20*(frq/16)+radio_frq[frq%16]; */ 206 /* frq = 20*(frq/16)+radio_frq[frq%16]; */
@@ -207,7 +210,7 @@ static void set_radio_freq(struct i2c_client *c, unsigned int frq)
207 TEA5767_ST_NOISE_CTL | TEA5767_JAPAN_BAND; 210 TEA5767_ST_NOISE_CTL | TEA5767_JAPAN_BAND;
208 buffer[4] = 0; 211 buffer[4] = 0;
209 212
210 if (t->audmode == V4L2_TUNER_MODE_MONO) { 213 if (params->audmode == V4L2_TUNER_MODE_MONO) {
211 tuner_dbg("TEA5767 set to mono\n"); 214 tuner_dbg("TEA5767 set to mono\n");
212 buffer[2] |= TEA5767_MONO; 215 buffer[2] |= TEA5767_MONO;
213 } else { 216 } else {
@@ -217,26 +220,26 @@ static void set_radio_freq(struct i2c_client *c, unsigned int frq)
217 /* Should be replaced */ 220 /* Should be replaced */
218 switch (TEA5767_HIGH_LO_32768) { 221 switch (TEA5767_HIGH_LO_32768) {
219 case TEA5767_HIGH_LO_13MHz: 222 case TEA5767_HIGH_LO_13MHz:
220 tuner_dbg ("TEA5767 radio HIGH LO inject xtal @ 13 MHz\n"); 223 tuner_dbg("radio HIGH LO inject xtal @ 13 MHz\n");
221 buffer[2] |= TEA5767_HIGH_LO_INJECT; 224 buffer[2] |= TEA5767_HIGH_LO_INJECT;
222 buffer[4] |= TEA5767_PLLREF_ENABLE; 225 buffer[4] |= TEA5767_PLLREF_ENABLE;
223 div = (frq * (4000 / 16) + 700000 + 225000 + 25000) / 50000; 226 div = (frq * (4000 / 16) + 700000 + 225000 + 25000) / 50000;
224 break; 227 break;
225 case TEA5767_LOW_LO_13MHz: 228 case TEA5767_LOW_LO_13MHz:
226 tuner_dbg ("TEA5767 radio LOW LO inject xtal @ 13 MHz\n"); 229 tuner_dbg("radio LOW LO inject xtal @ 13 MHz\n");
227 230
228 buffer[4] |= TEA5767_PLLREF_ENABLE; 231 buffer[4] |= TEA5767_PLLREF_ENABLE;
229 div = (frq * (4000 / 16) - 700000 - 225000 + 25000) / 50000; 232 div = (frq * (4000 / 16) - 700000 - 225000 + 25000) / 50000;
230 break; 233 break;
231 case TEA5767_LOW_LO_32768: 234 case TEA5767_LOW_LO_32768:
232 tuner_dbg ("TEA5767 radio LOW LO inject xtal @ 32,768 MHz\n"); 235 tuner_dbg("radio LOW LO inject xtal @ 32,768 MHz\n");
233 buffer[3] |= TEA5767_XTAL_32768; 236 buffer[3] |= TEA5767_XTAL_32768;
234 /* const 700=4000*175 Khz - to adjust freq to right value */ 237 /* const 700=4000*175 Khz - to adjust freq to right value */
235 div = ((frq * (4000 / 16) - 700000 - 225000) + 16384) >> 15; 238 div = ((frq * (4000 / 16) - 700000 - 225000) + 16384) >> 15;
236 break; 239 break;
237 case TEA5767_HIGH_LO_32768: 240 case TEA5767_HIGH_LO_32768:
238 default: 241 default:
239 tuner_dbg ("TEA5767 radio HIGH LO inject xtal @ 32,768 MHz\n"); 242 tuner_dbg("radio HIGH LO inject xtal @ 32,768 MHz\n");
240 243
241 buffer[2] |= TEA5767_HIGH_LO_INJECT; 244 buffer[2] |= TEA5767_HIGH_LO_INJECT;
242 buffer[3] |= TEA5767_XTAL_32768; 245 buffer[3] |= TEA5767_XTAL_32768;
@@ -246,51 +249,89 @@ static void set_radio_freq(struct i2c_client *c, unsigned int frq)
246 buffer[0] = (div >> 8) & 0x3f; 249 buffer[0] = (div >> 8) & 0x3f;
247 buffer[1] = div & 0xff; 250 buffer[1] = div & 0xff;
248 251
249 if (5 != (rc = i2c_master_send(c, buffer, 5))) 252 if (5 != (rc = tuner_i2c_xfer_send(&priv->i2c_props, buffer, 5)))
250 tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc); 253 tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc);
251 254
252 if (tuner_debug) { 255 if (debug) {
253 if (5 != (rc = i2c_master_recv(c, buffer, 5))) 256 if (5 != (rc = tuner_i2c_xfer_recv(&priv->i2c_props, buffer, 5)))
254 tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc); 257 tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc);
255 else 258 else
256 tea5767_status_dump(buffer); 259 tea5767_status_dump(buffer);
257 } 260 }
261
262 priv->frequency = frq * 125 / 2;
263
264 return 0;
258} 265}
259 266
260static int tea5767_signal(struct i2c_client *c) 267static int tea5767_read_status(struct dvb_frontend *fe, char *buffer)
261{ 268{
262 unsigned char buffer[5]; 269 struct tea5767_priv *priv = fe->tuner_priv;
263 int rc; 270 int rc;
264 struct tuner *t = i2c_get_clientdata(c);
265 271
266 memset(buffer, 0, sizeof(buffer)); 272 memset(buffer, 0, 5);
267 if (5 != (rc = i2c_master_recv(c, buffer, 5))) 273 if (5 != (rc = tuner_i2c_xfer_recv(&priv->i2c_props, buffer, 5))) {
268 tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc); 274 tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc);
275 return -EREMOTEIO;
276 }
277
278 return 0;
279}
280
281static inline int tea5767_signal(struct dvb_frontend *fe, const char *buffer)
282{
283 struct tea5767_priv *priv = fe->tuner_priv;
284
285 int signal = ((buffer[3] & TEA5767_ADC_LEVEL_MASK) << 8);
286
287 tuner_dbg("Signal strength: %d\n", signal);
288
289 return signal;
290}
291
292static inline int tea5767_stereo(struct dvb_frontend *fe, const char *buffer)
293{
294 struct tea5767_priv *priv = fe->tuner_priv;
295
296 int stereo = buffer[2] & TEA5767_STEREO_MASK;
297
298 tuner_dbg("Radio ST GET = %02x\n", stereo);
269 299
270 return ((buffer[3] & TEA5767_ADC_LEVEL_MASK) << 8); 300 return (stereo ? V4L2_TUNER_SUB_STEREO : 0);
271} 301}
272 302
273static int tea5767_stereo(struct i2c_client *c) 303static int tea5767_get_status(struct dvb_frontend *fe, u32 *status)
274{ 304{
275 unsigned char buffer[5]; 305 unsigned char buffer[5];
276 int rc;
277 struct tuner *t = i2c_get_clientdata(c);
278 306
279 memset(buffer, 0, sizeof(buffer)); 307 *status = 0;
280 if (5 != (rc = i2c_master_recv(c, buffer, 5))) 308
281 tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc); 309 if (0 == tea5767_read_status(fe, buffer)) {
310 if (tea5767_signal(fe, buffer))
311 *status = TUNER_STATUS_LOCKED;
312 if (tea5767_stereo(fe, buffer))
313 *status |= TUNER_STATUS_STEREO;
314 }
315
316 return 0;
317}
282 318
283 rc = buffer[2] & TEA5767_STEREO_MASK; 319static int tea5767_get_rf_strength(struct dvb_frontend *fe, u16 *strength)
320{
321 unsigned char buffer[5];
284 322
285 tuner_dbg("TEA5767 radio ST GET = %02x\n", rc); 323 *strength = 0;
286 324
287 return ((buffer[2] & TEA5767_STEREO_MASK) ? V4L2_TUNER_SUB_STEREO : 0); 325 if (0 == tea5767_read_status(fe, buffer))
326 *strength = tea5767_signal(fe, buffer);
327
328 return 0;
288} 329}
289 330
290static void tea5767_standby(struct i2c_client *c) 331static int tea5767_standby(struct dvb_frontend *fe)
291{ 332{
292 unsigned char buffer[5]; 333 unsigned char buffer[5];
293 struct tuner *t = i2c_get_clientdata(c); 334 struct tea5767_priv *priv = fe->tuner_priv;
294 unsigned div, rc; 335 unsigned div, rc;
295 336
296 div = (87500 * 4 + 700 + 225 + 25) / 50; /* Set frequency to 87.5 MHz */ 337 div = (87500 * 4 + 700 + 225 + 25) / 50; /* Set frequency to 87.5 MHz */
@@ -301,25 +342,27 @@ static void tea5767_standby(struct i2c_client *c)
301 TEA5767_ST_NOISE_CTL | TEA5767_JAPAN_BAND | TEA5767_STDBY; 342 TEA5767_ST_NOISE_CTL | TEA5767_JAPAN_BAND | TEA5767_STDBY;
302 buffer[4] = 0; 343 buffer[4] = 0;
303 344
304 if (5 != (rc = i2c_master_send(c, buffer, 5))) 345 if (5 != (rc = tuner_i2c_xfer_send(&priv->i2c_props, buffer, 5)))
305 tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc); 346 tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc);
347
348 return 0;
306} 349}
307 350
308int tea5767_autodetection(struct i2c_client *c) 351int tea5767_autodetection(struct i2c_adapter* i2c_adap, u8 i2c_addr)
309{ 352{
353 struct tuner_i2c_props i2c = { .adap = i2c_adap, .addr = i2c_addr };
310 unsigned char buffer[7] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; 354 unsigned char buffer[7] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
311 int rc; 355 int rc;
312 struct tuner *t = i2c_get_clientdata(c);
313 356
314 if ((rc = i2c_master_recv(c, buffer, 7))< 5) { 357 if ((rc = tuner_i2c_xfer_recv(&i2c, buffer, 7))< 5) {
315 tuner_warn("It is not a TEA5767. Received %i bytes.\n", rc); 358 printk(KERN_WARNING "It is not a TEA5767. Received %i bytes.\n", rc);
316 return EINVAL; 359 return EINVAL;
317 } 360 }
318 361
319 /* If all bytes are the same then it's a TV tuner and not a tea5767 */ 362 /* If all bytes are the same then it's a TV tuner and not a tea5767 */
320 if (buffer[0] == buffer[1] && buffer[0] == buffer[2] && 363 if (buffer[0] == buffer[1] && buffer[0] == buffer[2] &&
321 buffer[0] == buffer[3] && buffer[0] == buffer[4]) { 364 buffer[0] == buffer[3] && buffer[0] == buffer[4]) {
322 tuner_warn("All bytes are equal. It is not a TEA5767\n"); 365 printk(KERN_WARNING "All bytes are equal. It is not a TEA5767\n");
323 return EINVAL; 366 return EINVAL;
324 } 367 }
325 368
@@ -329,36 +372,74 @@ int tea5767_autodetection(struct i2c_client *c)
329 * Byte 5: bit 7:0 : == 0 372 * Byte 5: bit 7:0 : == 0
330 */ 373 */
331 if (((buffer[3] & 0x0f) != 0x00) || (buffer[4] != 0x00)) { 374 if (((buffer[3] & 0x0f) != 0x00) || (buffer[4] != 0x00)) {
332 tuner_warn("Chip ID is not zero. It is not a TEA5767\n"); 375 printk(KERN_WARNING "Chip ID is not zero. It is not a TEA5767\n");
333 return EINVAL; 376 return EINVAL;
334 } 377 }
335 378
336 /* It seems that tea5767 returns 0xff after the 5th byte */ 379 /* It seems that tea5767 returns 0xff after the 5th byte */
337 if ((buffer[5] != 0xff) || (buffer[6] != 0xff)) { 380 if ((buffer[5] != 0xff) || (buffer[6] != 0xff)) {
338 tuner_warn("Returned more than 5 bytes. It is not a TEA5767\n"); 381 printk(KERN_WARNING "Returned more than 5 bytes. It is not a TEA5767\n");
339 return EINVAL; 382 return EINVAL;
340 } 383 }
341 384
342 tuner_warn("TEA5767 detected.\n"); 385 printk(KERN_WARNING "TEA5767 detected.\n");
343 return 0; 386 return 0;
344} 387}
345 388
346static struct tuner_operations tea5767_tuner_ops = { 389static int tea5767_release(struct dvb_frontend *fe)
347 .set_tv_freq = set_tv_freq, 390{
348 .set_radio_freq = set_radio_freq, 391 kfree(fe->tuner_priv);
349 .has_signal = tea5767_signal, 392 fe->tuner_priv = NULL;
350 .is_stereo = tea5767_stereo, 393
351 .standby = tea5767_standby, 394 return 0;
395}
396
397static int tea5767_get_frequency(struct dvb_frontend *fe, u32 *frequency)
398{
399 struct tea5767_priv *priv = fe->tuner_priv;
400 *frequency = priv->frequency;
401 return 0;
402}
403
404static struct dvb_tuner_ops tea5767_tuner_ops = {
405 .info = {
406 .name = "tea5767", // Philips TEA5767HN FM Radio
407 },
408
409 .set_analog_params = set_radio_freq,
410 .sleep = tea5767_standby,
411 .release = tea5767_release,
412 .get_frequency = tea5767_get_frequency,
413 .get_status = tea5767_get_status,
414 .get_rf_strength = tea5767_get_rf_strength,
352}; 415};
353 416
354int tea5767_tuner_init(struct i2c_client *c) 417struct dvb_frontend *tea5767_attach(struct dvb_frontend *fe,
418 struct i2c_adapter* i2c_adap,
419 u8 i2c_addr)
355{ 420{
356 struct tuner *t = i2c_get_clientdata(c); 421 struct tea5767_priv *priv = NULL;
422
423 priv = kzalloc(sizeof(struct tea5767_priv), GFP_KERNEL);
424 if (priv == NULL)
425 return NULL;
426 fe->tuner_priv = priv;
427
428 priv->i2c_props.addr = i2c_addr;
429 priv->i2c_props.adap = i2c_adap;
357 430
358 tuner_info("type set to %d (%s)\n", t->type, "Philips TEA5767HN FM Radio"); 431 memcpy(&fe->ops.tuner_ops, &tea5767_tuner_ops,
359 strlcpy(c->name, "tea5767", sizeof(c->name)); 432 sizeof(struct dvb_tuner_ops));
360 433
361 memcpy(&t->ops, &tea5767_tuner_ops, sizeof(struct tuner_operations)); 434 tuner_info("type set to %s\n", "Philips TEA5767HN FM Radio");
362 435
363 return (0); 436 return fe;
364} 437}
438
439
440EXPORT_SYMBOL_GPL(tea5767_attach);
441EXPORT_SYMBOL_GPL(tea5767_autodetection);
442
443MODULE_DESCRIPTION("Philips TEA5767 FM tuner driver");
444MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
445MODULE_LICENSE("GPL");
diff --git a/drivers/media/video/tea5767.h b/drivers/media/video/tea5767.h
new file mode 100644
index 000000000000..5d78281adcc2
--- /dev/null
+++ b/drivers/media/video/tea5767.h
@@ -0,0 +1,47 @@
1/*
2 This program is free software; you can redistribute it and/or modify
3 it under the terms of the GNU General Public License as published by
4 the Free Software Foundation; either version 2 of the License, or
5 (at your option) any later version.
6
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
11
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
15*/
16
17#ifndef __TEA5767_H__
18#define __TEA5767_H__
19
20#include <linux/i2c.h>
21#include "dvb_frontend.h"
22
23#if defined(CONFIG_TUNER_TEA5767) || (defined(CONFIG_TUNER_TEA5767_MODULE) && defined(MODULE))
24extern int tea5767_autodetection(struct i2c_adapter* i2c_adap, u8 i2c_addr);
25
26extern struct dvb_frontend *tea5767_attach(struct dvb_frontend *fe,
27 struct i2c_adapter* i2c_adap,
28 u8 i2c_addr);
29#else
30static inline int tea5767_autodetection(struct i2c_adapter* i2c_adap,
31 u8 i2c_addr)
32{
33 printk(KERN_INFO "%s: not probed - driver disabled by Kconfig\n",
34 __FUNCTION__);
35 return -EINVAL;
36}
37
38static inline struct dvb_frontend *tea5767_attach(struct dvb_frontend *fe,
39 struct i2c_adapter* i2c_adap,
40 u8 i2c_addr)
41{
42 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
43 return NULL;
44}
45#endif
46
47#endif /* __TEA5767_H__ */
diff --git a/drivers/media/video/tuner-core.c b/drivers/media/video/tuner-core.c
index e646465464a1..94843086cda9 100644
--- a/drivers/media/video/tuner-core.c
+++ b/drivers/media/video/tuner-core.c
@@ -5,7 +5,6 @@
5 */ 5 */
6 6
7#include <linux/module.h> 7#include <linux/module.h>
8#include <linux/moduleparam.h>
9#include <linux/kernel.h> 8#include <linux/kernel.h>
10#include <linux/string.h> 9#include <linux/string.h>
11#include <linux/timer.h> 10#include <linux/timer.h>
@@ -15,12 +14,17 @@
15#include <linux/poll.h> 14#include <linux/poll.h>
16#include <linux/i2c.h> 15#include <linux/i2c.h>
17#include <linux/types.h> 16#include <linux/types.h>
18#include <linux/videodev.h>
19#include <linux/init.h> 17#include <linux/init.h>
20 18#include <linux/videodev.h>
21#include <media/tuner.h> 19#include <media/tuner.h>
20#include <media/tuner-types.h>
22#include <media/v4l2-common.h> 21#include <media/v4l2-common.h>
23#include "tuner-driver.h" 22#include "tuner-driver.h"
23#include "mt20xx.h"
24#include "tda8290.h"
25#include "tea5761.h"
26#include "tea5767.h"
27#include "tuner-simple.h"
24 28
25#define UNSET (-1U) 29#define UNSET (-1U)
26 30
@@ -72,6 +76,51 @@ static struct i2c_client client_template;
72 76
73/* ---------------------------------------------------------------------- */ 77/* ---------------------------------------------------------------------- */
74 78
79static void fe_set_freq(struct tuner *t, unsigned int freq)
80{
81 struct dvb_tuner_ops *fe_tuner_ops = &t->fe.ops.tuner_ops;
82
83 struct analog_parameters params = {
84 .frequency = freq,
85 .mode = t->mode,
86 .audmode = t->audmode,
87 .std = t->std
88 };
89
90 if (NULL == fe_tuner_ops->set_analog_params) {
91 tuner_warn("Tuner frontend module has no way to set freq\n");
92 return;
93 }
94 fe_tuner_ops->set_analog_params(&t->fe, &params);
95}
96
97static void fe_release(struct tuner *t)
98{
99 struct dvb_tuner_ops *fe_tuner_ops = &t->fe.ops.tuner_ops;
100
101 if (fe_tuner_ops->release)
102 fe_tuner_ops->release(&t->fe);
103}
104
105static void fe_standby(struct tuner *t)
106{
107 struct dvb_tuner_ops *fe_tuner_ops = &t->fe.ops.tuner_ops;
108
109 if (fe_tuner_ops->sleep)
110 fe_tuner_ops->sleep(&t->fe);
111}
112
113static int fe_has_signal(struct tuner *t)
114{
115 struct dvb_tuner_ops *fe_tuner_ops = &t->fe.ops.tuner_ops;
116 u16 strength;
117
118 if (fe_tuner_ops->get_rf_strength)
119 fe_tuner_ops->get_rf_strength(&t->fe, &strength);
120
121 return strength;
122}
123
75/* Set tuner frequency, freq in Units of 62.5kHz = 1/16MHz */ 124/* Set tuner frequency, freq in Units of 62.5kHz = 1/16MHz */
76static void set_tv_freq(struct i2c_client *c, unsigned int freq) 125static void set_tv_freq(struct i2c_client *c, unsigned int freq)
77{ 126{
@@ -96,7 +145,7 @@ static void set_tv_freq(struct i2c_client *c, unsigned int freq)
96 else 145 else
97 freq = tv_range[1] * 16; 146 freq = tv_range[1] * 16;
98 } 147 }
99 t->ops.set_tv_freq(c, freq); 148 t->ops.set_tv_freq(t, freq);
100} 149}
101 150
102static void set_radio_freq(struct i2c_client *c, unsigned int freq) 151static void set_radio_freq(struct i2c_client *c, unsigned int freq)
@@ -123,7 +172,7 @@ static void set_radio_freq(struct i2c_client *c, unsigned int freq)
123 freq = radio_range[1] * 16000; 172 freq = radio_range[1] * 16000;
124 } 173 }
125 174
126 t->ops.set_radio_freq(c, freq); 175 t->ops.set_radio_freq(t, freq);
127} 176}
128 177
129static void set_freq(struct i2c_client *c, unsigned long freq) 178static void set_freq(struct i2c_client *c, unsigned long freq)
@@ -147,11 +196,51 @@ static void set_freq(struct i2c_client *c, unsigned long freq)
147 } 196 }
148} 197}
149 198
199static void tuner_i2c_address_check(struct tuner *t)
200{
201 if ((t->type == UNSET || t->type == TUNER_ABSENT) ||
202 ((t->i2c.addr < 0x64) || (t->i2c.addr > 0x6f)))
203 return;
204
205 tuner_warn("====================== WARNING! ======================\n");
206 tuner_warn("Support for tuners in i2c address range 0x64 thru 0x6f\n");
207 tuner_warn("will soon be dropped. This message indicates that your\n");
208 tuner_warn("hardware has a %s tuner at i2c address 0x%02x.\n",
209 t->i2c.name, t->i2c.addr);
210 tuner_warn("To ensure continued support for your device, please\n");
211 tuner_warn("send a copy of this message, along with full dmesg\n");
212 tuner_warn("output to v4l-dvb-maintainer@linuxtv.org\n");
213 tuner_warn("Please use subject line: \"obsolete tuner i2c address.\"\n");
214 tuner_warn("driver: %s, addr: 0x%02x, type: %d (%s)\n",
215 t->i2c.adapter->name, t->i2c.addr, t->type,
216 tuners[t->type].name);
217 tuner_warn("====================== WARNING! ======================\n");
218}
219
220static void attach_tda8290(struct tuner *t)
221{
222 struct tda8290_config cfg = {
223 .lna_cfg = &t->config,
224 .tuner_callback = t->tuner_callback
225 };
226 tda8290_attach(&t->fe, t->i2c.adapter, t->i2c.addr, &cfg);
227}
228
229static void attach_simple_tuner(struct tuner *t)
230{
231 struct simple_tuner_config cfg = {
232 .type = t->type,
233 .tun = &tuners[t->type]
234 };
235 simple_tuner_attach(&t->fe, t->i2c.adapter, t->i2c.addr, &cfg);
236}
237
150static void set_type(struct i2c_client *c, unsigned int type, 238static void set_type(struct i2c_client *c, unsigned int type,
151 unsigned int new_mode_mask, unsigned int new_config, 239 unsigned int new_mode_mask, unsigned int new_config,
152 int (*tuner_callback) (void *dev, int command,int arg)) 240 int (*tuner_callback) (void *dev, int command,int arg))
153{ 241{
154 struct tuner *t = i2c_get_clientdata(c); 242 struct tuner *t = i2c_get_clientdata(c);
243 struct dvb_tuner_ops *fe_tuner_ops = &t->fe.ops.tuner_ops;
155 unsigned char buffer[4]; 244 unsigned char buffer[4];
156 245
157 if (type == UNSET || type == TUNER_ABSENT) { 246 if (type == UNSET || type == TUNER_ABSENT) {
@@ -180,7 +269,7 @@ static void set_type(struct i2c_client *c, unsigned int type,
180 269
181 /* discard private data, in case set_type() was previously called */ 270 /* discard private data, in case set_type() was previously called */
182 if (t->ops.release) 271 if (t->ops.release)
183 t->ops.release(c); 272 t->ops.release(t);
184 else { 273 else {
185 kfree(t->priv); 274 kfree(t->priv);
186 t->priv = NULL; 275 t->priv = NULL;
@@ -188,13 +277,15 @@ static void set_type(struct i2c_client *c, unsigned int type,
188 277
189 switch (t->type) { 278 switch (t->type) {
190 case TUNER_MT2032: 279 case TUNER_MT2032:
191 microtune_init(c); 280 microtune_attach(&t->fe, t->i2c.adapter, t->i2c.addr);
192 break; 281 break;
193 case TUNER_PHILIPS_TDA8290: 282 case TUNER_PHILIPS_TDA8290:
194 tda8290_init(c); 283 {
284 attach_tda8290(t);
195 break; 285 break;
286 }
196 case TUNER_TEA5767: 287 case TUNER_TEA5767:
197 if (tea5767_tuner_init(c) == EINVAL) { 288 if (tea5767_attach(&t->fe, t->i2c.adapter, t->i2c.addr) == NULL) {
198 t->type = TUNER_ABSENT; 289 t->type = TUNER_ABSENT;
199 t->mode_mask = T_UNINITIALIZED; 290 t->mode_mask = T_UNINITIALIZED;
200 return; 291 return;
@@ -203,7 +294,7 @@ static void set_type(struct i2c_client *c, unsigned int type,
203 break; 294 break;
204#ifdef CONFIG_TUNER_TEA5761 295#ifdef CONFIG_TUNER_TEA5761
205 case TUNER_TEA5761: 296 case TUNER_TEA5761:
206 if (tea5761_tuner_init(c) == EINVAL) { 297 if (tea5761_attach(&t->fe, t->i2c.adapter, t->i2c.addr) == NULL) {
207 t->type = TUNER_ABSENT; 298 t->type = TUNER_ABSENT;
208 t->mode_mask = T_UNINITIALIZED; 299 t->mode_mask = T_UNINITIALIZED;
209 return; 300 return;
@@ -221,7 +312,7 @@ static void set_type(struct i2c_client *c, unsigned int type,
221 buffer[2] = 0x86; 312 buffer[2] = 0x86;
222 buffer[3] = 0x54; 313 buffer[3] = 0x54;
223 i2c_master_send(c, buffer, 4); 314 i2c_master_send(c, buffer, 4);
224 default_tuner_init(c); 315 attach_simple_tuner(t);
225 break; 316 break;
226 case TUNER_PHILIPS_TD1316: 317 case TUNER_PHILIPS_TD1316:
227 buffer[0] = 0x0b; 318 buffer[0] = 0x0b;
@@ -229,16 +320,28 @@ static void set_type(struct i2c_client *c, unsigned int type,
229 buffer[2] = 0x86; 320 buffer[2] = 0x86;
230 buffer[3] = 0xa4; 321 buffer[3] = 0xa4;
231 i2c_master_send(c,buffer,4); 322 i2c_master_send(c,buffer,4);
232 default_tuner_init(c); 323 attach_simple_tuner(t);
233 break; 324 break;
234 case TUNER_TDA9887: 325 case TUNER_TDA9887:
235 tda9887_tuner_init(c); 326 tda9887_tuner_init(t);
236 break; 327 break;
237 default: 328 default:
238 default_tuner_init(c); 329 attach_simple_tuner(t);
239 break; 330 break;
240 } 331 }
241 332
333 if (fe_tuner_ops->set_analog_params) {
334 strlcpy(t->i2c.name, fe_tuner_ops->info.name, sizeof(t->i2c.name));
335
336 t->ops.set_tv_freq = fe_set_freq;
337 t->ops.set_radio_freq = fe_set_freq;
338 t->ops.standby = fe_standby;
339 t->ops.release = fe_release;
340 t->ops.has_signal = fe_has_signal;
341 }
342
343 tuner_info("type set to %s\n", t->i2c.name);
344
242 if (t->mode_mask == T_UNINITIALIZED) 345 if (t->mode_mask == T_UNINITIALIZED)
243 t->mode_mask = new_mode_mask; 346 t->mode_mask = new_mode_mask;
244 347
@@ -246,6 +349,7 @@ static void set_type(struct i2c_client *c, unsigned int type,
246 tuner_dbg("%s %s I2C addr 0x%02x with type %d used for 0x%02x\n", 349 tuner_dbg("%s %s I2C addr 0x%02x with type %d used for 0x%02x\n",
247 c->adapter->name, c->driver->driver.name, c->addr << 1, type, 350 c->adapter->name, c->driver->driver.name, c->addr << 1, type,
248 t->mode_mask); 351 t->mode_mask);
352 tuner_i2c_address_check(t);
249} 353}
250 354
251/* 355/*
@@ -406,10 +510,10 @@ static int tuner_fixup_std(struct tuner *t)
406 return 0; 510 return 0;
407} 511}
408 512
409static void tuner_status(struct i2c_client *client) 513static void tuner_status(struct tuner *t)
410{ 514{
411 struct tuner *t = i2c_get_clientdata(client);
412 unsigned long freq, freq_fraction; 515 unsigned long freq, freq_fraction;
516 struct dvb_tuner_ops *fe_tuner_ops = &t->fe.ops.tuner_ops;
413 const char *p; 517 const char *p;
414 518
415 switch (t->mode) { 519 switch (t->mode) {
@@ -430,11 +534,20 @@ static void tuner_status(struct i2c_client *client)
430 tuner_info("Standard: 0x%08lx\n", (unsigned long)t->std); 534 tuner_info("Standard: 0x%08lx\n", (unsigned long)t->std);
431 if (t->mode != V4L2_TUNER_RADIO) 535 if (t->mode != V4L2_TUNER_RADIO)
432 return; 536 return;
537 if (fe_tuner_ops->get_status) {
538 u32 tuner_status;
539
540 fe_tuner_ops->get_status(&t->fe, &tuner_status);
541 if (tuner_status & TUNER_STATUS_LOCKED)
542 tuner_info("Tuner is locked.\n");
543 if (tuner_status & TUNER_STATUS_STEREO)
544 tuner_info("Stereo: yes\n");
545 }
433 if (t->ops.has_signal) { 546 if (t->ops.has_signal) {
434 tuner_info("Signal strength: %d\n", t->ops.has_signal(client)); 547 tuner_info("Signal strength: %d\n", t->ops.has_signal(t));
435 } 548 }
436 if (t->ops.is_stereo) { 549 if (t->ops.is_stereo) {
437 tuner_info("Stereo: %s\n", t->ops.is_stereo(client) ? "yes" : "no"); 550 tuner_info("Stereo: %s\n", t->ops.is_stereo(t) ? "yes" : "no");
438 } 551 }
439} 552}
440 553
@@ -483,7 +596,7 @@ static int tuner_attach(struct i2c_adapter *adap, int addr, int kind)
483 switch (addr) { 596 switch (addr) {
484#ifdef CONFIG_TUNER_TEA5761 597#ifdef CONFIG_TUNER_TEA5761
485 case 0x10: 598 case 0x10:
486 if (tea5761_autodetection(&t->i2c) != EINVAL) { 599 if (tea5761_autodetection(t->i2c.adapter, t->i2c.addr) != EINVAL) {
487 t->type = TUNER_TEA5761; 600 t->type = TUNER_TEA5761;
488 t->mode_mask = T_RADIO; 601 t->mode_mask = T_RADIO;
489 t->mode = T_STANDBY; 602 t->mode = T_STANDBY;
@@ -500,7 +613,7 @@ static int tuner_attach(struct i2c_adapter *adap, int addr, int kind)
500 case 0x4b: 613 case 0x4b:
501 /* If chip is not tda8290, don't register. 614 /* If chip is not tda8290, don't register.
502 since it can be tda9887*/ 615 since it can be tda9887*/
503 if (tda8290_probe(&t->i2c) == 0) { 616 if (tda8290_probe(t->i2c.adapter, t->i2c.addr) == 0) {
504 tuner_dbg("chip at addr %x is a tda8290\n", addr); 617 tuner_dbg("chip at addr %x is a tda8290\n", addr);
505 } else { 618 } else {
506 /* Default is being tda9887 */ 619 /* Default is being tda9887 */
@@ -511,7 +624,7 @@ static int tuner_attach(struct i2c_adapter *adap, int addr, int kind)
511 } 624 }
512 break; 625 break;
513 case 0x60: 626 case 0x60:
514 if (tea5767_autodetection(&t->i2c) != EINVAL) { 627 if (tea5767_autodetection(t->i2c.adapter, t->i2c.addr) != EINVAL) {
515 t->type = TUNER_TEA5767; 628 t->type = TUNER_TEA5767;
516 t->mode_mask = T_RADIO; 629 t->mode_mask = T_RADIO;
517 t->mode = T_STANDBY; 630 t->mode = T_STANDBY;
@@ -548,6 +661,28 @@ static int tuner_probe(struct i2c_adapter *adap)
548 normal_i2c[1] = I2C_CLIENT_END; 661 normal_i2c[1] = I2C_CLIENT_END;
549 } 662 }
550 663
664 /* HACK: Ignore 0x6b and 0x6f on cx88 boards.
665 * FusionHDTV5 RT Gold has an ir receiver at 0x6b
666 * and an RTC at 0x6f which can get corrupted if probed.
667 */
668 if ((adap->id == I2C_HW_B_CX2388x) ||
669 (adap->id == I2C_HW_B_CX23885)) {
670 unsigned int i = 0;
671
672 while (i < I2C_CLIENT_MAX_OPTS && ignore[i] != I2C_CLIENT_END)
673 i += 2;
674 if (i + 4 < I2C_CLIENT_MAX_OPTS) {
675 ignore[i+0] = adap->nr;
676 ignore[i+1] = 0x6b;
677 ignore[i+2] = adap->nr;
678 ignore[i+3] = 0x6f;
679 ignore[i+4] = I2C_CLIENT_END;
680 } else
681 printk(KERN_WARNING "tuner: "
682 "too many options specified "
683 "in i2c probe ignore list!\n");
684 }
685
551 default_mode_mask = T_RADIO | T_ANALOG_TV | T_DIGITAL_TV; 686 default_mode_mask = T_RADIO | T_ANALOG_TV | T_DIGITAL_TV;
552 687
553 if (adap->class & I2C_CLASS_TV_ANALOG) 688 if (adap->class & I2C_CLASS_TV_ANALOG)
@@ -568,7 +703,7 @@ static int tuner_detach(struct i2c_client *client)
568 } 703 }
569 704
570 if (t->ops.release) 705 if (t->ops.release)
571 t->ops.release(client); 706 t->ops.release(t);
572 else { 707 else {
573 kfree(t->priv); 708 kfree(t->priv);
574 } 709 }
@@ -593,7 +728,7 @@ static inline int set_mode(struct i2c_client *client, struct tuner *t, int mode,
593 if (check_mode(t, cmd) == EINVAL) { 728 if (check_mode(t, cmd) == EINVAL) {
594 t->mode = T_STANDBY; 729 t->mode = T_STANDBY;
595 if (t->ops.standby) 730 if (t->ops.standby)
596 t->ops.standby (client); 731 t->ops.standby(t);
597 return EINVAL; 732 return EINVAL;
598 } 733 }
599 return 0; 734 return 0;
@@ -615,6 +750,7 @@ static inline int check_v4l2(struct tuner *t)
615static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg) 750static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
616{ 751{
617 struct tuner *t = i2c_get_clientdata(client); 752 struct tuner *t = i2c_get_clientdata(client);
753 struct dvb_tuner_ops *fe_tuner_ops = &t->fe.ops.tuner_ops;
618 754
619 if (tuner_debug>1) 755 if (tuner_debug>1)
620 v4l_i2c_print_ioctl(&(t->i2c),cmd); 756 v4l_i2c_print_ioctl(&(t->i2c),cmd);
@@ -642,7 +778,7 @@ static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
642 return 0; 778 return 0;
643 t->mode = T_STANDBY; 779 t->mode = T_STANDBY;
644 if (t->ops.standby) 780 if (t->ops.standby)
645 t->ops.standby (client); 781 t->ops.standby(t);
646 break; 782 break;
647#ifdef CONFIG_VIDEO_V4L1 783#ifdef CONFIG_VIDEO_V4L1
648 case VIDIOCSAUDIO: 784 case VIDIOCSAUDIO:
@@ -701,16 +837,27 @@ static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
701 return 0; 837 return 0;
702 838
703 if (V4L2_TUNER_RADIO == t->mode) { 839 if (V4L2_TUNER_RADIO == t->mode) {
704 if (t->ops.has_signal) 840 if (fe_tuner_ops->get_status) {
705 vt->signal = t->ops.has_signal(client); 841 u32 tuner_status;
706 if (t->ops.is_stereo) { 842
707 if (t->ops.is_stereo(client)) 843 fe_tuner_ops->get_status(&t->fe, &tuner_status);
708 vt->flags |= 844 if (tuner_status & TUNER_STATUS_STEREO)
709 VIDEO_TUNER_STEREO_ON; 845 vt->flags |= VIDEO_TUNER_STEREO_ON;
710 else 846 else
711 vt->flags &= 847 vt->flags &= ~VIDEO_TUNER_STEREO_ON;
712 ~VIDEO_TUNER_STEREO_ON; 848 } else {
849 if (t->ops.is_stereo) {
850 if (t->ops.is_stereo(t))
851 vt->flags |=
852 VIDEO_TUNER_STEREO_ON;
853 else
854 vt->flags &=
855 ~VIDEO_TUNER_STEREO_ON;
856 }
713 } 857 }
858 if (t->ops.has_signal)
859 vt->signal = t->ops.has_signal(t);
860
714 vt->flags |= VIDEO_TUNER_LOW; /* Allow freqs at 62.5 Hz */ 861 vt->flags |= VIDEO_TUNER_LOW; /* Allow freqs at 62.5 Hz */
715 862
716 vt->rangelow = radio_range[0] * 16000; 863 vt->rangelow = radio_range[0] * 16000;
@@ -732,9 +879,17 @@ static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
732 if (check_v4l2(t) == EINVAL) 879 if (check_v4l2(t) == EINVAL)
733 return 0; 880 return 0;
734 881
735 if (V4L2_TUNER_RADIO == t->mode && t->ops.is_stereo) 882 if (V4L2_TUNER_RADIO == t->mode) {
736 va->mode = t->ops.is_stereo(client) 883 if (fe_tuner_ops->get_status) {
737 ? VIDEO_SOUND_STEREO : VIDEO_SOUND_MONO; 884 u32 tuner_status;
885
886 fe_tuner_ops->get_status(&t->fe, &tuner_status);
887 va->mode = (tuner_status & TUNER_STATUS_STEREO)
888 ? VIDEO_SOUND_STEREO : VIDEO_SOUND_MONO;
889 } else if (t->ops.is_stereo)
890 va->mode = t->ops.is_stereo(t)
891 ? VIDEO_SOUND_STEREO : VIDEO_SOUND_MONO;
892 }
738 return 0; 893 return 0;
739 } 894 }
740#endif 895#endif
@@ -785,6 +940,15 @@ static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
785 return 0; 940 return 0;
786 switch_v4l2(); 941 switch_v4l2();
787 f->type = t->mode; 942 f->type = t->mode;
943 if (fe_tuner_ops->get_frequency) {
944 u32 abs_freq;
945
946 fe_tuner_ops->get_frequency(&t->fe, &abs_freq);
947 f->frequency = (V4L2_TUNER_RADIO == t->mode) ?
948 (abs_freq * 2 + 125/2) / 125 :
949 (abs_freq + 62500/2) / 62500;
950 break;
951 }
788 f->frequency = (V4L2_TUNER_RADIO == t->mode) ? 952 f->frequency = (V4L2_TUNER_RADIO == t->mode) ?
789 t->radio_freq : t->tv_freq; 953 t->radio_freq : t->tv_freq;
790 break; 954 break;
@@ -799,7 +963,7 @@ static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
799 963
800 tuner->type = t->mode; 964 tuner->type = t->mode;
801 if (t->ops.get_afc) 965 if (t->ops.get_afc)
802 tuner->afc=t->ops.get_afc(client); 966 tuner->afc=t->ops.get_afc(t);
803 if (t->mode == V4L2_TUNER_ANALOG_TV) 967 if (t->mode == V4L2_TUNER_ANALOG_TV)
804 tuner->capability |= V4L2_TUNER_CAP_NORM; 968 tuner->capability |= V4L2_TUNER_CAP_NORM;
805 if (t->mode != V4L2_TUNER_RADIO) { 969 if (t->mode != V4L2_TUNER_RADIO) {
@@ -809,16 +973,22 @@ static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
809 } 973 }
810 974
811 /* radio mode */ 975 /* radio mode */
812 if (t->ops.has_signal)
813 tuner->signal = t->ops.has_signal(client);
814
815 tuner->rxsubchans = 976 tuner->rxsubchans =
816 V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO; 977 V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO;
817 if (t->ops.is_stereo) { 978 if (fe_tuner_ops->get_status) {
818 tuner->rxsubchans = t->ops.is_stereo(client) ? 979 u32 tuner_status;
980
981 fe_tuner_ops->get_status(&t->fe, &tuner_status);
982 tuner->rxsubchans = (tuner_status & TUNER_STATUS_STEREO) ?
819 V4L2_TUNER_SUB_STEREO : V4L2_TUNER_SUB_MONO; 983 V4L2_TUNER_SUB_STEREO : V4L2_TUNER_SUB_MONO;
984 } else {
985 if (t->ops.is_stereo) {
986 tuner->rxsubchans = t->ops.is_stereo(t) ?
987 V4L2_TUNER_SUB_STEREO : V4L2_TUNER_SUB_MONO;
988 }
820 } 989 }
821 990 if (t->ops.has_signal)
991 tuner->signal = t->ops.has_signal(t);
822 tuner->capability |= 992 tuner->capability |=
823 V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO; 993 V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO;
824 tuner->audmode = t->audmode; 994 tuner->audmode = t->audmode;
@@ -844,7 +1014,7 @@ static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
844 } 1014 }
845 case VIDIOC_LOG_STATUS: 1015 case VIDIOC_LOG_STATUS:
846 if (t->ops.tuner_status) 1016 if (t->ops.tuner_status)
847 t->ops.tuner_status(client); 1017 t->ops.tuner_status(t);
848 break; 1018 break;
849 } 1019 }
850 1020
diff --git a/drivers/media/video/tuner-driver.h b/drivers/media/video/tuner-driver.h
index 0334a9125077..28a10da76d12 100644
--- a/drivers/media/video/tuner-driver.h
+++ b/drivers/media/video/tuner-driver.h
@@ -19,23 +19,27 @@
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20*/ 20*/
21 21
22#ifndef __TUNER_HW_H__ 22#ifndef __TUNER_DRIVER_H__
23#define __TUNER_HW_H__ 23#define __TUNER_DRIVER_H__
24 24
25#include <linux/videodev2.h> 25#include <linux/videodev2.h>
26#include <linux/i2c.h> 26#include <linux/i2c.h>
27#include "tuner-i2c.h"
28#include "dvb_frontend.h"
27 29
28extern unsigned const int tuner_count; 30extern unsigned const int tuner_count;
29 31
32struct tuner;
33
30struct tuner_operations { 34struct tuner_operations {
31 void (*set_tv_freq)(struct i2c_client *c, unsigned int freq); 35 void (*set_tv_freq)(struct tuner *t, unsigned int freq);
32 void (*set_radio_freq)(struct i2c_client *c, unsigned int freq); 36 void (*set_radio_freq)(struct tuner *t, unsigned int freq);
33 int (*has_signal)(struct i2c_client *c); 37 int (*has_signal)(struct tuner *t);
34 int (*is_stereo)(struct i2c_client *c); 38 int (*is_stereo)(struct tuner *t);
35 int (*get_afc)(struct i2c_client *c); 39 int (*get_afc)(struct tuner *t);
36 void (*tuner_status)(struct i2c_client *c); 40 void (*tuner_status)(struct tuner *t);
37 void (*standby)(struct i2c_client *c); 41 void (*standby)(struct tuner *t);
38 void (*release)(struct i2c_client *c); 42 void (*release)(struct tuner *t);
39}; 43};
40 44
41struct tuner { 45struct tuner {
@@ -49,13 +53,14 @@ struct tuner {
49 53
50 unsigned int tv_freq; /* keep track of the current settings */ 54 unsigned int tv_freq; /* keep track of the current settings */
51 unsigned int radio_freq; 55 unsigned int radio_freq;
52 u16 last_div;
53 unsigned int audmode; 56 unsigned int audmode;
54 v4l2_std_id std; 57 v4l2_std_id std;
55 58
56 int using_v4l2; 59 int using_v4l2;
57 void *priv; 60 void *priv;
58 61
62 struct dvb_frontend fe;
63
59 /* used by tda9887 */ 64 /* used by tda9887 */
60 unsigned int tda9887_config; 65 unsigned int tda9887_config;
61 66
@@ -67,20 +72,7 @@ struct tuner {
67 72
68/* ------------------------------------------------------------------------ */ 73/* ------------------------------------------------------------------------ */
69 74
70extern int default_tuner_init(struct i2c_client *c); 75extern int tda9887_tuner_init(struct tuner *t);
71
72extern int tda9887_tuner_init(struct i2c_client *c);
73
74extern int microtune_init(struct i2c_client *c);
75
76extern int tda8290_init(struct i2c_client *c);
77extern int tda8290_probe(struct i2c_client *c);
78
79extern int tea5761_tuner_init(struct i2c_client *c);
80extern int tea5761_autodetection(struct i2c_client *c);
81
82extern int tea5767_autodetection(struct i2c_client *c);
83extern int tea5767_tuner_init(struct i2c_client *c);
84 76
85/* ------------------------------------------------------------------------ */ 77/* ------------------------------------------------------------------------ */
86 78
@@ -96,7 +88,7 @@ extern int tea5767_tuner_init(struct i2c_client *c);
96 printk(KERN_DEBUG "%s %d-%04x: " fmt, t->i2c.driver->driver.name, \ 88 printk(KERN_DEBUG "%s %d-%04x: " fmt, t->i2c.driver->driver.name, \
97 i2c_adapter_id(t->i2c.adapter), t->i2c.addr , ##arg); } while (0) 89 i2c_adapter_id(t->i2c.adapter), t->i2c.addr , ##arg); } while (0)
98 90
99#endif /* __TUNER_HW_H__ */ 91#endif /* __TUNER_DRIVER_H__ */
100 92
101/* 93/*
102 * Overrides for Emacs so that we follow Linus's tabbing style. 94 * Overrides for Emacs so that we follow Linus's tabbing style.
diff --git a/drivers/media/video/tuner-i2c.h b/drivers/media/video/tuner-i2c.h
new file mode 100644
index 000000000000..159019ec3373
--- /dev/null
+++ b/drivers/media/video/tuner-i2c.h
@@ -0,0 +1,70 @@
1/*
2 tuner-i2c.h - i2c interface for different tuners
3
4 Copyright (C) 2007 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, 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#ifndef __TUNER_I2C_H__
22#define __TUNER_I2C_H__
23
24#include <linux/i2c.h>
25
26struct tuner_i2c_props {
27 u8 addr;
28 struct i2c_adapter *adap;
29};
30
31static inline int tuner_i2c_xfer_send(struct tuner_i2c_props *props, char *buf, int len)
32{
33 struct i2c_msg msg = { .addr = props->addr, .flags = 0,
34 .buf = buf, .len = len };
35 int ret = i2c_transfer(props->adap, &msg, 1);
36
37 return (ret == 1) ? len : ret;
38}
39
40static inline int tuner_i2c_xfer_recv(struct tuner_i2c_props *props, char *buf, int len)
41{
42 struct i2c_msg msg = { .addr = props->addr, .flags = I2C_M_RD,
43 .buf = buf, .len = len };
44 int ret = i2c_transfer(props->adap, &msg, 1);
45
46 return (ret == 1) ? len : ret;
47}
48
49#ifndef __TUNER_DRIVER_H__
50#define tuner_warn(fmt, arg...) do {\
51 printk(KERN_WARNING PREFIX "%d-%04x: " fmt, \
52 i2c_adapter_id(priv->i2c_props.adap), priv->i2c_props.addr , ##arg); } while (0)
53#define tuner_info(fmt, arg...) do {\
54 printk(KERN_INFO PREFIX "%d-%04x: " fmt, \
55 i2c_adapter_id(priv->i2c_props.adap), priv->i2c_props.addr , ##arg); } while (0)
56#define tuner_dbg(fmt, arg...) do {\
57 if ((debug)) \
58 printk(KERN_DEBUG PREFIX "%d-%04x: " fmt, \
59 i2c_adapter_id(priv->i2c_props.adap), priv->i2c_props.addr , ##arg); } while (0)
60#endif /* __TUNER_DRIVER_H__ */
61
62#endif /* __TUNER_I2C_H__ */
63
64/*
65 * Overrides for Emacs so that we follow Linus's tabbing style.
66 * ---------------------------------------------------------------------------
67 * Local variables:
68 * c-basic-offset: 8
69 * End:
70 */
diff --git a/drivers/media/video/tuner-simple.c b/drivers/media/video/tuner-simple.c
index 2d57e8bc0db3..7b93d3b1f4c6 100644
--- a/drivers/media/video/tuner-simple.c
+++ b/drivers/media/video/tuner-simple.c
@@ -1,7 +1,8 @@
1/* 1/*
2 *
3 * i2c tv tuner chip device driver 2 * i2c tv tuner chip device driver
4 * controls all those simple 4-control-bytes style tuners. 3 * controls all those simple 4-control-bytes style tuners.
4 *
5 * This "tuner-simple" module was split apart from the original "tuner" module.
5 */ 6 */
6#include <linux/delay.h> 7#include <linux/delay.h>
7#include <linux/i2c.h> 8#include <linux/i2c.h>
@@ -9,7 +10,14 @@
9#include <media/tuner.h> 10#include <media/tuner.h>
10#include <media/v4l2-common.h> 11#include <media/v4l2-common.h>
11#include <media/tuner-types.h> 12#include <media/tuner-types.h>
12#include "tuner-driver.h" 13#include "tuner-i2c.h"
14#include "tuner-simple.h"
15
16static int debug = 0;
17module_param(debug, int, 0644);
18MODULE_PARM_DESC(debug, "enable verbose debug messages");
19
20#define PREFIX "tuner-simple "
13 21
14static int offset = 0; 22static int offset = 0;
15module_param(offset, int, 0664); 23module_param(offset, int, 0664);
@@ -82,59 +90,102 @@ MODULE_PARM_DESC(offset,"Allows to specify an offset for tuner");
82#define TUNER_PLL_LOCKED 0x40 90#define TUNER_PLL_LOCKED 0x40
83#define TUNER_STEREO_MK3 0x04 91#define TUNER_STEREO_MK3 0x04
84 92
93struct tuner_simple_priv {
94 u16 last_div;
95 struct tuner_i2c_props i2c_props;
96
97 unsigned int type;
98 struct tunertype *tun;
99
100 u32 frequency;
101};
102
85/* ---------------------------------------------------------------------- */ 103/* ---------------------------------------------------------------------- */
86 104
87static int tuner_getstatus(struct i2c_client *c) 105static int tuner_read_status(struct dvb_frontend *fe)
88{ 106{
107 struct tuner_simple_priv *priv = fe->tuner_priv;
89 unsigned char byte; 108 unsigned char byte;
90 109
91 if (1 != i2c_master_recv(c,&byte,1)) 110 if (1 != tuner_i2c_xfer_recv(&priv->i2c_props,&byte,1))
92 return 0; 111 return 0;
93 112
94 return byte; 113 return byte;
95} 114}
96 115
97static int tuner_signal(struct i2c_client *c) 116static inline int tuner_signal(const int status)
98{ 117{
99 return (tuner_getstatus(c) & TUNER_SIGNAL) << 13; 118 return (status & TUNER_SIGNAL) << 13;
100} 119}
101 120
102static int tuner_stereo(struct i2c_client *c) 121static inline int tuner_stereo(const int type, const int status)
103{ 122{
104 int stereo, status; 123 switch (type) {
105 struct tuner *t = i2c_get_clientdata(c);
106
107 status = tuner_getstatus (c);
108
109 switch (t->type) {
110 case TUNER_PHILIPS_FM1216ME_MK3: 124 case TUNER_PHILIPS_FM1216ME_MK3:
111 case TUNER_PHILIPS_FM1236_MK3: 125 case TUNER_PHILIPS_FM1236_MK3:
112 case TUNER_PHILIPS_FM1256_IH3: 126 case TUNER_PHILIPS_FM1256_IH3:
113 case TUNER_LG_NTSC_TAPE: 127 case TUNER_LG_NTSC_TAPE:
114 stereo = ((status & TUNER_SIGNAL) == TUNER_STEREO_MK3); 128 return ((status & TUNER_SIGNAL) == TUNER_STEREO_MK3);
115 break;
116 default: 129 default:
117 stereo = status & TUNER_STEREO; 130 return status & TUNER_STEREO;
118 } 131 }
132}
133
134static inline int tuner_islocked(const int status)
135{
136 return (status & TUNER_FL);
137}
119 138
120 return stereo; 139static inline int tuner_afcstatus(const int status)
140{
141 return (status & TUNER_AFC) - 2;
121} 142}
122 143
123 144
145static int simple_get_status(struct dvb_frontend *fe, u32 *status)
146{
147 struct tuner_simple_priv *priv = fe->tuner_priv;
148 int tuner_status = tuner_read_status(fe);
149
150 *status = 0;
151
152 if (tuner_islocked(tuner_status))
153 *status = TUNER_STATUS_LOCKED;
154 if (tuner_stereo(priv->type, tuner_status))
155 *status |= TUNER_STATUS_STEREO;
156
157 tuner_dbg("AFC Status: %d\n", tuner_afcstatus(tuner_status));
158
159 return 0;
160}
161
162static int simple_get_rf_strength(struct dvb_frontend *fe, u16 *strength)
163{
164 struct tuner_simple_priv *priv = fe->tuner_priv;
165 int signal = tuner_signal(tuner_read_status(fe));
166
167 *strength = signal;
168
169 tuner_dbg("Signal strength: %d\n", signal);
170
171 return 0;
172}
173
124/* ---------------------------------------------------------------------- */ 174/* ---------------------------------------------------------------------- */
125 175
126static void default_set_tv_freq(struct i2c_client *c, unsigned int freq) 176static int simple_set_tv_freq(struct dvb_frontend *fe,
177 struct analog_parameters *params)
127{ 178{
128 struct tuner *t = i2c_get_clientdata(c); 179 struct tuner_simple_priv *priv = fe->tuner_priv;
129 u8 config, cb, tuneraddr; 180 u8 config, cb, tuneraddr;
130 u16 div; 181 u16 div;
131 struct tunertype *tun; 182 struct tunertype *tun;
132 u8 buffer[4]; 183 u8 buffer[4];
133 int rc, IFPCoff, i, j; 184 int rc, IFPCoff, i, j;
134 enum param_type desired_type; 185 enum param_type desired_type;
135 struct tuner_params *params; 186 struct tuner_params *t_params;
136 187
137 tun = &tuners[t->type]; 188 tun = priv->tun;
138 189
139 /* IFPCoff = Video Intermediate Frequency - Vif: 190 /* IFPCoff = Video Intermediate Frequency - Vif:
140 940 =16*58.75 NTSC/J (Japan) 191 940 =16*58.75 NTSC/J (Japan)
@@ -148,14 +199,14 @@ static void default_set_tv_freq(struct i2c_client *c, unsigned int freq)
148 171.2=16*10.70 FM Radio (at set_radio_freq) 199 171.2=16*10.70 FM Radio (at set_radio_freq)
149 */ 200 */
150 201
151 if (t->std == V4L2_STD_NTSC_M_JP) { 202 if (params->std == V4L2_STD_NTSC_M_JP) {
152 IFPCoff = 940; 203 IFPCoff = 940;
153 desired_type = TUNER_PARAM_TYPE_NTSC; 204 desired_type = TUNER_PARAM_TYPE_NTSC;
154 } else if ((t->std & V4L2_STD_MN) && 205 } else if ((params->std & V4L2_STD_MN) &&
155 !(t->std & ~V4L2_STD_MN)) { 206 !(params->std & ~V4L2_STD_MN)) {
156 IFPCoff = 732; 207 IFPCoff = 732;
157 desired_type = TUNER_PARAM_TYPE_NTSC; 208 desired_type = TUNER_PARAM_TYPE_NTSC;
158 } else if (t->std == V4L2_STD_SECAM_LC) { 209 } else if (params->std == V4L2_STD_SECAM_LC) {
159 IFPCoff = 543; 210 IFPCoff = 543;
160 desired_type = TUNER_PARAM_TYPE_SECAM; 211 desired_type = TUNER_PARAM_TYPE_SECAM;
161 } else { 212 } else {
@@ -168,49 +219,49 @@ static void default_set_tv_freq(struct i2c_client *c, unsigned int freq)
168 continue; 219 continue;
169 break; 220 break;
170 } 221 }
171 /* use default tuner_params if desired_type not available */ 222 /* use default tuner_t_params if desired_type not available */
172 if (desired_type != tun->params[j].type) { 223 if (desired_type != tun->params[j].type) {
173 tuner_dbg("IFPCoff = %d: tuner_params undefined for tuner %d\n", 224 tuner_dbg("IFPCoff = %d: tuner_t_params undefined for tuner %d\n",
174 IFPCoff,t->type); 225 IFPCoff, priv->type);
175 j = 0; 226 j = 0;
176 } 227 }
177 params = &tun->params[j]; 228 t_params = &tun->params[j];
178 229
179 for (i = 0; i < params->count; i++) { 230 for (i = 0; i < t_params->count; i++) {
180 if (freq > params->ranges[i].limit) 231 if (params->frequency > t_params->ranges[i].limit)
181 continue; 232 continue;
182 break; 233 break;
183 } 234 }
184 if (i == params->count) { 235 if (i == t_params->count) {
185 tuner_dbg("TV frequency out of range (%d > %d)", 236 tuner_dbg("TV frequency out of range (%d > %d)",
186 freq, params->ranges[i - 1].limit); 237 params->frequency, t_params->ranges[i - 1].limit);
187 freq = params->ranges[--i].limit; 238 params->frequency = t_params->ranges[--i].limit;
188 } 239 }
189 config = params->ranges[i].config; 240 config = t_params->ranges[i].config;
190 cb = params->ranges[i].cb; 241 cb = t_params->ranges[i].cb;
191 /* i == 0 -> VHF_LO 242 /* i == 0 -> VHF_LO
192 * i == 1 -> VHF_HI 243 * i == 1 -> VHF_HI
193 * i == 2 -> UHF */ 244 * i == 2 -> UHF */
194 tuner_dbg("tv: param %d, range %d\n",j,i); 245 tuner_dbg("tv: param %d, range %d\n",j,i);
195 246
196 div=freq + IFPCoff + offset; 247 div=params->frequency + IFPCoff + offset;
197 248
198 tuner_dbg("Freq= %d.%02d MHz, V_IF=%d.%02d MHz, Offset=%d.%02d MHz, div=%0d\n", 249 tuner_dbg("Freq= %d.%02d MHz, V_IF=%d.%02d MHz, Offset=%d.%02d MHz, div=%0d\n",
199 freq / 16, freq % 16 * 100 / 16, 250 params->frequency / 16, params->frequency % 16 * 100 / 16,
200 IFPCoff / 16, IFPCoff % 16 * 100 / 16, 251 IFPCoff / 16, IFPCoff % 16 * 100 / 16,
201 offset / 16, offset % 16 * 100 / 16, 252 offset / 16, offset % 16 * 100 / 16,
202 div); 253 div);
203 254
204 /* tv norm specific stuff for multi-norm tuners */ 255 /* tv norm specific stuff for multi-norm tuners */
205 switch (t->type) { 256 switch (priv->type) {
206 case TUNER_PHILIPS_SECAM: // FI1216MF 257 case TUNER_PHILIPS_SECAM: // FI1216MF
207 /* 0x01 -> ??? no change ??? */ 258 /* 0x01 -> ??? no change ??? */
208 /* 0x02 -> PAL BDGHI / SECAM L */ 259 /* 0x02 -> PAL BDGHI / SECAM L */
209 /* 0x04 -> ??? PAL others / SECAM others ??? */ 260 /* 0x04 -> ??? PAL others / SECAM others ??? */
210 cb &= ~0x03; 261 cb &= ~0x03;
211 if (t->std & V4L2_STD_SECAM_L) //also valid for V4L2_STD_SECAM 262 if (params->std & V4L2_STD_SECAM_L) //also valid for V4L2_STD_SECAM
212 cb |= PHILIPS_MF_SET_STD_L; 263 cb |= PHILIPS_MF_SET_STD_L;
213 else if (t->std & V4L2_STD_SECAM_LC) 264 else if (params->std & V4L2_STD_SECAM_LC)
214 cb |= PHILIPS_MF_SET_STD_LC; 265 cb |= PHILIPS_MF_SET_STD_LC;
215 else /* V4L2_STD_B|V4L2_STD_GH */ 266 else /* V4L2_STD_B|V4L2_STD_GH */
216 cb |= PHILIPS_MF_SET_STD_BG; 267 cb |= PHILIPS_MF_SET_STD_BG;
@@ -219,16 +270,16 @@ static void default_set_tv_freq(struct i2c_client *c, unsigned int freq)
219 case TUNER_TEMIC_4046FM5: 270 case TUNER_TEMIC_4046FM5:
220 cb &= ~0x0f; 271 cb &= ~0x0f;
221 272
222 if (t->std & V4L2_STD_PAL_BG) { 273 if (params->std & V4L2_STD_PAL_BG) {
223 cb |= TEMIC_SET_PAL_BG; 274 cb |= TEMIC_SET_PAL_BG;
224 275
225 } else if (t->std & V4L2_STD_PAL_I) { 276 } else if (params->std & V4L2_STD_PAL_I) {
226 cb |= TEMIC_SET_PAL_I; 277 cb |= TEMIC_SET_PAL_I;
227 278
228 } else if (t->std & V4L2_STD_PAL_DK) { 279 } else if (params->std & V4L2_STD_PAL_DK) {
229 cb |= TEMIC_SET_PAL_DK; 280 cb |= TEMIC_SET_PAL_DK;
230 281
231 } else if (t->std & V4L2_STD_SECAM_L) { 282 } else if (params->std & V4L2_STD_SECAM_L) {
232 cb |= TEMIC_SET_PAL_L; 283 cb |= TEMIC_SET_PAL_L;
233 284
234 } 285 }
@@ -237,13 +288,13 @@ static void default_set_tv_freq(struct i2c_client *c, unsigned int freq)
237 case TUNER_PHILIPS_FQ1216ME: 288 case TUNER_PHILIPS_FQ1216ME:
238 cb &= ~0x0f; 289 cb &= ~0x0f;
239 290
240 if (t->std & (V4L2_STD_PAL_BG|V4L2_STD_PAL_DK)) { 291 if (params->std & (V4L2_STD_PAL_BG|V4L2_STD_PAL_DK)) {
241 cb |= PHILIPS_SET_PAL_BGDK; 292 cb |= PHILIPS_SET_PAL_BGDK;
242 293
243 } else if (t->std & V4L2_STD_PAL_I) { 294 } else if (params->std & V4L2_STD_PAL_I) {
244 cb |= PHILIPS_SET_PAL_I; 295 cb |= PHILIPS_SET_PAL_I;
245 296
246 } else if (t->std & V4L2_STD_SECAM_L) { 297 } else if (params->std & V4L2_STD_SECAM_L) {
247 cb |= PHILIPS_SET_PAL_L; 298 cb |= PHILIPS_SET_PAL_L;
248 299
249 } 300 }
@@ -255,7 +306,7 @@ static void default_set_tv_freq(struct i2c_client *c, unsigned int freq)
255 /* 0x02 -> NTSC antenna input 1 */ 306 /* 0x02 -> NTSC antenna input 1 */
256 /* 0x03 -> NTSC antenna input 2 */ 307 /* 0x03 -> NTSC antenna input 2 */
257 cb &= ~0x03; 308 cb &= ~0x03;
258 if (!(t->std & V4L2_STD_ATSC)) 309 if (!(params->std & V4L2_STD_ATSC))
259 cb |= 2; 310 cb |= 2;
260 /* FIXME: input */ 311 /* FIXME: input */
261 break; 312 break;
@@ -275,23 +326,23 @@ static void default_set_tv_freq(struct i2c_client *c, unsigned int freq)
275 buffer[2] = 0x17; 326 buffer[2] = 0x17;
276 buffer[3] = 0x00; 327 buffer[3] = 0x00;
277 cb &= ~0x40; 328 cb &= ~0x40;
278 if (t->std & V4L2_STD_ATSC) { 329 if (params->std & V4L2_STD_ATSC) {
279 cb |= 0x40; 330 cb |= 0x40;
280 buffer[1] = 0x04; 331 buffer[1] = 0x04;
281 } 332 }
282 /* set to the correct mode (analog or digital) */ 333 /* set to the correct mode (analog or digital) */
283 tuneraddr = c->addr; 334 tuneraddr = priv->i2c_props.addr;
284 c->addr = 0x0a; 335 priv->i2c_props.addr = 0x0a;
285 if (2 != (rc = i2c_master_send(c,&buffer[0],2))) 336 if (2 != (rc = tuner_i2c_xfer_send(&priv->i2c_props,&buffer[0],2)))
286 tuner_warn("i2c i/o error: rc == %d (should be 2)\n",rc); 337 tuner_warn("i2c i/o error: rc == %d (should be 2)\n",rc);
287 if (2 != (rc = i2c_master_send(c,&buffer[2],2))) 338 if (2 != (rc = tuner_i2c_xfer_send(&priv->i2c_props,&buffer[2],2)))
288 tuner_warn("i2c i/o error: rc == %d (should be 2)\n",rc); 339 tuner_warn("i2c i/o error: rc == %d (should be 2)\n",rc);
289 c->addr = tuneraddr; 340 priv->i2c_props.addr = tuneraddr;
290 /* FIXME: input */ 341 /* FIXME: input */
291 break; 342 break;
292 } 343 }
293 344
294 if (params->cb_first_if_lower_freq && div < t->last_div) { 345 if (t_params->cb_first_if_lower_freq && div < priv->last_div) {
295 buffer[0] = config; 346 buffer[0] = config;
296 buffer[1] = cb; 347 buffer[1] = cb;
297 buffer[2] = (div>>8) & 0x7f; 348 buffer[2] = (div>>8) & 0x7f;
@@ -302,53 +353,53 @@ static void default_set_tv_freq(struct i2c_client *c, unsigned int freq)
302 buffer[2] = config; 353 buffer[2] = config;
303 buffer[3] = cb; 354 buffer[3] = cb;
304 } 355 }
305 t->last_div = div; 356 priv->last_div = div;
306 if (params->has_tda9887) { 357 if (t_params->has_tda9887) {
307 int config = 0; 358 int config = 0;
308 int is_secam_l = (t->std & (V4L2_STD_SECAM_L | V4L2_STD_SECAM_LC)) && 359 int is_secam_l = (params->std & (V4L2_STD_SECAM_L | V4L2_STD_SECAM_LC)) &&
309 !(t->std & ~(V4L2_STD_SECAM_L | V4L2_STD_SECAM_LC)); 360 !(params->std & ~(V4L2_STD_SECAM_L | V4L2_STD_SECAM_LC));
310 361
311 if (t->std == V4L2_STD_SECAM_LC) { 362 if (params->std == V4L2_STD_SECAM_LC) {
312 if (params->port1_active ^ params->port1_invert_for_secam_lc) 363 if (t_params->port1_active ^ t_params->port1_invert_for_secam_lc)
313 config |= TDA9887_PORT1_ACTIVE; 364 config |= TDA9887_PORT1_ACTIVE;
314 if (params->port2_active ^ params->port2_invert_for_secam_lc) 365 if (t_params->port2_active ^ t_params->port2_invert_for_secam_lc)
315 config |= TDA9887_PORT2_ACTIVE; 366 config |= TDA9887_PORT2_ACTIVE;
316 } 367 }
317 else { 368 else {
318 if (params->port1_active) 369 if (t_params->port1_active)
319 config |= TDA9887_PORT1_ACTIVE; 370 config |= TDA9887_PORT1_ACTIVE;
320 if (params->port2_active) 371 if (t_params->port2_active)
321 config |= TDA9887_PORT2_ACTIVE; 372 config |= TDA9887_PORT2_ACTIVE;
322 } 373 }
323 if (params->intercarrier_mode) 374 if (t_params->intercarrier_mode)
324 config |= TDA9887_INTERCARRIER; 375 config |= TDA9887_INTERCARRIER;
325 if (is_secam_l) { 376 if (is_secam_l) {
326 if (i == 0 && params->default_top_secam_low) 377 if (i == 0 && t_params->default_top_secam_low)
327 config |= TDA9887_TOP(params->default_top_secam_low); 378 config |= TDA9887_TOP(t_params->default_top_secam_low);
328 else if (i == 1 && params->default_top_secam_mid) 379 else if (i == 1 && t_params->default_top_secam_mid)
329 config |= TDA9887_TOP(params->default_top_secam_mid); 380 config |= TDA9887_TOP(t_params->default_top_secam_mid);
330 else if (params->default_top_secam_high) 381 else if (t_params->default_top_secam_high)
331 config |= TDA9887_TOP(params->default_top_secam_high); 382 config |= TDA9887_TOP(t_params->default_top_secam_high);
332 } 383 }
333 else { 384 else {
334 if (i == 0 && params->default_top_low) 385 if (i == 0 && t_params->default_top_low)
335 config |= TDA9887_TOP(params->default_top_low); 386 config |= TDA9887_TOP(t_params->default_top_low);
336 else if (i == 1 && params->default_top_mid) 387 else if (i == 1 && t_params->default_top_mid)
337 config |= TDA9887_TOP(params->default_top_mid); 388 config |= TDA9887_TOP(t_params->default_top_mid);
338 else if (params->default_top_high) 389 else if (t_params->default_top_high)
339 config |= TDA9887_TOP(params->default_top_high); 390 config |= TDA9887_TOP(t_params->default_top_high);
340 } 391 }
341 if (params->default_pll_gating_18) 392 if (t_params->default_pll_gating_18)
342 config |= TDA9887_GATING_18; 393 config |= TDA9887_GATING_18;
343 i2c_clients_command(c->adapter, TDA9887_SET_CONFIG, &config); 394 i2c_clients_command(priv->i2c_props.adap, TDA9887_SET_CONFIG, &config);
344 } 395 }
345 tuner_dbg("tv 0x%02x 0x%02x 0x%02x 0x%02x\n", 396 tuner_dbg("tv 0x%02x 0x%02x 0x%02x 0x%02x\n",
346 buffer[0],buffer[1],buffer[2],buffer[3]); 397 buffer[0],buffer[1],buffer[2],buffer[3]);
347 398
348 if (4 != (rc = i2c_master_send(c,buffer,4))) 399 if (4 != (rc = tuner_i2c_xfer_send(&priv->i2c_props,buffer,4)))
349 tuner_warn("i2c i/o error: rc == %d (should be 4)\n",rc); 400 tuner_warn("i2c i/o error: rc == %d (should be 4)\n",rc);
350 401
351 switch (t->type) { 402 switch (priv->type) {
352 case TUNER_LG_TDVS_H06XF: 403 case TUNER_LG_TDVS_H06XF:
353 /* Set the Auxiliary Byte. */ 404 /* Set the Auxiliary Byte. */
354 buffer[0] = buffer[2]; 405 buffer[0] = buffer[2];
@@ -357,7 +408,7 @@ static void default_set_tv_freq(struct i2c_client *c, unsigned int freq)
357 buffer[1] = 0x20; 408 buffer[1] = 0x20;
358 tuner_dbg("tv 0x%02x 0x%02x\n",buffer[0],buffer[1]); 409 tuner_dbg("tv 0x%02x 0x%02x\n",buffer[0],buffer[1]);
359 410
360 if (2 != (rc = i2c_master_send(c,buffer,2))) 411 if (2 != (rc = tuner_i2c_xfer_send(&priv->i2c_props,buffer,2)))
361 tuner_warn("i2c i/o error: rc == %d (should be 2)\n",rc); 412 tuner_warn("i2c i/o error: rc == %d (should be 2)\n",rc);
362 break; 413 break;
363 case TUNER_MICROTUNE_4042FI5: 414 case TUNER_MICROTUNE_4042FI5:
@@ -369,8 +420,8 @@ static void default_set_tv_freq(struct i2c_client *c, unsigned int freq)
369 /* Wait until the PLL locks */ 420 /* Wait until the PLL locks */
370 for (;;) { 421 for (;;) {
371 if (time_after(jiffies,timeout)) 422 if (time_after(jiffies,timeout))
372 return; 423 return 0;
373 if (1 != (rc = i2c_master_recv(c,&status_byte,1))) { 424 if (1 != (rc = tuner_i2c_xfer_recv(&priv->i2c_props,&status_byte,1))) {
374 tuner_warn("i2c i/o read error: rc == %d (should be 1)\n",rc); 425 tuner_warn("i2c i/o read error: rc == %d (should be 1)\n",rc);
375 break; 426 break;
376 } 427 }
@@ -388,68 +439,86 @@ static void default_set_tv_freq(struct i2c_client *c, unsigned int freq)
388 tuner_dbg("tv 0x%02x 0x%02x 0x%02x 0x%02x\n", 439 tuner_dbg("tv 0x%02x 0x%02x 0x%02x 0x%02x\n",
389 buffer[0],buffer[1],buffer[2],buffer[3]); 440 buffer[0],buffer[1],buffer[2],buffer[3]);
390 441
391 if (4 != (rc = i2c_master_send(c,buffer,4))) 442 if (4 != (rc = tuner_i2c_xfer_send(&priv->i2c_props,buffer,4)))
392 tuner_warn("i2c i/o error: rc == %d (should be 4)\n",rc); 443 tuner_warn("i2c i/o error: rc == %d (should be 4)\n",rc);
393 break; 444 break;
394 } 445 }
395 } 446 }
447 return 0;
396} 448}
397 449
398static void default_set_radio_freq(struct i2c_client *c, unsigned int freq) 450static int simple_set_radio_freq(struct dvb_frontend *fe,
451 struct analog_parameters *params)
399{ 452{
400 struct tunertype *tun; 453 struct tunertype *tun;
401 struct tuner *t = i2c_get_clientdata(c); 454 struct tuner_simple_priv *priv = fe->tuner_priv;
402 u8 buffer[4]; 455 u8 buffer[4];
403 u16 div; 456 u16 div;
404 int rc, j; 457 int rc, j;
405 enum param_type desired_type = TUNER_PARAM_TYPE_RADIO; 458 struct tuner_params *t_params;
406 struct tuner_params *params; 459 unsigned int freq = params->frequency;
407 460
408 tun = &tuners[t->type]; 461 tun = priv->tun;
409 462
410 for (j = 0; j < tun->count-1; j++) { 463 for (j = tun->count-1; j > 0; j--)
411 if (desired_type != tun->params[j].type) 464 if (tun->params[j].type == TUNER_PARAM_TYPE_RADIO)
412 continue; 465 break;
466 /* default t_params (j=0) will be used if desired type wasn't found */
467 t_params = &tun->params[j];
468
469 /* Select Radio 1st IF used */
470 switch (t_params->radio_if) {
471 case 0: /* 10.7 MHz */
472 freq += (unsigned int)(10.7*16000);
473 break;
474 case 1: /* 33.3 MHz */
475 freq += (unsigned int)(33.3*16000);
413 break; 476 break;
477 case 2: /* 41.3 MHz */
478 freq += (unsigned int)(41.3*16000);
479 break;
480 default:
481 tuner_warn("Unsupported radio_if value %d\n", t_params->radio_if);
482 return 0;
414 } 483 }
415 /* use default tuner_params if desired_type not available */
416 if (desired_type != tun->params[j].type)
417 j = 0;
418
419 div = (20 * freq / 16000) + (int)(20*10.7); /* IF 10.7 MHz */
420 params = &tun->params[j];
421 buffer[2] = (params->ranges[0].config & ~TUNER_RATIO_MASK) | TUNER_RATIO_SELECT_50; /* 50 kHz step */
422 484
423 switch (t->type) { 485 /* Bandswitch byte */
486 switch (priv->type) {
424 case TUNER_TENA_9533_DI: 487 case TUNER_TENA_9533_DI:
425 case TUNER_YMEC_TVF_5533MF: 488 case TUNER_YMEC_TVF_5533MF:
426 tuner_dbg ("This tuner doesn't have FM. Most cards has a TEA5767 for FM\n"); 489 tuner_dbg("This tuner doesn't have FM. Most cards have a TEA5767 for FM\n");
427 return; 490 return 0;
428 case TUNER_PHILIPS_FM1216ME_MK3: 491 case TUNER_PHILIPS_FM1216ME_MK3:
429 case TUNER_PHILIPS_FM1236_MK3: 492 case TUNER_PHILIPS_FM1236_MK3:
430 case TUNER_PHILIPS_FMD1216ME_MK3: 493 case TUNER_PHILIPS_FMD1216ME_MK3:
431 case TUNER_LG_NTSC_TAPE: 494 case TUNER_LG_NTSC_TAPE:
495 case TUNER_PHILIPS_FM1256_IH3:
432 buffer[3] = 0x19; 496 buffer[3] = 0x19;
433 break; 497 break;
434 case TUNER_TNF_5335MF: 498 case TUNER_TNF_5335MF:
435 buffer[3] = 0x11; 499 buffer[3] = 0x11;
436 break; 500 break;
437 case TUNER_PHILIPS_FM1256_IH3:
438 div = (20 * freq) / 16000 + (int)(33.3 * 20); /* IF 33.3 MHz */
439 buffer[3] = 0x19;
440 break;
441 case TUNER_LG_PAL_FM: 501 case TUNER_LG_PAL_FM:
442 buffer[3] = 0xa5; 502 buffer[3] = 0xa5;
443 break; 503 break;
444 case TUNER_MICROTUNE_4049FM5: 504 case TUNER_THOMSON_DTT761X:
445 div = (20 * freq) / 16000 + (int)(33.3 * 20); /* IF 33.3 MHz */ 505 buffer[3] = 0x39;
446 buffer[3] = 0xa4;
447 break; 506 break;
507 case TUNER_MICROTUNE_4049FM5:
448 default: 508 default:
449 buffer[3] = 0xa4; 509 buffer[3] = 0xa4;
450 break; 510 break;
451 } 511 }
452 if (params->cb_first_if_lower_freq && div < t->last_div) { 512
513 buffer[2] = (t_params->ranges[0].config & ~TUNER_RATIO_MASK) |
514 TUNER_RATIO_SELECT_50; /* 50 kHz step */
515
516 /* Convert from 1/16 kHz V4L steps to 1/20 MHz (=50 kHz) PLL steps
517 freq * (1 Mhz / 16000 V4L steps) * (20 PLL steps / 1 MHz) =
518 freq * (1/800) */
519 div = (freq + 400) / 800;
520
521 if (t_params->cb_first_if_lower_freq && div < priv->last_div) {
453 buffer[0] = buffer[2]; 522 buffer[0] = buffer[2];
454 buffer[1] = buffer[3]; 523 buffer[1] = buffer[3];
455 buffer[2] = (div>>8) & 0x7f; 524 buffer[2] = (div>>8) & 0x7f;
@@ -461,46 +530,108 @@ static void default_set_radio_freq(struct i2c_client *c, unsigned int freq)
461 530
462 tuner_dbg("radio 0x%02x 0x%02x 0x%02x 0x%02x\n", 531 tuner_dbg("radio 0x%02x 0x%02x 0x%02x 0x%02x\n",
463 buffer[0],buffer[1],buffer[2],buffer[3]); 532 buffer[0],buffer[1],buffer[2],buffer[3]);
464 t->last_div = div; 533 priv->last_div = div;
465 534
466 if (params->has_tda9887) { 535 if (t_params->has_tda9887) {
467 int config = 0; 536 int config = 0;
468 if (params->port1_active && !params->port1_fm_high_sensitivity) 537 if (t_params->port1_active && !t_params->port1_fm_high_sensitivity)
469 config |= TDA9887_PORT1_ACTIVE; 538 config |= TDA9887_PORT1_ACTIVE;
470 if (params->port2_active && !params->port2_fm_high_sensitivity) 539 if (t_params->port2_active && !t_params->port2_fm_high_sensitivity)
471 config |= TDA9887_PORT2_ACTIVE; 540 config |= TDA9887_PORT2_ACTIVE;
472 if (params->intercarrier_mode) 541 if (t_params->intercarrier_mode)
473 config |= TDA9887_INTERCARRIER; 542 config |= TDA9887_INTERCARRIER;
474/* if (params->port1_set_for_fm_mono) 543/* if (t_params->port1_set_for_fm_mono)
475 config &= ~TDA9887_PORT1_ACTIVE;*/ 544 config &= ~TDA9887_PORT1_ACTIVE;*/
476 if (params->fm_gain_normal) 545 if (t_params->fm_gain_normal)
477 config |= TDA9887_GAIN_NORMAL; 546 config |= TDA9887_GAIN_NORMAL;
478 i2c_clients_command(c->adapter, TDA9887_SET_CONFIG, &config); 547 if (t_params->radio_if == 2)
548 config |= TDA9887_RIF_41_3;
549 i2c_clients_command(priv->i2c_props.adap, TDA9887_SET_CONFIG, &config);
479 } 550 }
480 if (4 != (rc = i2c_master_send(c,buffer,4))) 551 if (4 != (rc = tuner_i2c_xfer_send(&priv->i2c_props,buffer,4)))
481 tuner_warn("i2c i/o error: rc == %d (should be 4)\n",rc); 552 tuner_warn("i2c i/o error: rc == %d (should be 4)\n",rc);
553
554 return 0;
482} 555}
483 556
484static struct tuner_operations simple_tuner_ops = { 557static int simple_set_params(struct dvb_frontend *fe,
485 .set_tv_freq = default_set_tv_freq, 558 struct analog_parameters *params)
486 .set_radio_freq = default_set_radio_freq, 559{
487 .has_signal = tuner_signal, 560 struct tuner_simple_priv *priv = fe->tuner_priv;
488 .is_stereo = tuner_stereo, 561 int ret = -EINVAL;
562
563 switch (params->mode) {
564 case V4L2_TUNER_RADIO:
565 ret = simple_set_radio_freq(fe, params);
566 priv->frequency = params->frequency * 125 / 2;
567 break;
568 case V4L2_TUNER_ANALOG_TV:
569 case V4L2_TUNER_DIGITAL_TV:
570 ret = simple_set_tv_freq(fe, params);
571 priv->frequency = params->frequency * 62500;
572 break;
573 }
574
575 return ret;
576}
577
578
579static int simple_release(struct dvb_frontend *fe)
580{
581 kfree(fe->tuner_priv);
582 fe->tuner_priv = NULL;
583
584 return 0;
585}
586
587static int simple_get_frequency(struct dvb_frontend *fe, u32 *frequency)
588{
589 struct tuner_simple_priv *priv = fe->tuner_priv;
590 *frequency = priv->frequency;
591 return 0;
592}
593
594static struct dvb_tuner_ops simple_tuner_ops = {
595 .set_analog_params = simple_set_params,
596 .release = simple_release,
597 .get_frequency = simple_get_frequency,
598 .get_status = simple_get_status,
599 .get_rf_strength = simple_get_rf_strength,
489}; 600};
490 601
491int default_tuner_init(struct i2c_client *c) 602struct dvb_frontend *simple_tuner_attach(struct dvb_frontend *fe,
603 struct i2c_adapter *i2c_adap,
604 u8 i2c_addr,
605 struct simple_tuner_config *cfg)
492{ 606{
493 struct tuner *t = i2c_get_clientdata(c); 607 struct tuner_simple_priv *priv = NULL;
494 608
495 tuner_info("type set to %d (%s)\n", 609 priv = kzalloc(sizeof(struct tuner_simple_priv), GFP_KERNEL);
496 t->type, tuners[t->type].name); 610 if (priv == NULL)
497 strlcpy(c->name, tuners[t->type].name, sizeof(c->name)); 611 return NULL;
612 fe->tuner_priv = priv;
498 613
499 memcpy(&t->ops, &simple_tuner_ops, sizeof(struct tuner_operations)); 614 priv->i2c_props.addr = i2c_addr;
615 priv->i2c_props.adap = i2c_adap;
616 priv->type = cfg->type;
617 priv->tun = cfg->tun;
500 618
501 return 0; 619 memcpy(&fe->ops.tuner_ops, &simple_tuner_ops, sizeof(struct dvb_tuner_ops));
620
621 tuner_info("type set to %d (%s)\n", cfg->type, cfg->tun->name);
622
623 strlcpy(fe->ops.tuner_ops.info.name, cfg->tun->name, sizeof(fe->ops.tuner_ops.info.name));
624
625 return fe;
502} 626}
503 627
628
629EXPORT_SYMBOL_GPL(simple_tuner_attach);
630
631MODULE_DESCRIPTION("Simple 4-control-bytes style tuner driver");
632MODULE_AUTHOR("Ralph Metzler, Gerd Knorr, Gunther Mayer");
633MODULE_LICENSE("GPL");
634
504/* 635/*
505 * Overrides for Emacs so that we follow Linus's tabbing style. 636 * Overrides for Emacs so that we follow Linus's tabbing style.
506 * --------------------------------------------------------------------------- 637 * ---------------------------------------------------------------------------
diff --git a/drivers/media/video/tuner-simple.h b/drivers/media/video/tuner-simple.h
new file mode 100644
index 000000000000..9089939a8c02
--- /dev/null
+++ b/drivers/media/video/tuner-simple.h
@@ -0,0 +1,46 @@
1/*
2 This program is free software; you can redistribute it and/or modify
3 it under the terms of the GNU General Public License as published by
4 the Free Software Foundation; either version 2 of the License, or
5 (at your option) any later version.
6
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
11
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
15*/
16
17#ifndef __TUNER_SIMPLE_H__
18#define __TUNER_SIMPLE_H__
19
20#include <linux/i2c.h>
21#include "dvb_frontend.h"
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))
31extern struct dvb_frontend *simple_tuner_attach(struct dvb_frontend *fe,
32 struct i2c_adapter *i2c_adap,
33 u8 i2c_addr,
34 struct simple_tuner_config *cfg);
35#else
36static inline struct dvb_frontend *simple_tuner_attach(struct dvb_frontend *fe,
37 struct i2c_adapter *i2c_adap,
38 u8 i2c_addr,
39 struct simple_tuner_config *cfg)
40{
41 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
42 return NULL;
43}
44#endif
45
46#endif /* __TUNER_SIMPLE_H__ */
diff --git a/drivers/media/video/tuner-types.c b/drivers/media/video/tuner-types.c
index 417f642b4359..c6a7934bd5a6 100644
--- a/drivers/media/video/tuner-types.c
+++ b/drivers/media/video/tuner-types.c
@@ -652,6 +652,7 @@ static struct tuner_params tuner_microtune_4049_fm5_params[] = {
652 .port1_invert_for_secam_lc = 1, 652 .port1_invert_for_secam_lc = 1,
653 .default_pll_gating_18 = 1, 653 .default_pll_gating_18 = 1,
654 .fm_gain_normal=1, 654 .fm_gain_normal=1,
655 .radio_if = 1, /* 33.3 MHz */
655 }, 656 },
656}; 657};
657 658
@@ -670,6 +671,9 @@ static struct tuner_params tuner_panasonic_vp27_params[] = {
670 .count = ARRAY_SIZE(tuner_panasonic_vp27_ntsc_ranges), 671 .count = ARRAY_SIZE(tuner_panasonic_vp27_ntsc_ranges),
671 .has_tda9887 = 1, 672 .has_tda9887 = 1,
672 .intercarrier_mode = 1, 673 .intercarrier_mode = 1,
674 .default_top_low = -3,
675 .default_top_mid = -3,
676 .default_top_high = -3,
673 }, 677 },
674}; 678};
675 679
@@ -730,6 +734,7 @@ static struct tuner_params tuner_philips_fm1256_ih3_params[] = {
730 .type = TUNER_PARAM_TYPE_PAL, 734 .type = TUNER_PARAM_TYPE_PAL,
731 .ranges = tuner_fm1236_mk3_ntsc_ranges, 735 .ranges = tuner_fm1236_mk3_ntsc_ranges,
732 .count = ARRAY_SIZE(tuner_fm1236_mk3_ntsc_ranges), 736 .count = ARRAY_SIZE(tuner_fm1236_mk3_ntsc_ranges),
737 .radio_if = 1, /* 33.3 MHz */
733 }, 738 },
734}; 739};
735 740
@@ -856,6 +861,9 @@ static struct tuner_params tuner_thomson_dtt761x_params[] = {
856 .type = TUNER_PARAM_TYPE_NTSC, 861 .type = TUNER_PARAM_TYPE_NTSC,
857 .ranges = tuner_thomson_dtt761x_ntsc_ranges, 862 .ranges = tuner_thomson_dtt761x_ntsc_ranges,
858 .count = ARRAY_SIZE(tuner_thomson_dtt761x_ntsc_ranges), 863 .count = ARRAY_SIZE(tuner_thomson_dtt761x_ntsc_ranges),
864 .has_tda9887 = 1,
865 .fm_gain_normal = 1,
866 .radio_if = 2, /* 41.3 MHz */
859 }, 867 },
860}; 868};
861 869
diff --git a/drivers/media/video/tvaudio.c b/drivers/media/video/tvaudio.c
index cffb011590e3..a19cdcc17ef7 100644
--- a/drivers/media/video/tvaudio.c
+++ b/drivers/media/video/tvaudio.c
@@ -15,7 +15,6 @@
15 */ 15 */
16 16
17#include <linux/module.h> 17#include <linux/module.h>
18#include <linux/moduleparam.h>
19#include <linux/kernel.h> 18#include <linux/kernel.h>
20#include <linux/sched.h> 19#include <linux/sched.h>
21#include <linux/string.h> 20#include <linux/string.h>
diff --git a/drivers/media/video/tveeprom.c b/drivers/media/video/tveeprom.c
index fdc3def437b1..4b2c4034f5b3 100644
--- a/drivers/media/video/tveeprom.c
+++ b/drivers/media/video/tveeprom.c
@@ -30,7 +30,6 @@
30 30
31 31
32#include <linux/module.h> 32#include <linux/module.h>
33#include <linux/moduleparam.h>
34#include <linux/errno.h> 33#include <linux/errno.h>
35#include <linux/kernel.h> 34#include <linux/kernel.h>
36#include <linux/init.h> 35#include <linux/init.h>
diff --git a/drivers/media/video/tvmixer.c b/drivers/media/video/tvmixer.c
index 3ae5a9cd2e28..9fa5b702e073 100644
--- a/drivers/media/video/tvmixer.c
+++ b/drivers/media/video/tvmixer.c
@@ -2,7 +2,6 @@
2 */ 2 */
3 3
4#include <linux/module.h> 4#include <linux/module.h>
5#include <linux/moduleparam.h>
6#include <linux/kernel.h> 5#include <linux/kernel.h>
7#include <linux/string.h> 6#include <linux/string.h>
8#include <linux/timer.h> 7#include <linux/timer.h>
@@ -238,13 +237,10 @@ static const struct file_operations tvmixer_fops = {
238 237
239static int tvmixer_adapters(struct i2c_adapter *adap) 238static int tvmixer_adapters(struct i2c_adapter *adap)
240{ 239{
241 struct list_head *item;
242 struct i2c_client *client; 240 struct i2c_client *client;
243 241
244 list_for_each(item,&adap->clients) { 242 list_for_each_entry(client, &adap->clients, list)
245 client = list_entry(item, struct i2c_client, list);
246 tvmixer_clients(client); 243 tvmixer_clients(client);
247 }
248 return 0; 244 return 0;
249} 245}
250 246
diff --git a/drivers/media/video/usbvision/usbvision-core.c b/drivers/media/video/usbvision/usbvision-core.c
index 5b1e346df206..c7d5f9ed22d7 100644
--- a/drivers/media/video/usbvision/usbvision-core.c
+++ b/drivers/media/video/usbvision/usbvision-core.c
@@ -45,7 +45,6 @@
45#include <media/tuner.h> 45#include <media/tuner.h>
46#include <media/audiochip.h> 46#include <media/audiochip.h>
47 47
48#include <linux/moduleparam.h>
49#include <linux/workqueue.h> 48#include <linux/workqueue.h>
50 49
51#ifdef CONFIG_KMOD 50#ifdef CONFIG_KMOD
diff --git a/drivers/media/video/usbvision/usbvision-i2c.c b/drivers/media/video/usbvision/usbvision-i2c.c
index 025be555194f..c66aef63916f 100644
--- a/drivers/media/video/usbvision/usbvision-i2c.c
+++ b/drivers/media/video/usbvision/usbvision-i2c.c
@@ -134,8 +134,6 @@ static inline int usb_find_address(struct i2c_adapter *i2c_adap,
134 addr = (msg->addr << 1); 134 addr = (msg->addr << 1);
135 if (flags & I2C_M_RD) 135 if (flags & I2C_M_RD)
136 addr |= 1; 136 addr |= 1;
137 if (flags & I2C_M_REV_DIR_ADDR)
138 addr ^= 1;
139 137
140 add[0] = addr; 138 add[0] = addr;
141 if (flags & I2C_M_RD) 139 if (flags & I2C_M_RD)
@@ -192,7 +190,7 @@ static int algo_control(struct i2c_adapter *adapter, unsigned int cmd, unsigned
192 190
193static u32 functionality(struct i2c_adapter *adap) 191static u32 functionality(struct i2c_adapter *adap)
194{ 192{
195 return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR | I2C_FUNC_PROTOCOL_MANGLING; 193 return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR;
196} 194}
197 195
198 196
diff --git a/drivers/media/video/usbvision/usbvision-video.c b/drivers/media/video/usbvision/usbvision-video.c
index 0cb006f2943d..e2f3c01cfa13 100644
--- a/drivers/media/video/usbvision/usbvision-video.c
+++ b/drivers/media/video/usbvision/usbvision-video.c
@@ -68,7 +68,6 @@
68#include <media/tuner.h> 68#include <media/tuner.h>
69#include <media/audiochip.h> 69#include <media/audiochip.h>
70 70
71#include <linux/moduleparam.h>
72#include <linux/workqueue.h> 71#include <linux/workqueue.h>
73 72
74#ifdef CONFIG_KMOD 73#ifdef CONFIG_KMOD
@@ -183,20 +182,22 @@ MODULE_ALIAS(DRIVER_ALIAS);
183 182
184#define YES_NO(x) ((x) ? "Yes" : "No") 183#define YES_NO(x) ((x) ? "Yes" : "No")
185 184
186static inline struct usb_usbvision *cd_to_usbvision(struct class_device *cd) 185static inline struct usb_usbvision *cd_to_usbvision(struct device *cd)
187{ 186{
188 struct video_device *vdev = 187 struct video_device *vdev =
189 container_of(cd, struct video_device, class_dev); 188 container_of(cd, struct video_device, class_dev);
190 return video_get_drvdata(vdev); 189 return video_get_drvdata(vdev);
191} 190}
192 191
193static ssize_t show_version(struct class_device *cd, char *buf) 192static ssize_t show_version(struct device *cd,
193 struct device_attribute *attr, char *buf)
194{ 194{
195 return sprintf(buf, "%s\n", USBVISION_VERSION_STRING); 195 return sprintf(buf, "%s\n", USBVISION_VERSION_STRING);
196} 196}
197static CLASS_DEVICE_ATTR(version, S_IRUGO, show_version, NULL); 197static DEVICE_ATTR(version, S_IRUGO, show_version, NULL);
198 198
199static ssize_t show_model(struct class_device *cd, char *buf) 199static ssize_t show_model(struct device *cd,
200 struct device_attribute *attr, char *buf)
200{ 201{
201 struct video_device *vdev = 202 struct video_device *vdev =
202 container_of(cd, struct video_device, class_dev); 203 container_of(cd, struct video_device, class_dev);
@@ -204,9 +205,10 @@ static ssize_t show_model(struct class_device *cd, char *buf)
204 return sprintf(buf, "%s\n", 205 return sprintf(buf, "%s\n",
205 usbvision_device_data[usbvision->DevModel].ModelString); 206 usbvision_device_data[usbvision->DevModel].ModelString);
206} 207}
207static CLASS_DEVICE_ATTR(model, S_IRUGO, show_model, NULL); 208static DEVICE_ATTR(model, S_IRUGO, show_model, NULL);
208 209
209static ssize_t show_hue(struct class_device *cd, char *buf) 210static ssize_t show_hue(struct device *cd,
211 struct device_attribute *attr, char *buf)
210{ 212{
211 struct video_device *vdev = 213 struct video_device *vdev =
212 container_of(cd, struct video_device, class_dev); 214 container_of(cd, struct video_device, class_dev);
@@ -218,9 +220,10 @@ static ssize_t show_hue(struct class_device *cd, char *buf)
218 call_i2c_clients(usbvision, VIDIOC_G_CTRL, &ctrl); 220 call_i2c_clients(usbvision, VIDIOC_G_CTRL, &ctrl);
219 return sprintf(buf, "%d\n", ctrl.value); 221 return sprintf(buf, "%d\n", ctrl.value);
220} 222}
221static CLASS_DEVICE_ATTR(hue, S_IRUGO, show_hue, NULL); 223static DEVICE_ATTR(hue, S_IRUGO, show_hue, NULL);
222 224
223static ssize_t show_contrast(struct class_device *cd, char *buf) 225static ssize_t show_contrast(struct device *cd,
226 struct device_attribute *attr, char *buf)
224{ 227{
225 struct video_device *vdev = 228 struct video_device *vdev =
226 container_of(cd, struct video_device, class_dev); 229 container_of(cd, struct video_device, class_dev);
@@ -232,9 +235,10 @@ static ssize_t show_contrast(struct class_device *cd, char *buf)
232 call_i2c_clients(usbvision, VIDIOC_G_CTRL, &ctrl); 235 call_i2c_clients(usbvision, VIDIOC_G_CTRL, &ctrl);
233 return sprintf(buf, "%d\n", ctrl.value); 236 return sprintf(buf, "%d\n", ctrl.value);
234} 237}
235static CLASS_DEVICE_ATTR(contrast, S_IRUGO, show_contrast, NULL); 238static DEVICE_ATTR(contrast, S_IRUGO, show_contrast, NULL);
236 239
237static ssize_t show_brightness(struct class_device *cd, char *buf) 240static ssize_t show_brightness(struct device *cd,
241 struct device_attribute *attr, char *buf)
238{ 242{
239 struct video_device *vdev = 243 struct video_device *vdev =
240 container_of(cd, struct video_device, class_dev); 244 container_of(cd, struct video_device, class_dev);
@@ -246,9 +250,10 @@ static ssize_t show_brightness(struct class_device *cd, char *buf)
246 call_i2c_clients(usbvision, VIDIOC_G_CTRL, &ctrl); 250 call_i2c_clients(usbvision, VIDIOC_G_CTRL, &ctrl);
247 return sprintf(buf, "%d\n", ctrl.value); 251 return sprintf(buf, "%d\n", ctrl.value);
248} 252}
249static CLASS_DEVICE_ATTR(brightness, S_IRUGO, show_brightness, NULL); 253static DEVICE_ATTR(brightness, S_IRUGO, show_brightness, NULL);
250 254
251static ssize_t show_saturation(struct class_device *cd, char *buf) 255static ssize_t show_saturation(struct device *cd,
256 struct device_attribute *attr, char *buf)
252{ 257{
253 struct video_device *vdev = 258 struct video_device *vdev =
254 container_of(cd, struct video_device, class_dev); 259 container_of(cd, struct video_device, class_dev);
@@ -260,9 +265,10 @@ static ssize_t show_saturation(struct class_device *cd, char *buf)
260 call_i2c_clients(usbvision, VIDIOC_G_CTRL, &ctrl); 265 call_i2c_clients(usbvision, VIDIOC_G_CTRL, &ctrl);
261 return sprintf(buf, "%d\n", ctrl.value); 266 return sprintf(buf, "%d\n", ctrl.value);
262} 267}
263static CLASS_DEVICE_ATTR(saturation, S_IRUGO, show_saturation, NULL); 268static DEVICE_ATTR(saturation, S_IRUGO, show_saturation, NULL);
264 269
265static ssize_t show_streaming(struct class_device *cd, char *buf) 270static ssize_t show_streaming(struct device *cd,
271 struct device_attribute *attr, char *buf)
266{ 272{
267 struct video_device *vdev = 273 struct video_device *vdev =
268 container_of(cd, struct video_device, class_dev); 274 container_of(cd, struct video_device, class_dev);
@@ -270,9 +276,10 @@ static ssize_t show_streaming(struct class_device *cd, char *buf)
270 return sprintf(buf, "%s\n", 276 return sprintf(buf, "%s\n",
271 YES_NO(usbvision->streaming==Stream_On?1:0)); 277 YES_NO(usbvision->streaming==Stream_On?1:0));
272} 278}
273static CLASS_DEVICE_ATTR(streaming, S_IRUGO, show_streaming, NULL); 279static DEVICE_ATTR(streaming, S_IRUGO, show_streaming, NULL);
274 280
275static ssize_t show_compression(struct class_device *cd, char *buf) 281static ssize_t show_compression(struct device *cd,
282 struct device_attribute *attr, char *buf)
276{ 283{
277 struct video_device *vdev = 284 struct video_device *vdev =
278 container_of(cd, struct video_device, class_dev); 285 container_of(cd, struct video_device, class_dev);
@@ -280,16 +287,17 @@ static ssize_t show_compression(struct class_device *cd, char *buf)
280 return sprintf(buf, "%s\n", 287 return sprintf(buf, "%s\n",
281 YES_NO(usbvision->isocMode==ISOC_MODE_COMPRESS)); 288 YES_NO(usbvision->isocMode==ISOC_MODE_COMPRESS));
282} 289}
283static CLASS_DEVICE_ATTR(compression, S_IRUGO, show_compression, NULL); 290static DEVICE_ATTR(compression, S_IRUGO, show_compression, NULL);
284 291
285static ssize_t show_device_bridge(struct class_device *cd, char *buf) 292static ssize_t show_device_bridge(struct device *cd,
293 struct device_attribute *attr, char *buf)
286{ 294{
287 struct video_device *vdev = 295 struct video_device *vdev =
288 container_of(cd, struct video_device, class_dev); 296 container_of(cd, struct video_device, class_dev);
289 struct usb_usbvision *usbvision = video_get_drvdata(vdev); 297 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
290 return sprintf(buf, "%d\n", usbvision->bridgeType); 298 return sprintf(buf, "%d\n", usbvision->bridgeType);
291} 299}
292static CLASS_DEVICE_ATTR(bridge, S_IRUGO, show_device_bridge, NULL); 300static DEVICE_ATTR(bridge, S_IRUGO, show_device_bridge, NULL);
293 301
294static void usbvision_create_sysfs(struct video_device *vdev) 302static void usbvision_create_sysfs(struct video_device *vdev)
295{ 303{
@@ -297,40 +305,40 @@ static void usbvision_create_sysfs(struct video_device *vdev)
297 if (!vdev) 305 if (!vdev)
298 return; 306 return;
299 do { 307 do {
300 res=class_device_create_file(&vdev->class_dev, 308 res = device_create_file(&vdev->class_dev,
301 &class_device_attr_version); 309 &dev_attr_version);
302 if (res<0) 310 if (res<0)
303 break; 311 break;
304 res=class_device_create_file(&vdev->class_dev, 312 res = device_create_file(&vdev->class_dev,
305 &class_device_attr_model); 313 &dev_attr_model);
306 if (res<0) 314 if (res<0)
307 break; 315 break;
308 res=class_device_create_file(&vdev->class_dev, 316 res = device_create_file(&vdev->class_dev,
309 &class_device_attr_hue); 317 &dev_attr_hue);
310 if (res<0) 318 if (res<0)
311 break; 319 break;
312 res=class_device_create_file(&vdev->class_dev, 320 res = device_create_file(&vdev->class_dev,
313 &class_device_attr_contrast); 321 &dev_attr_contrast);
314 if (res<0) 322 if (res<0)
315 break; 323 break;
316 res=class_device_create_file(&vdev->class_dev, 324 res = device_create_file(&vdev->class_dev,
317 &class_device_attr_brightness); 325 &dev_attr_brightness);
318 if (res<0) 326 if (res<0)
319 break; 327 break;
320 res=class_device_create_file(&vdev->class_dev, 328 res = device_create_file(&vdev->class_dev,
321 &class_device_attr_saturation); 329 &dev_attr_saturation);
322 if (res<0) 330 if (res<0)
323 break; 331 break;
324 res=class_device_create_file(&vdev->class_dev, 332 res = device_create_file(&vdev->class_dev,
325 &class_device_attr_streaming); 333 &dev_attr_streaming);
326 if (res<0) 334 if (res<0)
327 break; 335 break;
328 res=class_device_create_file(&vdev->class_dev, 336 res = device_create_file(&vdev->class_dev,
329 &class_device_attr_compression); 337 &dev_attr_compression);
330 if (res<0) 338 if (res<0)
331 break; 339 break;
332 res=class_device_create_file(&vdev->class_dev, 340 res = device_create_file(&vdev->class_dev,
333 &class_device_attr_bridge); 341 &dev_attr_bridge);
334 if (res>=0) 342 if (res>=0)
335 return; 343 return;
336 } while (0); 344 } while (0);
@@ -341,24 +349,24 @@ static void usbvision_create_sysfs(struct video_device *vdev)
341static void usbvision_remove_sysfs(struct video_device *vdev) 349static void usbvision_remove_sysfs(struct video_device *vdev)
342{ 350{
343 if (vdev) { 351 if (vdev) {
344 class_device_remove_file(&vdev->class_dev, 352 device_remove_file(&vdev->class_dev,
345 &class_device_attr_version); 353 &dev_attr_version);
346 class_device_remove_file(&vdev->class_dev, 354 device_remove_file(&vdev->class_dev,
347 &class_device_attr_model); 355 &dev_attr_model);
348 class_device_remove_file(&vdev->class_dev, 356 device_remove_file(&vdev->class_dev,
349 &class_device_attr_hue); 357 &dev_attr_hue);
350 class_device_remove_file(&vdev->class_dev, 358 device_remove_file(&vdev->class_dev,
351 &class_device_attr_contrast); 359 &dev_attr_contrast);
352 class_device_remove_file(&vdev->class_dev, 360 device_remove_file(&vdev->class_dev,
353 &class_device_attr_brightness); 361 &dev_attr_brightness);
354 class_device_remove_file(&vdev->class_dev, 362 device_remove_file(&vdev->class_dev,
355 &class_device_attr_saturation); 363 &dev_attr_saturation);
356 class_device_remove_file(&vdev->class_dev, 364 device_remove_file(&vdev->class_dev,
357 &class_device_attr_streaming); 365 &dev_attr_streaming);
358 class_device_remove_file(&vdev->class_dev, 366 device_remove_file(&vdev->class_dev,
359 &class_device_attr_compression); 367 &dev_attr_compression);
360 class_device_remove_file(&vdev->class_dev, 368 device_remove_file(&vdev->class_dev,
361 &class_device_attr_bridge); 369 &dev_attr_bridge);
362 } 370 }
363} 371}
364 372
diff --git a/drivers/media/video/v4l1-compat.c b/drivers/media/video/v4l1-compat.c
index ede8543818bf..9eac65f34bff 100644
--- a/drivers/media/video/v4l1-compat.c
+++ b/drivers/media/video/v4l1-compat.c
@@ -19,7 +19,6 @@
19 19
20#include <linux/init.h> 20#include <linux/init.h>
21#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/moduleparam.h>
23#include <linux/types.h> 22#include <linux/types.h>
24#include <linux/kernel.h> 23#include <linux/kernel.h>
25#include <linux/sched.h> 24#include <linux/sched.h>
diff --git a/drivers/media/video/v4l2-common.c b/drivers/media/video/v4l2-common.c
index d2915d3530ea..c3440b280d20 100644
--- a/drivers/media/video/v4l2-common.c
+++ b/drivers/media/video/v4l2-common.c
@@ -65,11 +65,6 @@
65#include <linux/kmod.h> 65#include <linux/kmod.h>
66#endif 66#endif
67 67
68#if defined(CONFIG_UST) || defined(CONFIG_UST_MODULE)
69#include <linux/ust.h>
70#endif
71
72
73#include <linux/videodev.h> 68#include <linux/videodev.h>
74 69
75MODULE_AUTHOR("Bill Dirks, Justin Schoeman, Gerd Knorr"); 70MODULE_AUTHOR("Bill Dirks, Justin Schoeman, Gerd Knorr");
@@ -716,6 +711,7 @@ int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 ste
716 case V4L2_CID_AUDIO_MUTE: 711 case V4L2_CID_AUDIO_MUTE:
717 case V4L2_CID_AUDIO_LOUDNESS: 712 case V4L2_CID_AUDIO_LOUDNESS:
718 case V4L2_CID_MPEG_AUDIO_MUTE: 713 case V4L2_CID_MPEG_AUDIO_MUTE:
714 case V4L2_CID_MPEG_VIDEO_MUTE:
719 case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE: 715 case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE:
720 case V4L2_CID_MPEG_VIDEO_PULLDOWN: 716 case V4L2_CID_MPEG_VIDEO_PULLDOWN:
721 qctrl->type = V4L2_CTRL_TYPE_BOOLEAN; 717 qctrl->type = V4L2_CTRL_TYPE_BOOLEAN;
diff --git a/drivers/media/video/v4l2-int-device.c b/drivers/media/video/v4l2-int-device.c
new file mode 100644
index 000000000000..8b4ef530a3a8
--- /dev/null
+++ b/drivers/media/video/v4l2-int-device.c
@@ -0,0 +1,158 @@
1/*
2 * drivers/media/video/v4l2-int-device.c
3 *
4 * V4L2 internal ioctl interface.
5 *
6 * Copyright (C) 2007 Nokia Corporation.
7 *
8 * Contact: Sakari Ailus <sakari.ailus@nokia.com>
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * version 2 as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
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., 51 Franklin St, Fifth Floor, Boston, MA
22 * 02110-1301 USA
23 */
24
25#include <linux/kernel.h>
26#include <linux/list.h>
27#include <linux/sort.h>
28#include <linux/string.h>
29
30#include <media/v4l2-int-device.h>
31
32static DEFINE_MUTEX(mutex);
33static LIST_HEAD(int_list);
34
35static void v4l2_int_device_try_attach_all(void)
36{
37 struct v4l2_int_device *m, *s;
38
39 list_for_each_entry(m, &int_list, head) {
40 if (m->type != v4l2_int_type_master)
41 continue;
42
43 list_for_each_entry(s, &int_list, head) {
44 if (s->type != v4l2_int_type_slave)
45 continue;
46
47 /* Slave is connected? */
48 if (s->u.slave->master)
49 continue;
50
51 /* Slave wants to attach to master? */
52 if (s->u.slave->attach_to[0] != 0
53 && strncmp(m->name, s->u.slave->attach_to,
54 V4L2NAMESIZE))
55 continue;
56
57 if (!try_module_get(m->module))
58 continue;
59
60 if (m->u.master->attach(m, s)) {
61 module_put(m->module);
62 continue;
63 }
64
65 s->u.slave->master = m;
66 }
67 }
68}
69
70static int ioctl_sort_cmp(const void *a, const void *b)
71{
72 const struct v4l2_int_ioctl_desc *d1 = a, *d2 = b;
73
74 if (d1->num > d2->num)
75 return 1;
76
77 if (d1->num < d2->num)
78 return -1;
79
80 return 0;
81}
82
83int v4l2_int_device_register(struct v4l2_int_device *d)
84{
85 if (d->type == v4l2_int_type_slave)
86 sort(d->u.slave->ioctls, d->u.slave->num_ioctls,
87 sizeof(struct v4l2_int_ioctl_desc),
88 &ioctl_sort_cmp, NULL);
89 mutex_lock(&mutex);
90 list_add(&d->head, &int_list);
91 v4l2_int_device_try_attach_all();
92 mutex_unlock(&mutex);
93
94 return 0;
95}
96EXPORT_SYMBOL_GPL(v4l2_int_device_register);
97
98void v4l2_int_device_unregister(struct v4l2_int_device *d)
99{
100 mutex_lock(&mutex);
101 list_del(&d->head);
102 if (d->type == v4l2_int_type_slave
103 && d->u.slave->master != NULL) {
104 d->u.slave->master->u.master->detach(d);
105 module_put(d->u.slave->master->module);
106 d->u.slave->master = NULL;
107 }
108 mutex_unlock(&mutex);
109}
110EXPORT_SYMBOL_GPL(v4l2_int_device_unregister);
111
112/* Adapted from search_extable in extable.c. */
113static v4l2_int_ioctl_func *find_ioctl(struct v4l2_int_slave *slave, int cmd,
114 v4l2_int_ioctl_func *no_such_ioctl)
115{
116 const struct v4l2_int_ioctl_desc *first = slave->ioctls;
117 const struct v4l2_int_ioctl_desc *last =
118 first + slave->num_ioctls - 1;
119
120 while (first <= last) {
121 const struct v4l2_int_ioctl_desc *mid;
122
123 mid = (last - first) / 2 + first;
124
125 if (mid->num < cmd)
126 first = mid + 1;
127 else if (mid->num > cmd)
128 last = mid - 1;
129 else
130 return mid->func;
131 }
132
133 return no_such_ioctl;
134}
135
136static int no_such_ioctl_0(struct v4l2_int_device *d)
137{
138 return -ENOIOCTLCMD;
139}
140
141int v4l2_int_ioctl_0(struct v4l2_int_device *d, int cmd)
142{
143 return ((v4l2_int_ioctl_func_0 *)
144 find_ioctl(d->u.slave, cmd,
145 (v4l2_int_ioctl_func *)no_such_ioctl_0))(d);
146}
147
148static int no_such_ioctl_1(struct v4l2_int_device *d, void *arg)
149{
150 return -ENOIOCTLCMD;
151}
152
153int v4l2_int_ioctl_1(struct v4l2_int_device *d, int cmd, void *arg)
154{
155 return ((v4l2_int_ioctl_func_1 *)
156 find_ioctl(d->u.slave, cmd,
157 (v4l2_int_ioctl_func *)no_such_ioctl_1))(d, arg);
158}
diff --git a/drivers/media/video/video-buf-dvb.c b/drivers/media/video/video-buf-dvb.c
deleted file mode 100644
index e617925ba31e..000000000000
--- a/drivers/media/video/video-buf-dvb.c
+++ /dev/null
@@ -1,255 +0,0 @@
1/*
2 *
3 * some helper function for simple DVB cards which simply DMA the
4 * complete transport stream and let the computer sort everything else
5 * (i.e. we are using the software demux, ...). Also uses the
6 * video-buf to manage DMA buffers.
7 *
8 * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SUSE Labs]
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 */
15
16
17#include <linux/module.h>
18#include <linux/init.h>
19#include <linux/device.h>
20#include <linux/fs.h>
21#include <linux/kthread.h>
22#include <linux/file.h>
23#include <linux/freezer.h>
24
25#include <media/video-buf.h>
26#include <media/video-buf-dvb.h>
27
28/* ------------------------------------------------------------------ */
29
30MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
31MODULE_LICENSE("GPL");
32
33static unsigned int debug = 0;
34module_param(debug, int, 0644);
35MODULE_PARM_DESC(debug,"enable debug messages");
36
37#define dprintk(fmt, arg...) if (debug) \
38 printk(KERN_DEBUG "%s/dvb: " fmt, dvb->name , ## arg)
39
40/* ------------------------------------------------------------------ */
41
42static int videobuf_dvb_thread(void *data)
43{
44 struct videobuf_dvb *dvb = data;
45 struct videobuf_buffer *buf;
46 unsigned long flags;
47 int err;
48
49 dprintk("dvb thread started\n");
50 set_freezable();
51 videobuf_read_start(&dvb->dvbq);
52
53 for (;;) {
54 /* fetch next buffer */
55 buf = list_entry(dvb->dvbq.stream.next,
56 struct videobuf_buffer, stream);
57 list_del(&buf->stream);
58 err = videobuf_waiton(buf,0,1);
59 BUG_ON(0 != err);
60
61 /* no more feeds left or stop_feed() asked us to quit */
62 if (0 == dvb->nfeeds)
63 break;
64 if (kthread_should_stop())
65 break;
66 try_to_freeze();
67
68 /* feed buffer data to demux */
69 if (buf->state == STATE_DONE)
70 dvb_dmx_swfilter(&dvb->demux, buf->dma.vmalloc,
71 buf->size);
72
73 /* requeue buffer */
74 list_add_tail(&buf->stream,&dvb->dvbq.stream);
75 spin_lock_irqsave(dvb->dvbq.irqlock,flags);
76 dvb->dvbq.ops->buf_queue(&dvb->dvbq,buf);
77 spin_unlock_irqrestore(dvb->dvbq.irqlock,flags);
78 }
79
80 videobuf_read_stop(&dvb->dvbq);
81 dprintk("dvb thread stopped\n");
82
83 /* Hmm, linux becomes *very* unhappy without this ... */
84 while (!kthread_should_stop()) {
85 set_current_state(TASK_INTERRUPTIBLE);
86 schedule();
87 }
88 return 0;
89}
90
91static int videobuf_dvb_start_feed(struct dvb_demux_feed *feed)
92{
93 struct dvb_demux *demux = feed->demux;
94 struct videobuf_dvb *dvb = demux->priv;
95 int rc;
96
97 if (!demux->dmx.frontend)
98 return -EINVAL;
99
100 mutex_lock(&dvb->lock);
101 dvb->nfeeds++;
102 rc = dvb->nfeeds;
103
104 if (NULL != dvb->thread)
105 goto out;
106 dvb->thread = kthread_run(videobuf_dvb_thread,
107 dvb, "%s dvb", dvb->name);
108 if (IS_ERR(dvb->thread)) {
109 rc = PTR_ERR(dvb->thread);
110 dvb->thread = NULL;
111 }
112
113out:
114 mutex_unlock(&dvb->lock);
115 return rc;
116}
117
118static int videobuf_dvb_stop_feed(struct dvb_demux_feed *feed)
119{
120 struct dvb_demux *demux = feed->demux;
121 struct videobuf_dvb *dvb = demux->priv;
122 int err = 0;
123
124 mutex_lock(&dvb->lock);
125 dvb->nfeeds--;
126 if (0 == dvb->nfeeds && NULL != dvb->thread) {
127 // FIXME: cx8802_cancel_buffers(dev);
128 err = kthread_stop(dvb->thread);
129 dvb->thread = NULL;
130 }
131 mutex_unlock(&dvb->lock);
132 return err;
133}
134
135/* ------------------------------------------------------------------ */
136
137int videobuf_dvb_register(struct videobuf_dvb *dvb,
138 struct module *module,
139 void *adapter_priv,
140 struct device *device)
141{
142 int result;
143
144 mutex_init(&dvb->lock);
145
146 /* register adapter */
147 result = dvb_register_adapter(&dvb->adapter, dvb->name, module, device);
148 if (result < 0) {
149 printk(KERN_WARNING "%s: dvb_register_adapter failed (errno = %d)\n",
150 dvb->name, result);
151 goto fail_adapter;
152 }
153 dvb->adapter.priv = adapter_priv;
154
155 /* register frontend */
156 result = dvb_register_frontend(&dvb->adapter, dvb->frontend);
157 if (result < 0) {
158 printk(KERN_WARNING "%s: dvb_register_frontend failed (errno = %d)\n",
159 dvb->name, result);
160 goto fail_frontend;
161 }
162
163 /* register demux stuff */
164 dvb->demux.dmx.capabilities =
165 DMX_TS_FILTERING | DMX_SECTION_FILTERING |
166 DMX_MEMORY_BASED_FILTERING;
167 dvb->demux.priv = dvb;
168 dvb->demux.filternum = 256;
169 dvb->demux.feednum = 256;
170 dvb->demux.start_feed = videobuf_dvb_start_feed;
171 dvb->demux.stop_feed = videobuf_dvb_stop_feed;
172 result = dvb_dmx_init(&dvb->demux);
173 if (result < 0) {
174 printk(KERN_WARNING "%s: dvb_dmx_init failed (errno = %d)\n",
175 dvb->name, result);
176 goto fail_dmx;
177 }
178
179 dvb->dmxdev.filternum = 256;
180 dvb->dmxdev.demux = &dvb->demux.dmx;
181 dvb->dmxdev.capabilities = 0;
182 result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter);
183 if (result < 0) {
184 printk(KERN_WARNING "%s: dvb_dmxdev_init failed (errno = %d)\n",
185 dvb->name, result);
186 goto fail_dmxdev;
187 }
188
189 dvb->fe_hw.source = DMX_FRONTEND_0;
190 result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw);
191 if (result < 0) {
192 printk(KERN_WARNING "%s: add_frontend failed (DMX_FRONTEND_0, errno = %d)\n",
193 dvb->name, result);
194 goto fail_fe_hw;
195 }
196
197 dvb->fe_mem.source = DMX_MEMORY_FE;
198 result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem);
199 if (result < 0) {
200 printk(KERN_WARNING "%s: add_frontend failed (DMX_MEMORY_FE, errno = %d)\n",
201 dvb->name, result);
202 goto fail_fe_mem;
203 }
204
205 result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw);
206 if (result < 0) {
207 printk(KERN_WARNING "%s: connect_frontend failed (errno = %d)\n",
208 dvb->name, result);
209 goto fail_fe_conn;
210 }
211
212 /* register network adapter */
213 dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx);
214 return 0;
215
216fail_fe_conn:
217 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
218fail_fe_mem:
219 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
220fail_fe_hw:
221 dvb_dmxdev_release(&dvb->dmxdev);
222fail_dmxdev:
223 dvb_dmx_release(&dvb->demux);
224fail_dmx:
225 dvb_unregister_frontend(dvb->frontend);
226fail_frontend:
227 dvb_frontend_detach(dvb->frontend);
228 dvb_unregister_adapter(&dvb->adapter);
229fail_adapter:
230 return result;
231}
232
233void videobuf_dvb_unregister(struct videobuf_dvb *dvb)
234{
235 dvb_net_release(&dvb->net);
236 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
237 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
238 dvb_dmxdev_release(&dvb->dmxdev);
239 dvb_dmx_release(&dvb->demux);
240 dvb_unregister_frontend(dvb->frontend);
241 dvb_frontend_detach(dvb->frontend);
242 dvb_unregister_adapter(&dvb->adapter);
243}
244
245EXPORT_SYMBOL(videobuf_dvb_register);
246EXPORT_SYMBOL(videobuf_dvb_unregister);
247
248/* ------------------------------------------------------------------ */
249/*
250 * Local variables:
251 * c-basic-offset: 8
252 * compile-command: "make DVB=1"
253 * End:
254 */
255
diff --git a/drivers/media/video/video-buf.c b/drivers/media/video/video-buf.c
deleted file mode 100644
index a32dfbe0585a..000000000000
--- a/drivers/media/video/video-buf.c
+++ /dev/null
@@ -1,1425 +0,0 @@
1/*
2 *
3 * generic helper functions for video4linux capture buffers, to handle
4 * memory management and PCI DMA.
5 * Right now, bttv, saa7134, saa7146 and cx88 use it.
6 *
7 * The functions expect the hardware being able to scatter gatter
8 * (i.e. the buffers are not linear in physical memory, but fragmented
9 * into PAGE_SIZE chunks). They also assume the driver does not need
10 * to touch the video data.
11 *
12 * device specific map/unmap/sync stuff now are mapped as operations
13 * to allow its usage by USB and virtual devices.
14 *
15 * (c) 2001-2004 Gerd Knorr <kraxel@bytesex.org> [SUSE Labs]
16 * (c) 2006 Mauro Carvalho Chehab <mchehab@infradead.org>
17 * (c) 2006 Ted Walther and John Sokol
18 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
23 */
24
25#include <linux/init.h>
26#include <linux/module.h>
27#include <linux/moduleparam.h>
28#include <linux/vmalloc.h>
29#include <linux/pagemap.h>
30#include <linux/slab.h>
31#include <linux/pci.h>
32#include <linux/interrupt.h>
33#include <asm/page.h>
34#include <asm/pgtable.h>
35
36#include <media/video-buf.h>
37
38#define MAGIC_DMABUF 0x19721112
39#define MAGIC_BUFFER 0x20040302
40#define MAGIC_CHECK(is,should) if (unlikely((is) != (should))) \
41 { printk(KERN_ERR "magic mismatch: %x (expected %x)\n",is,should); BUG(); }
42
43static int debug = 0;
44module_param(debug, int, 0644);
45
46MODULE_DESCRIPTION("helper module to manage video4linux pci dma buffers");
47MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
48MODULE_LICENSE("GPL");
49
50#define dprintk(level, fmt, arg...) if (debug >= level) \
51 printk(KERN_DEBUG "vbuf: " fmt , ## arg)
52
53struct scatterlist*
54videobuf_vmalloc_to_sg(unsigned char *virt, int nr_pages)
55{
56 struct scatterlist *sglist;
57 struct page *pg;
58 int i;
59
60 sglist = kcalloc(nr_pages, sizeof(struct scatterlist), GFP_KERNEL);
61 if (NULL == sglist)
62 return NULL;
63 for (i = 0; i < nr_pages; i++, virt += PAGE_SIZE) {
64 pg = vmalloc_to_page(virt);
65 if (NULL == pg)
66 goto err;
67 BUG_ON(PageHighMem(pg));
68 sglist[i].page = pg;
69 sglist[i].length = PAGE_SIZE;
70 }
71 return sglist;
72
73 err:
74 kfree(sglist);
75 return NULL;
76}
77
78struct scatterlist*
79videobuf_pages_to_sg(struct page **pages, int nr_pages, int offset)
80{
81 struct scatterlist *sglist;
82 int i = 0;
83
84 if (NULL == pages[0])
85 return NULL;
86 sglist = kcalloc(nr_pages, sizeof(*sglist), GFP_KERNEL);
87 if (NULL == sglist)
88 return NULL;
89
90 if (NULL == pages[0])
91 goto nopage;
92 if (PageHighMem(pages[0]))
93 /* DMA to highmem pages might not work */
94 goto highmem;
95 sglist[0].page = pages[0];
96 sglist[0].offset = offset;
97 sglist[0].length = PAGE_SIZE - offset;
98 for (i = 1; i < nr_pages; i++) {
99 if (NULL == pages[i])
100 goto nopage;
101 if (PageHighMem(pages[i]))
102 goto highmem;
103 sglist[i].page = pages[i];
104 sglist[i].length = PAGE_SIZE;
105 }
106 return sglist;
107
108 nopage:
109 dprintk(2,"sgl: oops - no page\n");
110 kfree(sglist);
111 return NULL;
112
113 highmem:
114 dprintk(2,"sgl: oops - highmem page\n");
115 kfree(sglist);
116 return NULL;
117}
118
119/* --------------------------------------------------------------------- */
120
121void videobuf_dma_init(struct videobuf_dmabuf *dma)
122{
123 memset(dma,0,sizeof(*dma));
124 dma->magic = MAGIC_DMABUF;
125}
126
127int videobuf_dma_init_user(struct videobuf_dmabuf *dma, int direction,
128 unsigned long data, unsigned long size)
129{
130 unsigned long first,last;
131 int err, rw = 0;
132
133 dma->direction = direction;
134 switch (dma->direction) {
135 case PCI_DMA_FROMDEVICE: rw = READ; break;
136 case PCI_DMA_TODEVICE: rw = WRITE; break;
137 default: BUG();
138 }
139
140 first = (data & PAGE_MASK) >> PAGE_SHIFT;
141 last = ((data+size-1) & PAGE_MASK) >> PAGE_SHIFT;
142 dma->offset = data & ~PAGE_MASK;
143 dma->nr_pages = last-first+1;
144 dma->pages = kmalloc(dma->nr_pages * sizeof(struct page*),
145 GFP_KERNEL);
146 if (NULL == dma->pages)
147 return -ENOMEM;
148 dprintk(1,"init user [0x%lx+0x%lx => %d pages]\n",
149 data,size,dma->nr_pages);
150
151 dma->varea = (void *) data;
152
153 down_read(&current->mm->mmap_sem);
154 err = get_user_pages(current,current->mm,
155 data & PAGE_MASK, dma->nr_pages,
156 rw == READ, 1, /* force */
157 dma->pages, NULL);
158 up_read(&current->mm->mmap_sem);
159 if (err != dma->nr_pages) {
160 dma->nr_pages = (err >= 0) ? err : 0;
161 dprintk(1,"get_user_pages: err=%d [%d]\n",err,dma->nr_pages);
162 return err < 0 ? err : -EINVAL;
163 }
164 return 0;
165}
166
167int videobuf_dma_init_kernel(struct videobuf_dmabuf *dma, int direction,
168 int nr_pages)
169{
170 dprintk(1,"init kernel [%d pages]\n",nr_pages);
171 dma->direction = direction;
172 dma->vmalloc = vmalloc_32(nr_pages << PAGE_SHIFT);
173 if (NULL == dma->vmalloc) {
174 dprintk(1,"vmalloc_32(%d pages) failed\n",nr_pages);
175 return -ENOMEM;
176 }
177 dprintk(1,"vmalloc is at addr 0x%08lx, size=%d\n",
178 (unsigned long)dma->vmalloc,
179 nr_pages << PAGE_SHIFT);
180 memset(dma->vmalloc,0,nr_pages << PAGE_SHIFT);
181 dma->nr_pages = nr_pages;
182 return 0;
183}
184
185int videobuf_dma_init_overlay(struct videobuf_dmabuf *dma, int direction,
186 dma_addr_t addr, int nr_pages)
187{
188 dprintk(1,"init overlay [%d pages @ bus 0x%lx]\n",
189 nr_pages,(unsigned long)addr);
190 dma->direction = direction;
191 if (0 == addr)
192 return -EINVAL;
193
194 dma->bus_addr = addr;
195 dma->nr_pages = nr_pages;
196 return 0;
197}
198
199int videobuf_dma_map(struct videobuf_queue* q,struct videobuf_dmabuf *dma)
200{
201 void *dev=q->dev;
202
203 MAGIC_CHECK(dma->magic,MAGIC_DMABUF);
204 BUG_ON(0 == dma->nr_pages);
205
206 if (dma->pages) {
207 dma->sglist = videobuf_pages_to_sg(dma->pages, dma->nr_pages,
208 dma->offset);
209 }
210 if (dma->vmalloc) {
211 dma->sglist = videobuf_vmalloc_to_sg
212 (dma->vmalloc,dma->nr_pages);
213 }
214 if (dma->bus_addr) {
215 dma->sglist = kmalloc(sizeof(struct scatterlist), GFP_KERNEL);
216 if (NULL != dma->sglist) {
217 dma->sglen = 1;
218 sg_dma_address(&dma->sglist[0]) = dma->bus_addr & PAGE_MASK;
219 dma->sglist[0].offset = dma->bus_addr & ~PAGE_MASK;
220 sg_dma_len(&dma->sglist[0]) = dma->nr_pages * PAGE_SIZE;
221 }
222 }
223 if (NULL == dma->sglist) {
224 dprintk(1,"scatterlist is NULL\n");
225 return -ENOMEM;
226 }
227 if (!dma->bus_addr) {
228 if (q->ops->vb_map_sg) {
229 dma->sglen = q->ops->vb_map_sg(dev,dma->sglist,
230 dma->nr_pages, dma->direction);
231 }
232 if (0 == dma->sglen) {
233 printk(KERN_WARNING
234 "%s: videobuf_map_sg failed\n",__FUNCTION__);
235 kfree(dma->sglist);
236 dma->sglist = NULL;
237 dma->sglen = 0;
238 return -EIO;
239 }
240 }
241 return 0;
242}
243
244int videobuf_dma_sync(struct videobuf_queue* q,struct videobuf_dmabuf *dma)
245{
246 void *dev=q->dev;
247
248 MAGIC_CHECK(dma->magic,MAGIC_DMABUF);
249 BUG_ON(!dma->sglen);
250
251 if (!dma->bus_addr && q->ops->vb_dma_sync_sg)
252 q->ops->vb_dma_sync_sg(dev,dma->sglist,dma->nr_pages,
253 dma->direction);
254
255 return 0;
256}
257
258int videobuf_dma_unmap(struct videobuf_queue* q,struct videobuf_dmabuf *dma)
259{
260 void *dev=q->dev;
261
262 MAGIC_CHECK(dma->magic,MAGIC_DMABUF);
263 if (!dma->sglen)
264 return 0;
265
266 if (!dma->bus_addr && q->ops->vb_unmap_sg)
267 q->ops->vb_unmap_sg(dev,dma->sglist,dma->nr_pages,
268 dma->direction);
269 kfree(dma->sglist);
270 dma->sglist = NULL;
271 dma->sglen = 0;
272 return 0;
273}
274
275int videobuf_dma_free(struct videobuf_dmabuf *dma)
276{
277 MAGIC_CHECK(dma->magic,MAGIC_DMABUF);
278 BUG_ON(dma->sglen);
279
280 if (dma->pages) {
281 int i;
282 for (i=0; i < dma->nr_pages; i++)
283 page_cache_release(dma->pages[i]);
284 kfree(dma->pages);
285 dma->pages = NULL;
286 }
287
288 vfree(dma->vmalloc);
289 dma->vmalloc = NULL;
290 dma->varea = NULL;
291
292 if (dma->bus_addr) {
293 dma->bus_addr = 0;
294 }
295 dma->direction = PCI_DMA_NONE;
296 return 0;
297}
298
299/* --------------------------------------------------------------------- */
300
301void* videobuf_alloc(unsigned int size)
302{
303 struct videobuf_buffer *vb;
304
305 vb = kzalloc(size,GFP_KERNEL);
306 if (NULL != vb) {
307 videobuf_dma_init(&vb->dma);
308 init_waitqueue_head(&vb->done);
309 vb->magic = MAGIC_BUFFER;
310 }
311 return vb;
312}
313
314int videobuf_waiton(struct videobuf_buffer *vb, int non_blocking, int intr)
315{
316 int retval = 0;
317 DECLARE_WAITQUEUE(wait, current);
318
319 MAGIC_CHECK(vb->magic,MAGIC_BUFFER);
320 add_wait_queue(&vb->done, &wait);
321 while (vb->state == STATE_ACTIVE || vb->state == STATE_QUEUED) {
322 if (non_blocking) {
323 retval = -EAGAIN;
324 break;
325 }
326 set_current_state(intr ? TASK_INTERRUPTIBLE
327 : TASK_UNINTERRUPTIBLE);
328 if (vb->state == STATE_ACTIVE || vb->state == STATE_QUEUED)
329 schedule();
330 set_current_state(TASK_RUNNING);
331 if (intr && signal_pending(current)) {
332 dprintk(1,"buffer waiton: -EINTR\n");
333 retval = -EINTR;
334 break;
335 }
336 }
337 remove_wait_queue(&vb->done, &wait);
338 return retval;
339}
340
341int
342videobuf_iolock(struct videobuf_queue* q, struct videobuf_buffer *vb,
343 struct v4l2_framebuffer *fbuf)
344{
345 int err,pages;
346 dma_addr_t bus;
347
348 MAGIC_CHECK(vb->magic,MAGIC_BUFFER);
349 switch (vb->memory) {
350 case V4L2_MEMORY_MMAP:
351 case V4L2_MEMORY_USERPTR:
352 if (0 == vb->baddr) {
353 /* no userspace addr -- kernel bounce buffer */
354 pages = PAGE_ALIGN(vb->size) >> PAGE_SHIFT;
355 err = videobuf_dma_init_kernel(&vb->dma,PCI_DMA_FROMDEVICE,
356 pages);
357 if (0 != err)
358 return err;
359 } else {
360 /* dma directly to userspace */
361 err = videobuf_dma_init_user(&vb->dma,PCI_DMA_FROMDEVICE,
362 vb->baddr,vb->bsize);
363 if (0 != err)
364 return err;
365 }
366 break;
367 case V4L2_MEMORY_OVERLAY:
368 if (NULL == fbuf)
369 return -EINVAL;
370 /* FIXME: need sanity checks for vb->boff */
371 /*
372 * Using a double cast to avoid compiler warnings when
373 * building for PAE. Compiler doesn't like direct casting
374 * of a 32 bit ptr to 64 bit integer.
375 */
376 bus = (dma_addr_t)(unsigned long)fbuf->base + vb->boff;
377 pages = PAGE_ALIGN(vb->size) >> PAGE_SHIFT;
378 err = videobuf_dma_init_overlay(&vb->dma,PCI_DMA_FROMDEVICE,
379 bus, pages);
380 if (0 != err)
381 return err;
382 break;
383 default:
384 BUG();
385 }
386 err = videobuf_dma_map(q,&vb->dma);
387 if (0 != err)
388 return err;
389
390 return 0;
391}
392
393/* --------------------------------------------------------------------- */
394
395void videobuf_queue_pci(struct videobuf_queue* q)
396{
397 /* If not specified, defaults to PCI map sg */
398 if (!q->ops->vb_map_sg)
399 q->ops->vb_map_sg=(vb_map_sg_t *)pci_map_sg;
400
401 if (!q->ops->vb_dma_sync_sg)
402 q->ops->vb_dma_sync_sg=(vb_map_sg_t *)pci_dma_sync_sg_for_cpu;
403 if (!q->ops->vb_unmap_sg)
404 q->ops->vb_unmap_sg=(vb_map_sg_t *)pci_unmap_sg;
405}
406
407int videobuf_pci_dma_map(struct pci_dev *pci,struct videobuf_dmabuf *dma)
408{
409 struct videobuf_queue q;
410 struct videobuf_queue_ops qops;
411
412 q.dev=pci;
413 qops.vb_map_sg=(vb_map_sg_t *)pci_map_sg;
414 qops.vb_unmap_sg=(vb_map_sg_t *)pci_unmap_sg;
415 q.ops = &qops;
416
417 return (videobuf_dma_map(&q,dma));
418}
419
420int videobuf_pci_dma_unmap(struct pci_dev *pci,struct videobuf_dmabuf *dma)
421{
422 struct videobuf_queue q;
423 struct videobuf_queue_ops qops;
424
425 q.dev=pci;
426 qops.vb_map_sg=(vb_map_sg_t *)pci_map_sg;
427 qops.vb_unmap_sg=(vb_map_sg_t *)pci_unmap_sg;
428 q.ops = &qops;
429
430 return (videobuf_dma_unmap(&q,dma));
431}
432
433void videobuf_queue_init(struct videobuf_queue* q,
434 struct videobuf_queue_ops *ops,
435 void *dev,
436 spinlock_t *irqlock,
437 enum v4l2_buf_type type,
438 enum v4l2_field field,
439 unsigned int msize,
440 void *priv)
441{
442 memset(q,0,sizeof(*q));
443 q->irqlock = irqlock;
444 q->dev = dev;
445 q->type = type;
446 q->field = field;
447 q->msize = msize;
448 q->ops = ops;
449 q->priv_data = priv;
450
451 videobuf_queue_pci(q);
452
453 mutex_init(&q->lock);
454 INIT_LIST_HEAD(&q->stream);
455}
456
457int
458videobuf_queue_is_busy(struct videobuf_queue *q)
459{
460 int i;
461
462 if (q->streaming) {
463 dprintk(1,"busy: streaming active\n");
464 return 1;
465 }
466 if (q->reading) {
467 dprintk(1,"busy: pending read #1\n");
468 return 1;
469 }
470 if (q->read_buf) {
471 dprintk(1,"busy: pending read #2\n");
472 return 1;
473 }
474 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
475 if (NULL == q->bufs[i])
476 continue;
477 if (q->bufs[i]->map) {
478 dprintk(1,"busy: buffer #%d mapped\n",i);
479 return 1;
480 }
481 if (q->bufs[i]->state == STATE_QUEUED) {
482 dprintk(1,"busy: buffer #%d queued\n",i);
483 return 1;
484 }
485 if (q->bufs[i]->state == STATE_ACTIVE) {
486 dprintk(1,"busy: buffer #%d avtive\n",i);
487 return 1;
488 }
489 }
490 return 0;
491}
492
493void
494videobuf_queue_cancel(struct videobuf_queue *q)
495{
496 unsigned long flags=0;
497 int i;
498
499 /* remove queued buffers from list */
500 if (q->irqlock)
501 spin_lock_irqsave(q->irqlock,flags);
502 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
503 if (NULL == q->bufs[i])
504 continue;
505 if (q->bufs[i]->state == STATE_QUEUED) {
506 list_del(&q->bufs[i]->queue);
507 q->bufs[i]->state = STATE_ERROR;
508 }
509 }
510 if (q->irqlock)
511 spin_unlock_irqrestore(q->irqlock,flags);
512
513 /* free all buffers + clear queue */
514 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
515 if (NULL == q->bufs[i])
516 continue;
517 q->ops->buf_release(q,q->bufs[i]);
518 }
519 INIT_LIST_HEAD(&q->stream);
520}
521
522/* --------------------------------------------------------------------- */
523
524enum v4l2_field
525videobuf_next_field(struct videobuf_queue *q)
526{
527 enum v4l2_field field = q->field;
528
529 BUG_ON(V4L2_FIELD_ANY == field);
530
531 if (V4L2_FIELD_ALTERNATE == field) {
532 if (V4L2_FIELD_TOP == q->last) {
533 field = V4L2_FIELD_BOTTOM;
534 q->last = V4L2_FIELD_BOTTOM;
535 } else {
536 field = V4L2_FIELD_TOP;
537 q->last = V4L2_FIELD_TOP;
538 }
539 }
540 return field;
541}
542
543void
544videobuf_status(struct v4l2_buffer *b, struct videobuf_buffer *vb,
545 enum v4l2_buf_type type)
546{
547 MAGIC_CHECK(vb->magic,MAGIC_BUFFER);
548
549 b->index = vb->i;
550 b->type = type;
551
552 b->memory = vb->memory;
553 switch (b->memory) {
554 case V4L2_MEMORY_MMAP:
555 b->m.offset = vb->boff;
556 b->length = vb->bsize;
557 break;
558 case V4L2_MEMORY_USERPTR:
559 b->m.userptr = vb->baddr;
560 b->length = vb->bsize;
561 break;
562 case V4L2_MEMORY_OVERLAY:
563 b->m.offset = vb->boff;
564 break;
565 }
566
567 b->flags = 0;
568 if (vb->map)
569 b->flags |= V4L2_BUF_FLAG_MAPPED;
570
571 switch (vb->state) {
572 case STATE_PREPARED:
573 case STATE_QUEUED:
574 case STATE_ACTIVE:
575 b->flags |= V4L2_BUF_FLAG_QUEUED;
576 break;
577 case STATE_DONE:
578 case STATE_ERROR:
579 b->flags |= V4L2_BUF_FLAG_DONE;
580 break;
581 case STATE_NEEDS_INIT:
582 case STATE_IDLE:
583 /* nothing */
584 break;
585 }
586
587 if (vb->input != UNSET) {
588 b->flags |= V4L2_BUF_FLAG_INPUT;
589 b->input = vb->input;
590 }
591
592 b->field = vb->field;
593 b->timestamp = vb->ts;
594 b->bytesused = vb->size;
595 b->sequence = vb->field_count >> 1;
596}
597
598int
599videobuf_reqbufs(struct videobuf_queue *q,
600 struct v4l2_requestbuffers *req)
601{
602 unsigned int size,count;
603 int retval;
604
605 if (req->type != q->type) {
606 dprintk(1,"reqbufs: queue type invalid\n");
607 return -EINVAL;
608 }
609 if (req->count < 1) {
610 dprintk(1,"reqbufs: count invalid (%d)\n",req->count);
611 return -EINVAL;
612 }
613 if (req->memory != V4L2_MEMORY_MMAP &&
614 req->memory != V4L2_MEMORY_USERPTR &&
615 req->memory != V4L2_MEMORY_OVERLAY) {
616 dprintk(1,"reqbufs: memory type invalid\n");
617 return -EINVAL;
618 }
619
620 if (q->streaming) {
621 dprintk(1,"reqbufs: streaming already exists\n");
622 return -EBUSY;
623 }
624 if (!list_empty(&q->stream)) {
625 dprintk(1,"reqbufs: stream running\n");
626 return -EBUSY;
627 }
628
629 mutex_lock(&q->lock);
630 count = req->count;
631 if (count > VIDEO_MAX_FRAME)
632 count = VIDEO_MAX_FRAME;
633 size = 0;
634 q->ops->buf_setup(q,&count,&size);
635 size = PAGE_ALIGN(size);
636 dprintk(1,"reqbufs: bufs=%d, size=0x%x [%d pages total]\n",
637 count, size, (count*size)>>PAGE_SHIFT);
638
639 retval = videobuf_mmap_setup(q,count,size,req->memory);
640 if (retval < 0) {
641 dprintk(1,"reqbufs: mmap setup returned %d\n",retval);
642 goto done;
643 }
644
645 req->count = count;
646
647 done:
648 mutex_unlock(&q->lock);
649 return retval;
650}
651
652int
653videobuf_querybuf(struct videobuf_queue *q, struct v4l2_buffer *b)
654{
655 if (unlikely(b->type != q->type)) {
656 dprintk(1,"querybuf: Wrong type.\n");
657 return -EINVAL;
658 }
659 if (unlikely(b->index < 0 || b->index >= VIDEO_MAX_FRAME)) {
660 dprintk(1,"querybuf: index out of range.\n");
661 return -EINVAL;
662 }
663 if (unlikely(NULL == q->bufs[b->index])) {
664 dprintk(1,"querybuf: buffer is null.\n");
665 return -EINVAL;
666 }
667 videobuf_status(b,q->bufs[b->index],q->type);
668 return 0;
669}
670
671int
672videobuf_qbuf(struct videobuf_queue *q,
673 struct v4l2_buffer *b)
674{
675 struct videobuf_buffer *buf;
676 enum v4l2_field field;
677 unsigned long flags=0;
678 int retval;
679
680 mutex_lock(&q->lock);
681 retval = -EBUSY;
682 if (q->reading) {
683 dprintk(1,"qbuf: Reading running...\n");
684 goto done;
685 }
686 retval = -EINVAL;
687 if (b->type != q->type) {
688 dprintk(1,"qbuf: Wrong type.\n");
689 goto done;
690 }
691 if (b->index < 0 || b->index >= VIDEO_MAX_FRAME) {
692 dprintk(1,"qbuf: index out of range.\n");
693 goto done;
694 }
695 buf = q->bufs[b->index];
696 if (NULL == buf) {
697 dprintk(1,"qbuf: buffer is null.\n");
698 goto done;
699 }
700 MAGIC_CHECK(buf->magic,MAGIC_BUFFER);
701 if (buf->memory != b->memory) {
702 dprintk(1,"qbuf: memory type is wrong.\n");
703 goto done;
704 }
705 if (buf->state != STATE_NEEDS_INIT && buf->state != STATE_IDLE) {
706 dprintk(1,"qbuf: buffer is already queued or active.\n");
707 goto done;
708 }
709
710 if (b->flags & V4L2_BUF_FLAG_INPUT) {
711 if (b->input >= q->inputs) {
712 dprintk(1,"qbuf: wrong input.\n");
713 goto done;
714 }
715 buf->input = b->input;
716 } else {
717 buf->input = UNSET;
718 }
719
720 switch (b->memory) {
721 case V4L2_MEMORY_MMAP:
722 if (0 == buf->baddr) {
723 dprintk(1,"qbuf: mmap requested but buffer addr is zero!\n");
724 goto done;
725 }
726 break;
727 case V4L2_MEMORY_USERPTR:
728 if (b->length < buf->bsize) {
729 dprintk(1,"qbuf: buffer length is not enough\n");
730 goto done;
731 }
732 if (STATE_NEEDS_INIT != buf->state && buf->baddr != b->m.userptr)
733 q->ops->buf_release(q,buf);
734 buf->baddr = b->m.userptr;
735 break;
736 case V4L2_MEMORY_OVERLAY:
737 buf->boff = b->m.offset;
738 break;
739 default:
740 dprintk(1,"qbuf: wrong memory type\n");
741 goto done;
742 }
743
744 dprintk(1,"qbuf: requesting next field\n");
745 field = videobuf_next_field(q);
746 retval = q->ops->buf_prepare(q,buf,field);
747 if (0 != retval) {
748 dprintk(1,"qbuf: buffer_prepare returned %d\n",retval);
749 goto done;
750 }
751
752 list_add_tail(&buf->stream,&q->stream);
753 if (q->streaming) {
754 if (q->irqlock)
755 spin_lock_irqsave(q->irqlock,flags);
756 q->ops->buf_queue(q,buf);
757 if (q->irqlock)
758 spin_unlock_irqrestore(q->irqlock,flags);
759 }
760 dprintk(1,"qbuf: succeded\n");
761 retval = 0;
762
763 done:
764 mutex_unlock(&q->lock);
765 return retval;
766}
767
768int
769videobuf_dqbuf(struct videobuf_queue *q,
770 struct v4l2_buffer *b, int nonblocking)
771{
772 struct videobuf_buffer *buf;
773 int retval;
774
775 mutex_lock(&q->lock);
776 retval = -EBUSY;
777 if (q->reading) {
778 dprintk(1,"dqbuf: Reading running...\n");
779 goto done;
780 }
781 retval = -EINVAL;
782 if (b->type != q->type) {
783 dprintk(1,"dqbuf: Wrong type.\n");
784 goto done;
785 }
786 if (list_empty(&q->stream)) {
787 dprintk(1,"dqbuf: stream running\n");
788 goto done;
789 }
790 buf = list_entry(q->stream.next, struct videobuf_buffer, stream);
791 retval = videobuf_waiton(buf, nonblocking, 1);
792 if (retval < 0) {
793 dprintk(1,"dqbuf: waiton returned %d\n",retval);
794 goto done;
795 }
796 switch (buf->state) {
797 case STATE_ERROR:
798 dprintk(1,"dqbuf: state is error\n");
799 retval = -EIO;
800 videobuf_dma_sync(q,&buf->dma);
801 buf->state = STATE_IDLE;
802 break;
803 case STATE_DONE:
804 dprintk(1,"dqbuf: state is done\n");
805 videobuf_dma_sync(q,&buf->dma);
806 buf->state = STATE_IDLE;
807 break;
808 default:
809 dprintk(1,"dqbuf: state invalid\n");
810 retval = -EINVAL;
811 goto done;
812 }
813 list_del(&buf->stream);
814 memset(b,0,sizeof(*b));
815 videobuf_status(b,buf,q->type);
816
817 done:
818 mutex_unlock(&q->lock);
819 return retval;
820}
821
822int videobuf_streamon(struct videobuf_queue *q)
823{
824 struct videobuf_buffer *buf;
825 struct list_head *list;
826 unsigned long flags=0;
827 int retval;
828
829 mutex_lock(&q->lock);
830 retval = -EBUSY;
831 if (q->reading)
832 goto done;
833 retval = 0;
834 if (q->streaming)
835 goto done;
836 q->streaming = 1;
837 if (q->irqlock)
838 spin_lock_irqsave(q->irqlock,flags);
839 list_for_each(list,&q->stream) {
840 buf = list_entry(list, struct videobuf_buffer, stream);
841 if (buf->state == STATE_PREPARED)
842 q->ops->buf_queue(q,buf);
843 }
844 if (q->irqlock)
845 spin_unlock_irqrestore(q->irqlock,flags);
846
847 done:
848 mutex_unlock(&q->lock);
849 return retval;
850}
851
852int videobuf_streamoff(struct videobuf_queue *q)
853{
854 int retval = -EINVAL;
855
856 mutex_lock(&q->lock);
857 if (!q->streaming)
858 goto done;
859 videobuf_queue_cancel(q);
860 q->streaming = 0;
861 retval = 0;
862
863 done:
864 mutex_unlock(&q->lock);
865 return retval;
866}
867
868static ssize_t
869videobuf_read_zerocopy(struct videobuf_queue *q, char __user *data,
870 size_t count, loff_t *ppos)
871{
872 enum v4l2_field field;
873 unsigned long flags=0;
874 int retval;
875
876 /* setup stuff */
877 q->read_buf = videobuf_alloc(q->msize);
878 if (NULL == q->read_buf)
879 return -ENOMEM;
880
881 q->read_buf->memory = V4L2_MEMORY_USERPTR;
882 q->read_buf->baddr = (unsigned long)data;
883 q->read_buf->bsize = count;
884 field = videobuf_next_field(q);
885 retval = q->ops->buf_prepare(q,q->read_buf,field);
886 if (0 != retval)
887 goto done;
888
889 /* start capture & wait */
890 if (q->irqlock)
891 spin_lock_irqsave(q->irqlock,flags);
892 q->ops->buf_queue(q,q->read_buf);
893 if (q->irqlock)
894 spin_unlock_irqrestore(q->irqlock,flags);
895 retval = videobuf_waiton(q->read_buf,0,0);
896 if (0 == retval) {
897 videobuf_dma_sync(q,&q->read_buf->dma);
898 if (STATE_ERROR == q->read_buf->state)
899 retval = -EIO;
900 else
901 retval = q->read_buf->size;
902 }
903
904 done:
905 /* cleanup */
906 q->ops->buf_release(q,q->read_buf);
907 kfree(q->read_buf);
908 q->read_buf = NULL;
909 return retval;
910}
911
912ssize_t videobuf_read_one(struct videobuf_queue *q,
913 char __user *data, size_t count, loff_t *ppos,
914 int nonblocking)
915{
916 enum v4l2_field field;
917 unsigned long flags=0;
918 unsigned size, nbufs, bytes;
919 int retval;
920
921 mutex_lock(&q->lock);
922
923 nbufs = 1; size = 0;
924 q->ops->buf_setup(q,&nbufs,&size);
925 if (NULL == q->read_buf &&
926 count >= size &&
927 !nonblocking) {
928 retval = videobuf_read_zerocopy(q,data,count,ppos);
929 if (retval >= 0 || retval == -EIO)
930 /* ok, all done */
931 goto done;
932 /* fallback to kernel bounce buffer on failures */
933 }
934
935 if (NULL == q->read_buf) {
936 /* need to capture a new frame */
937 retval = -ENOMEM;
938 q->read_buf = videobuf_alloc(q->msize);
939 dprintk(1,"video alloc=0x%p\n", q->read_buf);
940 if (NULL == q->read_buf)
941 goto done;
942 q->read_buf->memory = V4L2_MEMORY_USERPTR;
943 q->read_buf->bsize = count; /* preferred size */
944 field = videobuf_next_field(q);
945 retval = q->ops->buf_prepare(q,q->read_buf,field);
946 if (0 != retval) {
947 kfree (q->read_buf);
948 q->read_buf = NULL;
949 goto done;
950 }
951 if (q->irqlock)
952 spin_lock_irqsave(q->irqlock,flags);
953 q->ops->buf_queue(q,q->read_buf);
954 if (q->irqlock)
955 spin_unlock_irqrestore(q->irqlock,flags);
956 q->read_off = 0;
957 }
958
959 /* wait until capture is done */
960 retval = videobuf_waiton(q->read_buf, nonblocking, 1);
961 if (0 != retval)
962 goto done;
963 videobuf_dma_sync(q,&q->read_buf->dma);
964
965 if (STATE_ERROR == q->read_buf->state) {
966 /* catch I/O errors */
967 q->ops->buf_release(q,q->read_buf);
968 kfree(q->read_buf);
969 q->read_buf = NULL;
970 retval = -EIO;
971 goto done;
972 }
973
974 /* copy to userspace */
975 bytes = count;
976 if (bytes > q->read_buf->size - q->read_off)
977 bytes = q->read_buf->size - q->read_off;
978 retval = -EFAULT;
979 if (copy_to_user(data, q->read_buf->dma.vmalloc+q->read_off, bytes))
980 goto done;
981
982 retval = bytes;
983 q->read_off += bytes;
984 if (q->read_off == q->read_buf->size) {
985 /* all data copied, cleanup */
986 q->ops->buf_release(q,q->read_buf);
987 kfree(q->read_buf);
988 q->read_buf = NULL;
989 }
990
991 done:
992 mutex_unlock(&q->lock);
993 return retval;
994}
995
996int videobuf_read_start(struct videobuf_queue *q)
997{
998 enum v4l2_field field;
999 unsigned long flags=0;
1000 int count = 0, size = 0;
1001 int err, i;
1002
1003 q->ops->buf_setup(q,&count,&size);
1004 if (count < 2)
1005 count = 2;
1006 if (count > VIDEO_MAX_FRAME)
1007 count = VIDEO_MAX_FRAME;
1008 size = PAGE_ALIGN(size);
1009
1010 err = videobuf_mmap_setup(q, count, size, V4L2_MEMORY_USERPTR);
1011 if (err)
1012 return err;
1013 for (i = 0; i < count; i++) {
1014 field = videobuf_next_field(q);
1015 err = q->ops->buf_prepare(q,q->bufs[i],field);
1016 if (err)
1017 return err;
1018 list_add_tail(&q->bufs[i]->stream, &q->stream);
1019 }
1020 if (q->irqlock)
1021 spin_lock_irqsave(q->irqlock,flags);
1022 for (i = 0; i < count; i++)
1023 q->ops->buf_queue(q,q->bufs[i]);
1024 if (q->irqlock)
1025 spin_unlock_irqrestore(q->irqlock,flags);
1026 q->reading = 1;
1027 return 0;
1028}
1029
1030void videobuf_read_stop(struct videobuf_queue *q)
1031{
1032 int i;
1033
1034 videobuf_queue_cancel(q);
1035 videobuf_mmap_free(q);
1036 INIT_LIST_HEAD(&q->stream);
1037 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
1038 if (NULL == q->bufs[i])
1039 continue;
1040 kfree(q->bufs[i]);
1041 q->bufs[i] = NULL;
1042 }
1043 q->read_buf = NULL;
1044 q->reading = 0;
1045}
1046
1047ssize_t videobuf_read_stream(struct videobuf_queue *q,
1048 char __user *data, size_t count, loff_t *ppos,
1049 int vbihack, int nonblocking)
1050{
1051 unsigned int *fc, bytes;
1052 int err, retval;
1053 unsigned long flags=0;
1054
1055 dprintk(2,"%s\n",__FUNCTION__);
1056 mutex_lock(&q->lock);
1057 retval = -EBUSY;
1058 if (q->streaming)
1059 goto done;
1060 if (!q->reading) {
1061 retval = videobuf_read_start(q);
1062 if (retval < 0)
1063 goto done;
1064 }
1065
1066 retval = 0;
1067 while (count > 0) {
1068 /* get / wait for data */
1069 if (NULL == q->read_buf) {
1070 q->read_buf = list_entry(q->stream.next,
1071 struct videobuf_buffer,
1072 stream);
1073 list_del(&q->read_buf->stream);
1074 q->read_off = 0;
1075 }
1076 err = videobuf_waiton(q->read_buf, nonblocking, 1);
1077 if (err < 0) {
1078 if (0 == retval)
1079 retval = err;
1080 break;
1081 }
1082
1083 if (q->read_buf->state == STATE_DONE) {
1084 if (vbihack) {
1085 /* dirty, undocumented hack -- pass the frame counter
1086 * within the last four bytes of each vbi data block.
1087 * We need that one to maintain backward compatibility
1088 * to all vbi decoding software out there ... */
1089 fc = (unsigned int*)q->read_buf->dma.vmalloc;
1090 fc += (q->read_buf->size>>2) -1;
1091 *fc = q->read_buf->field_count >> 1;
1092 dprintk(1,"vbihack: %d\n",*fc);
1093 }
1094
1095 /* copy stuff */
1096 bytes = count;
1097 if (bytes > q->read_buf->size - q->read_off)
1098 bytes = q->read_buf->size - q->read_off;
1099 if (copy_to_user(data + retval,
1100 q->read_buf->dma.vmalloc + q->read_off,
1101 bytes)) {
1102 if (0 == retval)
1103 retval = -EFAULT;
1104 break;
1105 }
1106 count -= bytes;
1107 retval += bytes;
1108 q->read_off += bytes;
1109 } else {
1110 /* some error */
1111 q->read_off = q->read_buf->size;
1112 if (0 == retval)
1113 retval = -EIO;
1114 }
1115
1116 /* requeue buffer when done with copying */
1117 if (q->read_off == q->read_buf->size) {
1118 list_add_tail(&q->read_buf->stream,
1119 &q->stream);
1120 if (q->irqlock)
1121 spin_lock_irqsave(q->irqlock,flags);
1122 q->ops->buf_queue(q,q->read_buf);
1123 if (q->irqlock)
1124 spin_unlock_irqrestore(q->irqlock,flags);
1125 q->read_buf = NULL;
1126 }
1127 if (retval < 0)
1128 break;
1129 }
1130
1131 done:
1132 mutex_unlock(&q->lock);
1133 return retval;
1134}
1135
1136unsigned int videobuf_poll_stream(struct file *file,
1137 struct videobuf_queue *q,
1138 poll_table *wait)
1139{
1140 struct videobuf_buffer *buf = NULL;
1141 unsigned int rc = 0;
1142
1143 mutex_lock(&q->lock);
1144 if (q->streaming) {
1145 if (!list_empty(&q->stream))
1146 buf = list_entry(q->stream.next,
1147 struct videobuf_buffer, stream);
1148 } else {
1149 if (!q->reading)
1150 videobuf_read_start(q);
1151 if (!q->reading) {
1152 rc = POLLERR;
1153 } else if (NULL == q->read_buf) {
1154 q->read_buf = list_entry(q->stream.next,
1155 struct videobuf_buffer,
1156 stream);
1157 list_del(&q->read_buf->stream);
1158 q->read_off = 0;
1159 }
1160 buf = q->read_buf;
1161 }
1162 if (!buf)
1163 rc = POLLERR;
1164
1165 if (0 == rc) {
1166 poll_wait(file, &buf->done, wait);
1167 if (buf->state == STATE_DONE ||
1168 buf->state == STATE_ERROR)
1169 rc = POLLIN|POLLRDNORM;
1170 }
1171 mutex_unlock(&q->lock);
1172 return rc;
1173}
1174
1175/* --------------------------------------------------------------------- */
1176
1177static void
1178videobuf_vm_open(struct vm_area_struct *vma)
1179{
1180 struct videobuf_mapping *map = vma->vm_private_data;
1181
1182 dprintk(2,"vm_open %p [count=%d,vma=%08lx-%08lx]\n",map,
1183 map->count,vma->vm_start,vma->vm_end);
1184 map->count++;
1185}
1186
1187static void
1188videobuf_vm_close(struct vm_area_struct *vma)
1189{
1190 struct videobuf_mapping *map = vma->vm_private_data;
1191 struct videobuf_queue *q = map->q;
1192 int i;
1193
1194 dprintk(2,"vm_close %p [count=%d,vma=%08lx-%08lx]\n",map,
1195 map->count,vma->vm_start,vma->vm_end);
1196
1197 map->count--;
1198 if (0 == map->count) {
1199 dprintk(1,"munmap %p q=%p\n",map,q);
1200 mutex_lock(&q->lock);
1201 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
1202 if (NULL == q->bufs[i])
1203 continue;
1204 if (q->bufs[i])
1205 ;
1206 if (q->bufs[i]->map != map)
1207 continue;
1208 q->bufs[i]->map = NULL;
1209 q->bufs[i]->baddr = 0;
1210 q->ops->buf_release(q,q->bufs[i]);
1211 }
1212 mutex_unlock(&q->lock);
1213 kfree(map);
1214 }
1215 return;
1216}
1217
1218/*
1219 * Get a anonymous page for the mapping. Make sure we can DMA to that
1220 * memory location with 32bit PCI devices (i.e. don't use highmem for
1221 * now ...). Bounce buffers don't work very well for the data rates
1222 * video capture has.
1223 */
1224static struct page*
1225videobuf_vm_nopage(struct vm_area_struct *vma, unsigned long vaddr,
1226 int *type)
1227{
1228 struct page *page;
1229
1230 dprintk(3,"nopage: fault @ %08lx [vma %08lx-%08lx]\n",
1231 vaddr,vma->vm_start,vma->vm_end);
1232 if (vaddr > vma->vm_end)
1233 return NOPAGE_SIGBUS;
1234 page = alloc_page(GFP_USER | __GFP_DMA32);
1235 if (!page)
1236 return NOPAGE_OOM;
1237 clear_user_page(page_address(page), vaddr, page);
1238 if (type)
1239 *type = VM_FAULT_MINOR;
1240 return page;
1241}
1242
1243static struct vm_operations_struct videobuf_vm_ops =
1244{
1245 .open = videobuf_vm_open,
1246 .close = videobuf_vm_close,
1247 .nopage = videobuf_vm_nopage,
1248};
1249
1250int videobuf_mmap_setup(struct videobuf_queue *q,
1251 unsigned int bcount, unsigned int bsize,
1252 enum v4l2_memory memory)
1253{
1254 unsigned int i;
1255 int err;
1256
1257 err = videobuf_mmap_free(q);
1258 if (0 != err)
1259 return err;
1260
1261 for (i = 0; i < bcount; i++) {
1262 q->bufs[i] = videobuf_alloc(q->msize);
1263 q->bufs[i]->i = i;
1264 q->bufs[i]->input = UNSET;
1265 q->bufs[i]->memory = memory;
1266 q->bufs[i]->bsize = bsize;
1267 switch (memory) {
1268 case V4L2_MEMORY_MMAP:
1269 q->bufs[i]->boff = bsize * i;
1270 break;
1271 case V4L2_MEMORY_USERPTR:
1272 case V4L2_MEMORY_OVERLAY:
1273 /* nothing */
1274 break;
1275 }
1276 }
1277 dprintk(1,"mmap setup: %d buffers, %d bytes each\n",
1278 bcount,bsize);
1279 return 0;
1280}
1281
1282int videobuf_mmap_free(struct videobuf_queue *q)
1283{
1284 int i;
1285
1286 for (i = 0; i < VIDEO_MAX_FRAME; i++)
1287 if (q->bufs[i] && q->bufs[i]->map)
1288 return -EBUSY;
1289 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
1290 if (NULL == q->bufs[i])
1291 continue;
1292 q->ops->buf_release(q,q->bufs[i]);
1293 kfree(q->bufs[i]);
1294 q->bufs[i] = NULL;
1295 }
1296 return 0;
1297}
1298
1299int videobuf_mmap_mapper(struct videobuf_queue *q,
1300 struct vm_area_struct *vma)
1301{
1302 struct videobuf_mapping *map;
1303 unsigned int first,last,size,i;
1304 int retval;
1305
1306 mutex_lock(&q->lock);
1307 retval = -EINVAL;
1308 if (!(vma->vm_flags & VM_WRITE)) {
1309 dprintk(1,"mmap app bug: PROT_WRITE please\n");
1310 goto done;
1311 }
1312 if (!(vma->vm_flags & VM_SHARED)) {
1313 dprintk(1,"mmap app bug: MAP_SHARED please\n");
1314 goto done;
1315 }
1316
1317 /* look for first buffer to map */
1318 for (first = 0; first < VIDEO_MAX_FRAME; first++) {
1319 if (NULL == q->bufs[first])
1320 continue;
1321 if (V4L2_MEMORY_MMAP != q->bufs[first]->memory)
1322 continue;
1323 if (q->bufs[first]->boff == (vma->vm_pgoff << PAGE_SHIFT))
1324 break;
1325 }
1326 if (VIDEO_MAX_FRAME == first) {
1327 dprintk(1,"mmap app bug: offset invalid [offset=0x%lx]\n",
1328 (vma->vm_pgoff << PAGE_SHIFT));
1329 goto done;
1330 }
1331
1332 /* look for last buffer to map */
1333 for (size = 0, last = first; last < VIDEO_MAX_FRAME; last++) {
1334 if (NULL == q->bufs[last])
1335 continue;
1336 if (V4L2_MEMORY_MMAP != q->bufs[last]->memory)
1337 continue;
1338 if (q->bufs[last]->map) {
1339 retval = -EBUSY;
1340 goto done;
1341 }
1342 size += q->bufs[last]->bsize;
1343 if (size == (vma->vm_end - vma->vm_start))
1344 break;
1345 }
1346 if (VIDEO_MAX_FRAME == last) {
1347 dprintk(1,"mmap app bug: size invalid [size=0x%lx]\n",
1348 (vma->vm_end - vma->vm_start));
1349 goto done;
1350 }
1351
1352 /* create mapping + update buffer list */
1353 retval = -ENOMEM;
1354 map = kmalloc(sizeof(struct videobuf_mapping),GFP_KERNEL);
1355 if (NULL == map)
1356 goto done;
1357 for (size = 0, i = first; i <= last; size += q->bufs[i++]->bsize) {
1358 q->bufs[i]->map = map;
1359 q->bufs[i]->baddr = vma->vm_start + size;
1360 }
1361 map->count = 1;
1362 map->start = vma->vm_start;
1363 map->end = vma->vm_end;
1364 map->q = q;
1365 vma->vm_ops = &videobuf_vm_ops;
1366 vma->vm_flags |= VM_DONTEXPAND | VM_RESERVED;
1367 vma->vm_flags &= ~VM_IO; /* using shared anonymous pages */
1368 vma->vm_private_data = map;
1369 dprintk(1,"mmap %p: q=%p %08lx-%08lx pgoff %08lx bufs %d-%d\n",
1370 map,q,vma->vm_start,vma->vm_end,vma->vm_pgoff,first,last);
1371 retval = 0;
1372
1373 done:
1374 mutex_unlock(&q->lock);
1375 return retval;
1376}
1377
1378/* --------------------------------------------------------------------- */
1379
1380EXPORT_SYMBOL_GPL(videobuf_vmalloc_to_sg);
1381
1382EXPORT_SYMBOL_GPL(videobuf_dma_init);
1383EXPORT_SYMBOL_GPL(videobuf_dma_init_user);
1384EXPORT_SYMBOL_GPL(videobuf_dma_init_kernel);
1385EXPORT_SYMBOL_GPL(videobuf_dma_init_overlay);
1386EXPORT_SYMBOL_GPL(videobuf_dma_map);
1387EXPORT_SYMBOL_GPL(videobuf_dma_sync);
1388EXPORT_SYMBOL_GPL(videobuf_dma_unmap);
1389EXPORT_SYMBOL_GPL(videobuf_dma_free);
1390
1391EXPORT_SYMBOL_GPL(videobuf_pci_dma_map);
1392EXPORT_SYMBOL_GPL(videobuf_pci_dma_unmap);
1393
1394EXPORT_SYMBOL_GPL(videobuf_alloc);
1395EXPORT_SYMBOL_GPL(videobuf_waiton);
1396EXPORT_SYMBOL_GPL(videobuf_iolock);
1397
1398EXPORT_SYMBOL_GPL(videobuf_queue_init);
1399EXPORT_SYMBOL_GPL(videobuf_queue_cancel);
1400EXPORT_SYMBOL_GPL(videobuf_queue_is_busy);
1401
1402EXPORT_SYMBOL_GPL(videobuf_next_field);
1403EXPORT_SYMBOL_GPL(videobuf_status);
1404EXPORT_SYMBOL_GPL(videobuf_reqbufs);
1405EXPORT_SYMBOL_GPL(videobuf_querybuf);
1406EXPORT_SYMBOL_GPL(videobuf_qbuf);
1407EXPORT_SYMBOL_GPL(videobuf_dqbuf);
1408EXPORT_SYMBOL_GPL(videobuf_streamon);
1409EXPORT_SYMBOL_GPL(videobuf_streamoff);
1410
1411EXPORT_SYMBOL_GPL(videobuf_read_start);
1412EXPORT_SYMBOL_GPL(videobuf_read_stop);
1413EXPORT_SYMBOL_GPL(videobuf_read_stream);
1414EXPORT_SYMBOL_GPL(videobuf_read_one);
1415EXPORT_SYMBOL_GPL(videobuf_poll_stream);
1416
1417EXPORT_SYMBOL_GPL(videobuf_mmap_setup);
1418EXPORT_SYMBOL_GPL(videobuf_mmap_free);
1419EXPORT_SYMBOL_GPL(videobuf_mmap_mapper);
1420
1421/*
1422 * Local variables:
1423 * c-basic-offset: 8
1424 * End:
1425 */
diff --git a/drivers/media/video/videobuf-core.c b/drivers/media/video/videobuf-core.c
new file mode 100644
index 000000000000..c606332512b6
--- /dev/null
+++ b/drivers/media/video/videobuf-core.c
@@ -0,0 +1,1006 @@
1/*
2 * generic helper functions for handling video4linux capture buffers
3 *
4 * (c) 2007 Mauro Carvalho Chehab, <mchehab@infradead.org>
5 *
6 * Highly based on video-buf written originally by:
7 * (c) 2001,02 Gerd Knorr <kraxel@bytesex.org>
8 * (c) 2006 Mauro Carvalho Chehab, <mchehab@infradead.org>
9 * (c) 2006 Ted Walther and John Sokol
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2
14 */
15
16#include <linux/init.h>
17#include <linux/module.h>
18#include <linux/moduleparam.h>
19#include <linux/slab.h>
20#include <linux/interrupt.h>
21
22#include <media/videobuf-core.h>
23
24#define MAGIC_BUFFER 0x20070728
25#define MAGIC_CHECK(is,should) if (unlikely((is) != (should))) \
26 { printk(KERN_ERR "magic mismatch: %x (expected %x)\n",is,should); BUG(); }
27
28static int debug = 0;
29module_param(debug, int, 0644);
30
31MODULE_DESCRIPTION("helper module to manage video4linux buffers");
32MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
33MODULE_LICENSE("GPL");
34
35#define dprintk(level, fmt, arg...) if (debug >= level) \
36 printk(KERN_DEBUG "vbuf: " fmt , ## arg)
37
38/* --------------------------------------------------------------------- */
39
40#define CALL(q, f, arg...) \
41 ( (q->int_ops->f)? q->int_ops->f(arg) : 0)
42
43void* videobuf_alloc(struct videobuf_queue* q)
44{
45 struct videobuf_buffer *vb;
46
47 BUG_ON (q->msize<sizeof(*vb));
48
49 if (!q->int_ops || !q->int_ops->alloc) {
50 printk(KERN_ERR "No specific ops defined!\n");
51 BUG();
52 }
53
54 vb = q->int_ops->alloc(q->msize);
55
56 if (NULL != vb) {
57 init_waitqueue_head(&vb->done);
58 vb->magic = MAGIC_BUFFER;
59 }
60
61 return vb;
62}
63
64int videobuf_waiton(struct videobuf_buffer *vb, int non_blocking, int intr)
65{
66 int retval = 0;
67 DECLARE_WAITQUEUE(wait, current);
68
69 MAGIC_CHECK(vb->magic,MAGIC_BUFFER);
70 add_wait_queue(&vb->done, &wait);
71 while (vb->state == STATE_ACTIVE || vb->state == STATE_QUEUED) {
72 if (non_blocking) {
73 retval = -EAGAIN;
74 break;
75 }
76 set_current_state(intr ? TASK_INTERRUPTIBLE
77 : TASK_UNINTERRUPTIBLE);
78 if (vb->state == STATE_ACTIVE || vb->state == STATE_QUEUED)
79 schedule();
80 set_current_state(TASK_RUNNING);
81 if (intr && signal_pending(current)) {
82 dprintk(1,"buffer waiton: -EINTR\n");
83 retval = -EINTR;
84 break;
85 }
86 }
87 remove_wait_queue(&vb->done, &wait);
88 return retval;
89}
90
91int videobuf_iolock(struct videobuf_queue* q, struct videobuf_buffer *vb,
92 struct v4l2_framebuffer *fbuf)
93{
94 MAGIC_CHECK(vb->magic,MAGIC_BUFFER);
95 MAGIC_CHECK(q->int_ops->magic,MAGIC_QTYPE_OPS);
96
97 /* FIXME: This is required to avoid OOPS on some cases, since mmap_mapper()
98 method should be called before _iolock.
99 On some cases, the mmap_mapper() is called only after scheduling.
100
101 However, this way is just too dirty! Better to wait for some event.
102 */
103 schedule_timeout(HZ);
104
105 return CALL(q,iolock,q,vb,fbuf);
106}
107
108/* --------------------------------------------------------------------- */
109
110
111void videobuf_queue_core_init(struct videobuf_queue* q,
112 struct videobuf_queue_ops *ops,
113 void *dev,
114 spinlock_t *irqlock,
115 enum v4l2_buf_type type,
116 enum v4l2_field field,
117 unsigned int msize,
118 void *priv,
119 struct videobuf_qtype_ops *int_ops)
120{
121 memset(q,0,sizeof(*q));
122 q->irqlock = irqlock;
123 q->dev = dev;
124 q->type = type;
125 q->field = field;
126 q->msize = msize;
127 q->ops = ops;
128 q->priv_data = priv;
129 q->int_ops = int_ops;
130
131 /* All buffer operations are mandatory */
132 BUG_ON (!q->ops->buf_setup);
133 BUG_ON (!q->ops->buf_prepare);
134 BUG_ON (!q->ops->buf_queue);
135 BUG_ON (!q->ops->buf_release);
136
137 /* Having implementations for abstract methods are mandatory */
138 BUG_ON (!q->int_ops);
139
140 mutex_init(&q->lock);
141 INIT_LIST_HEAD(&q->stream);
142}
143
144int videobuf_queue_is_busy(struct videobuf_queue *q)
145{
146 int i;
147
148 MAGIC_CHECK(q->int_ops->magic,MAGIC_QTYPE_OPS);
149
150 if (q->streaming) {
151 dprintk(1,"busy: streaming active\n");
152 return 1;
153 }
154 if (q->reading) {
155 dprintk(1,"busy: pending read #1\n");
156 return 1;
157 }
158 if (q->read_buf) {
159 dprintk(1,"busy: pending read #2\n");
160 return 1;
161 }
162 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
163 if (NULL == q->bufs[i])
164 continue;
165 if (q->bufs[i]->map) {
166 dprintk(1,"busy: buffer #%d mapped\n",i);
167 return 1;
168 }
169 if (q->bufs[i]->state == STATE_QUEUED) {
170 dprintk(1,"busy: buffer #%d queued\n",i);
171 return 1;
172 }
173 if (q->bufs[i]->state == STATE_ACTIVE) {
174 dprintk(1,"busy: buffer #%d avtive\n",i);
175 return 1;
176 }
177 }
178 return 0;
179}
180
181void videobuf_queue_cancel(struct videobuf_queue *q)
182{
183 unsigned long flags=0;
184 int i;
185
186 /* remove queued buffers from list */
187 if (q->irqlock)
188 spin_lock_irqsave(q->irqlock,flags);
189 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
190 if (NULL == q->bufs[i])
191 continue;
192 if (q->bufs[i]->state == STATE_QUEUED) {
193 list_del(&q->bufs[i]->queue);
194 q->bufs[i]->state = STATE_ERROR;
195 }
196 }
197 if (q->irqlock)
198 spin_unlock_irqrestore(q->irqlock,flags);
199
200 /* free all buffers + clear queue */
201 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
202 if (NULL == q->bufs[i])
203 continue;
204 q->ops->buf_release(q,q->bufs[i]);
205 }
206 INIT_LIST_HEAD(&q->stream);
207}
208
209/* --------------------------------------------------------------------- */
210
211enum v4l2_field videobuf_next_field(struct videobuf_queue *q)
212{
213 enum v4l2_field field = q->field;
214
215 BUG_ON(V4L2_FIELD_ANY == field);
216
217 if (V4L2_FIELD_ALTERNATE == field) {
218 if (V4L2_FIELD_TOP == q->last) {
219 field = V4L2_FIELD_BOTTOM;
220 q->last = V4L2_FIELD_BOTTOM;
221 } else {
222 field = V4L2_FIELD_TOP;
223 q->last = V4L2_FIELD_TOP;
224 }
225 }
226 return field;
227}
228
229static void videobuf_status(struct videobuf_queue *q, struct v4l2_buffer *b,
230 struct videobuf_buffer *vb, enum v4l2_buf_type type)
231{
232 MAGIC_CHECK(vb->magic,MAGIC_BUFFER);
233 MAGIC_CHECK(q->int_ops->magic,MAGIC_QTYPE_OPS);
234
235 b->index = vb->i;
236 b->type = type;
237
238 b->memory = vb->memory;
239 switch (b->memory) {
240 case V4L2_MEMORY_MMAP:
241 b->m.offset = vb->boff;
242 b->length = vb->bsize;
243 break;
244 case V4L2_MEMORY_USERPTR:
245 b->m.userptr = vb->baddr;
246 b->length = vb->bsize;
247 break;
248 case V4L2_MEMORY_OVERLAY:
249 b->m.offset = vb->boff;
250 break;
251 }
252
253 b->flags = 0;
254 if (vb->map)
255 b->flags |= V4L2_BUF_FLAG_MAPPED;
256
257 switch (vb->state) {
258 case STATE_PREPARED:
259 case STATE_QUEUED:
260 case STATE_ACTIVE:
261 b->flags |= V4L2_BUF_FLAG_QUEUED;
262 break;
263 case STATE_DONE:
264 case STATE_ERROR:
265 b->flags |= V4L2_BUF_FLAG_DONE;
266 break;
267 case STATE_NEEDS_INIT:
268 case STATE_IDLE:
269 /* nothing */
270 break;
271 }
272
273 if (vb->input != UNSET) {
274 b->flags |= V4L2_BUF_FLAG_INPUT;
275 b->input = vb->input;
276 }
277
278 b->field = vb->field;
279 b->timestamp = vb->ts;
280 b->bytesused = vb->size;
281 b->sequence = vb->field_count >> 1;
282}
283
284int videobuf_reqbufs(struct videobuf_queue *q,
285 struct v4l2_requestbuffers *req)
286{
287 unsigned int size,count;
288 int retval;
289
290 if (req->type != q->type) {
291 dprintk(1,"reqbufs: queue type invalid\n");
292 return -EINVAL;
293 }
294 if (req->count < 1) {
295 dprintk(1,"reqbufs: count invalid (%d)\n",req->count);
296 return -EINVAL;
297 }
298 if (req->memory != V4L2_MEMORY_MMAP &&
299 req->memory != V4L2_MEMORY_USERPTR &&
300 req->memory != V4L2_MEMORY_OVERLAY) {
301 dprintk(1,"reqbufs: memory type invalid\n");
302 return -EINVAL;
303 }
304
305 mutex_lock(&q->lock);
306 if (q->streaming) {
307 dprintk(1,"reqbufs: streaming already exists\n");
308 retval = -EBUSY;
309 goto done;
310 }
311 if (!list_empty(&q->stream)) {
312 dprintk(1,"reqbufs: stream running\n");
313 retval = -EBUSY;
314 goto done;
315 }
316
317 count = req->count;
318 if (count > VIDEO_MAX_FRAME)
319 count = VIDEO_MAX_FRAME;
320 size = 0;
321 q->ops->buf_setup(q,&count,&size);
322 size = PAGE_ALIGN(size);
323 dprintk(1,"reqbufs: bufs=%d, size=0x%x [%d pages total]\n",
324 count, size, (count*size)>>PAGE_SHIFT);
325
326 retval = videobuf_mmap_setup(q,count,size,req->memory);
327 if (retval < 0) {
328 dprintk(1,"reqbufs: mmap setup returned %d\n",retval);
329 goto done;
330 }
331
332 req->count = retval;
333
334 done:
335 mutex_unlock(&q->lock);
336 return retval;
337}
338
339int videobuf_querybuf(struct videobuf_queue *q, struct v4l2_buffer *b)
340{
341 if (unlikely(b->type != q->type)) {
342 dprintk(1,"querybuf: Wrong type.\n");
343 return -EINVAL;
344 }
345 if (unlikely(b->index < 0 || b->index >= VIDEO_MAX_FRAME)) {
346 dprintk(1,"querybuf: index out of range.\n");
347 return -EINVAL;
348 }
349 if (unlikely(NULL == q->bufs[b->index])) {
350 dprintk(1,"querybuf: buffer is null.\n");
351 return -EINVAL;
352 }
353 videobuf_status(q,b,q->bufs[b->index],q->type);
354 return 0;
355}
356
357int videobuf_qbuf(struct videobuf_queue *q,
358 struct v4l2_buffer *b)
359{
360 struct videobuf_buffer *buf;
361 enum v4l2_field field;
362 unsigned long flags=0;
363 int retval;
364
365 MAGIC_CHECK(q->int_ops->magic,MAGIC_QTYPE_OPS);
366
367 if (b->memory == V4L2_MEMORY_MMAP)
368 down_read(&current->mm->mmap_sem);
369
370 mutex_lock(&q->lock);
371 retval = -EBUSY;
372 if (q->reading) {
373 dprintk(1,"qbuf: Reading running...\n");
374 goto done;
375 }
376 retval = -EINVAL;
377 if (b->type != q->type) {
378 dprintk(1,"qbuf: Wrong type.\n");
379 goto done;
380 }
381 if (b->index < 0 || b->index >= VIDEO_MAX_FRAME) {
382 dprintk(1,"qbuf: index out of range.\n");
383 goto done;
384 }
385 buf = q->bufs[b->index];
386 if (NULL == buf) {
387 dprintk(1,"qbuf: buffer is null.\n");
388 goto done;
389 }
390 MAGIC_CHECK(buf->magic,MAGIC_BUFFER);
391 if (buf->memory != b->memory) {
392 dprintk(1,"qbuf: memory type is wrong.\n");
393 goto done;
394 }
395 if (buf->state != STATE_NEEDS_INIT && buf->state != STATE_IDLE) {
396 dprintk(1,"qbuf: buffer is already queued or active.\n");
397 goto done;
398 }
399
400 if (b->flags & V4L2_BUF_FLAG_INPUT) {
401 if (b->input >= q->inputs) {
402 dprintk(1,"qbuf: wrong input.\n");
403 goto done;
404 }
405 buf->input = b->input;
406 } else {
407 buf->input = UNSET;
408 }
409
410 switch (b->memory) {
411 case V4L2_MEMORY_MMAP:
412 if (0 == buf->baddr) {
413 dprintk(1,"qbuf: mmap requested but buffer addr is zero!\n");
414 goto done;
415 }
416 break;
417 case V4L2_MEMORY_USERPTR:
418 if (b->length < buf->bsize) {
419 dprintk(1,"qbuf: buffer length is not enough\n");
420 goto done;
421 }
422 if (STATE_NEEDS_INIT != buf->state && buf->baddr != b->m.userptr)
423 q->ops->buf_release(q,buf);
424 buf->baddr = b->m.userptr;
425 break;
426 case V4L2_MEMORY_OVERLAY:
427 buf->boff = b->m.offset;
428 break;
429 default:
430 dprintk(1,"qbuf: wrong memory type\n");
431 goto done;
432 }
433
434 dprintk(1,"qbuf: requesting next field\n");
435 field = videobuf_next_field(q);
436 retval = q->ops->buf_prepare(q,buf,field);
437 if (0 != retval) {
438 dprintk(1,"qbuf: buffer_prepare returned %d\n",retval);
439 goto done;
440 }
441
442 list_add_tail(&buf->stream,&q->stream);
443 if (q->streaming) {
444 if (q->irqlock)
445 spin_lock_irqsave(q->irqlock,flags);
446 q->ops->buf_queue(q,buf);
447 if (q->irqlock)
448 spin_unlock_irqrestore(q->irqlock,flags);
449 }
450 dprintk(1,"qbuf: succeded\n");
451 retval = 0;
452
453 done:
454 mutex_unlock(&q->lock);
455
456 if (b->memory == V4L2_MEMORY_MMAP)
457 up_read(&current->mm->mmap_sem);
458
459 return retval;
460}
461
462int videobuf_dqbuf(struct videobuf_queue *q,
463 struct v4l2_buffer *b, int nonblocking)
464{
465 struct videobuf_buffer *buf;
466 int retval;
467
468 MAGIC_CHECK(q->int_ops->magic,MAGIC_QTYPE_OPS);
469
470 mutex_lock(&q->lock);
471 retval = -EBUSY;
472 if (q->reading) {
473 dprintk(1,"dqbuf: Reading running...\n");
474 goto done;
475 }
476 retval = -EINVAL;
477 if (b->type != q->type) {
478 dprintk(1,"dqbuf: Wrong type.\n");
479 goto done;
480 }
481 if (list_empty(&q->stream)) {
482 dprintk(1,"dqbuf: stream running\n");
483 goto done;
484 }
485 buf = list_entry(q->stream.next, struct videobuf_buffer, stream);
486 retval = videobuf_waiton(buf, nonblocking, 1);
487 if (retval < 0) {
488 dprintk(1,"dqbuf: waiton returned %d\n",retval);
489 goto done;
490 }
491 switch (buf->state) {
492 case STATE_ERROR:
493 dprintk(1,"dqbuf: state is error\n");
494 retval = -EIO;
495 CALL(q,sync,q, buf);
496 buf->state = STATE_IDLE;
497 break;
498 case STATE_DONE:
499 dprintk(1,"dqbuf: state is done\n");
500 CALL(q,sync,q, buf);
501 buf->state = STATE_IDLE;
502 break;
503 default:
504 dprintk(1,"dqbuf: state invalid\n");
505 retval = -EINVAL;
506 goto done;
507 }
508 list_del(&buf->stream);
509 memset(b,0,sizeof(*b));
510 videobuf_status(q,b,buf,q->type);
511
512 done:
513 mutex_unlock(&q->lock);
514 return retval;
515}
516
517int videobuf_streamon(struct videobuf_queue *q)
518{
519 struct videobuf_buffer *buf;
520 unsigned long flags=0;
521 int retval;
522
523 mutex_lock(&q->lock);
524 retval = -EBUSY;
525 if (q->reading)
526 goto done;
527 retval = 0;
528 if (q->streaming)
529 goto done;
530 q->streaming = 1;
531 if (q->irqlock)
532 spin_lock_irqsave(q->irqlock,flags);
533 list_for_each_entry(buf, &q->stream, stream)
534 if (buf->state == STATE_PREPARED)
535 q->ops->buf_queue(q,buf);
536 if (q->irqlock)
537 spin_unlock_irqrestore(q->irqlock,flags);
538
539 done:
540 mutex_unlock(&q->lock);
541 return retval;
542}
543
544int videobuf_streamoff(struct videobuf_queue *q)
545{
546 int retval = -EINVAL;
547
548 mutex_lock(&q->lock);
549 if (!q->streaming)
550 goto done;
551 videobuf_queue_cancel(q);
552 q->streaming = 0;
553 retval = 0;
554
555 done:
556 mutex_unlock(&q->lock);
557 return retval;
558}
559
560static ssize_t videobuf_read_zerocopy(struct videobuf_queue *q,
561 char __user *data,
562 size_t count, loff_t *ppos)
563{
564 enum v4l2_field field;
565 unsigned long flags=0;
566 int retval;
567
568 MAGIC_CHECK(q->int_ops->magic,MAGIC_QTYPE_OPS);
569
570 /* setup stuff */
571 q->read_buf = videobuf_alloc(q);
572 if (NULL == q->read_buf)
573 return -ENOMEM;
574
575 q->read_buf->memory = V4L2_MEMORY_USERPTR;
576 q->read_buf->baddr = (unsigned long)data;
577 q->read_buf->bsize = count;
578
579 field = videobuf_next_field(q);
580 retval = q->ops->buf_prepare(q,q->read_buf,field);
581 if (0 != retval)
582 goto done;
583
584 /* start capture & wait */
585 if (q->irqlock)
586 spin_lock_irqsave(q->irqlock,flags);
587 q->ops->buf_queue(q,q->read_buf);
588 if (q->irqlock)
589 spin_unlock_irqrestore(q->irqlock,flags);
590 retval = videobuf_waiton(q->read_buf,0,0);
591 if (0 == retval) {
592 CALL(q,sync,q,q->read_buf);
593 if (STATE_ERROR == q->read_buf->state)
594 retval = -EIO;
595 else
596 retval = q->read_buf->size;
597 }
598
599 done:
600 /* cleanup */
601 q->ops->buf_release(q,q->read_buf);
602 kfree(q->read_buf);
603 q->read_buf = NULL;
604 return retval;
605}
606
607ssize_t videobuf_read_one(struct videobuf_queue *q,
608 char __user *data, size_t count, loff_t *ppos,
609 int nonblocking)
610{
611 enum v4l2_field field;
612 unsigned long flags=0;
613 unsigned size, nbufs;
614 int retval;
615
616 MAGIC_CHECK(q->int_ops->magic,MAGIC_QTYPE_OPS);
617
618 mutex_lock(&q->lock);
619
620 nbufs = 1; size = 0;
621 q->ops->buf_setup(q,&nbufs,&size);
622
623 if (NULL == q->read_buf &&
624 count >= size &&
625 !nonblocking) {
626 retval = videobuf_read_zerocopy(q,data,count,ppos);
627 if (retval >= 0 || retval == -EIO)
628 /* ok, all done */
629 goto done;
630 /* fallback to kernel bounce buffer on failures */
631 }
632
633 if (NULL == q->read_buf) {
634 /* need to capture a new frame */
635 retval = -ENOMEM;
636 q->read_buf = videobuf_alloc(q);
637
638 dprintk(1,"video alloc=0x%p\n", q->read_buf);
639 if (NULL == q->read_buf)
640 goto done;
641 q->read_buf->memory = V4L2_MEMORY_USERPTR;
642 q->read_buf->bsize = count; /* preferred size */
643 field = videobuf_next_field(q);
644 retval = q->ops->buf_prepare(q,q->read_buf,field);
645
646 if (0 != retval) {
647 kfree (q->read_buf);
648 q->read_buf = NULL;
649 goto done;
650 }
651 if (q->irqlock)
652 spin_lock_irqsave(q->irqlock,flags);
653
654 q->ops->buf_queue(q,q->read_buf);
655 if (q->irqlock)
656 spin_unlock_irqrestore(q->irqlock,flags);
657 q->read_off = 0;
658 }
659
660 /* wait until capture is done */
661 retval = videobuf_waiton(q->read_buf, nonblocking, 1);
662 if (0 != retval)
663 goto done;
664
665 CALL(q,sync,q,q->read_buf);
666
667 if (STATE_ERROR == q->read_buf->state) {
668 /* catch I/O errors */
669 q->ops->buf_release(q,q->read_buf);
670 kfree(q->read_buf);
671 q->read_buf = NULL;
672 retval = -EIO;
673 goto done;
674 }
675
676 /* Copy to userspace */
677 retval=CALL(q,copy_to_user,q,data,count,nonblocking);
678 if (retval<0)
679 goto done;
680
681 q->read_off += retval;
682 if (q->read_off == q->read_buf->size) {
683 /* all data copied, cleanup */
684 q->ops->buf_release(q,q->read_buf);
685 kfree(q->read_buf);
686 q->read_buf = NULL;
687 }
688
689 done:
690 mutex_unlock(&q->lock);
691 return retval;
692}
693
694int videobuf_read_start(struct videobuf_queue *q)
695{
696 enum v4l2_field field;
697 unsigned long flags=0;
698 unsigned int count = 0, size = 0;
699 int err, i;
700
701 q->ops->buf_setup(q,&count,&size);
702 if (count < 2)
703 count = 2;
704 if (count > VIDEO_MAX_FRAME)
705 count = VIDEO_MAX_FRAME;
706 size = PAGE_ALIGN(size);
707
708 err = videobuf_mmap_setup(q, count, size, V4L2_MEMORY_USERPTR);
709 if (err < 0)
710 return err;
711
712 count = err;
713
714 for (i = 0; i < count; i++) {
715 field = videobuf_next_field(q);
716 err = q->ops->buf_prepare(q,q->bufs[i],field);
717 if (err)
718 return err;
719 list_add_tail(&q->bufs[i]->stream, &q->stream);
720 }
721 if (q->irqlock)
722 spin_lock_irqsave(q->irqlock,flags);
723 for (i = 0; i < count; i++)
724 q->ops->buf_queue(q,q->bufs[i]);
725 if (q->irqlock)
726 spin_unlock_irqrestore(q->irqlock,flags);
727 q->reading = 1;
728 return 0;
729}
730
731void videobuf_read_stop(struct videobuf_queue *q)
732{
733 int i;
734
735 videobuf_queue_cancel(q);
736 videobuf_mmap_free(q);
737 INIT_LIST_HEAD(&q->stream);
738 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
739 if (NULL == q->bufs[i])
740 continue;
741 kfree(q->bufs[i]);
742 q->bufs[i] = NULL;
743 }
744 q->read_buf = NULL;
745 q->reading = 0;
746}
747
748ssize_t videobuf_read_stream(struct videobuf_queue *q,
749 char __user *data, size_t count, loff_t *ppos,
750 int vbihack, int nonblocking)
751{
752 int rc, retval;
753 unsigned long flags=0;
754
755 MAGIC_CHECK(q->int_ops->magic,MAGIC_QTYPE_OPS);
756
757 dprintk(2,"%s\n",__FUNCTION__);
758 mutex_lock(&q->lock);
759 retval = -EBUSY;
760 if (q->streaming)
761 goto done;
762 if (!q->reading) {
763 retval = videobuf_read_start(q);
764 if (retval < 0)
765 goto done;
766 }
767
768 retval = 0;
769 while (count > 0) {
770 /* get / wait for data */
771 if (NULL == q->read_buf) {
772 q->read_buf = list_entry(q->stream.next,
773 struct videobuf_buffer,
774 stream);
775 list_del(&q->read_buf->stream);
776 q->read_off = 0;
777 }
778 rc = videobuf_waiton(q->read_buf, nonblocking, 1);
779 if (rc < 0) {
780 if (0 == retval)
781 retval = rc;
782 break;
783 }
784
785 if (q->read_buf->state == STATE_DONE) {
786 rc = CALL (q,copy_stream, q, data + retval, count,
787 retval, vbihack, nonblocking);
788 if (rc < 0) {
789 retval = rc;
790 break;
791 }
792 retval += rc;
793 count -= rc;
794 q->read_off += rc;
795 } else {
796 /* some error */
797 q->read_off = q->read_buf->size;
798 if (0 == retval)
799 retval = -EIO;
800 }
801
802 /* requeue buffer when done with copying */
803 if (q->read_off == q->read_buf->size) {
804 list_add_tail(&q->read_buf->stream,
805 &q->stream);
806 if (q->irqlock)
807 spin_lock_irqsave(q->irqlock,flags);
808 q->ops->buf_queue(q,q->read_buf);
809 if (q->irqlock)
810 spin_unlock_irqrestore(q->irqlock,flags);
811 q->read_buf = NULL;
812 }
813 if (retval < 0)
814 break;
815 }
816
817 done:
818 mutex_unlock(&q->lock);
819 return retval;
820}
821
822unsigned int videobuf_poll_stream(struct file *file,
823 struct videobuf_queue *q,
824 poll_table *wait)
825{
826 struct videobuf_buffer *buf = NULL;
827 unsigned int rc = 0;
828
829 mutex_lock(&q->lock);
830 if (q->streaming) {
831 if (!list_empty(&q->stream))
832 buf = list_entry(q->stream.next,
833 struct videobuf_buffer, stream);
834 } else {
835 if (!q->reading)
836 videobuf_read_start(q);
837 if (!q->reading) {
838 rc = POLLERR;
839 } else if (NULL == q->read_buf) {
840 q->read_buf = list_entry(q->stream.next,
841 struct videobuf_buffer,
842 stream);
843 list_del(&q->read_buf->stream);
844 q->read_off = 0;
845 }
846 buf = q->read_buf;
847 }
848 if (!buf)
849 rc = POLLERR;
850
851 if (0 == rc) {
852 poll_wait(file, &buf->done, wait);
853 if (buf->state == STATE_DONE ||
854 buf->state == STATE_ERROR)
855 rc = POLLIN|POLLRDNORM;
856 }
857 mutex_unlock(&q->lock);
858 return rc;
859}
860
861int videobuf_mmap_setup(struct videobuf_queue *q,
862 unsigned int bcount, unsigned int bsize,
863 enum v4l2_memory memory)
864{
865 unsigned int i;
866 int err;
867
868 MAGIC_CHECK(q->int_ops->magic,MAGIC_QTYPE_OPS);
869
870 err = videobuf_mmap_free(q);
871 if (0 != err)
872 return err;
873
874 /* Allocate and initialize buffers */
875 for (i = 0; i < bcount; i++) {
876 q->bufs[i] = videobuf_alloc(q);
877
878 if (q->bufs[i] == NULL)
879 break;
880
881 q->bufs[i]->i = i;
882 q->bufs[i]->input = UNSET;
883 q->bufs[i]->memory = memory;
884 q->bufs[i]->bsize = bsize;
885 switch (memory) {
886 case V4L2_MEMORY_MMAP:
887 q->bufs[i]->boff = bsize * i;
888 break;
889 case V4L2_MEMORY_USERPTR:
890 case V4L2_MEMORY_OVERLAY:
891 /* nothing */
892 break;
893 }
894 }
895
896 if (!i)
897 return -ENOMEM;
898
899 dprintk(1,"mmap setup: %d buffers, %d bytes each\n",
900 i, bsize);
901
902 return i;
903}
904
905int videobuf_mmap_free(struct videobuf_queue *q)
906{
907 int i;
908 int rc;
909
910 if (!q)
911 return 0;
912
913 MAGIC_CHECK(q->int_ops->magic,MAGIC_QTYPE_OPS);
914
915 rc = CALL(q,mmap_free,q);
916 if (rc<0)
917 return rc;
918
919 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
920 if (NULL == q->bufs[i])
921 continue;
922 q->ops->buf_release(q,q->bufs[i]);
923 kfree(q->bufs[i]);
924 q->bufs[i] = NULL;
925 }
926
927 return rc;
928}
929
930int videobuf_mmap_mapper(struct videobuf_queue *q,
931 struct vm_area_struct *vma)
932{
933 int retval;
934
935 MAGIC_CHECK(q->int_ops->magic,MAGIC_QTYPE_OPS);
936
937 mutex_lock(&q->lock);
938 retval=CALL(q,mmap_mapper,q,vma);
939 mutex_unlock(&q->lock);
940
941 return retval;
942}
943
944#ifdef CONFIG_VIDEO_V4L1_COMPAT
945int videobuf_cgmbuf(struct videobuf_queue *q,
946 struct video_mbuf *mbuf, int count)
947{
948 struct v4l2_requestbuffers req;
949 int rc,i;
950
951 MAGIC_CHECK(q->int_ops->magic,MAGIC_QTYPE_OPS);
952
953 memset(&req,0,sizeof(req));
954 req.type = q->type;
955 req.count = count;
956 req.memory = V4L2_MEMORY_MMAP;
957 rc = videobuf_reqbufs(q,&req);
958 if (rc < 0)
959 return rc;
960
961 mbuf->frames = req.count;
962 mbuf->size = 0;
963 for (i = 0; i < mbuf->frames; i++) {
964 mbuf->offsets[i] = q->bufs[i]->boff;
965 mbuf->size += q->bufs[i]->bsize;
966 }
967
968 return 0;
969}
970#endif
971
972/* --------------------------------------------------------------------- */
973
974EXPORT_SYMBOL_GPL(videobuf_waiton);
975EXPORT_SYMBOL_GPL(videobuf_iolock);
976
977EXPORT_SYMBOL_GPL(videobuf_alloc);
978
979EXPORT_SYMBOL_GPL(videobuf_queue_core_init);
980EXPORT_SYMBOL_GPL(videobuf_queue_cancel);
981EXPORT_SYMBOL_GPL(videobuf_queue_is_busy);
982
983EXPORT_SYMBOL_GPL(videobuf_next_field);
984EXPORT_SYMBOL_GPL(videobuf_reqbufs);
985EXPORT_SYMBOL_GPL(videobuf_querybuf);
986EXPORT_SYMBOL_GPL(videobuf_qbuf);
987EXPORT_SYMBOL_GPL(videobuf_dqbuf);
988EXPORT_SYMBOL_GPL(videobuf_cgmbuf);
989EXPORT_SYMBOL_GPL(videobuf_streamon);
990EXPORT_SYMBOL_GPL(videobuf_streamoff);
991
992EXPORT_SYMBOL_GPL(videobuf_read_start);
993EXPORT_SYMBOL_GPL(videobuf_read_stop);
994EXPORT_SYMBOL_GPL(videobuf_read_stream);
995EXPORT_SYMBOL_GPL(videobuf_read_one);
996EXPORT_SYMBOL_GPL(videobuf_poll_stream);
997
998EXPORT_SYMBOL_GPL(videobuf_mmap_setup);
999EXPORT_SYMBOL_GPL(videobuf_mmap_free);
1000EXPORT_SYMBOL_GPL(videobuf_mmap_mapper);
1001
1002/*
1003 * Local variables:
1004 * c-basic-offset: 8
1005 * End:
1006 */
diff --git a/drivers/media/video/videobuf-dma-sg.c b/drivers/media/video/videobuf-dma-sg.c
new file mode 100644
index 000000000000..8bb7fdd306d6
--- /dev/null
+++ b/drivers/media/video/videobuf-dma-sg.c
@@ -0,0 +1,726 @@
1/*
2 * helper functions for PCI DMA video4linux capture buffers
3 *
4 * The functions expect the hardware being able to scatter gatter
5 * (i.e. the buffers are not linear in physical memory, but fragmented
6 * into PAGE_SIZE chunks). They also assume the driver does not need
7 * to touch the video data.
8 *
9 * (c) 2007 Mauro Carvalho Chehab, <mchehab@infradead.org>
10 *
11 * Highly based on video-buf written originally by:
12 * (c) 2001,02 Gerd Knorr <kraxel@bytesex.org>
13 * (c) 2006 Mauro Carvalho Chehab, <mchehab@infradead.org>
14 * (c) 2006 Ted Walther and John Sokol
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
19 */
20
21#include <linux/init.h>
22#include <linux/module.h>
23#include <linux/moduleparam.h>
24#include <linux/slab.h>
25#include <linux/interrupt.h>
26
27#include <linux/pci.h>
28#include <linux/vmalloc.h>
29#include <linux/pagemap.h>
30#include <asm/page.h>
31#include <asm/pgtable.h>
32
33#include <media/videobuf-dma-sg.h>
34
35#define MAGIC_DMABUF 0x19721112
36#define MAGIC_SG_MEM 0x17890714
37
38#define MAGIC_CHECK(is,should) if (unlikely((is) != (should))) \
39 { printk(KERN_ERR "magic mismatch: %x (expected %x)\n",is,should); BUG(); }
40
41static int debug = 0;
42module_param(debug, int, 0644);
43
44MODULE_DESCRIPTION("helper module to manage video4linux pci dma sg buffers");
45MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
46MODULE_LICENSE("GPL");
47
48#define dprintk(level, fmt, arg...) if (debug >= level) \
49 printk(KERN_DEBUG "vbuf-sg: " fmt , ## arg)
50
51/* --------------------------------------------------------------------- */
52
53struct scatterlist*
54videobuf_vmalloc_to_sg(unsigned char *virt, int nr_pages)
55{
56 struct scatterlist *sglist;
57 struct page *pg;
58 int i;
59
60 sglist = kcalloc(nr_pages, sizeof(struct scatterlist), GFP_KERNEL);
61 if (NULL == sglist)
62 return NULL;
63 for (i = 0; i < nr_pages; i++, virt += PAGE_SIZE) {
64 pg = vmalloc_to_page(virt);
65 if (NULL == pg)
66 goto err;
67 BUG_ON(PageHighMem(pg));
68 sglist[i].page = pg;
69 sglist[i].length = PAGE_SIZE;
70 }
71 return sglist;
72
73 err:
74 kfree(sglist);
75 return NULL;
76}
77
78struct scatterlist*
79videobuf_pages_to_sg(struct page **pages, int nr_pages, int offset)
80{
81 struct scatterlist *sglist;
82 int i = 0;
83
84 if (NULL == pages[0])
85 return NULL;
86 sglist = kcalloc(nr_pages, sizeof(*sglist), GFP_KERNEL);
87 if (NULL == sglist)
88 return NULL;
89
90 if (NULL == pages[0])
91 goto nopage;
92 if (PageHighMem(pages[0]))
93 /* DMA to highmem pages might not work */
94 goto highmem;
95 sglist[0].page = pages[0];
96 sglist[0].offset = offset;
97 sglist[0].length = PAGE_SIZE - offset;
98 for (i = 1; i < nr_pages; i++) {
99 if (NULL == pages[i])
100 goto nopage;
101 if (PageHighMem(pages[i]))
102 goto highmem;
103 sglist[i].page = pages[i];
104 sglist[i].length = PAGE_SIZE;
105 }
106 return sglist;
107
108 nopage:
109 dprintk(2,"sgl: oops - no page\n");
110 kfree(sglist);
111 return NULL;
112
113 highmem:
114 dprintk(2,"sgl: oops - highmem page\n");
115 kfree(sglist);
116 return NULL;
117}
118
119/* --------------------------------------------------------------------- */
120
121struct videobuf_dmabuf *videobuf_to_dma (struct videobuf_buffer *buf)
122{
123 struct videbuf_pci_sg_memory *mem=buf->priv;
124 BUG_ON (!mem);
125
126 MAGIC_CHECK(mem->magic,MAGIC_SG_MEM);
127
128 return &mem->dma;
129}
130
131void videobuf_dma_init(struct videobuf_dmabuf *dma)
132{
133 memset(dma,0,sizeof(*dma));
134 dma->magic = MAGIC_DMABUF;
135}
136
137static int videobuf_dma_init_user_locked(struct videobuf_dmabuf *dma,
138 int direction, unsigned long data, unsigned long size)
139{
140 unsigned long first,last;
141 int err, rw = 0;
142
143 dma->direction = direction;
144 switch (dma->direction) {
145 case PCI_DMA_FROMDEVICE: rw = READ; break;
146 case PCI_DMA_TODEVICE: rw = WRITE; break;
147 default: BUG();
148 }
149
150 first = (data & PAGE_MASK) >> PAGE_SHIFT;
151 last = ((data+size-1) & PAGE_MASK) >> PAGE_SHIFT;
152 dma->offset = data & ~PAGE_MASK;
153 dma->nr_pages = last-first+1;
154 dma->pages = kmalloc(dma->nr_pages * sizeof(struct page*),
155 GFP_KERNEL);
156 if (NULL == dma->pages)
157 return -ENOMEM;
158 dprintk(1,"init user [0x%lx+0x%lx => %d pages]\n",
159 data,size,dma->nr_pages);
160
161 dma->varea = (void *) data;
162
163
164 err = get_user_pages(current,current->mm,
165 data & PAGE_MASK, dma->nr_pages,
166 rw == READ, 1, /* force */
167 dma->pages, NULL);
168
169 if (err != dma->nr_pages) {
170 dma->nr_pages = (err >= 0) ? err : 0;
171 dprintk(1,"get_user_pages: err=%d [%d]\n",err,dma->nr_pages);
172 return err < 0 ? err : -EINVAL;
173 }
174 return 0;
175}
176
177int videobuf_dma_init_user(struct videobuf_dmabuf *dma, int direction,
178 unsigned long data, unsigned long size)
179{
180 int ret;
181 down_read(&current->mm->mmap_sem);
182 ret = videobuf_dma_init_user_locked(dma, direction, data, size);
183 up_read(&current->mm->mmap_sem);
184
185 return ret;
186}
187
188int videobuf_dma_init_kernel(struct videobuf_dmabuf *dma, int direction,
189 int nr_pages)
190{
191 dprintk(1,"init kernel [%d pages]\n",nr_pages);
192 dma->direction = direction;
193 dma->vmalloc = vmalloc_32(nr_pages << PAGE_SHIFT);
194 if (NULL == dma->vmalloc) {
195 dprintk(1,"vmalloc_32(%d pages) failed\n",nr_pages);
196 return -ENOMEM;
197 }
198 dprintk(1,"vmalloc is at addr 0x%08lx, size=%d\n",
199 (unsigned long)dma->vmalloc,
200 nr_pages << PAGE_SHIFT);
201 memset(dma->vmalloc,0,nr_pages << PAGE_SHIFT);
202 dma->nr_pages = nr_pages;
203 return 0;
204}
205
206int videobuf_dma_init_overlay(struct videobuf_dmabuf *dma, int direction,
207 dma_addr_t addr, int nr_pages)
208{
209 dprintk(1,"init overlay [%d pages @ bus 0x%lx]\n",
210 nr_pages,(unsigned long)addr);
211 dma->direction = direction;
212 if (0 == addr)
213 return -EINVAL;
214
215 dma->bus_addr = addr;
216 dma->nr_pages = nr_pages;
217 return 0;
218}
219
220int videobuf_dma_map(struct videobuf_queue* q,struct videobuf_dmabuf *dma)
221{
222 void *dev=q->dev;
223
224 MAGIC_CHECK(dma->magic,MAGIC_DMABUF);
225 BUG_ON(0 == dma->nr_pages);
226
227 if (dma->pages) {
228 dma->sglist = videobuf_pages_to_sg(dma->pages, dma->nr_pages,
229 dma->offset);
230 }
231 if (dma->vmalloc) {
232 dma->sglist = videobuf_vmalloc_to_sg
233 (dma->vmalloc,dma->nr_pages);
234 }
235 if (dma->bus_addr) {
236 dma->sglist = kmalloc(sizeof(struct scatterlist), GFP_KERNEL);
237 if (NULL != dma->sglist) {
238 dma->sglen = 1;
239 sg_dma_address(&dma->sglist[0]) = dma->bus_addr & PAGE_MASK;
240 dma->sglist[0].offset = dma->bus_addr & ~PAGE_MASK;
241 sg_dma_len(&dma->sglist[0]) = dma->nr_pages * PAGE_SIZE;
242 }
243 }
244 if (NULL == dma->sglist) {
245 dprintk(1,"scatterlist is NULL\n");
246 return -ENOMEM;
247 }
248 if (!dma->bus_addr) {
249 dma->sglen = pci_map_sg(dev,dma->sglist,
250 dma->nr_pages, dma->direction);
251 if (0 == dma->sglen) {
252 printk(KERN_WARNING
253 "%s: videobuf_map_sg failed\n",__FUNCTION__);
254 kfree(dma->sglist);
255 dma->sglist = NULL;
256 dma->sglen = 0;
257 return -EIO;
258 }
259 }
260 return 0;
261}
262
263int videobuf_dma_sync(struct videobuf_queue *q,struct videobuf_dmabuf *dma)
264{
265 void *dev=q->dev;
266
267 MAGIC_CHECK(dma->magic,MAGIC_DMABUF);
268 BUG_ON(!dma->sglen);
269
270 pci_dma_sync_sg_for_cpu (dev,dma->sglist,dma->nr_pages,dma->direction);
271 return 0;
272}
273
274int videobuf_dma_unmap(struct videobuf_queue* q,struct videobuf_dmabuf *dma)
275{
276 void *dev=q->dev;
277
278 MAGIC_CHECK(dma->magic,MAGIC_DMABUF);
279 if (!dma->sglen)
280 return 0;
281
282 pci_unmap_sg (dev,dma->sglist,dma->nr_pages,dma->direction);
283
284 kfree(dma->sglist);
285 dma->sglist = NULL;
286 dma->sglen = 0;
287 return 0;
288}
289
290int videobuf_dma_free(struct videobuf_dmabuf *dma)
291{
292 MAGIC_CHECK(dma->magic,MAGIC_DMABUF);
293 BUG_ON(dma->sglen);
294
295 if (dma->pages) {
296 int i;
297 for (i=0; i < dma->nr_pages; i++)
298 page_cache_release(dma->pages[i]);
299 kfree(dma->pages);
300 dma->pages = NULL;
301 }
302
303 vfree(dma->vmalloc);
304 dma->vmalloc = NULL;
305 dma->varea = NULL;
306
307 if (dma->bus_addr) {
308 dma->bus_addr = 0;
309 }
310 dma->direction = PCI_DMA_NONE;
311 return 0;
312}
313
314/* --------------------------------------------------------------------- */
315
316int videobuf_pci_dma_map(struct pci_dev *pci,struct videobuf_dmabuf *dma)
317{
318 struct videobuf_queue q;
319
320 q.dev=pci;
321
322 return (videobuf_dma_map(&q,dma));
323}
324
325int videobuf_pci_dma_unmap(struct pci_dev *pci,struct videobuf_dmabuf *dma)
326{
327 struct videobuf_queue q;
328
329 q.dev=pci;
330
331 return (videobuf_dma_unmap(&q,dma));
332}
333
334/* --------------------------------------------------------------------- */
335
336static void
337videobuf_vm_open(struct vm_area_struct *vma)
338{
339 struct videobuf_mapping *map = vma->vm_private_data;
340
341 dprintk(2,"vm_open %p [count=%d,vma=%08lx-%08lx]\n",map,
342 map->count,vma->vm_start,vma->vm_end);
343 map->count++;
344}
345
346static void
347videobuf_vm_close(struct vm_area_struct *vma)
348{
349 struct videobuf_mapping *map = vma->vm_private_data;
350 struct videobuf_queue *q = map->q;
351 struct videbuf_pci_sg_memory *mem;
352 int i;
353
354 dprintk(2,"vm_close %p [count=%d,vma=%08lx-%08lx]\n",map,
355 map->count,vma->vm_start,vma->vm_end);
356
357 map->count--;
358 if (0 == map->count) {
359 dprintk(1,"munmap %p q=%p\n",map,q);
360 mutex_lock(&q->lock);
361 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
362 if (NULL == q->bufs[i])
363 continue;
364 mem=q->bufs[i]->priv;
365
366 if (!mem)
367 continue;
368
369 MAGIC_CHECK(mem->magic,MAGIC_SG_MEM);
370
371 if (q->bufs[i]->map != map)
372 continue;
373 q->bufs[i]->map = NULL;
374 q->bufs[i]->baddr = 0;
375 q->ops->buf_release(q,q->bufs[i]);
376 }
377 mutex_unlock(&q->lock);
378 kfree(map);
379 }
380 return;
381}
382
383/*
384 * Get a anonymous page for the mapping. Make sure we can DMA to that
385 * memory location with 32bit PCI devices (i.e. don't use highmem for
386 * now ...). Bounce buffers don't work very well for the data rates
387 * video capture has.
388 */
389static struct page*
390videobuf_vm_nopage(struct vm_area_struct *vma, unsigned long vaddr,
391 int *type)
392{
393 struct page *page;
394
395 dprintk(3,"nopage: fault @ %08lx [vma %08lx-%08lx]\n",
396 vaddr,vma->vm_start,vma->vm_end);
397 if (vaddr > vma->vm_end)
398 return NOPAGE_SIGBUS;
399 page = alloc_page(GFP_USER | __GFP_DMA32);
400 if (!page)
401 return NOPAGE_OOM;
402 clear_user_page(page_address(page), vaddr, page);
403 if (type)
404 *type = VM_FAULT_MINOR;
405 return page;
406}
407
408static struct vm_operations_struct videobuf_vm_ops =
409{
410 .open = videobuf_vm_open,
411 .close = videobuf_vm_close,
412 .nopage = videobuf_vm_nopage,
413};
414
415/* ---------------------------------------------------------------------
416 * PCI handlers for the generic methods
417 */
418
419/* Allocated area consists on 3 parts:
420 struct video_buffer
421 struct <driver>_buffer (cx88_buffer, saa7134_buf, ...)
422 struct videobuf_pci_sg_memory
423 */
424
425static void *__videobuf_alloc(size_t size)
426{
427 struct videbuf_pci_sg_memory *mem;
428 struct videobuf_buffer *vb;
429
430 vb = kzalloc(size+sizeof(*mem),GFP_KERNEL);
431
432 mem = vb->priv = ((char *)vb)+size;
433 mem->magic=MAGIC_SG_MEM;
434
435 videobuf_dma_init(&mem->dma);
436
437 dprintk(1,"%s: allocated at %p(%ld+%ld) & %p(%ld)\n",
438 __FUNCTION__,vb,(long)sizeof(*vb),(long)size-sizeof(*vb),
439 mem,(long)sizeof(*mem));
440
441 return vb;
442}
443
444static int __videobuf_iolock (struct videobuf_queue* q,
445 struct videobuf_buffer *vb,
446 struct v4l2_framebuffer *fbuf)
447{
448 int err,pages;
449 dma_addr_t bus;
450 struct videbuf_pci_sg_memory *mem=vb->priv;
451 BUG_ON(!mem);
452
453 MAGIC_CHECK(mem->magic,MAGIC_SG_MEM);
454
455 switch (vb->memory) {
456 case V4L2_MEMORY_MMAP:
457 case V4L2_MEMORY_USERPTR:
458 if (0 == vb->baddr) {
459 /* no userspace addr -- kernel bounce buffer */
460 pages = PAGE_ALIGN(vb->size) >> PAGE_SHIFT;
461 err = videobuf_dma_init_kernel( &mem->dma,
462 PCI_DMA_FROMDEVICE,
463 pages );
464 if (0 != err)
465 return err;
466 } else if (vb->memory == V4L2_MEMORY_USERPTR) {
467 /* dma directly to userspace */
468 err = videobuf_dma_init_user( &mem->dma,
469 PCI_DMA_FROMDEVICE,
470 vb->baddr,vb->bsize );
471 if (0 != err)
472 return err;
473 } else {
474 /* NOTE: HACK: videobuf_iolock on V4L2_MEMORY_MMAP
475 buffers can only be called from videobuf_qbuf
476 we take current->mm->mmap_sem there, to prevent
477 locking inversion, so don't take it here */
478
479 err = videobuf_dma_init_user_locked(&mem->dma,
480 PCI_DMA_FROMDEVICE,
481 vb->baddr, vb->bsize);
482 if (0 != err)
483 return err;
484 }
485 break;
486 case V4L2_MEMORY_OVERLAY:
487 if (NULL == fbuf)
488 return -EINVAL;
489 /* FIXME: need sanity checks for vb->boff */
490 /*
491 * Using a double cast to avoid compiler warnings when
492 * building for PAE. Compiler doesn't like direct casting
493 * of a 32 bit ptr to 64 bit integer.
494 */
495 bus = (dma_addr_t)(unsigned long)fbuf->base + vb->boff;
496 pages = PAGE_ALIGN(vb->size) >> PAGE_SHIFT;
497 err = videobuf_dma_init_overlay(&mem->dma,PCI_DMA_FROMDEVICE,
498 bus, pages);
499 if (0 != err)
500 return err;
501 break;
502 default:
503 BUG();
504 }
505 err = videobuf_dma_map(q,&mem->dma);
506 if (0 != err)
507 return err;
508
509 return 0;
510}
511
512static int __videobuf_sync(struct videobuf_queue *q,
513 struct videobuf_buffer *buf)
514{
515 struct videbuf_pci_sg_memory *mem=buf->priv;
516 BUG_ON (!mem);
517 MAGIC_CHECK(mem->magic,MAGIC_SG_MEM);
518
519 return videobuf_dma_sync(q,&mem->dma);
520}
521
522static int __videobuf_mmap_free(struct videobuf_queue *q)
523{
524 int i;
525
526 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
527 if (q->bufs[i]) {
528 if (q->bufs[i]->map)
529 return -EBUSY;
530 }
531 }
532
533 return 0;
534}
535
536static int __videobuf_mmap_mapper(struct videobuf_queue *q,
537 struct vm_area_struct *vma)
538{
539 struct videbuf_pci_sg_memory *mem;
540 struct videobuf_mapping *map;
541 unsigned int first,last,size,i;
542 int retval;
543
544 retval = -EINVAL;
545 if (!(vma->vm_flags & VM_WRITE)) {
546 dprintk(1,"mmap app bug: PROT_WRITE please\n");
547 goto done;
548 }
549 if (!(vma->vm_flags & VM_SHARED)) {
550 dprintk(1,"mmap app bug: MAP_SHARED please\n");
551 goto done;
552 }
553
554 /* look for first buffer to map */
555 for (first = 0; first < VIDEO_MAX_FRAME; first++) {
556 if (NULL == q->bufs[first])
557 continue;
558 mem=q->bufs[first]->priv;
559 BUG_ON (!mem);
560 MAGIC_CHECK(mem->magic,MAGIC_SG_MEM);
561
562 if (V4L2_MEMORY_MMAP != q->bufs[first]->memory)
563 continue;
564 if (q->bufs[first]->boff == (vma->vm_pgoff << PAGE_SHIFT))
565 break;
566 }
567 if (VIDEO_MAX_FRAME == first) {
568 dprintk(1,"mmap app bug: offset invalid [offset=0x%lx]\n",
569 (vma->vm_pgoff << PAGE_SHIFT));
570 goto done;
571 }
572
573 /* look for last buffer to map */
574 for (size = 0, last = first; last < VIDEO_MAX_FRAME; last++) {
575 if (NULL == q->bufs[last])
576 continue;
577 if (V4L2_MEMORY_MMAP != q->bufs[last]->memory)
578 continue;
579 if (q->bufs[last]->map) {
580 retval = -EBUSY;
581 goto done;
582 }
583 size += q->bufs[last]->bsize;
584 if (size == (vma->vm_end - vma->vm_start))
585 break;
586 }
587 if (VIDEO_MAX_FRAME == last) {
588 dprintk(1,"mmap app bug: size invalid [size=0x%lx]\n",
589 (vma->vm_end - vma->vm_start));
590 goto done;
591 }
592
593 /* create mapping + update buffer list */
594 retval = -ENOMEM;
595 map = kmalloc(sizeof(struct videobuf_mapping),GFP_KERNEL);
596 if (NULL == map)
597 goto done;
598 for (size = 0, i = first; i <= last; size += q->bufs[i++]->bsize) {
599 q->bufs[i]->map = map;
600 q->bufs[i]->baddr = vma->vm_start + size;
601 }
602 map->count = 1;
603 map->start = vma->vm_start;
604 map->end = vma->vm_end;
605 map->q = q;
606 vma->vm_ops = &videobuf_vm_ops;
607 vma->vm_flags |= VM_DONTEXPAND | VM_RESERVED;
608 vma->vm_flags &= ~VM_IO; /* using shared anonymous pages */
609 vma->vm_private_data = map;
610 dprintk(1,"mmap %p: q=%p %08lx-%08lx pgoff %08lx bufs %d-%d\n",
611 map,q,vma->vm_start,vma->vm_end,vma->vm_pgoff,first,last);
612 retval = 0;
613
614 done:
615 return retval;
616}
617
618static int __videobuf_copy_to_user ( struct videobuf_queue *q,
619 char __user *data, size_t count,
620 int nonblocking )
621{
622 struct videbuf_pci_sg_memory *mem=q->read_buf->priv;
623 BUG_ON (!mem);
624 MAGIC_CHECK(mem->magic,MAGIC_SG_MEM);
625
626 /* copy to userspace */
627 if (count > q->read_buf->size - q->read_off)
628 count = q->read_buf->size - q->read_off;
629
630 if (copy_to_user(data, mem->dma.vmalloc+q->read_off, count))
631 return -EFAULT;
632
633 return count;
634}
635
636static int __videobuf_copy_stream ( struct videobuf_queue *q,
637 char __user *data, size_t count, size_t pos,
638 int vbihack, int nonblocking )
639{
640 unsigned int *fc;
641 struct videbuf_pci_sg_memory *mem=q->read_buf->priv;
642 BUG_ON (!mem);
643 MAGIC_CHECK(mem->magic,MAGIC_SG_MEM);
644
645 if (vbihack) {
646 /* dirty, undocumented hack -- pass the frame counter
647 * within the last four bytes of each vbi data block.
648 * We need that one to maintain backward compatibility
649 * to all vbi decoding software out there ... */
650 fc = (unsigned int*)mem->dma.vmalloc;
651 fc += (q->read_buf->size>>2) -1;
652 *fc = q->read_buf->field_count >> 1;
653 dprintk(1,"vbihack: %d\n",*fc);
654 }
655
656 /* copy stuff using the common method */
657 count = __videobuf_copy_to_user (q,data,count,nonblocking);
658
659 if ( (count==-EFAULT) && (0 == pos) )
660 return -EFAULT;
661
662 return count;
663}
664
665static struct videobuf_qtype_ops pci_ops = {
666 .magic = MAGIC_QTYPE_OPS,
667
668 .alloc = __videobuf_alloc,
669 .iolock = __videobuf_iolock,
670 .sync = __videobuf_sync,
671 .mmap_free = __videobuf_mmap_free,
672 .mmap_mapper = __videobuf_mmap_mapper,
673 .copy_to_user = __videobuf_copy_to_user,
674 .copy_stream = __videobuf_copy_stream,
675};
676
677void *videobuf_pci_alloc (size_t size)
678{
679 struct videobuf_queue q;
680
681 /* Required to make generic handler to call __videobuf_alloc */
682 q.int_ops=&pci_ops;
683
684 q.msize=size;
685
686 return videobuf_alloc (&q);
687}
688
689void videobuf_queue_pci_init(struct videobuf_queue* q,
690 struct videobuf_queue_ops *ops,
691 void *dev,
692 spinlock_t *irqlock,
693 enum v4l2_buf_type type,
694 enum v4l2_field field,
695 unsigned int msize,
696 void *priv)
697{
698 videobuf_queue_core_init(q, ops, dev, irqlock, type, field, msize,
699 priv, &pci_ops);
700}
701
702/* --------------------------------------------------------------------- */
703
704EXPORT_SYMBOL_GPL(videobuf_vmalloc_to_sg);
705
706EXPORT_SYMBOL_GPL(videobuf_to_dma);
707EXPORT_SYMBOL_GPL(videobuf_dma_init);
708EXPORT_SYMBOL_GPL(videobuf_dma_init_user);
709EXPORT_SYMBOL_GPL(videobuf_dma_init_kernel);
710EXPORT_SYMBOL_GPL(videobuf_dma_init_overlay);
711EXPORT_SYMBOL_GPL(videobuf_dma_map);
712EXPORT_SYMBOL_GPL(videobuf_dma_sync);
713EXPORT_SYMBOL_GPL(videobuf_dma_unmap);
714EXPORT_SYMBOL_GPL(videobuf_dma_free);
715
716EXPORT_SYMBOL_GPL(videobuf_pci_dma_map);
717EXPORT_SYMBOL_GPL(videobuf_pci_dma_unmap);
718EXPORT_SYMBOL_GPL(videobuf_pci_alloc);
719
720EXPORT_SYMBOL_GPL(videobuf_queue_pci_init);
721
722/*
723 * Local variables:
724 * c-basic-offset: 8
725 * End:
726 */
diff --git a/drivers/media/video/videobuf-dvb.c b/drivers/media/video/videobuf-dvb.c
new file mode 100644
index 000000000000..880317e04a02
--- /dev/null
+++ b/drivers/media/video/videobuf-dvb.c
@@ -0,0 +1,256 @@
1/*
2 *
3 * some helper function for simple DVB cards which simply DMA the
4 * complete transport stream and let the computer sort everything else
5 * (i.e. we are using the software demux, ...). Also uses the
6 * video-buf to manage DMA buffers.
7 *
8 * (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SUSE Labs]
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 */
15
16
17#include <linux/module.h>
18#include <linux/init.h>
19#include <linux/device.h>
20#include <linux/fs.h>
21#include <linux/kthread.h>
22#include <linux/file.h>
23#include <linux/freezer.h>
24
25#include <media/videobuf-dma-sg.h>
26#include <media/videobuf-dvb.h>
27
28/* ------------------------------------------------------------------ */
29
30MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
31MODULE_LICENSE("GPL");
32
33static unsigned int debug = 0;
34module_param(debug, int, 0644);
35MODULE_PARM_DESC(debug,"enable debug messages");
36
37#define dprintk(fmt, arg...) if (debug) \
38 printk(KERN_DEBUG "%s/dvb: " fmt, dvb->name , ## arg)
39
40/* ------------------------------------------------------------------ */
41
42static int videobuf_dvb_thread(void *data)
43{
44 struct videobuf_dvb *dvb = data;
45 struct videobuf_buffer *buf;
46 unsigned long flags;
47 int err;
48 struct videobuf_dmabuf *dma;
49
50 dprintk("dvb thread started\n");
51 set_freezable();
52 videobuf_read_start(&dvb->dvbq);
53
54 for (;;) {
55 /* fetch next buffer */
56 buf = list_entry(dvb->dvbq.stream.next,
57 struct videobuf_buffer, stream);
58 list_del(&buf->stream);
59 err = videobuf_waiton(buf,0,1);
60
61 /* no more feeds left or stop_feed() asked us to quit */
62 if (0 == dvb->nfeeds)
63 break;
64 if (kthread_should_stop())
65 break;
66 try_to_freeze();
67
68 /* feed buffer data to demux */
69 dma=videobuf_to_dma(buf);
70 if (buf->state == STATE_DONE)
71 dvb_dmx_swfilter(&dvb->demux, dma->vmalloc,
72 buf->size);
73
74 /* requeue buffer */
75 list_add_tail(&buf->stream,&dvb->dvbq.stream);
76 spin_lock_irqsave(dvb->dvbq.irqlock,flags);
77 dvb->dvbq.ops->buf_queue(&dvb->dvbq,buf);
78 spin_unlock_irqrestore(dvb->dvbq.irqlock,flags);
79 }
80
81 videobuf_read_stop(&dvb->dvbq);
82 dprintk("dvb thread stopped\n");
83
84 /* Hmm, linux becomes *very* unhappy without this ... */
85 while (!kthread_should_stop()) {
86 set_current_state(TASK_INTERRUPTIBLE);
87 schedule();
88 }
89 return 0;
90}
91
92static int videobuf_dvb_start_feed(struct dvb_demux_feed *feed)
93{
94 struct dvb_demux *demux = feed->demux;
95 struct videobuf_dvb *dvb = demux->priv;
96 int rc;
97
98 if (!demux->dmx.frontend)
99 return -EINVAL;
100
101 mutex_lock(&dvb->lock);
102 dvb->nfeeds++;
103 rc = dvb->nfeeds;
104
105 if (NULL != dvb->thread)
106 goto out;
107 dvb->thread = kthread_run(videobuf_dvb_thread,
108 dvb, "%s dvb", dvb->name);
109 if (IS_ERR(dvb->thread)) {
110 rc = PTR_ERR(dvb->thread);
111 dvb->thread = NULL;
112 }
113
114out:
115 mutex_unlock(&dvb->lock);
116 return rc;
117}
118
119static int videobuf_dvb_stop_feed(struct dvb_demux_feed *feed)
120{
121 struct dvb_demux *demux = feed->demux;
122 struct videobuf_dvb *dvb = demux->priv;
123 int err = 0;
124
125 mutex_lock(&dvb->lock);
126 dvb->nfeeds--;
127 if (0 == dvb->nfeeds && NULL != dvb->thread) {
128 // FIXME: cx8802_cancel_buffers(dev);
129 err = kthread_stop(dvb->thread);
130 dvb->thread = NULL;
131 }
132 mutex_unlock(&dvb->lock);
133 return err;
134}
135
136/* ------------------------------------------------------------------ */
137
138int videobuf_dvb_register(struct videobuf_dvb *dvb,
139 struct module *module,
140 void *adapter_priv,
141 struct device *device)
142{
143 int result;
144
145 mutex_init(&dvb->lock);
146
147 /* register adapter */
148 result = dvb_register_adapter(&dvb->adapter, dvb->name, module, device);
149 if (result < 0) {
150 printk(KERN_WARNING "%s: dvb_register_adapter failed (errno = %d)\n",
151 dvb->name, result);
152 goto fail_adapter;
153 }
154 dvb->adapter.priv = adapter_priv;
155
156 /* register frontend */
157 result = dvb_register_frontend(&dvb->adapter, dvb->frontend);
158 if (result < 0) {
159 printk(KERN_WARNING "%s: dvb_register_frontend failed (errno = %d)\n",
160 dvb->name, result);
161 goto fail_frontend;
162 }
163
164 /* register demux stuff */
165 dvb->demux.dmx.capabilities =
166 DMX_TS_FILTERING | DMX_SECTION_FILTERING |
167 DMX_MEMORY_BASED_FILTERING;
168 dvb->demux.priv = dvb;
169 dvb->demux.filternum = 256;
170 dvb->demux.feednum = 256;
171 dvb->demux.start_feed = videobuf_dvb_start_feed;
172 dvb->demux.stop_feed = videobuf_dvb_stop_feed;
173 result = dvb_dmx_init(&dvb->demux);
174 if (result < 0) {
175 printk(KERN_WARNING "%s: dvb_dmx_init failed (errno = %d)\n",
176 dvb->name, result);
177 goto fail_dmx;
178 }
179
180 dvb->dmxdev.filternum = 256;
181 dvb->dmxdev.demux = &dvb->demux.dmx;
182 dvb->dmxdev.capabilities = 0;
183 result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter);
184 if (result < 0) {
185 printk(KERN_WARNING "%s: dvb_dmxdev_init failed (errno = %d)\n",
186 dvb->name, result);
187 goto fail_dmxdev;
188 }
189
190 dvb->fe_hw.source = DMX_FRONTEND_0;
191 result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw);
192 if (result < 0) {
193 printk(KERN_WARNING "%s: add_frontend failed (DMX_FRONTEND_0, errno = %d)\n",
194 dvb->name, result);
195 goto fail_fe_hw;
196 }
197
198 dvb->fe_mem.source = DMX_MEMORY_FE;
199 result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem);
200 if (result < 0) {
201 printk(KERN_WARNING "%s: add_frontend failed (DMX_MEMORY_FE, errno = %d)\n",
202 dvb->name, result);
203 goto fail_fe_mem;
204 }
205
206 result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw);
207 if (result < 0) {
208 printk(KERN_WARNING "%s: connect_frontend failed (errno = %d)\n",
209 dvb->name, result);
210 goto fail_fe_conn;
211 }
212
213 /* register network adapter */
214 dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx);
215 return 0;
216
217fail_fe_conn:
218 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
219fail_fe_mem:
220 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
221fail_fe_hw:
222 dvb_dmxdev_release(&dvb->dmxdev);
223fail_dmxdev:
224 dvb_dmx_release(&dvb->demux);
225fail_dmx:
226 dvb_unregister_frontend(dvb->frontend);
227fail_frontend:
228 dvb_frontend_detach(dvb->frontend);
229 dvb_unregister_adapter(&dvb->adapter);
230fail_adapter:
231 return result;
232}
233
234void videobuf_dvb_unregister(struct videobuf_dvb *dvb)
235{
236 dvb_net_release(&dvb->net);
237 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
238 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
239 dvb_dmxdev_release(&dvb->dmxdev);
240 dvb_dmx_release(&dvb->demux);
241 dvb_unregister_frontend(dvb->frontend);
242 dvb_frontend_detach(dvb->frontend);
243 dvb_unregister_adapter(&dvb->adapter);
244}
245
246EXPORT_SYMBOL(videobuf_dvb_register);
247EXPORT_SYMBOL(videobuf_dvb_unregister);
248
249/* ------------------------------------------------------------------ */
250/*
251 * Local variables:
252 * c-basic-offset: 8
253 * compile-command: "make DVB=1"
254 * End:
255 */
256
diff --git a/drivers/media/video/videobuf-vmalloc.c b/drivers/media/video/videobuf-vmalloc.c
new file mode 100644
index 000000000000..2e3689a12a28
--- /dev/null
+++ b/drivers/media/video/videobuf-vmalloc.c
@@ -0,0 +1,370 @@
1/*
2 * helper functions for vmalloc video4linux capture buffers
3 *
4 * The functions expect the hardware being able to scatter gatter
5 * (i.e. the buffers are not linear in physical memory, but fragmented
6 * into PAGE_SIZE chunks). They also assume the driver does not need
7 * to touch the video data.
8 *
9 * (c) 2007 Mauro Carvalho Chehab, <mchehab@infradead.org>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2
14 */
15
16#include <linux/init.h>
17#include <linux/module.h>
18#include <linux/moduleparam.h>
19#include <linux/slab.h>
20#include <linux/interrupt.h>
21
22#include <linux/pci.h>
23#include <linux/vmalloc.h>
24#include <linux/pagemap.h>
25#include <asm/page.h>
26#include <asm/pgtable.h>
27
28#include <media/videobuf-vmalloc.h>
29
30#define MAGIC_DMABUF 0x17760309
31#define MAGIC_VMAL_MEM 0x18221223
32
33#define MAGIC_CHECK(is,should) if (unlikely((is) != (should))) \
34 { printk(KERN_ERR "magic mismatch: %x (expected %x)\n",is,should); BUG(); }
35
36static int debug = 0;
37module_param(debug, int, 0644);
38
39MODULE_DESCRIPTION("helper module to manage video4linux vmalloc buffers");
40MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
41MODULE_LICENSE("GPL");
42
43#define dprintk(level, fmt, arg...) if (debug >= level) \
44 printk(KERN_DEBUG "vbuf-sg: " fmt , ## arg)
45
46
47/***************************************************************************/
48
49static void
50videobuf_vm_open(struct vm_area_struct *vma)
51{
52 struct videobuf_mapping *map = vma->vm_private_data;
53
54 dprintk(2,"vm_open %p [count=%d,vma=%08lx-%08lx]\n",map,
55 map->count,vma->vm_start,vma->vm_end);
56
57 map->count++;
58}
59
60static void
61videobuf_vm_close(struct vm_area_struct *vma)
62{
63 struct videobuf_mapping *map = vma->vm_private_data;
64 struct videobuf_queue *q = map->q;
65 int i;
66
67 dprintk(2,"vm_close %p [count=%d,vma=%08lx-%08lx]\n",map,
68 map->count,vma->vm_start,vma->vm_end);
69
70 map->count--;
71 if (0 == map->count) {
72 dprintk(1,"munmap %p q=%p\n",map,q);
73 mutex_lock(&q->lock);
74 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
75 if (NULL == q->bufs[i])
76 continue;
77
78 if (q->bufs[i]->map != map)
79 continue;
80
81 q->ops->buf_release(q,q->bufs[i]);
82
83 q->bufs[i]->map = NULL;
84 q->bufs[i]->baddr = 0;
85 }
86 mutex_unlock(&q->lock);
87 kfree(map);
88 }
89 return;
90}
91
92static struct vm_operations_struct videobuf_vm_ops =
93{
94 .open = videobuf_vm_open,
95 .close = videobuf_vm_close,
96};
97
98/* ---------------------------------------------------------------------
99 * vmalloc handlers for the generic methods
100 */
101
102/* Allocated area consists on 3 parts:
103 struct video_buffer
104 struct <driver>_buffer (cx88_buffer, saa7134_buf, ...)
105 struct videobuf_pci_sg_memory
106 */
107
108static void *__videobuf_alloc(size_t size)
109{
110 struct videbuf_vmalloc_memory *mem;
111 struct videobuf_buffer *vb;
112
113 vb = kzalloc(size+sizeof(*mem),GFP_KERNEL);
114
115 mem = vb->priv = ((char *)vb)+size;
116 mem->magic=MAGIC_VMAL_MEM;
117
118 dprintk(1,"%s: allocated at %p(%ld+%ld) & %p(%ld)\n",
119 __FUNCTION__,vb,(long)sizeof(*vb),(long)size-sizeof(*vb),
120 mem,(long)sizeof(*mem));
121
122 return vb;
123}
124
125static int __videobuf_iolock (struct videobuf_queue* q,
126 struct videobuf_buffer *vb,
127 struct v4l2_framebuffer *fbuf)
128{
129 int pages;
130
131 struct videbuf_vmalloc_memory *mem=vb->priv;
132
133
134 BUG_ON(!mem);
135
136 MAGIC_CHECK(mem->magic,MAGIC_VMAL_MEM);
137
138 pages = PAGE_ALIGN(vb->size) >> PAGE_SHIFT;
139
140 /* Currently, doesn't support V4L2_MEMORY_OVERLAY */
141 if ((vb->memory != V4L2_MEMORY_MMAP) &&
142 (vb->memory != V4L2_MEMORY_USERPTR) ) {
143 printk(KERN_ERR "Method currently unsupported.\n");
144 return -EINVAL;
145 }
146
147 /* FIXME: should be tested with kernel mmap mem */
148 mem->vmalloc=vmalloc_user (PAGE_ALIGN(vb->size));
149 if (NULL == mem->vmalloc) {
150 printk(KERN_ERR "vmalloc (%d pages) failed\n",pages);
151 return -ENOMEM;
152 }
153
154 dprintk(1,"vmalloc is at addr 0x%08lx, size=%d\n",
155 (unsigned long)mem->vmalloc,
156 pages << PAGE_SHIFT);
157
158 /* It seems that some kernel versions need to do remap *after*
159 the mmap() call
160 */
161 if (mem->vma) {
162 int retval=remap_vmalloc_range(mem->vma, mem->vmalloc,0);
163 kfree(mem->vma);
164 mem->vma=NULL;
165 if (retval<0) {
166 dprintk(1,"mmap app bug: remap_vmalloc_range area %p error %d\n",
167 mem->vmalloc,retval);
168 return retval;
169 }
170 }
171
172 return 0;
173}
174
175static int __videobuf_sync(struct videobuf_queue *q,
176 struct videobuf_buffer *buf)
177{
178 return 0;
179}
180
181static int __videobuf_mmap_free(struct videobuf_queue *q)
182{
183 unsigned int i;
184
185 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
186 if (q->bufs[i]) {
187 if (q->bufs[i]->map)
188 return -EBUSY;
189 }
190 }
191
192 return 0;
193}
194
195static int __videobuf_mmap_mapper(struct videobuf_queue *q,
196 struct vm_area_struct *vma)
197{
198 struct videbuf_vmalloc_memory *mem;
199 struct videobuf_mapping *map;
200 unsigned int first;
201 int retval;
202 unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
203
204 if (! (vma->vm_flags & VM_WRITE) || ! (vma->vm_flags & VM_SHARED))
205 return -EINVAL;
206
207 /* look for first buffer to map */
208 for (first = 0; first < VIDEO_MAX_FRAME; first++) {
209 if (NULL == q->bufs[first])
210 continue;
211
212 if (V4L2_MEMORY_MMAP != q->bufs[first]->memory)
213 continue;
214 if (q->bufs[first]->boff == offset)
215 break;
216 }
217 if (VIDEO_MAX_FRAME == first) {
218 dprintk(1,"mmap app bug: offset invalid [offset=0x%lx]\n",
219 (vma->vm_pgoff << PAGE_SHIFT));
220 return -EINVAL;
221 }
222
223 /* create mapping + update buffer list */
224 map = q->bufs[first]->map = kmalloc(sizeof(struct videobuf_mapping),GFP_KERNEL);
225 if (NULL == map)
226 return -ENOMEM;
227
228 map->start = vma->vm_start;
229 map->end = vma->vm_end;
230 map->q = q;
231
232 q->bufs[first]->baddr = vma->vm_start;
233
234 vma->vm_ops = &videobuf_vm_ops;
235 vma->vm_flags |= VM_DONTEXPAND | VM_RESERVED;
236 vma->vm_private_data = map;
237
238 mem=q->bufs[first]->priv;
239 BUG_ON (!mem);
240 MAGIC_CHECK(mem->magic,MAGIC_VMAL_MEM);
241
242 /* Try to remap memory */
243 retval=remap_vmalloc_range(vma, mem->vmalloc,0);
244 if (retval<0) {
245 dprintk(1,"mmap: postponing remap_vmalloc_range\n");
246
247 mem->vma=kmalloc(sizeof(*vma),GFP_KERNEL);
248 if (!mem->vma) {
249 kfree(map);
250 q->bufs[first]->map=NULL;
251 return -ENOMEM;
252 }
253 memcpy(mem->vma,vma,sizeof(*vma));
254 }
255
256 dprintk(1,"mmap %p: q=%p %08lx-%08lx (%lx) pgoff %08lx buf %d\n",
257 map,q,vma->vm_start,vma->vm_end,
258 (long int) q->bufs[first]->bsize,
259 vma->vm_pgoff,first);
260
261 videobuf_vm_open(vma);
262
263 return (0);
264}
265
266static int __videobuf_copy_to_user ( struct videobuf_queue *q,
267 char __user *data, size_t count,
268 int nonblocking )
269{
270 struct videbuf_vmalloc_memory *mem=q->read_buf->priv;
271 BUG_ON (!mem);
272 MAGIC_CHECK(mem->magic,MAGIC_VMAL_MEM);
273
274 BUG_ON (!mem->vmalloc);
275
276 /* copy to userspace */
277 if (count > q->read_buf->size - q->read_off)
278 count = q->read_buf->size - q->read_off;
279
280 if (copy_to_user(data, mem->vmalloc+q->read_off, count))
281 return -EFAULT;
282
283 return count;
284}
285
286static int __videobuf_copy_stream ( struct videobuf_queue *q,
287 char __user *data, size_t count, size_t pos,
288 int vbihack, int nonblocking )
289{
290 unsigned int *fc;
291 struct videbuf_vmalloc_memory *mem=q->read_buf->priv;
292 BUG_ON (!mem);
293 MAGIC_CHECK(mem->magic,MAGIC_VMAL_MEM);
294
295 if (vbihack) {
296 /* dirty, undocumented hack -- pass the frame counter
297 * within the last four bytes of each vbi data block.
298 * We need that one to maintain backward compatibility
299 * to all vbi decoding software out there ... */
300 fc = (unsigned int*)mem->vmalloc;
301 fc += (q->read_buf->size>>2) -1;
302 *fc = q->read_buf->field_count >> 1;
303 dprintk(1,"vbihack: %d\n",*fc);
304 }
305
306 /* copy stuff using the common method */
307 count = __videobuf_copy_to_user (q,data,count,nonblocking);
308
309 if ( (count==-EFAULT) && (0 == pos) )
310 return -EFAULT;
311
312 return count;
313}
314
315static struct videobuf_qtype_ops qops = {
316 .magic = MAGIC_QTYPE_OPS,
317
318 .alloc = __videobuf_alloc,
319 .iolock = __videobuf_iolock,
320 .sync = __videobuf_sync,
321 .mmap_free = __videobuf_mmap_free,
322 .mmap_mapper = __videobuf_mmap_mapper,
323 .copy_to_user = __videobuf_copy_to_user,
324 .copy_stream = __videobuf_copy_stream,
325};
326
327void videobuf_queue_vmalloc_init(struct videobuf_queue* q,
328 struct videobuf_queue_ops *ops,
329 void *dev,
330 spinlock_t *irqlock,
331 enum v4l2_buf_type type,
332 enum v4l2_field field,
333 unsigned int msize,
334 void *priv)
335{
336 videobuf_queue_core_init(q, ops, dev, irqlock, type, field, msize,
337 priv, &qops);
338}
339
340EXPORT_SYMBOL_GPL(videobuf_queue_vmalloc_init);
341
342void *videobuf_to_vmalloc (struct videobuf_buffer *buf)
343{
344 struct videbuf_vmalloc_memory *mem=buf->priv;
345 BUG_ON (!mem);
346 MAGIC_CHECK(mem->magic,MAGIC_VMAL_MEM);
347
348 return mem->vmalloc;
349}
350EXPORT_SYMBOL_GPL(videobuf_to_vmalloc);
351
352void videobuf_vmalloc_free (struct videobuf_buffer *buf)
353{
354 struct videbuf_vmalloc_memory *mem=buf->priv;
355 BUG_ON (!mem);
356
357 MAGIC_CHECK(mem->magic,MAGIC_VMAL_MEM);
358
359 vfree(mem->vmalloc);
360 mem->vmalloc=NULL;
361
362 return;
363}
364EXPORT_SYMBOL_GPL(videobuf_vmalloc_free);
365
366/*
367 * Local variables:
368 * c-basic-offset: 8
369 * End:
370 */
diff --git a/drivers/media/video/videodev.c b/drivers/media/video/videodev.c
index b876aca69c73..8d8e517b344f 100644
--- a/drivers/media/video/videodev.c
+++ b/drivers/media/video/videodev.c
@@ -54,15 +54,14 @@
54 * sysfs stuff 54 * sysfs stuff
55 */ 55 */
56 56
57static ssize_t show_name(struct class_device *cd, char *buf) 57static ssize_t show_name(struct device *cd,
58 struct device_attribute *attr, char *buf)
58{ 59{
59 struct video_device *vfd = container_of(cd, struct video_device, 60 struct video_device *vfd = container_of(cd, struct video_device,
60 class_dev); 61 class_dev);
61 return sprintf(buf,"%.*s\n",(int)sizeof(vfd->name),vfd->name); 62 return sprintf(buf, "%.*s\n", (int)sizeof(vfd->name), vfd->name);
62} 63}
63 64
64static CLASS_DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
65
66struct video_device *video_device_alloc(void) 65struct video_device *video_device_alloc(void)
67{ 66{
68 struct video_device *vfd; 67 struct video_device *vfd;
@@ -76,7 +75,7 @@ void video_device_release(struct video_device *vfd)
76 kfree(vfd); 75 kfree(vfd);
77} 76}
78 77
79static void video_release(struct class_device *cd) 78static void video_release(struct device *cd)
80{ 79{
81 struct video_device *vfd = container_of(cd, struct video_device, 80 struct video_device *vfd = container_of(cd, struct video_device,
82 class_dev); 81 class_dev);
@@ -89,9 +88,15 @@ static void video_release(struct class_device *cd)
89 vfd->release(vfd); 88 vfd->release(vfd);
90} 89}
91 90
91static struct device_attribute video_device_attrs[] = {
92 __ATTR(name, S_IRUGO, show_name, NULL),
93 __ATTR_NULL
94};
95
92static struct class video_class = { 96static struct class video_class = {
93 .name = VIDEO_NAME, 97 .name = VIDEO_NAME,
94 .release = video_release, 98 .dev_attrs = video_device_attrs,
99 .dev_release = video_release,
95}; 100};
96 101
97/* 102/*
@@ -448,7 +453,7 @@ static int __video_do_ioctl(struct inode *inode, struct file *file,
448 if (cmd == VIDIOCGMBUF) { 453 if (cmd == VIDIOCGMBUF) {
449 struct video_mbuf *p=arg; 454 struct video_mbuf *p=arg;
450 455
451 memset(p,0,sizeof(p)); 456 memset(p, 0, sizeof(*p));
452 457
453 if (!vfd->vidiocgmbuf) 458 if (!vfd->vidiocgmbuf)
454 return ret; 459 return ret;
@@ -1753,22 +1758,16 @@ int video_register_device(struct video_device *vfd, int type, int nr)
1753 /* sysfs class */ 1758 /* sysfs class */
1754 memset(&vfd->class_dev, 0x00, sizeof(vfd->class_dev)); 1759 memset(&vfd->class_dev, 0x00, sizeof(vfd->class_dev));
1755 if (vfd->dev) 1760 if (vfd->dev)
1756 vfd->class_dev.dev = vfd->dev; 1761 vfd->class_dev.parent = vfd->dev;
1757 vfd->class_dev.class = &video_class; 1762 vfd->class_dev.class = &video_class;
1758 vfd->class_dev.devt = MKDEV(VIDEO_MAJOR, vfd->minor); 1763 vfd->class_dev.devt = MKDEV(VIDEO_MAJOR, vfd->minor);
1759 sprintf(vfd->class_dev.class_id, "%s%d", name_base, i - base); 1764 sprintf(vfd->class_dev.bus_id, "%s%d", name_base, i - base);
1760 ret = class_device_register(&vfd->class_dev); 1765 ret = device_register(&vfd->class_dev);
1761 if (ret < 0) { 1766 if (ret < 0) {
1762 printk(KERN_ERR "%s: class_device_register failed\n", 1767 printk(KERN_ERR "%s: device_register failed\n",
1763 __FUNCTION__); 1768 __FUNCTION__);
1764 goto fail_minor; 1769 goto fail_minor;
1765 } 1770 }
1766 ret = class_device_create_file(&vfd->class_dev, &class_device_attr_name);
1767 if (ret < 0) {
1768 printk(KERN_ERR "%s: class_device_create_file 'name' failed\n",
1769 __FUNCTION__);
1770 goto fail_classdev;
1771 }
1772 1771
1773#if 1 1772#if 1
1774 /* needed until all drivers are fixed */ 1773 /* needed until all drivers are fixed */
@@ -1779,8 +1778,6 @@ int video_register_device(struct video_device *vfd, int type, int nr)
1779#endif 1778#endif
1780 return 0; 1779 return 0;
1781 1780
1782fail_classdev:
1783 class_device_unregister(&vfd->class_dev);
1784fail_minor: 1781fail_minor:
1785 mutex_lock(&videodev_lock); 1782 mutex_lock(&videodev_lock);
1786 video_device[vfd->minor] = NULL; 1783 video_device[vfd->minor] = NULL;
@@ -1804,7 +1801,7 @@ void video_unregister_device(struct video_device *vfd)
1804 panic("videodev: bad unregister"); 1801 panic("videodev: bad unregister");
1805 1802
1806 video_device[vfd->minor]=NULL; 1803 video_device[vfd->minor]=NULL;
1807 class_device_unregister(&vfd->class_dev); 1804 device_unregister(&vfd->class_dev);
1808 mutex_unlock(&videodev_lock); 1805 mutex_unlock(&videodev_lock);
1809} 1806}
1810 1807
diff --git a/drivers/media/video/vino.c b/drivers/media/video/vino.c
index a0c1647a2ba4..9a03dc82c6ca 100644
--- a/drivers/media/video/vino.c
+++ b/drivers/media/video/vino.c
@@ -28,7 +28,6 @@
28#include <linux/interrupt.h> 28#include <linux/interrupt.h>
29#include <linux/kernel.h> 29#include <linux/kernel.h>
30#include <linux/mm.h> 30#include <linux/mm.h>
31#include <linux/moduleparam.h>
32#include <linux/time.h> 31#include <linux/time.h>
33#include <linux/version.h> 32#include <linux/version.h>
34 33
diff --git a/drivers/media/video/vivi.c b/drivers/media/video/vivi.c
index f6d3a9460ccc..b532aa280a1b 100644
--- a/drivers/media/video/vivi.c
+++ b/drivers/media/video/vivi.c
@@ -33,7 +33,7 @@
33#include <linux/videodev.h> 33#include <linux/videodev.h>
34#endif 34#endif
35#include <linux/interrupt.h> 35#include <linux/interrupt.h>
36#include <media/video-buf.h> 36#include <media/videobuf-vmalloc.h>
37#include <media/v4l2-common.h> 37#include <media/v4l2-common.h>
38#include <linux/kthread.h> 38#include <linux/kthread.h>
39#include <linux/highmem.h> 39#include <linux/highmem.h>
@@ -145,7 +145,6 @@ struct vivi_buffer {
145 struct videobuf_buffer vb; 145 struct videobuf_buffer vb;
146 146
147 struct vivi_fmt *fmt; 147 struct vivi_fmt *fmt;
148
149}; 148};
150 149
151struct vivi_dmaqueue { 150struct vivi_dmaqueue {
@@ -171,7 +170,6 @@ struct vivi_dev {
171 int users; 170 int users;
172 171
173 /* various device info */ 172 /* various device info */
174 unsigned int resources;
175 struct video_device vfd; 173 struct video_device vfd;
176 174
177 struct vivi_dmaqueue vidq; 175 struct vivi_dmaqueue vidq;
@@ -230,9 +228,8 @@ static u8 bars[8][3] = {
230#define TSTAMP_MAX_Y TSTAMP_MIN_Y+15 228#define TSTAMP_MAX_Y TSTAMP_MIN_Y+15
231#define TSTAMP_MIN_X 64 229#define TSTAMP_MIN_X 64
232 230
233
234static void gen_line(char *basep,int inipos,int wmax, 231static void gen_line(char *basep,int inipos,int wmax,
235 int hmax, int line, char *timestr) 232 int hmax, int line, int count, char *timestr)
236{ 233{
237 int w,i,j,pos=inipos,y; 234 int w,i,j,pos=inipos,y;
238 char *p,*s; 235 char *p,*s;
@@ -243,9 +240,10 @@ static void gen_line(char *basep,int inipos,int wmax,
243 240
244 /* Generate a standard color bar pattern */ 241 /* Generate a standard color bar pattern */
245 for (w=0;w<wmax;w++) { 242 for (w=0;w<wmax;w++) {
246 r=bars[w*7/wmax][0]; 243 int colorpos=((w+count)*8/(wmax+1)) % 8;
247 g=bars[w*7/wmax][1]; 244 r=bars[colorpos][0];
248 b=bars[w*7/wmax][2]; 245 g=bars[colorpos][1];
246 b=bars[colorpos][2];
249 247
250 for (color=0;color<4;color++) { 248 for (color=0;color<4;color++) {
251 p=basep+pos; 249 p=basep+pos;
@@ -326,27 +324,27 @@ static void vivi_fillbuff(struct vivi_dev *dev,struct vivi_buffer *buf)
326 int hmax = buf->vb.height; 324 int hmax = buf->vb.height;
327 int wmax = buf->vb.width; 325 int wmax = buf->vb.width;
328 struct timeval ts; 326 struct timeval ts;
329 char *tmpbuf; 327 char *tmpbuf = kmalloc(wmax*2,GFP_KERNEL);
330 328 void *vbuf=videobuf_to_vmalloc (&buf->vb);
331 if (buf->vb.dma.varea) { 329 /* FIXME: move to dev struct */
332 tmpbuf=kmalloc (wmax*2, GFP_KERNEL); 330 static int mv_count=0;
333 } else {
334 tmpbuf=buf->vb.dma.vmalloc;
335 }
336 331
332 if (!tmpbuf)
333 return;
337 334
338 for (h=0;h<hmax;h++) { 335 for (h=0;h<hmax;h++) {
339 if (buf->vb.dma.varea) { 336 gen_line(tmpbuf,0,wmax,hmax,h,mv_count,
340 gen_line(tmpbuf,0,wmax,hmax,h,dev->timestr); 337 dev->timestr);
341 /* FIXME: replacing to __copy_to_user */ 338 /* FIXME: replacing to __copy_to_user */
342 if (copy_to_user(buf->vb.dma.varea+pos,tmpbuf,wmax*2)!=0) 339 if (copy_to_user(vbuf+pos,tmpbuf,wmax*2)!=0)
343 dprintk(2,"vivifill copy_to_user failed.\n"); 340 dprintk(2,"vivifill copy_to_user failed.\n");
344 } else {
345 gen_line(tmpbuf,pos,wmax,hmax,h,dev->timestr);
346 }
347 pos += wmax*2; 341 pos += wmax*2;
348 } 342 }
349 343
344 mv_count++;
345
346 kfree(tmpbuf);
347
350 /* Updates stream time */ 348 /* Updates stream time */
351 349
352 dev->us+=jiffies_to_usecs(jiffies-dev->jiffies); 350 dev->us+=jiffies_to_usecs(jiffies-dev->jiffies);
@@ -369,7 +367,7 @@ static void vivi_fillbuff(struct vivi_dev *dev,struct vivi_buffer *buf)
369 dev->h,dev->m,dev->s,(dev->us+500)/1000); 367 dev->h,dev->m,dev->s,(dev->us+500)/1000);
370 368
371 dprintk(2,"vivifill at %s: Buffer 0x%08lx size= %d\n",dev->timestr, 369 dprintk(2,"vivifill at %s: Buffer 0x%08lx size= %d\n",dev->timestr,
372 (unsigned long)buf->vb.dma.varea,pos); 370 (unsigned long)tmpbuf,pos);
373 371
374 /* Advice that buffer was filled */ 372 /* Advice that buffer was filled */
375 buf->vb.state = STATE_DONE; 373 buf->vb.state = STATE_DONE;
@@ -509,7 +507,6 @@ static void vivi_stop_thread(struct vivi_dmaqueue *dma_q)
509static int restart_video_queue(struct vivi_dmaqueue *dma_q) 507static int restart_video_queue(struct vivi_dmaqueue *dma_q)
510{ 508{
511 struct vivi_buffer *buf, *prev; 509 struct vivi_buffer *buf, *prev;
512 struct list_head *item;
513 510
514 dprintk(1,"%s dma_q=0x%08lx\n",__FUNCTION__,(unsigned long)dma_q); 511 dprintk(1,"%s dma_q=0x%08lx\n",__FUNCTION__,(unsigned long)dma_q);
515 512
@@ -523,9 +520,7 @@ static int restart_video_queue(struct vivi_dmaqueue *dma_q)
523// vivi_start_thread(dma_q); 520// vivi_start_thread(dma_q);
524 521
525 /* cancel all outstanding capture / vbi requests */ 522 /* cancel all outstanding capture / vbi requests */
526 list_for_each(item,&dma_q->active) { 523 list_for_each_entry_safe(buf, prev, &dma_q->active, vb.queue) {
527 buf = list_entry(item, struct vivi_buffer, vb.queue);
528
529 list_del(&buf->vb.queue); 524 list_del(&buf->vb.queue);
530 buf->vb.state = STATE_ERROR; 525 buf->vb.state = STATE_ERROR;
531 wake_up(&buf->vb.done); 526 wake_up(&buf->vb.done);
@@ -597,8 +592,12 @@ buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size)
597 592
598 if (0 == *count) 593 if (0 == *count)
599 *count = 32; 594 *count = 32;
595
600 while (*size * *count > vid_limit * 1024 * 1024) 596 while (*size * *count > vid_limit * 1024 * 1024)
601 (*count)--; 597 (*count)--;
598
599 dprintk(1,"%s, count=%d, size=%d\n",__FUNCTION__,*count, *size);
600
602 return 0; 601 return 0;
603} 602}
604 603
@@ -609,10 +608,8 @@ static void free_buffer(struct videobuf_queue *vq, struct vivi_buffer *buf)
609 if (in_interrupt()) 608 if (in_interrupt())
610 BUG(); 609 BUG();
611 610
612
613 videobuf_waiton(&buf->vb,0,0); 611 videobuf_waiton(&buf->vb,0,0);
614 videobuf_dma_unmap(vq, &buf->vb.dma); 612 videobuf_vmalloc_free(&buf->vb);
615 videobuf_dma_free(&buf->vb.dma);
616 buf->vb.state = STATE_NEEDS_INIT; 613 buf->vb.state = STATE_NEEDS_INIT;
617} 614}
618 615
@@ -626,7 +623,7 @@ buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
626 struct vivi_buffer *buf = container_of(vb,struct vivi_buffer,vb); 623 struct vivi_buffer *buf = container_of(vb,struct vivi_buffer,vb);
627 int rc, init_buffer = 0; 624 int rc, init_buffer = 0;
628 625
629// dprintk(1,"%s, field=%d\n",__FUNCTION__,field); 626 dprintk(1,"%s, field=%d\n",__FUNCTION__,field);
630 627
631 BUG_ON(NULL == fh->fmt); 628 BUG_ON(NULL == fh->fmt);
632 if (fh->width < 48 || fh->width > norm_maxw() || 629 if (fh->width < 48 || fh->width > norm_maxw() ||
@@ -718,54 +715,14 @@ static void buffer_release(struct videobuf_queue *vq, struct videobuf_buffer *vb
718 free_buffer(vq,buf); 715 free_buffer(vq,buf);
719} 716}
720 717
721
722static struct videobuf_queue_ops vivi_video_qops = { 718static struct videobuf_queue_ops vivi_video_qops = {
723 .buf_setup = buffer_setup, 719 .buf_setup = buffer_setup,
724 .buf_prepare = buffer_prepare, 720 .buf_prepare = buffer_prepare,
725 .buf_queue = buffer_queue, 721 .buf_queue = buffer_queue,
726 .buf_release = buffer_release, 722 .buf_release = buffer_release,
727
728 /* Non-pci handling routines */
729// .vb_map_sg = vivi_map_sg,
730// .vb_dma_sync_sg = vivi_dma_sync_sg,
731// .vb_unmap_sg = vivi_unmap_sg,
732}; 723};
733 724
734/* ------------------------------------------------------------------ 725/* ------------------------------------------------------------------
735 IOCTL handling
736 ------------------------------------------------------------------*/
737
738
739static int res_get(struct vivi_dev *dev, struct vivi_fh *fh)
740{
741 /* is it free? */
742 mutex_lock(&dev->lock);
743 if (dev->resources) {
744 /* no, someone else uses it */
745 mutex_unlock(&dev->lock);
746 return 0;
747 }
748 /* it's free, grab it */
749 dev->resources =1;
750 dprintk(1,"res: get\n");
751 mutex_unlock(&dev->lock);
752 return 1;
753}
754
755static int res_locked(struct vivi_dev *dev)
756{
757 return (dev->resources);
758}
759
760static void res_free(struct vivi_dev *dev, struct vivi_fh *fh)
761{
762 mutex_lock(&dev->lock);
763 dev->resources = 0;
764 dprintk(1,"res: put\n");
765 mutex_lock(&dev->lock);
766}
767
768/* ------------------------------------------------------------------
769 IOCTL vidioc handling 726 IOCTL vidioc handling
770 ------------------------------------------------------------------*/ 727 ------------------------------------------------------------------*/
771static int vidioc_querycap (struct file *file, void *priv, 728static int vidioc_querycap (struct file *file, void *priv,
@@ -825,8 +782,7 @@ static int vidioc_try_fmt_cap (struct file *file, void *priv,
825 field = f->fmt.pix.field; 782 field = f->fmt.pix.field;
826 783
827 if (field == V4L2_FIELD_ANY) { 784 if (field == V4L2_FIELD_ANY) {
828// field=V4L2_FIELD_INTERLACED; 785 field=V4L2_FIELD_INTERLACED;
829 field=V4L2_FIELD_SEQ_TB;
830 } else if (V4L2_FIELD_INTERLACED != field) { 786 } else if (V4L2_FIELD_INTERLACED != field) {
831 dprintk(1,"Field type invalid.\n"); 787 dprintk(1,"Field type invalid.\n");
832 return -EINVAL; 788 return -EINVAL;
@@ -904,57 +860,33 @@ static int vidioc_dqbuf (struct file *file, void *priv, struct v4l2_buffer *p)
904static int vidiocgmbuf (struct file *file, void *priv, struct video_mbuf *mbuf) 860static int vidiocgmbuf (struct file *file, void *priv, struct video_mbuf *mbuf)
905{ 861{
906 struct vivi_fh *fh=priv; 862 struct vivi_fh *fh=priv;
907 struct videobuf_queue *q=&fh->vb_vidq;
908 struct v4l2_requestbuffers req;
909 unsigned int i;
910 int ret;
911
912 req.type = q->type;
913 req.count = 8;
914 req.memory = V4L2_MEMORY_MMAP;
915 ret = videobuf_reqbufs(q,&req);
916 if (ret < 0)
917 return (ret);
918 863
919 mbuf->frames = req.count; 864 return videobuf_cgmbuf (&fh->vb_vidq, mbuf, 8);
920 mbuf->size = 0;
921 for (i = 0; i < mbuf->frames; i++) {
922 mbuf->offsets[i] = q->bufs[i]->boff;
923 mbuf->size += q->bufs[i]->bsize;
924 }
925 return (0);
926} 865}
927#endif 866#endif
928 867
929static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i) 868static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
930{ 869{
931 struct vivi_fh *fh=priv; 870 struct vivi_fh *fh=priv;
932 struct vivi_dev *dev = fh->dev;
933 871
934 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 872 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
935 return -EINVAL; 873 return -EINVAL;
936 if (i != fh->type) 874 if (i != fh->type)
937 return -EINVAL; 875 return -EINVAL;
938 876
939 if (!res_get(dev,fh)) 877 return videobuf_streamon(&fh->vb_vidq);
940 return -EBUSY;
941 return (videobuf_streamon(&fh->vb_vidq));
942} 878}
943 879
944static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i) 880static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
945{ 881{
946 struct vivi_fh *fh=priv; 882 struct vivi_fh *fh=priv;
947 struct vivi_dev *dev = fh->dev;
948 883
949 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 884 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
950 return -EINVAL; 885 return -EINVAL;
951 if (i != fh->type) 886 if (i != fh->type)
952 return -EINVAL; 887 return -EINVAL;
953 888
954 videobuf_streamoff(&fh->vb_vidq); 889 return videobuf_streamoff(&fh->vb_vidq);
955 res_free(dev,fh);
956
957 return (0);
958} 890}
959 891
960static int vidioc_s_std (struct file *file, void *priv, v4l2_std_id *i) 892static int vidioc_s_std (struct file *file, void *priv, v4l2_std_id *i)
@@ -1047,31 +979,25 @@ static int vidioc_s_ctrl (struct file *file, void *priv,
1047static int vivi_open(struct inode *inode, struct file *file) 979static int vivi_open(struct inode *inode, struct file *file)
1048{ 980{
1049 int minor = iminor(inode); 981 int minor = iminor(inode);
1050 struct vivi_dev *h,*dev = NULL; 982 struct vivi_dev *dev;
1051 struct vivi_fh *fh; 983 struct vivi_fh *fh;
1052 struct list_head *list;
1053 enum v4l2_buf_type type = 0;
1054 int i; 984 int i;
1055 985
1056 printk(KERN_DEBUG "vivi: open called (minor=%d)\n",minor); 986 printk(KERN_DEBUG "vivi: open called (minor=%d)\n",minor);
1057 987
1058 list_for_each(list,&vivi_devlist) { 988 list_for_each_entry(dev, &vivi_devlist, vivi_devlist)
1059 h = list_entry(list, struct vivi_dev, vivi_devlist); 989 if (dev->vfd.minor == minor)
1060 if (h->vfd.minor == minor) { 990 goto found;
1061 dev = h; 991 return -ENODEV;
1062 type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 992found:
1063 }
1064 }
1065 if (NULL == dev)
1066 return -ENODEV;
1067 993
1068 994
1069 995
1070 /* If more than one user, mutex should be added */ 996 /* If more than one user, mutex should be added */
1071 dev->users++; 997 dev->users++;
1072 998
1073 dprintk(1,"open minor=%d type=%s users=%d\n", 999 dprintk(1, "open minor=%d type=%s users=%d\n", minor,
1074 minor,v4l2_type_names[type],dev->users); 1000 v4l2_type_names[V4L2_BUF_TYPE_VIDEO_CAPTURE], dev->users);
1075 1001
1076 /* allocate + initialize per filehandle data */ 1002 /* allocate + initialize per filehandle data */
1077 fh = kzalloc(sizeof(*fh),GFP_KERNEL); 1003 fh = kzalloc(sizeof(*fh),GFP_KERNEL);
@@ -1106,7 +1032,7 @@ static int vivi_open(struct inode *inode, struct file *file)
1106 sprintf(dev->timestr,"%02d:%02d:%02d:%03d", 1032 sprintf(dev->timestr,"%02d:%02d:%02d:%03d",
1107 dev->h,dev->m,dev->s,(dev->us+500)/1000); 1033 dev->h,dev->m,dev->s,(dev->us+500)/1000);
1108 1034
1109 videobuf_queue_init(&fh->vb_vidq, &vivi_video_qops, 1035 videobuf_queue_vmalloc_init(&fh->vb_vidq, &vivi_video_qops,
1110 NULL, NULL, 1036 NULL, NULL,
1111 fh->type, 1037 fh->type,
1112 V4L2_FIELD_INTERLACED, 1038 V4L2_FIELD_INTERLACED,
@@ -1121,9 +1047,7 @@ vivi_read(struct file *file, char __user *data, size_t count, loff_t *ppos)
1121 struct vivi_fh *fh = file->private_data; 1047 struct vivi_fh *fh = file->private_data;
1122 1048
1123 if (fh->type==V4L2_BUF_TYPE_VIDEO_CAPTURE) { 1049 if (fh->type==V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1124 if (res_locked(fh->dev)) 1050 return videobuf_read_stream(&fh->vb_vidq, data, count, ppos, 0,
1125 return -EBUSY;
1126 return videobuf_read_one(&fh->vb_vidq, data, count, ppos,
1127 file->f_flags & O_NONBLOCK); 1051 file->f_flags & O_NONBLOCK);
1128 } 1052 }
1129 return 0; 1053 return 0;
@@ -1133,31 +1057,14 @@ static unsigned int
1133vivi_poll(struct file *file, struct poll_table_struct *wait) 1057vivi_poll(struct file *file, struct poll_table_struct *wait)
1134{ 1058{
1135 struct vivi_fh *fh = file->private_data; 1059 struct vivi_fh *fh = file->private_data;
1136 struct vivi_buffer *buf; 1060 struct videobuf_queue *q = &fh->vb_vidq;
1137 1061
1138 dprintk(1,"%s\n",__FUNCTION__); 1062 dprintk(1,"%s\n",__FUNCTION__);
1139 1063
1140 if (V4L2_BUF_TYPE_VIDEO_CAPTURE != fh->type) 1064 if (V4L2_BUF_TYPE_VIDEO_CAPTURE != fh->type)
1141 return POLLERR; 1065 return POLLERR;
1142 1066
1143 if (res_get(fh->dev,fh)) { 1067 return videobuf_poll_stream(file, q, wait);
1144 dprintk(1,"poll: mmap interface\n");
1145 /* streaming capture */
1146 if (list_empty(&fh->vb_vidq.stream))
1147 return POLLERR;
1148 buf = list_entry(fh->vb_vidq.stream.next,struct vivi_buffer,vb.stream);
1149 } else {
1150 dprintk(1,"poll: read() interface\n");
1151 /* read() capture */
1152 buf = (struct vivi_buffer*)fh->vb_vidq.read_buf;
1153 if (NULL == buf)
1154 return POLLERR;
1155 }
1156 poll_wait(file, &buf->vb.done, wait);
1157 if (buf->vb.state == STATE_DONE ||
1158 buf->vb.state == STATE_ERROR)
1159 return POLLIN|POLLRDNORM;
1160 return 0;
1161} 1068}
1162 1069
1163static int vivi_release(struct inode *inode, struct file *file) 1070static int vivi_release(struct inode *inode, struct file *file)
@@ -1205,7 +1112,7 @@ static const struct file_operations vivi_fops = {
1205 .read = vivi_read, 1112 .read = vivi_read,
1206 .poll = vivi_poll, 1113 .poll = vivi_poll,
1207 .ioctl = video_ioctl2, /* V4L2 ioctl handler */ 1114 .ioctl = video_ioctl2, /* V4L2 ioctl handler */
1208 .mmap = vivi_mmap, 1115 .mmap = vivi_mmap,
1209 .llseek = no_llseek, 1116 .llseek = no_llseek,
1210}; 1117};
1211 1118
diff --git a/drivers/media/video/vp27smpx.c b/drivers/media/video/vp27smpx.c
new file mode 100644
index 000000000000..63002e0ac764
--- /dev/null
+++ b/drivers/media/video/vp27smpx.c
@@ -0,0 +1,212 @@
1/*
2 * vp27smpx - driver version 0.0.1
3 *
4 * Copyright (C) 2007 Hans Verkuil <hverkuil@xs4all.nl>
5 *
6 * Based on a tvaudio patch from Takahiro Adachi <tadachi@tadachi-net.com>
7 * and Kazuhiko Kawakami <kazz-0@mail.goo.ne.jp>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program 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 this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24#include <linux/module.h>
25#include <linux/types.h>
26#include <linux/ioctl.h>
27#include <asm/uaccess.h>
28#include <linux/i2c.h>
29#include <linux/i2c-id.h>
30#include <linux/videodev.h>
31#include <media/v4l2-common.h>
32#include <media/v4l2-chip-ident.h>
33
34MODULE_DESCRIPTION("vp27smpx driver");
35MODULE_AUTHOR("Hans Verkuil");
36MODULE_LICENSE("GPL");
37
38static unsigned short normal_i2c[] = { 0xb6 >> 1, I2C_CLIENT_END };
39
40
41I2C_CLIENT_INSMOD;
42
43/* ----------------------------------------------------------------------- */
44
45struct vp27smpx_state {
46 int radio;
47 u32 audmode;
48};
49
50static void vp27smpx_set_audmode(struct i2c_client *client, u32 audmode)
51{
52 struct vp27smpx_state *state = i2c_get_clientdata(client);
53 u8 data[3] = { 0x00, 0x00, 0x04 };
54
55 switch (audmode) {
56 case V4L2_TUNER_MODE_MONO:
57 case V4L2_TUNER_MODE_LANG1:
58 break;
59 case V4L2_TUNER_MODE_STEREO:
60 case V4L2_TUNER_MODE_LANG1_LANG2:
61 data[1] = 0x01;
62 break;
63 case V4L2_TUNER_MODE_LANG2:
64 data[1] = 0x02;
65 break;
66 }
67
68 if (i2c_master_send(client, data, sizeof(data)) != sizeof(data)) {
69 v4l_err(client, "%s: I/O error setting audmode\n", client->name);
70 }
71 else {
72 state->audmode = audmode;
73 }
74}
75
76static int vp27smpx_command(struct i2c_client *client, unsigned int cmd,
77 void *arg)
78{
79 struct vp27smpx_state *state = i2c_get_clientdata(client);
80 struct v4l2_tuner *vt = arg;
81
82 switch (cmd) {
83 case AUDC_SET_RADIO:
84 state->radio = 1;
85 break;
86
87 case VIDIOC_S_STD:
88 state->radio = 0;
89 break;
90
91 case VIDIOC_S_TUNER:
92 if (!state->radio)
93 vp27smpx_set_audmode(client, vt->audmode);
94 break;
95
96 case VIDIOC_G_TUNER:
97 if (state->radio)
98 break;
99 vt->audmode = state->audmode;
100 vt->capability = V4L2_TUNER_CAP_STEREO |
101 V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2;
102 vt->rxsubchans = V4L2_TUNER_SUB_MONO;
103 break;
104
105 case VIDIOC_G_CHIP_IDENT:
106 return v4l2_chip_ident_i2c_client(client, arg, V4L2_IDENT_VP27SMPX, 0);
107
108 case VIDIOC_LOG_STATUS:
109 v4l_info(client, "Audio Mode: %u%s\n", state->audmode,
110 state->radio ? " (Radio)" : "");
111 break;
112
113 default:
114 return -EINVAL;
115 }
116 return 0;
117}
118
119/* ----------------------------------------------------------------------- */
120
121/* i2c implementation */
122
123/*
124 * Generic i2c probe
125 * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1'
126 */
127
128static struct i2c_driver i2c_driver;
129
130static int vp27smpx_attach(struct i2c_adapter *adapter, int address, int kind)
131{
132 struct i2c_client *client;
133 struct vp27smpx_state *state;
134
135 /* Check if the adapter supports the needed features */
136 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
137 return 0;
138
139 client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
140 if (client == 0)
141 return -ENOMEM;
142
143 client->addr = address;
144 client->adapter = adapter;
145 client->driver = &i2c_driver;
146 snprintf(client->name, sizeof(client->name) - 1, "vp27smpx");
147
148 v4l_info(client, "chip found @ 0x%x (%s)\n", address << 1, adapter->name);
149
150 state = kzalloc(sizeof(struct vp27smpx_state), GFP_KERNEL);
151 if (state == NULL) {
152 kfree(client);
153 return -ENOMEM;
154 }
155 state->audmode = V4L2_TUNER_MODE_STEREO;
156 i2c_set_clientdata(client, state);
157
158 /* initialize vp27smpx */
159 vp27smpx_set_audmode(client, state->audmode);
160 i2c_attach_client(client);
161
162 return 0;
163}
164
165static int vp27smpx_probe(struct i2c_adapter *adapter)
166{
167 if (adapter->class & I2C_CLASS_TV_ANALOG)
168 return i2c_probe(adapter, &addr_data, vp27smpx_attach);
169 return 0;
170}
171
172static int vp27smpx_detach(struct i2c_client *client)
173{
174 struct vp27smpx_state *state = i2c_get_clientdata(client);
175 int err;
176
177 err = i2c_detach_client(client);
178 if (err) {
179 return err;
180 }
181 kfree(state);
182 kfree(client);
183
184 return 0;
185}
186
187/* ----------------------------------------------------------------------- */
188
189/* i2c implementation */
190static struct i2c_driver i2c_driver = {
191 .driver = {
192 .name = "vp27smpx",
193 },
194 .id = I2C_DRIVERID_VP27SMPX,
195 .attach_adapter = vp27smpx_probe,
196 .detach_client = vp27smpx_detach,
197 .command = vp27smpx_command,
198};
199
200
201static int __init vp27smpx_init_module(void)
202{
203 return i2c_add_driver(&i2c_driver);
204}
205
206static void __exit vp27smpx_cleanup_module(void)
207{
208 i2c_del_driver(&i2c_driver);
209}
210
211module_init(vp27smpx_init_module);
212module_exit(vp27smpx_cleanup_module);
diff --git a/drivers/media/video/w9968cf.c b/drivers/media/video/w9968cf.c
index 8f31613b9903..5a1b5f5a7d46 100644
--- a/drivers/media/video/w9968cf.c
+++ b/drivers/media/video/w9968cf.c
@@ -42,7 +42,6 @@
42#include <asm/page.h> 42#include <asm/page.h>
43#include <asm/uaccess.h> 43#include <asm/uaccess.h>
44#include <linux/page-flags.h> 44#include <linux/page-flags.h>
45#include <linux/moduleparam.h>
46 45
47#include "w9968cf.h" 46#include "w9968cf.h"
48#include "w9968cf_decoder.h" 47#include "w9968cf_decoder.h"
@@ -2680,7 +2679,7 @@ static int w9968cf_open(struct inode* inode, struct file* filp)
2680 2679
2681 /* This the only safe way to prevent race conditions with disconnect */ 2680 /* This the only safe way to prevent race conditions with disconnect */
2682 if (!down_read_trylock(&w9968cf_disconnect)) 2681 if (!down_read_trylock(&w9968cf_disconnect))
2683 return -ERESTARTSYS; 2682 return -EAGAIN;
2684 2683
2685 cam = (struct w9968cf_device*)video_get_drvdata(video_devdata(filp)); 2684 cam = (struct w9968cf_device*)video_get_drvdata(video_devdata(filp));
2686 2685
diff --git a/drivers/media/video/zc0301/zc0301_core.c b/drivers/media/video/zc0301/zc0301_core.c
index 703b741e46df..08a93c31c0a0 100644
--- a/drivers/media/video/zc0301/zc0301_core.c
+++ b/drivers/media/video/zc0301/zc0301_core.c
@@ -26,7 +26,6 @@
26#include <linux/init.h> 26#include <linux/init.h>
27#include <linux/kernel.h> 27#include <linux/kernel.h>
28#include <linux/param.h> 28#include <linux/param.h>
29#include <linux/moduleparam.h>
30#include <linux/errno.h> 29#include <linux/errno.h>
31#include <linux/slab.h> 30#include <linux/slab.h>
32#include <linux/device.h> 31#include <linux/device.h>
@@ -656,7 +655,7 @@ static int zc0301_open(struct inode* inode, struct file* filp)
656 int err = 0; 655 int err = 0;
657 656
658 if (!down_read_trylock(&zc0301_dev_lock)) 657 if (!down_read_trylock(&zc0301_dev_lock))
659 return -ERESTARTSYS; 658 return -EAGAIN;
660 659
661 cam = video_get_drvdata(video_devdata(filp)); 660 cam = video_get_drvdata(video_devdata(filp));
662 661
diff --git a/drivers/media/video/zoran_card.c b/drivers/media/video/zoran_card.c
index 73162a3a61dd..48da36a15fca 100644
--- a/drivers/media/video/zoran_card.c
+++ b/drivers/media/video/zoran_card.c
@@ -64,15 +64,15 @@
64extern const struct zoran_format zoran_formats[]; 64extern const struct zoran_format zoran_formats[];
65 65
66static int card[BUZ_MAX] = { -1, -1, -1, -1 }; 66static int card[BUZ_MAX] = { -1, -1, -1, -1 };
67module_param_array(card, int, NULL, 0); 67module_param_array(card, int, NULL, 0444);
68MODULE_PARM_DESC(card, "The type of card"); 68MODULE_PARM_DESC(card, "The type of card");
69 69
70static int encoder[BUZ_MAX] = { -1, -1, -1, -1 }; 70static int encoder[BUZ_MAX] = { -1, -1, -1, -1 };
71module_param_array(encoder, int, NULL, 0); 71module_param_array(encoder, int, NULL, 0444);
72MODULE_PARM_DESC(encoder, "i2c TV encoder"); 72MODULE_PARM_DESC(encoder, "i2c TV encoder");
73 73
74static int decoder[BUZ_MAX] = { -1, -1, -1, -1 }; 74static int decoder[BUZ_MAX] = { -1, -1, -1, -1 };
75module_param_array(decoder, int, NULL, 0); 75module_param_array(decoder, int, NULL, 0444);
76MODULE_PARM_DESC(decoder, "i2c TV decoder"); 76MODULE_PARM_DESC(decoder, "i2c TV decoder");
77 77
78/* 78/*
@@ -84,29 +84,31 @@ MODULE_PARM_DESC(decoder, "i2c TV decoder");
84 */ 84 */
85 85
86static unsigned long vidmem = 0; /* Video memory base address */ 86static unsigned long vidmem = 0; /* Video memory base address */
87module_param(vidmem, ulong, 0); 87module_param(vidmem, ulong, 0444);
88MODULE_PARM_DESC(vidmem, "Default video memory base address");
88 89
89/* 90/*
90 Default input and video norm at startup of the driver. 91 Default input and video norm at startup of the driver.
91*/ 92*/
92 93
93static int default_input = 0; /* 0=Composite, 1=S-Video */ 94static unsigned int default_input = 0; /* 0=Composite, 1=S-Video */
94module_param(default_input, int, 0); 95module_param(default_input, uint, 0444);
95MODULE_PARM_DESC(default_input, 96MODULE_PARM_DESC(default_input,
96 "Default input (0=Composite, 1=S-Video, 2=Internal)"); 97 "Default input (0=Composite, 1=S-Video, 2=Internal)");
97 98
98static int default_mux = 1; /* 6 Eyes input selection */ 99static int default_mux = 1; /* 6 Eyes input selection */
99module_param(default_mux, int, 0); 100module_param(default_mux, int, 0644);
100MODULE_PARM_DESC(default_mux, 101MODULE_PARM_DESC(default_mux,
101 "Default 6 Eyes mux setting (Input selection)"); 102 "Default 6 Eyes mux setting (Input selection)");
102 103
103static int default_norm = 0; /* 0=PAL, 1=NTSC 2=SECAM */ 104static int default_norm = 0; /* 0=PAL, 1=NTSC 2=SECAM */
104module_param(default_norm, int, 0); 105module_param(default_norm, int, 0444);
105MODULE_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)");
106 107
107static int video_nr = -1; /* /dev/videoN, -1 for autodetect */ 108/* /dev/videoN, -1 for autodetect */
108module_param(video_nr, int, 0); 109static int video_nr[BUZ_MAX] = {-1, -1, -1, -1};
109MODULE_PARM_DESC(video_nr, "video device number"); 110module_param_array(video_nr, int, NULL, 0444);
111MODULE_PARM_DESC(video_nr, "video device number (-1=Auto)");
110 112
111/* 113/*
112 Number and size of grab buffers for Video 4 Linux 114 Number and size of grab buffers for Video 4 Linux
@@ -127,28 +129,27 @@ MODULE_PARM_DESC(video_nr, "video device number");
127 129
128int v4l_nbufs = 2; 130int v4l_nbufs = 2;
129int v4l_bufsize = 128; /* Everybody should be able to work with this setting */ 131int v4l_bufsize = 128; /* Everybody should be able to work with this setting */
130module_param(v4l_nbufs, int, 0); 132module_param(v4l_nbufs, int, 0644);
131MODULE_PARM_DESC(v4l_nbufs, "Maximum number of V4L buffers to use"); 133MODULE_PARM_DESC(v4l_nbufs, "Maximum number of V4L buffers to use");
132module_param(v4l_bufsize, int, 0); 134module_param(v4l_bufsize, int, 0644);
133MODULE_PARM_DESC(v4l_bufsize, "Maximum size per V4L buffer (in kB)"); 135MODULE_PARM_DESC(v4l_bufsize, "Maximum size per V4L buffer (in kB)");
134 136
135int jpg_nbufs = 32; 137int jpg_nbufs = 32;
136int jpg_bufsize = 512; /* max size for 100% quality full-PAL frame */ 138int jpg_bufsize = 512; /* max size for 100% quality full-PAL frame */
137module_param(jpg_nbufs, int, 0); 139module_param(jpg_nbufs, int, 0644);
138MODULE_PARM_DESC(jpg_nbufs, "Maximum number of JPG buffers to use"); 140MODULE_PARM_DESC(jpg_nbufs, "Maximum number of JPG buffers to use");
139module_param(jpg_bufsize, int, 0); 141module_param(jpg_bufsize, int, 0644);
140MODULE_PARM_DESC(jpg_bufsize, "Maximum size per JPG buffer (in kB)"); 142MODULE_PARM_DESC(jpg_bufsize, "Maximum size per JPG buffer (in kB)");
141 143
142int pass_through = 0; /* 1=Pass through TV signal when device is not used */ 144int pass_through = 0; /* 1=Pass through TV signal when device is not used */
143 /* 0=Show color bar when device is not used (LML33: only if lml33dpath=1) */ 145 /* 0=Show color bar when device is not used (LML33: only if lml33dpath=1) */
144module_param(pass_through, int, 0); 146module_param(pass_through, int, 0644);
145MODULE_PARM_DESC(pass_through, 147MODULE_PARM_DESC(pass_through,
146 "Pass TV signal through to TV-out when idling"); 148 "Pass TV signal through to TV-out when idling");
147 149
148static int debug = 1; 150int zr36067_debug = 1;
149int *zr_debug = &debug; 151module_param_named(debug, zr36067_debug, int, 0644);
150module_param(debug, int, 0); 152MODULE_PARM_DESC(debug, "Debug level (0-5)");
151MODULE_PARM_DESC(debug, "Debug level (0-4)");
152 153
153MODULE_DESCRIPTION("Zoran-36057/36067 JPEG codec driver"); 154MODULE_DESCRIPTION("Zoran-36057/36067 JPEG codec driver");
154MODULE_AUTHOR("Serguei Miridonov"); 155MODULE_AUTHOR("Serguei Miridonov");
@@ -161,12 +162,6 @@ static struct pci_device_id zr36067_pci_tbl[] = {
161}; 162};
162MODULE_DEVICE_TABLE(pci, zr36067_pci_tbl); 163MODULE_DEVICE_TABLE(pci, zr36067_pci_tbl);
163 164
164#define dprintk(num, format, args...) \
165 do { \
166 if (*zr_debug >= num) \
167 printk(format, ##args); \
168 } while (0)
169
170int zoran_num; /* number of Buzs in use */ 165int zoran_num; /* number of Buzs in use */
171struct zoran zoran[BUZ_MAX]; 166struct zoran zoran[BUZ_MAX];
172 167
@@ -1075,7 +1070,7 @@ test_interrupts (struct zoran *zr)
1075 if (timeout) { 1070 if (timeout) {
1076 dprintk(1, ": time spent: %d\n", 1 * HZ - timeout); 1071 dprintk(1, ": time spent: %d\n", 1 * HZ - timeout);
1077 } 1072 }
1078 if (*zr_debug > 1) 1073 if (zr36067_debug > 1)
1079 print_interrupts(zr); 1074 print_interrupts(zr);
1080 btwrite(icr, ZR36057_ICR); 1075 btwrite(icr, ZR36057_ICR);
1081} 1076}
@@ -1121,7 +1116,14 @@ zr36057_init (struct zoran *zr)
1121 zr->timing = zr->card.tvn[zr->norm]; 1116 zr->timing = zr->card.tvn[zr->norm];
1122 } 1117 }
1123 1118
1124 zr->input = default_input = (default_input ? 1 : 0); 1119 if (default_input > zr->card.inputs-1) {
1120 dprintk(1,
1121 KERN_WARNING
1122 "%s: default_input value %d out of range (0-%d)\n",
1123 ZR_DEVNAME(zr), default_input, zr->card.inputs-1);
1124 default_input = 0;
1125 }
1126 zr->input = default_input;
1125 1127
1126 /* Should the following be reset at every open ? */ 1128 /* Should the following be reset at every open ? */
1127 zr->hue = 32768; 1129 zr->hue = 32768;
@@ -1153,12 +1155,12 @@ zr36057_init (struct zoran *zr)
1153 */ 1155 */
1154 memcpy(zr->video_dev, &zoran_template, sizeof(zoran_template)); 1156 memcpy(zr->video_dev, &zoran_template, sizeof(zoran_template));
1155 strcpy(zr->video_dev->name, ZR_DEVNAME(zr)); 1157 strcpy(zr->video_dev->name, ZR_DEVNAME(zr));
1156 err = video_register_device(zr->video_dev, VFL_TYPE_GRABBER, video_nr); 1158 err = video_register_device(zr->video_dev, VFL_TYPE_GRABBER, video_nr[zr->id]);
1157 if (err < 0) 1159 if (err < 0)
1158 goto exit_unregister; 1160 goto exit_unregister;
1159 1161
1160 zoran_init_hardware(zr); 1162 zoran_init_hardware(zr);
1161 if (*zr_debug > 2) 1163 if (zr36067_debug > 2)
1162 detect_guest_activity(zr); 1164 detect_guest_activity(zr);
1163 test_interrupts(zr); 1165 test_interrupts(zr);
1164 if (!pass_through) { 1166 if (!pass_through) {
@@ -1620,7 +1622,7 @@ init_dc10_cards (void)
1620 } 1622 }
1621 1623
1622 /* random nonsense */ 1624 /* random nonsense */
1623 dprintk(5, KERN_DEBUG "Jotti is een held!\n"); 1625 dprintk(6, KERN_DEBUG "Jotti is een held!\n");
1624 1626
1625 /* some mainboards might not do PCI-PCI data transfer well */ 1627 /* some mainboards might not do PCI-PCI data transfer well */
1626 if (pci_pci_problems & (PCIPCI_FAIL|PCIAGP_FAIL|PCIPCI_ALIMAGIK)) { 1628 if (pci_pci_problems & (PCIPCI_FAIL|PCIAGP_FAIL|PCIPCI_ALIMAGIK)) {
diff --git a/drivers/media/video/zoran_card.h b/drivers/media/video/zoran_card.h
index ad997c30bee5..8444ca0a5f3f 100644
--- a/drivers/media/video/zoran_card.h
+++ b/drivers/media/video/zoran_card.h
@@ -30,6 +30,14 @@
30#ifndef __ZORAN_CARD_H__ 30#ifndef __ZORAN_CARD_H__
31#define __ZORAN_CARD_H__ 31#define __ZORAN_CARD_H__
32 32
33extern int zr36067_debug;
34
35#define dprintk(num, format, args...) \
36 do { \
37 if (zr36067_debug >= num) \
38 printk(format, ##args); \
39 } while (0)
40
33/* Anybody who uses more than four? */ 41/* Anybody who uses more than four? */
34#define BUZ_MAX 4 42#define BUZ_MAX 4
35extern int zoran_num; 43extern int zoran_num;
diff --git a/drivers/media/video/zoran_device.c b/drivers/media/video/zoran_device.c
index ba2f4ed29483..68c7c505587e 100644
--- a/drivers/media/video/zoran_device.c
+++ b/drivers/media/video/zoran_device.c
@@ -52,6 +52,7 @@
52#include "videocodec.h" 52#include "videocodec.h"
53#include "zoran.h" 53#include "zoran.h"
54#include "zoran_device.h" 54#include "zoran_device.h"
55#include "zoran_card.h"
55 56
56#define IRQ_MASK ( ZR36057_ISR_GIRQ0 | \ 57#define IRQ_MASK ( ZR36057_ISR_GIRQ0 | \
57 ZR36057_ISR_GIRQ1 | \ 58 ZR36057_ISR_GIRQ1 | \
@@ -59,14 +60,6 @@
59 60
60extern const struct zoran_format zoran_formats[]; 61extern const struct zoran_format zoran_formats[];
61 62
62extern int *zr_debug;
63
64#define dprintk(num, format, args...) \
65 do { \
66 if (*zr_debug >= num) \
67 printk(format, ##args); \
68 } while (0)
69
70static int lml33dpath = 0; /* 1 will use digital path in capture 63static int lml33dpath = 0; /* 1 will use digital path in capture
71 * mode instead of analog. It can be 64 * mode instead of analog. It can be
72 * used for picture adjustments using 65 * used for picture adjustments using
@@ -76,7 +69,7 @@ static int lml33dpath = 0; /* 1 will use digital path in capture
76 * load on Bt819 input, there will be 69 * load on Bt819 input, there will be
77 * some image imperfections */ 70 * some image imperfections */
78 71
79module_param(lml33dpath, bool, 0); 72module_param(lml33dpath, bool, 0644);
80MODULE_PARM_DESC(lml33dpath, 73MODULE_PARM_DESC(lml33dpath,
81 "Use digital path capture mode (on LML33 cards)"); 74 "Use digital path capture mode (on LML33 cards)");
82 75
@@ -174,7 +167,7 @@ post_office_read (struct zoran *zr,
174static void 167static void
175dump_guests (struct zoran *zr) 168dump_guests (struct zoran *zr)
176{ 169{
177 if (*zr_debug > 2) { 170 if (zr36067_debug > 2) {
178 int i, guest[8]; 171 int i, guest[8];
179 172
180 for (i = 1; i < 8; i++) { // Don't read jpeg codec here 173 for (i = 1; i < 8; i++) { // Don't read jpeg codec here
@@ -1271,7 +1264,7 @@ error_handler (struct zoran *zr,
1271 zr->num_errors++; 1264 zr->num_errors++;
1272 1265
1273 /* Report error */ 1266 /* Report error */
1274 if (*zr_debug > 1 && zr->num_errors <= 8) { 1267 if (zr36067_debug > 1 && zr->num_errors <= 8) {
1275 long frame; 1268 long frame;
1276 frame = 1269 frame =
1277 zr->jpg_pend[zr->jpg_dma_tail & BUZ_MASK_FRAME]; 1270 zr->jpg_pend[zr->jpg_dma_tail & BUZ_MASK_FRAME];
@@ -1531,7 +1524,7 @@ zoran_irq (int irq,
1531 1524
1532 if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS || 1525 if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS ||
1533 zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) { 1526 zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) {
1534 if (*zr_debug > 1 && 1527 if (zr36067_debug > 1 &&
1535 (!zr->frame_num || zr->JPEG_error)) { 1528 (!zr->frame_num || zr->JPEG_error)) {
1536 printk(KERN_INFO 1529 printk(KERN_INFO
1537 "%s: first frame ready: state=0x%08x odd_even=%d field_per_buff=%d delay=%d\n", 1530 "%s: first frame ready: state=0x%08x odd_even=%d field_per_buff=%d delay=%d\n",
@@ -1568,7 +1561,7 @@ zoran_irq (int irq,
1568 zr->JPEG_missed; 1561 zr->JPEG_missed;
1569 } 1562 }
1570 1563
1571 if (*zr_debug > 2 && zr->frame_num < 6) { 1564 if (zr36067_debug > 2 && zr->frame_num < 6) {
1572 int i; 1565 int i;
1573 printk("%s: seq=%ld stat_com:", 1566 printk("%s: seq=%ld stat_com:",
1574 ZR_DEVNAME(zr), zr->jpg_seq_num); 1567 ZR_DEVNAME(zr), zr->jpg_seq_num);
diff --git a/drivers/media/video/zoran_driver.c b/drivers/media/video/zoran_driver.c
index 72a037b75d63..1c14fa2bd411 100644
--- a/drivers/media/video/zoran_driver.c
+++ b/drivers/media/video/zoran_driver.c
@@ -200,14 +200,6 @@ const struct zoran_format zoran_formats[] = {
200// RJ: Test only - want to test BUZ_USE_HIMEM even when CONFIG_BIGPHYS_AREA is defined 200// RJ: Test only - want to test BUZ_USE_HIMEM even when CONFIG_BIGPHYS_AREA is defined
201 201
202 202
203extern int *zr_debug;
204
205#define dprintk(num, format, args...) \
206 do { \
207 if (*zr_debug >= num) \
208 printk(format, ##args); \
209 } while (0)
210
211extern int v4l_nbufs; 203extern int v4l_nbufs;
212extern int v4l_bufsize; 204extern int v4l_bufsize;
213extern int jpg_nbufs; 205extern int jpg_nbufs;
@@ -215,8 +207,8 @@ extern int jpg_bufsize;
215extern int pass_through; 207extern int pass_through;
216 208
217static int lock_norm = 0; /* 1=Don't change TV standard (norm) */ 209static int lock_norm = 0; /* 1=Don't change TV standard (norm) */
218module_param(lock_norm, int, 0); 210module_param(lock_norm, int, 0644);
219MODULE_PARM_DESC(lock_norm, "Users can't change norm"); 211MODULE_PARM_DESC(lock_norm, "Prevent norm changes (1 = ignore, >1 = fail)");
220 212
221#ifdef CONFIG_VIDEO_V4L2 213#ifdef CONFIG_VIDEO_V4L2
222 /* small helper function for calculating buffersizes for v4l2 214 /* small helper function for calculating buffersizes for v4l2
@@ -347,10 +339,7 @@ v4l_fbuffer_alloc (struct file *file)
347 if (fh->v4l_buffers.buffer_size <= MAX_KMALLOC_MEM) { 339 if (fh->v4l_buffers.buffer_size <= MAX_KMALLOC_MEM) {
348 /* Use kmalloc */ 340 /* Use kmalloc */
349 341
350 mem = 342 mem = kmalloc(fh->v4l_buffers.buffer_size, GFP_KERNEL);
351 (unsigned char *) kmalloc(fh->v4l_buffers.
352 buffer_size,
353 GFP_KERNEL);
354 if (mem == 0) { 343 if (mem == 0) {
355 dprintk(1, 344 dprintk(1,
356 KERN_ERR 345 KERN_ERR
@@ -1106,12 +1095,10 @@ jpg_sync (struct file *file,
1106 frame = zr->jpg_pend[zr->jpg_que_tail & BUZ_MASK_FRAME]; 1095 frame = zr->jpg_pend[zr->jpg_que_tail & BUZ_MASK_FRAME];
1107 1096
1108 /* buffer should now be in BUZ_STATE_DONE */ 1097 /* buffer should now be in BUZ_STATE_DONE */
1109 if (*zr_debug > 0) 1098 if (zr->jpg_buffers.buffer[frame].state != BUZ_STATE_DONE)
1110 if (zr->jpg_buffers.buffer[frame].state != BUZ_STATE_DONE) 1099 dprintk(2,
1111 dprintk(2, 1100 KERN_ERR "%s: jpg_sync() - internal state error\n",
1112 KERN_ERR 1101 ZR_DEVNAME(zr));
1113 "%s: jpg_sync() - internal state error\n",
1114 ZR_DEVNAME(zr));
1115 1102
1116 *bs = zr->jpg_buffers.buffer[frame].bs; 1103 *bs = zr->jpg_buffers.buffer[frame].bs;
1117 bs->frame = frame; 1104 bs->frame = frame;
@@ -1389,7 +1376,7 @@ zoran_close (struct inode *inode,
1389 /* disable interrupts */ 1376 /* disable interrupts */
1390 btand(~ZR36057_ICR_IntPinEn, ZR36057_ICR); 1377 btand(~ZR36057_ICR_IntPinEn, ZR36057_ICR);
1391 1378
1392 if (*zr_debug > 1) 1379 if (zr36067_debug > 1)
1393 print_interrupts(zr); 1380 print_interrupts(zr);
1394 1381
1395 /* Overlay off */ 1382 /* Overlay off */
@@ -3206,7 +3193,7 @@ zoran_do_ioctl (struct inode *inode,
3206 "%s: VIDIOC_QUERYBUF - index=%d, type=%d\n", 3193 "%s: VIDIOC_QUERYBUF - index=%d, type=%d\n",
3207 ZR_DEVNAME(zr), buf->index, buf->type); 3194 ZR_DEVNAME(zr), buf->index, buf->type);
3208 3195
3209 memset(buf, 0, sizeof(buf)); 3196 memset(buf, 0, sizeof(*buf));
3210 buf->type = type; 3197 buf->type = type;
3211 buf->index = index; 3198 buf->index = index;
3212 3199
diff --git a/drivers/media/video/zoran_procfs.c b/drivers/media/video/zoran_procfs.c
index 446ae8d5c3df..328ed6e7ac6a 100644
--- a/drivers/media/video/zoran_procfs.c
+++ b/drivers/media/video/zoran_procfs.c
@@ -48,14 +48,7 @@
48#include "videocodec.h" 48#include "videocodec.h"
49#include "zoran.h" 49#include "zoran.h"
50#include "zoran_procfs.h" 50#include "zoran_procfs.h"
51 51#include "zoran_card.h"
52extern int *zr_debug;
53
54#define dprintk(num, format, args...) \
55 do { \
56 if (*zr_debug >= num) \
57 printk(format, ##args); \
58 } while (0)
59 52
60#ifdef CONFIG_PROC_FS 53#ifdef CONFIG_PROC_FS
61struct procfs_params_zr36067 { 54struct procfs_params_zr36067 {
diff --git a/drivers/media/video/zr36016.c b/drivers/media/video/zr36016.c
index 62f77584fb85..dd084555da8f 100644
--- a/drivers/media/video/zr36016.c
+++ b/drivers/media/video/zr36016.c
@@ -38,11 +38,11 @@
38 #include<linux/videodev.h> */ 38 #include<linux/videodev.h> */
39 39
40/* I/O commands, error codes */ 40/* I/O commands, error codes */
41#include<asm/io.h> 41#include <asm/io.h>
42//#include<errno.h> 42//#include<errno.h>
43 43
44/* v4l API */ 44/* v4l API */
45#include<linux/videodev.h> 45#include <linux/videodev.h>
46 46
47/* headerfile of this module */ 47/* headerfile of this module */
48#include"zr36016.h" 48#include"zr36016.h"
diff --git a/drivers/media/video/zr36050.c b/drivers/media/video/zr36050.c
index a6bbd125631c..9f622e00c479 100644
--- a/drivers/media/video/zr36050.c
+++ b/drivers/media/video/zr36050.c
@@ -38,14 +38,14 @@
38 #include<linux/videodev.h> */ 38 #include<linux/videodev.h> */
39 39
40/* I/O commands, error codes */ 40/* I/O commands, error codes */
41#include<asm/io.h> 41#include <asm/io.h>
42//#include<errno.h> 42//#include<errno.h>
43 43
44/* headerfile of this module */ 44/* headerfile of this module */
45#include"zr36050.h" 45#include "zr36050.h"
46 46
47/* codec io API */ 47/* codec io API */
48#include"videocodec.h" 48#include "videocodec.h"
49 49
50/* it doesn't make sense to have more than 20 or so, 50/* it doesn't make sense to have more than 20 or so,
51 just to prevent some unwanted loops */ 51 just to prevent some unwanted loops */
diff --git a/drivers/media/video/zr36060.c b/drivers/media/video/zr36060.c
index 97c8f9b9dc12..1ef14fef08e6 100644
--- a/drivers/media/video/zr36060.c
+++ b/drivers/media/video/zr36060.c
@@ -38,14 +38,14 @@
38 #include<linux/videodev.h> */ 38 #include<linux/videodev.h> */
39 39
40/* I/O commands, error codes */ 40/* I/O commands, error codes */
41#include<asm/io.h> 41#include <asm/io.h>
42//#include<errno.h> 42//#include<errno.h>
43 43
44/* headerfile of this module */ 44/* headerfile of this module */
45#include"zr36060.h" 45#include "zr36060.h"
46 46
47/* codec io API */ 47/* codec io API */
48#include"videocodec.h" 48#include "videocodec.h"
49 49
50/* it doesn't make sense to have more than 20 or so, 50/* it doesn't make sense to have more than 20 or so,
51 just to prevent some unwanted loops */ 51 just to prevent some unwanted loops */
diff --git a/drivers/mmc/card/Kconfig b/drivers/mmc/card/Kconfig
index a49cb9737cd8..aa8a4e461942 100644
--- a/drivers/mmc/card/Kconfig
+++ b/drivers/mmc/card/Kconfig
@@ -32,3 +32,10 @@ config MMC_BLOCK_BOUNCE
32 32
33 If unsure, say Y here. 33 If unsure, say Y here.
34 34
35config SDIO_UART
36 tristate "SDIO UART/GPS class support"
37 depends on MMC
38 help
39 SDIO function driver for SDIO cards that implements the UART
40 class, as well as the GPS class which appears like a UART.
41
diff --git a/drivers/mmc/card/Makefile b/drivers/mmc/card/Makefile
index cf8c939867f5..fc5a784cfa1a 100644
--- a/drivers/mmc/card/Makefile
+++ b/drivers/mmc/card/Makefile
@@ -9,3 +9,5 @@ endif
9obj-$(CONFIG_MMC_BLOCK) += mmc_block.o 9obj-$(CONFIG_MMC_BLOCK) += mmc_block.o
10mmc_block-objs := block.o queue.o 10mmc_block-objs := block.o queue.o
11 11
12obj-$(CONFIG_SDIO_UART) += sdio_uart.o
13
diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index 93fe2e5dd616..e38d5a3b2a89 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -151,17 +151,19 @@ static u32 mmc_sd_num_wr_blocks(struct mmc_card *card)
151 151
152 cmd.opcode = MMC_APP_CMD; 152 cmd.opcode = MMC_APP_CMD;
153 cmd.arg = card->rca << 16; 153 cmd.arg = card->rca << 16;
154 cmd.flags = MMC_RSP_R1 | MMC_CMD_AC; 154 cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC;
155 155
156 err = mmc_wait_for_cmd(card->host, &cmd, 0); 156 err = mmc_wait_for_cmd(card->host, &cmd, 0);
157 if ((err != MMC_ERR_NONE) || !(cmd.resp[0] & R1_APP_CMD)) 157 if (err)
158 return (u32)-1;
159 if (!mmc_host_is_spi(card->host) && !(cmd.resp[0] & R1_APP_CMD))
158 return (u32)-1; 160 return (u32)-1;
159 161
160 memset(&cmd, 0, sizeof(struct mmc_command)); 162 memset(&cmd, 0, sizeof(struct mmc_command));
161 163
162 cmd.opcode = SD_APP_SEND_NUM_WR_BLKS; 164 cmd.opcode = SD_APP_SEND_NUM_WR_BLKS;
163 cmd.arg = 0; 165 cmd.arg = 0;
164 cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC; 166 cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
165 167
166 memset(&data, 0, sizeof(struct mmc_data)); 168 memset(&data, 0, sizeof(struct mmc_data));
167 169
@@ -192,7 +194,7 @@ static u32 mmc_sd_num_wr_blocks(struct mmc_card *card)
192 194
193 mmc_wait_for_req(card->host, &mrq); 195 mmc_wait_for_req(card->host, &mrq);
194 196
195 if (cmd.error != MMC_ERR_NONE || data.error != MMC_ERR_NONE) 197 if (cmd.error || data.error)
196 return (u32)-1; 198 return (u32)-1;
197 199
198 blocks = ntohl(blocks); 200 blocks = ntohl(blocks);
@@ -220,17 +222,15 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
220 brq.cmd.arg = req->sector; 222 brq.cmd.arg = req->sector;
221 if (!mmc_card_blockaddr(card)) 223 if (!mmc_card_blockaddr(card))
222 brq.cmd.arg <<= 9; 224 brq.cmd.arg <<= 9;
223 brq.cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC; 225 brq.cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
224 brq.data.blksz = 1 << md->block_bits; 226 brq.data.blksz = 1 << md->block_bits;
225 brq.stop.opcode = MMC_STOP_TRANSMISSION; 227 brq.stop.opcode = MMC_STOP_TRANSMISSION;
226 brq.stop.arg = 0; 228 brq.stop.arg = 0;
227 brq.stop.flags = MMC_RSP_R1B | MMC_CMD_AC; 229 brq.stop.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC;
228 brq.data.blocks = req->nr_sectors >> (md->block_bits - 9); 230 brq.data.blocks = req->nr_sectors >> (md->block_bits - 9);
229 if (brq.data.blocks > card->host->max_blk_count) 231 if (brq.data.blocks > card->host->max_blk_count)
230 brq.data.blocks = card->host->max_blk_count; 232 brq.data.blocks = card->host->max_blk_count;
231 233
232 mmc_set_data_timeout(&brq.data, card, rq_data_dir(req) != READ);
233
234 /* 234 /*
235 * If the host doesn't support multiple block writes, force 235 * If the host doesn't support multiple block writes, force
236 * block writes to single block. SD cards are excepted from 236 * block writes to single block. SD cards are excepted from
@@ -243,8 +243,12 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
243 brq.data.blocks = 1; 243 brq.data.blocks = 1;
244 244
245 if (brq.data.blocks > 1) { 245 if (brq.data.blocks > 1) {
246 brq.data.flags |= MMC_DATA_MULTI; 246 /* SPI multiblock writes terminate using a special
247 brq.mrq.stop = &brq.stop; 247 * token, not a STOP_TRANSMISSION request.
248 */
249 if (!mmc_host_is_spi(card->host)
250 || rq_data_dir(req) == READ)
251 brq.mrq.stop = &brq.stop;
248 readcmd = MMC_READ_MULTIPLE_BLOCK; 252 readcmd = MMC_READ_MULTIPLE_BLOCK;
249 writecmd = MMC_WRITE_MULTIPLE_BLOCK; 253 writecmd = MMC_WRITE_MULTIPLE_BLOCK;
250 } else { 254 } else {
@@ -261,6 +265,8 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
261 brq.data.flags |= MMC_DATA_WRITE; 265 brq.data.flags |= MMC_DATA_WRITE;
262 } 266 }
263 267
268 mmc_set_data_timeout(&brq.data, card);
269
264 brq.data.sg = mq->sg; 270 brq.data.sg = mq->sg;
265 brq.data.sg_len = mmc_queue_map_sg(mq); 271 brq.data.sg_len = mmc_queue_map_sg(mq);
266 272
@@ -302,7 +308,7 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
302 goto cmd_err; 308 goto cmd_err;
303 } 309 }
304 310
305 if (rq_data_dir(req) != READ) { 311 if (!mmc_host_is_spi(card->host) && rq_data_dir(req) != READ) {
306 do { 312 do {
307 int err; 313 int err;
308 314
@@ -510,7 +516,7 @@ mmc_blk_set_blksize(struct mmc_blk_data *md, struct mmc_card *card)
510 mmc_claim_host(card->host); 516 mmc_claim_host(card->host);
511 cmd.opcode = MMC_SET_BLOCKLEN; 517 cmd.opcode = MMC_SET_BLOCKLEN;
512 cmd.arg = 1 << md->block_bits; 518 cmd.arg = 1 << md->block_bits;
513 cmd.flags = MMC_RSP_R1 | MMC_CMD_AC; 519 cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC;
514 err = mmc_wait_for_cmd(card->host, &cmd, 5); 520 err = mmc_wait_for_cmd(card->host, &cmd, 5);
515 mmc_release_host(card->host); 521 mmc_release_host(card->host);
516 522
diff --git a/drivers/mmc/card/sdio_uart.c b/drivers/mmc/card/sdio_uart.c
new file mode 100644
index 000000000000..d552de683110
--- /dev/null
+++ b/drivers/mmc/card/sdio_uart.c
@@ -0,0 +1,1158 @@
1/*
2 * linux/drivers/mmc/card/sdio_uart.c - SDIO UART/GPS driver
3 *
4 * Based on drivers/serial/8250.c and drivers/serial/serial_core.c
5 * by Russell King.
6 *
7 * Author: Nicolas Pitre
8 * Created: June 15, 2007
9 * Copyright: MontaVista Software, Inc.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or (at
14 * your option) any later version.
15 */
16
17/*
18 * Note: Although this driver assumes a 16550A-like UART implementation,
19 * it is not possible to leverage the common 8250/16550 driver, nor the
20 * core UART infrastructure, as they assumes direct access to the hardware
21 * registers, often under a spinlock. This is not possible in the SDIO
22 * context as SDIO access functions must be able to sleep.
23 *
24 * Because we need to lock the SDIO host to ensure an exclusive access to
25 * the card, we simply rely on that lock to also prevent and serialize
26 * concurrent access to the same port.
27 */
28
29#include <linux/module.h>
30#include <linux/init.h>
31#include <linux/kernel.h>
32#include <linux/mutex.h>
33#include <linux/serial_reg.h>
34#include <linux/circ_buf.h>
35#include <linux/gfp.h>
36#include <linux/tty.h>
37#include <linux/tty_flip.h>
38
39#include <linux/mmc/core.h>
40#include <linux/mmc/card.h>
41#include <linux/mmc/sdio_func.h>
42#include <linux/mmc/sdio_ids.h>
43
44
45#define UART_NR 8 /* Number of UARTs this driver can handle */
46
47
48#define UART_XMIT_SIZE PAGE_SIZE
49#define WAKEUP_CHARS 256
50
51#define circ_empty(circ) ((circ)->head == (circ)->tail)
52#define circ_clear(circ) ((circ)->head = (circ)->tail = 0)
53
54#define circ_chars_pending(circ) \
55 (CIRC_CNT((circ)->head, (circ)->tail, UART_XMIT_SIZE))
56
57#define circ_chars_free(circ) \
58 (CIRC_SPACE((circ)->head, (circ)->tail, UART_XMIT_SIZE))
59
60
61struct uart_icount {
62 __u32 cts;
63 __u32 dsr;
64 __u32 rng;
65 __u32 dcd;
66 __u32 rx;
67 __u32 tx;
68 __u32 frame;
69 __u32 overrun;
70 __u32 parity;
71 __u32 brk;
72};
73
74struct sdio_uart_port {
75 struct kref kref;
76 struct tty_struct *tty;
77 unsigned int index;
78 unsigned int opened;
79 struct mutex open_lock;
80 struct sdio_func *func;
81 struct mutex func_lock;
82 struct task_struct *in_sdio_uart_irq;
83 unsigned int regs_offset;
84 struct circ_buf xmit;
85 spinlock_t write_lock;
86 struct uart_icount icount;
87 unsigned int uartclk;
88 unsigned int mctrl;
89 unsigned int read_status_mask;
90 unsigned int ignore_status_mask;
91 unsigned char x_char;
92 unsigned char ier;
93 unsigned char lcr;
94};
95
96static struct sdio_uart_port *sdio_uart_table[UART_NR];
97static DEFINE_SPINLOCK(sdio_uart_table_lock);
98
99static int sdio_uart_add_port(struct sdio_uart_port *port)
100{
101 int index, ret = -EBUSY;
102
103 kref_init(&port->kref);
104 mutex_init(&port->open_lock);
105 mutex_init(&port->func_lock);
106 spin_lock_init(&port->write_lock);
107
108 spin_lock(&sdio_uart_table_lock);
109 for (index = 0; index < UART_NR; index++) {
110 if (!sdio_uart_table[index]) {
111 port->index = index;
112 sdio_uart_table[index] = port;
113 ret = 0;
114 break;
115 }
116 }
117 spin_unlock(&sdio_uart_table_lock);
118
119 return ret;
120}
121
122static struct sdio_uart_port *sdio_uart_port_get(unsigned index)
123{
124 struct sdio_uart_port *port;
125
126 if (index >= UART_NR)
127 return NULL;
128
129 spin_lock(&sdio_uart_table_lock);
130 port = sdio_uart_table[index];
131 if (port)
132 kref_get(&port->kref);
133 spin_unlock(&sdio_uart_table_lock);
134
135 return port;
136}
137
138static void sdio_uart_port_destroy(struct kref *kref)
139{
140 struct sdio_uart_port *port =
141 container_of(kref, struct sdio_uart_port, kref);
142 kfree(port);
143}
144
145static void sdio_uart_port_put(struct sdio_uart_port *port)
146{
147 kref_put(&port->kref, sdio_uart_port_destroy);
148}
149
150static void sdio_uart_port_remove(struct sdio_uart_port *port)
151{
152 struct sdio_func *func;
153
154 BUG_ON(sdio_uart_table[port->index] != port);
155
156 spin_lock(&sdio_uart_table_lock);
157 sdio_uart_table[port->index] = NULL;
158 spin_unlock(&sdio_uart_table_lock);
159
160 /*
161 * We're killing a port that potentially still is in use by
162 * the tty layer. Be careful to prevent any further access
163 * to the SDIO function and arrange for the tty layer to
164 * give up on that port ASAP.
165 * Beware: the lock ordering is critical.
166 */
167 mutex_lock(&port->open_lock);
168 mutex_lock(&port->func_lock);
169 func = port->func;
170 sdio_claim_host(func);
171 port->func = NULL;
172 mutex_unlock(&port->func_lock);
173 if (port->opened)
174 tty_hangup(port->tty);
175 mutex_unlock(&port->open_lock);
176 sdio_release_irq(func);
177 sdio_disable_func(func);
178 sdio_release_host(func);
179
180 sdio_uart_port_put(port);
181}
182
183static int sdio_uart_claim_func(struct sdio_uart_port *port)
184{
185 mutex_lock(&port->func_lock);
186 if (unlikely(!port->func)) {
187 mutex_unlock(&port->func_lock);
188 return -ENODEV;
189 }
190 if (likely(port->in_sdio_uart_irq != current))
191 sdio_claim_host(port->func);
192 mutex_unlock(&port->func_lock);
193 return 0;
194}
195
196static inline void sdio_uart_release_func(struct sdio_uart_port *port)
197{
198 if (likely(port->in_sdio_uart_irq != current))
199 sdio_release_host(port->func);
200}
201
202static inline unsigned int sdio_in(struct sdio_uart_port *port, int offset)
203{
204 unsigned char c;
205 c = sdio_readb(port->func, port->regs_offset + offset, NULL);
206 return c;
207}
208
209static inline void sdio_out(struct sdio_uart_port *port, int offset, int value)
210{
211 sdio_writeb(port->func, value, port->regs_offset + offset, NULL);
212}
213
214static unsigned int sdio_uart_get_mctrl(struct sdio_uart_port *port)
215{
216 unsigned char status;
217 unsigned int ret;
218
219 status = sdio_in(port, UART_MSR);
220
221 ret = 0;
222 if (status & UART_MSR_DCD)
223 ret |= TIOCM_CAR;
224 if (status & UART_MSR_RI)
225 ret |= TIOCM_RNG;
226 if (status & UART_MSR_DSR)
227 ret |= TIOCM_DSR;
228 if (status & UART_MSR_CTS)
229 ret |= TIOCM_CTS;
230 return ret;
231}
232
233static void sdio_uart_write_mctrl(struct sdio_uart_port *port, unsigned int mctrl)
234{
235 unsigned char mcr = 0;
236
237 if (mctrl & TIOCM_RTS)
238 mcr |= UART_MCR_RTS;
239 if (mctrl & TIOCM_DTR)
240 mcr |= UART_MCR_DTR;
241 if (mctrl & TIOCM_OUT1)
242 mcr |= UART_MCR_OUT1;
243 if (mctrl & TIOCM_OUT2)
244 mcr |= UART_MCR_OUT2;
245 if (mctrl & TIOCM_LOOP)
246 mcr |= UART_MCR_LOOP;
247
248 sdio_out(port, UART_MCR, mcr);
249}
250
251static inline void sdio_uart_update_mctrl(struct sdio_uart_port *port,
252 unsigned int set, unsigned int clear)
253{
254 unsigned int old;
255
256 old = port->mctrl;
257 port->mctrl = (old & ~clear) | set;
258 if (old != port->mctrl)
259 sdio_uart_write_mctrl(port, port->mctrl);
260}
261
262#define sdio_uart_set_mctrl(port, x) sdio_uart_update_mctrl(port, x, 0)
263#define sdio_uart_clear_mctrl(port, x) sdio_uart_update_mctrl(port, 0, x)
264
265static void sdio_uart_change_speed(struct sdio_uart_port *port,
266 struct ktermios *termios,
267 struct ktermios *old)
268{
269 unsigned char cval, fcr = 0;
270 unsigned int baud, quot;
271
272 switch (termios->c_cflag & CSIZE) {
273 case CS5:
274 cval = UART_LCR_WLEN5;
275 break;
276 case CS6:
277 cval = UART_LCR_WLEN6;
278 break;
279 case CS7:
280 cval = UART_LCR_WLEN7;
281 break;
282 default:
283 case CS8:
284 cval = UART_LCR_WLEN8;
285 break;
286 }
287
288 if (termios->c_cflag & CSTOPB)
289 cval |= UART_LCR_STOP;
290 if (termios->c_cflag & PARENB)
291 cval |= UART_LCR_PARITY;
292 if (!(termios->c_cflag & PARODD))
293 cval |= UART_LCR_EPAR;
294
295 for (;;) {
296 baud = tty_termios_baud_rate(termios);
297 if (baud == 0)
298 baud = 9600; /* Special case: B0 rate. */
299 if (baud <= port->uartclk)
300 break;
301 /*
302 * Oops, the quotient was zero. Try again with the old
303 * baud rate if possible, otherwise default to 9600.
304 */
305 termios->c_cflag &= ~CBAUD;
306 if (old) {
307 termios->c_cflag |= old->c_cflag & CBAUD;
308 old = NULL;
309 } else
310 termios->c_cflag |= B9600;
311 }
312 quot = (2 * port->uartclk + baud) / (2 * baud);
313
314 if (baud < 2400)
315 fcr = UART_FCR_ENABLE_FIFO | UART_FCR_TRIGGER_1;
316 else
317 fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10;
318
319 port->read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR;
320 if (termios->c_iflag & INPCK)
321 port->read_status_mask |= UART_LSR_FE | UART_LSR_PE;
322 if (termios->c_iflag & (BRKINT | PARMRK))
323 port->read_status_mask |= UART_LSR_BI;
324
325 /*
326 * Characters to ignore
327 */
328 port->ignore_status_mask = 0;
329 if (termios->c_iflag & IGNPAR)
330 port->ignore_status_mask |= UART_LSR_PE | UART_LSR_FE;
331 if (termios->c_iflag & IGNBRK) {
332 port->ignore_status_mask |= UART_LSR_BI;
333 /*
334 * If we're ignoring parity and break indicators,
335 * ignore overruns too (for real raw support).
336 */
337 if (termios->c_iflag & IGNPAR)
338 port->ignore_status_mask |= UART_LSR_OE;
339 }
340
341 /*
342 * ignore all characters if CREAD is not set
343 */
344 if ((termios->c_cflag & CREAD) == 0)
345 port->ignore_status_mask |= UART_LSR_DR;
346
347 /*
348 * CTS flow control flag and modem status interrupts
349 */
350 port->ier &= ~UART_IER_MSI;
351 if ((termios->c_cflag & CRTSCTS) || !(termios->c_cflag & CLOCAL))
352 port->ier |= UART_IER_MSI;
353
354 port->lcr = cval;
355
356 sdio_out(port, UART_IER, port->ier);
357 sdio_out(port, UART_LCR, cval | UART_LCR_DLAB);
358 sdio_out(port, UART_DLL, quot & 0xff);
359 sdio_out(port, UART_DLM, quot >> 8);
360 sdio_out(port, UART_LCR, cval);
361 sdio_out(port, UART_FCR, fcr);
362
363 sdio_uart_write_mctrl(port, port->mctrl);
364}
365
366static void sdio_uart_start_tx(struct sdio_uart_port *port)
367{
368 if (!(port->ier & UART_IER_THRI)) {
369 port->ier |= UART_IER_THRI;
370 sdio_out(port, UART_IER, port->ier);
371 }
372}
373
374static void sdio_uart_stop_tx(struct sdio_uart_port *port)
375{
376 if (port->ier & UART_IER_THRI) {
377 port->ier &= ~UART_IER_THRI;
378 sdio_out(port, UART_IER, port->ier);
379 }
380}
381
382static void sdio_uart_stop_rx(struct sdio_uart_port *port)
383{
384 port->ier &= ~UART_IER_RLSI;
385 port->read_status_mask &= ~UART_LSR_DR;
386 sdio_out(port, UART_IER, port->ier);
387}
388
389static void sdio_uart_receive_chars(struct sdio_uart_port *port, int *status)
390{
391 struct tty_struct *tty = port->tty;
392 unsigned int ch, flag;
393 int max_count = 256;
394
395 do {
396 ch = sdio_in(port, UART_RX);
397 flag = TTY_NORMAL;
398 port->icount.rx++;
399
400 if (unlikely(*status & (UART_LSR_BI | UART_LSR_PE |
401 UART_LSR_FE | UART_LSR_OE))) {
402 /*
403 * For statistics only
404 */
405 if (*status & UART_LSR_BI) {
406 *status &= ~(UART_LSR_FE | UART_LSR_PE);
407 port->icount.brk++;
408 } else if (*status & UART_LSR_PE)
409 port->icount.parity++;
410 else if (*status & UART_LSR_FE)
411 port->icount.frame++;
412 if (*status & UART_LSR_OE)
413 port->icount.overrun++;
414
415 /*
416 * Mask off conditions which should be ignored.
417 */
418 *status &= port->read_status_mask;
419 if (*status & UART_LSR_BI) {
420 flag = TTY_BREAK;
421 } else if (*status & UART_LSR_PE)
422 flag = TTY_PARITY;
423 else if (*status & UART_LSR_FE)
424 flag = TTY_FRAME;
425 }
426
427 if ((*status & port->ignore_status_mask & ~UART_LSR_OE) == 0)
428 tty_insert_flip_char(tty, ch, flag);
429
430 /*
431 * Overrun is special. Since it's reported immediately,
432 * it doesn't affect the current character.
433 */
434 if (*status & ~port->ignore_status_mask & UART_LSR_OE)
435 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
436
437 *status = sdio_in(port, UART_LSR);
438 } while ((*status & UART_LSR_DR) && (max_count-- > 0));
439 tty_flip_buffer_push(tty);
440}
441
442static void sdio_uart_transmit_chars(struct sdio_uart_port *port)
443{
444 struct circ_buf *xmit = &port->xmit;
445 int count;
446
447 if (port->x_char) {
448 sdio_out(port, UART_TX, port->x_char);
449 port->icount.tx++;
450 port->x_char = 0;
451 return;
452 }
453 if (circ_empty(xmit) || port->tty->stopped || port->tty->hw_stopped) {
454 sdio_uart_stop_tx(port);
455 return;
456 }
457
458 count = 16;
459 do {
460 sdio_out(port, UART_TX, xmit->buf[xmit->tail]);
461 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
462 port->icount.tx++;
463 if (circ_empty(xmit))
464 break;
465 } while (--count > 0);
466
467 if (circ_chars_pending(xmit) < WAKEUP_CHARS)
468 tty_wakeup(port->tty);
469
470 if (circ_empty(xmit))
471 sdio_uart_stop_tx(port);
472}
473
474static void sdio_uart_check_modem_status(struct sdio_uart_port *port)
475{
476 int status;
477
478 status = sdio_in(port, UART_MSR);
479
480 if ((status & UART_MSR_ANY_DELTA) == 0)
481 return;
482
483 if (status & UART_MSR_TERI)
484 port->icount.rng++;
485 if (status & UART_MSR_DDSR)
486 port->icount.dsr++;
487 if (status & UART_MSR_DDCD)
488 port->icount.dcd++;
489 if (status & UART_MSR_DCTS) {
490 port->icount.cts++;
491 if (port->tty->termios->c_cflag & CRTSCTS) {
492 int cts = (status & UART_MSR_CTS);
493 if (port->tty->hw_stopped) {
494 if (cts) {
495 port->tty->hw_stopped = 0;
496 sdio_uart_start_tx(port);
497 tty_wakeup(port->tty);
498 }
499 } else {
500 if (!cts) {
501 port->tty->hw_stopped = 1;
502 sdio_uart_stop_tx(port);
503 }
504 }
505 }
506 }
507}
508
509/*
510 * This handles the interrupt from one port.
511 */
512static void sdio_uart_irq(struct sdio_func *func)
513{
514 struct sdio_uart_port *port = sdio_get_drvdata(func);
515 unsigned int iir, lsr;
516
517 /*
518 * In a few places sdio_uart_irq() is called directly instead of
519 * waiting for the actual interrupt to be raised and the SDIO IRQ
520 * thread scheduled in order to reduce latency. However, some
521 * interaction with the tty core may end up calling us back
522 * (serial echo, flow control, etc.) through those same places
523 * causing undesirable effects. Let's stop the recursion here.
524 */
525 if (unlikely(port->in_sdio_uart_irq == current))
526 return;
527
528 iir = sdio_in(port, UART_IIR);
529 if (iir & UART_IIR_NO_INT)
530 return;
531
532 port->in_sdio_uart_irq = current;
533 lsr = sdio_in(port, UART_LSR);
534 if (lsr & UART_LSR_DR)
535 sdio_uart_receive_chars(port, &lsr);
536 sdio_uart_check_modem_status(port);
537 if (lsr & UART_LSR_THRE)
538 sdio_uart_transmit_chars(port);
539 port->in_sdio_uart_irq = NULL;
540}
541
542static int sdio_uart_startup(struct sdio_uart_port *port)
543{
544 unsigned long page;
545 int ret;
546
547 /*
548 * Set the TTY IO error marker - we will only clear this
549 * once we have successfully opened the port.
550 */
551 set_bit(TTY_IO_ERROR, &port->tty->flags);
552
553 /* Initialise and allocate the transmit buffer. */
554 page = __get_free_page(GFP_KERNEL);
555 if (!page)
556 return -ENOMEM;
557 port->xmit.buf = (unsigned char *)page;
558 circ_clear(&port->xmit);
559
560 ret = sdio_uart_claim_func(port);
561 if (ret)
562 goto err1;
563 ret = sdio_enable_func(port->func);
564 if (ret)
565 goto err2;
566 ret = sdio_claim_irq(port->func, sdio_uart_irq);
567 if (ret)
568 goto err3;
569
570 /*
571 * Clear the FIFO buffers and disable them.
572 * (they will be reenabled in sdio_change_speed())
573 */
574 sdio_out(port, UART_FCR, UART_FCR_ENABLE_FIFO);
575 sdio_out(port, UART_FCR, UART_FCR_ENABLE_FIFO |
576 UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT);
577 sdio_out(port, UART_FCR, 0);
578
579 /*
580 * Clear the interrupt registers.
581 */
582 (void) sdio_in(port, UART_LSR);
583 (void) sdio_in(port, UART_RX);
584 (void) sdio_in(port, UART_IIR);
585 (void) sdio_in(port, UART_MSR);
586
587 /*
588 * Now, initialize the UART
589 */
590 sdio_out(port, UART_LCR, UART_LCR_WLEN8);
591
592 port->ier = UART_IER_RLSI | UART_IER_RDI | UART_IER_RTOIE | UART_IER_UUE;
593 port->mctrl = TIOCM_OUT2;
594
595 sdio_uart_change_speed(port, port->tty->termios, NULL);
596
597 if (port->tty->termios->c_cflag & CBAUD)
598 sdio_uart_set_mctrl(port, TIOCM_RTS | TIOCM_DTR);
599
600 if (port->tty->termios->c_cflag & CRTSCTS)
601 if (!(sdio_uart_get_mctrl(port) & TIOCM_CTS))
602 port->tty->hw_stopped = 1;
603
604 clear_bit(TTY_IO_ERROR, &port->tty->flags);
605
606 /* Kick the IRQ handler once while we're still holding the host lock */
607 sdio_uart_irq(port->func);
608
609 sdio_uart_release_func(port);
610 return 0;
611
612err3:
613 sdio_disable_func(port->func);
614err2:
615 sdio_uart_release_func(port);
616err1:
617 free_page((unsigned long)port->xmit.buf);
618 return ret;
619}
620
621static void sdio_uart_shutdown(struct sdio_uart_port *port)
622{
623 int ret;
624
625 ret = sdio_uart_claim_func(port);
626 if (ret)
627 goto skip;
628
629 sdio_uart_stop_rx(port);
630
631 /* TODO: wait here for TX FIFO to drain */
632
633 /* Turn off DTR and RTS early. */
634 if (port->tty->termios->c_cflag & HUPCL)
635 sdio_uart_clear_mctrl(port, TIOCM_DTR | TIOCM_RTS);
636
637 /* Disable interrupts from this port */
638 sdio_release_irq(port->func);
639 port->ier = 0;
640 sdio_out(port, UART_IER, 0);
641
642 sdio_uart_clear_mctrl(port, TIOCM_OUT2);
643
644 /* Disable break condition and FIFOs. */
645 port->lcr &= ~UART_LCR_SBC;
646 sdio_out(port, UART_LCR, port->lcr);
647 sdio_out(port, UART_FCR, UART_FCR_ENABLE_FIFO |
648 UART_FCR_CLEAR_RCVR |
649 UART_FCR_CLEAR_XMIT);
650 sdio_out(port, UART_FCR, 0);
651
652 sdio_disable_func(port->func);
653
654 sdio_uart_release_func(port);
655
656skip:
657 /* Free the transmit buffer page. */
658 free_page((unsigned long)port->xmit.buf);
659}
660
661static int sdio_uart_open (struct tty_struct *tty, struct file * filp)
662{
663 struct sdio_uart_port *port;
664 int ret;
665
666 port = sdio_uart_port_get(tty->index);
667 if (!port)
668 return -ENODEV;
669
670 mutex_lock(&port->open_lock);
671
672 /*
673 * Make sure not to mess up with a dead port
674 * which has not been closed yet.
675 */
676 if (tty->driver_data && tty->driver_data != port) {
677 mutex_unlock(&port->open_lock);
678 sdio_uart_port_put(port);
679 return -EBUSY;
680 }
681
682 if (!port->opened) {
683 tty->driver_data = port;
684 port->tty = tty;
685 ret = sdio_uart_startup(port);
686 if (ret) {
687 tty->driver_data = NULL;
688 port->tty = NULL;
689 mutex_unlock(&port->open_lock);
690 sdio_uart_port_put(port);
691 return ret;
692 }
693 }
694 port->opened++;
695 mutex_unlock(&port->open_lock);
696 return 0;
697}
698
699static void sdio_uart_close(struct tty_struct *tty, struct file * filp)
700{
701 struct sdio_uart_port *port = tty->driver_data;
702
703 if (!port)
704 return;
705
706 mutex_lock(&port->open_lock);
707 BUG_ON(!port->opened);
708
709 /*
710 * This is messy. The tty layer calls us even when open()
711 * returned an error. Ignore this close request if tty->count
712 * is larger than port->count.
713 */
714 if (tty->count > port->opened) {
715 mutex_unlock(&port->open_lock);
716 return;
717 }
718
719 if (--port->opened == 0) {
720 tty->closing = 1;
721 sdio_uart_shutdown(port);
722 tty_ldisc_flush(tty);
723 port->tty = NULL;
724 tty->driver_data = NULL;
725 tty->closing = 0;
726 }
727 mutex_unlock(&port->open_lock);
728 sdio_uart_port_put(port);
729}
730
731static int sdio_uart_write(struct tty_struct * tty, const unsigned char *buf,
732 int count)
733{
734 struct sdio_uart_port *port = tty->driver_data;
735 struct circ_buf *circ = &port->xmit;
736 int c, ret = 0;
737
738 if (!port->func)
739 return -ENODEV;
740
741 spin_lock(&port->write_lock);
742 while (1) {
743 c = CIRC_SPACE_TO_END(circ->head, circ->tail, UART_XMIT_SIZE);
744 if (count < c)
745 c = count;
746 if (c <= 0)
747 break;
748 memcpy(circ->buf + circ->head, buf, c);
749 circ->head = (circ->head + c) & (UART_XMIT_SIZE - 1);
750 buf += c;
751 count -= c;
752 ret += c;
753 }
754 spin_unlock(&port->write_lock);
755
756 if ( !(port->ier & UART_IER_THRI)) {
757 int err = sdio_uart_claim_func(port);
758 if (!err) {
759 sdio_uart_start_tx(port);
760 sdio_uart_irq(port->func);
761 sdio_uart_release_func(port);
762 } else
763 ret = err;
764 }
765
766 return ret;
767}
768
769static int sdio_uart_write_room(struct tty_struct *tty)
770{
771 struct sdio_uart_port *port = tty->driver_data;
772 return port ? circ_chars_free(&port->xmit) : 0;
773}
774
775static int sdio_uart_chars_in_buffer(struct tty_struct *tty)
776{
777 struct sdio_uart_port *port = tty->driver_data;
778 return port ? circ_chars_pending(&port->xmit) : 0;
779}
780
781static void sdio_uart_send_xchar(struct tty_struct *tty, char ch)
782{
783 struct sdio_uart_port *port = tty->driver_data;
784
785 port->x_char = ch;
786 if (ch && !(port->ier & UART_IER_THRI)) {
787 if (sdio_uart_claim_func(port) != 0)
788 return;
789 sdio_uart_start_tx(port);
790 sdio_uart_irq(port->func);
791 sdio_uart_release_func(port);
792 }
793}
794
795static void sdio_uart_throttle(struct tty_struct *tty)
796{
797 struct sdio_uart_port *port = tty->driver_data;
798
799 if (!I_IXOFF(tty) && !(tty->termios->c_cflag & CRTSCTS))
800 return;
801
802 if (sdio_uart_claim_func(port) != 0)
803 return;
804
805 if (I_IXOFF(tty)) {
806 port->x_char = STOP_CHAR(tty);
807 sdio_uart_start_tx(port);
808 }
809
810 if (tty->termios->c_cflag & CRTSCTS)
811 sdio_uart_clear_mctrl(port, TIOCM_RTS);
812
813 sdio_uart_irq(port->func);
814 sdio_uart_release_func(port);
815}
816
817static void sdio_uart_unthrottle(struct tty_struct *tty)
818{
819 struct sdio_uart_port *port = tty->driver_data;
820
821 if (!I_IXOFF(tty) && !(tty->termios->c_cflag & CRTSCTS))
822 return;
823
824 if (sdio_uart_claim_func(port) != 0)
825 return;
826
827 if (I_IXOFF(tty)) {
828 if (port->x_char) {
829 port->x_char = 0;
830 } else {
831 port->x_char = START_CHAR(tty);
832 sdio_uart_start_tx(port);
833 }
834 }
835
836 if (tty->termios->c_cflag & CRTSCTS)
837 sdio_uart_set_mctrl(port, TIOCM_RTS);
838
839 sdio_uart_irq(port->func);
840 sdio_uart_release_func(port);
841}
842
843static void sdio_uart_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
844{
845 struct sdio_uart_port *port = tty->driver_data;
846 unsigned int cflag = tty->termios->c_cflag;
847
848#define RELEVANT_IFLAG(iflag) ((iflag) & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
849
850 if ((cflag ^ old_termios->c_cflag) == 0 &&
851 RELEVANT_IFLAG(tty->termios->c_iflag ^ old_termios->c_iflag) == 0)
852 return;
853
854 if (sdio_uart_claim_func(port) != 0)
855 return;
856
857 sdio_uart_change_speed(port, tty->termios, old_termios);
858
859 /* Handle transition to B0 status */
860 if ((old_termios->c_cflag & CBAUD) && !(cflag & CBAUD))
861 sdio_uart_clear_mctrl(port, TIOCM_RTS | TIOCM_DTR);
862
863 /* Handle transition away from B0 status */
864 if (!(old_termios->c_cflag & CBAUD) && (cflag & CBAUD)) {
865 unsigned int mask = TIOCM_DTR;
866 if (!(cflag & CRTSCTS) || !test_bit(TTY_THROTTLED, &tty->flags))
867 mask |= TIOCM_RTS;
868 sdio_uart_set_mctrl(port, mask);
869 }
870
871 /* Handle turning off CRTSCTS */
872 if ((old_termios->c_cflag & CRTSCTS) && !(cflag & CRTSCTS)) {
873 tty->hw_stopped = 0;
874 sdio_uart_start_tx(port);
875 }
876
877 /* Handle turning on CRTSCTS */
878 if (!(old_termios->c_cflag & CRTSCTS) && (cflag & CRTSCTS)) {
879 if (!(sdio_uart_get_mctrl(port) & TIOCM_CTS)) {
880 tty->hw_stopped = 1;
881 sdio_uart_stop_tx(port);
882 }
883 }
884
885 sdio_uart_release_func(port);
886}
887
888static void sdio_uart_break_ctl(struct tty_struct *tty, int break_state)
889{
890 struct sdio_uart_port *port = tty->driver_data;
891
892 if (sdio_uart_claim_func(port) != 0)
893 return;
894
895 if (break_state == -1)
896 port->lcr |= UART_LCR_SBC;
897 else
898 port->lcr &= ~UART_LCR_SBC;
899 sdio_out(port, UART_LCR, port->lcr);
900
901 sdio_uart_release_func(port);
902}
903
904static int sdio_uart_tiocmget(struct tty_struct *tty, struct file *file)
905{
906 struct sdio_uart_port *port = tty->driver_data;
907 int result;
908
909 result = sdio_uart_claim_func(port);
910 if (!result) {
911 result = port->mctrl | sdio_uart_get_mctrl(port);
912 sdio_uart_release_func(port);
913 }
914
915 return result;
916}
917
918static int sdio_uart_tiocmset(struct tty_struct *tty, struct file *file,
919 unsigned int set, unsigned int clear)
920{
921 struct sdio_uart_port *port = tty->driver_data;
922 int result;
923
924 result =sdio_uart_claim_func(port);
925 if(!result) {
926 sdio_uart_update_mctrl(port, set, clear);
927 sdio_uart_release_func(port);
928 }
929
930 return result;
931}
932
933static int sdio_uart_read_proc(char *page, char **start, off_t off,
934 int count, int *eof, void *data)
935{
936 int i, len = 0;
937 off_t begin = 0;
938
939 len += sprintf(page, "serinfo:1.0 driver%s%s revision:%s\n",
940 "", "", "");
941 for (i = 0; i < UART_NR && len < PAGE_SIZE - 96; i++) {
942 struct sdio_uart_port *port = sdio_uart_port_get(i);
943 if (port) {
944 len += sprintf(page+len, "%d: uart:SDIO", i);
945 if(capable(CAP_SYS_ADMIN)) {
946 len += sprintf(page + len, " tx:%d rx:%d",
947 port->icount.tx, port->icount.rx);
948 if (port->icount.frame)
949 len += sprintf(page + len, " fe:%d",
950 port->icount.frame);
951 if (port->icount.parity)
952 len += sprintf(page + len, " pe:%d",
953 port->icount.parity);
954 if (port->icount.brk)
955 len += sprintf(page + len, " brk:%d",
956 port->icount.brk);
957 if (port->icount.overrun)
958 len += sprintf(page + len, " oe:%d",
959 port->icount.overrun);
960 if (port->icount.cts)
961 len += sprintf(page + len, " cts:%d",
962 port->icount.cts);
963 if (port->icount.dsr)
964 len += sprintf(page + len, " dsr:%d",
965 port->icount.dsr);
966 if (port->icount.rng)
967 len += sprintf(page + len, " rng:%d",
968 port->icount.rng);
969 if (port->icount.dcd)
970 len += sprintf(page + len, " dcd:%d",
971 port->icount.dcd);
972 }
973 strcat(page, "\n");
974 len++;
975 sdio_uart_port_put(port);
976 }
977
978 if (len + begin > off + count)
979 goto done;
980 if (len + begin < off) {
981 begin += len;
982 len = 0;
983 }
984 }
985 *eof = 1;
986
987done:
988 if (off >= len + begin)
989 return 0;
990 *start = page + (off - begin);
991 return (count < begin + len - off) ? count : (begin + len - off);
992}
993
994static const struct tty_operations sdio_uart_ops = {
995 .open = sdio_uart_open,
996 .close = sdio_uart_close,
997 .write = sdio_uart_write,
998 .write_room = sdio_uart_write_room,
999 .chars_in_buffer = sdio_uart_chars_in_buffer,
1000 .send_xchar = sdio_uart_send_xchar,
1001 .throttle = sdio_uart_throttle,
1002 .unthrottle = sdio_uart_unthrottle,
1003 .set_termios = sdio_uart_set_termios,
1004 .break_ctl = sdio_uart_break_ctl,
1005 .tiocmget = sdio_uart_tiocmget,
1006 .tiocmset = sdio_uart_tiocmset,
1007 .read_proc = sdio_uart_read_proc,
1008};
1009
1010static struct tty_driver *sdio_uart_tty_driver;
1011
1012static int sdio_uart_probe(struct sdio_func *func,
1013 const struct sdio_device_id *id)
1014{
1015 struct sdio_uart_port *port;
1016 int ret;
1017
1018 port = kzalloc(sizeof(struct sdio_uart_port), GFP_KERNEL);
1019 if (!port)
1020 return -ENOMEM;
1021
1022 if (func->class == SDIO_CLASS_UART) {
1023 printk(KERN_WARNING "%s: need info on UART class basic setup\n",
1024 sdio_func_id(func));
1025 kfree(port);
1026 return -ENOSYS;
1027 } else if (func->class == SDIO_CLASS_GPS) {
1028 /*
1029 * We need tuple 0x91. It contains SUBTPL_SIOREG
1030 * and SUBTPL_RCVCAPS.
1031 */
1032 struct sdio_func_tuple *tpl;
1033 for (tpl = func->tuples; tpl; tpl = tpl->next) {
1034 if (tpl->code != 0x91)
1035 continue;
1036 if (tpl->size < 10)
1037 continue;
1038 if (tpl->data[1] == 0) /* SUBTPL_SIOREG */
1039 break;
1040 }
1041 if (!tpl) {
1042 printk(KERN_WARNING
1043 "%s: can't find tuple 0x91 subtuple 0 (SUBTPL_SIOREG) for GPS class\n",
1044 sdio_func_id(func));
1045 kfree(port);
1046 return -EINVAL;
1047 }
1048 printk(KERN_DEBUG "%s: Register ID = 0x%02x, Exp ID = 0x%02x\n",
1049 sdio_func_id(func), tpl->data[2], tpl->data[3]);
1050 port->regs_offset = (tpl->data[4] << 0) |
1051 (tpl->data[5] << 8) |
1052 (tpl->data[6] << 16);
1053 printk(KERN_DEBUG "%s: regs offset = 0x%x\n",
1054 sdio_func_id(func), port->regs_offset);
1055 port->uartclk = tpl->data[7] * 115200;
1056 if (port->uartclk == 0)
1057 port->uartclk = 115200;
1058 printk(KERN_DEBUG "%s: clk %d baudcode %u 4800-div %u\n",
1059 sdio_func_id(func), port->uartclk,
1060 tpl->data[7], tpl->data[8] | (tpl->data[9] << 8));
1061 } else {
1062 kfree(port);
1063 return -EINVAL;
1064 }
1065
1066 port->func = func;
1067 sdio_set_drvdata(func, port);
1068
1069 ret = sdio_uart_add_port(port);
1070 if (ret) {
1071 kfree(port);
1072 } else {
1073 struct device *dev;
1074 dev = tty_register_device(sdio_uart_tty_driver, port->index, &func->dev);
1075 if (IS_ERR(dev)) {
1076 sdio_uart_port_remove(port);
1077 ret = PTR_ERR(dev);
1078 }
1079 }
1080
1081 return ret;
1082}
1083
1084static void sdio_uart_remove(struct sdio_func *func)
1085{
1086 struct sdio_uart_port *port = sdio_get_drvdata(func);
1087
1088 tty_unregister_device(sdio_uart_tty_driver, port->index);
1089 sdio_uart_port_remove(port);
1090}
1091
1092static const struct sdio_device_id sdio_uart_ids[] = {
1093 { SDIO_DEVICE_CLASS(SDIO_CLASS_UART) },
1094 { SDIO_DEVICE_CLASS(SDIO_CLASS_GPS) },
1095 { /* end: all zeroes */ },
1096};
1097
1098MODULE_DEVICE_TABLE(sdio, sdio_uart_ids);
1099
1100static struct sdio_driver sdio_uart_driver = {
1101 .probe = sdio_uart_probe,
1102 .remove = sdio_uart_remove,
1103 .name = "sdio_uart",
1104 .id_table = sdio_uart_ids,
1105};
1106
1107static int __init sdio_uart_init(void)
1108{
1109 int ret;
1110 struct tty_driver *tty_drv;
1111
1112 sdio_uart_tty_driver = tty_drv = alloc_tty_driver(UART_NR);
1113 if (!tty_drv)
1114 return -ENOMEM;
1115
1116 tty_drv->owner = THIS_MODULE;
1117 tty_drv->driver_name = "sdio_uart";
1118 tty_drv->name = "ttySDIO";
1119 tty_drv->major = 0; /* dynamically allocated */
1120 tty_drv->minor_start = 0;
1121 tty_drv->type = TTY_DRIVER_TYPE_SERIAL;
1122 tty_drv->subtype = SERIAL_TYPE_NORMAL;
1123 tty_drv->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
1124 tty_drv->init_termios = tty_std_termios;
1125 tty_drv->init_termios.c_cflag = B4800 | CS8 | CREAD | HUPCL | CLOCAL;
1126 tty_drv->init_termios.c_ispeed = 4800;
1127 tty_drv->init_termios.c_ospeed = 4800;
1128 tty_set_operations(tty_drv, &sdio_uart_ops);
1129
1130 ret = tty_register_driver(tty_drv);
1131 if (ret)
1132 goto err1;
1133
1134 ret = sdio_register_driver(&sdio_uart_driver);
1135 if (ret)
1136 goto err2;
1137
1138 return 0;
1139
1140err2:
1141 tty_unregister_driver(tty_drv);
1142err1:
1143 put_tty_driver(tty_drv);
1144 return ret;
1145}
1146
1147static void __exit sdio_uart_exit(void)
1148{
1149 sdio_unregister_driver(&sdio_uart_driver);
1150 tty_unregister_driver(sdio_uart_tty_driver);
1151 put_tty_driver(sdio_uart_tty_driver);
1152}
1153
1154module_init(sdio_uart_init);
1155module_exit(sdio_uart_exit);
1156
1157MODULE_AUTHOR("Nicolas Pitre");
1158MODULE_LICENSE("GPL");
diff --git a/drivers/mmc/core/Makefile b/drivers/mmc/core/Makefile
index 3fdd08c7f143..4985807257a8 100644
--- a/drivers/mmc/core/Makefile
+++ b/drivers/mmc/core/Makefile
@@ -8,5 +8,7 @@ endif
8 8
9obj-$(CONFIG_MMC) += mmc_core.o 9obj-$(CONFIG_MMC) += mmc_core.o
10mmc_core-y := core.o sysfs.o bus.o host.o \ 10mmc_core-y := core.o sysfs.o bus.o host.o \
11 mmc.o mmc_ops.o sd.o sd_ops.o 11 mmc.o mmc_ops.o sd.o sd_ops.o \
12 sdio.o sdio_ops.o sdio_bus.o \
13 sdio_cis.o sdio_io.o sdio_irq.o
12 14
diff --git a/drivers/mmc/core/bus.c b/drivers/mmc/core/bus.c
index 817a79462b3d..8d6f6014870f 100644
--- a/drivers/mmc/core/bus.c
+++ b/drivers/mmc/core/bus.c
@@ -19,6 +19,7 @@
19 19
20#include "sysfs.h" 20#include "sysfs.h"
21#include "core.h" 21#include "core.h"
22#include "sdio_cis.h"
22#include "bus.h" 23#include "bus.h"
23 24
24#define dev_to_mmc_card(d) container_of(d, struct mmc_card, dev) 25#define dev_to_mmc_card(d) container_of(d, struct mmc_card, dev)
@@ -34,6 +35,8 @@ static ssize_t mmc_type_show(struct device *dev,
34 return sprintf(buf, "MMC\n"); 35 return sprintf(buf, "MMC\n");
35 case MMC_TYPE_SD: 36 case MMC_TYPE_SD:
36 return sprintf(buf, "SD\n"); 37 return sprintf(buf, "SD\n");
38 case MMC_TYPE_SDIO:
39 return sprintf(buf, "SDIO\n");
37 default: 40 default:
38 return -EFAULT; 41 return -EFAULT;
39 } 42 }
@@ -59,28 +62,34 @@ mmc_bus_uevent(struct device *dev, char **envp, int num_envp, char *buf,
59 int buf_size) 62 int buf_size)
60{ 63{
61 struct mmc_card *card = dev_to_mmc_card(dev); 64 struct mmc_card *card = dev_to_mmc_card(dev);
62 int retval = 0, i = 0, length = 0; 65 const char *type;
63 66 int i = 0, length = 0;
64#define add_env(fmt,val) do { \
65 retval = add_uevent_var(envp, num_envp, &i, \
66 buf, buf_size, &length, \
67 fmt, val); \
68 if (retval) \
69 return retval; \
70} while (0);
71 67
72 switch (card->type) { 68 switch (card->type) {
73 case MMC_TYPE_MMC: 69 case MMC_TYPE_MMC:
74 add_env("MMC_TYPE=%s", "MMC"); 70 type = "MMC";
75 break; 71 break;
76 case MMC_TYPE_SD: 72 case MMC_TYPE_SD:
77 add_env("MMC_TYPE=%s", "SD"); 73 type = "SD";
74 break;
75 case MMC_TYPE_SDIO:
76 type = "SDIO";
78 break; 77 break;
78 default:
79 type = NULL;
79 } 80 }
80 81
81 add_env("MMC_NAME=%s", mmc_card_name(card)); 82 if (type) {
83 if (add_uevent_var(envp, num_envp, &i,
84 buf, buf_size, &length,
85 "MMC_TYPE=%s", type))
86 return -ENOMEM;
87 }
82 88
83#undef add_env 89 if (add_uevent_var(envp, num_envp, &i,
90 buf, buf_size, &length,
91 "MMC_NAME=%s", mmc_card_name(card)))
92 return -ENOMEM;
84 93
85 envp[i] = NULL; 94 envp[i] = NULL;
86 95
@@ -176,6 +185,11 @@ static void mmc_release_card(struct device *dev)
176{ 185{
177 struct mmc_card *card = dev_to_mmc_card(dev); 186 struct mmc_card *card = dev_to_mmc_card(dev);
178 187
188 sdio_free_common_cis(card);
189
190 if (card->info)
191 kfree(card->info);
192
179 kfree(card); 193 kfree(card);
180} 194}
181 195
@@ -221,15 +235,25 @@ int mmc_add_card(struct mmc_card *card)
221 if (mmc_card_blockaddr(card)) 235 if (mmc_card_blockaddr(card))
222 type = "SDHC"; 236 type = "SDHC";
223 break; 237 break;
238 case MMC_TYPE_SDIO:
239 type = "SDIO";
240 break;
224 default: 241 default:
225 type = "?"; 242 type = "?";
226 break; 243 break;
227 } 244 }
228 245
229 printk(KERN_INFO "%s: new %s%s card at address %04x\n", 246 if (mmc_host_is_spi(card->host)) {
230 mmc_hostname(card->host), 247 printk(KERN_INFO "%s: new %s%s card on SPI\n",
231 mmc_card_highspeed(card) ? "high speed " : "", 248 mmc_hostname(card->host),
232 type, card->rca); 249 mmc_card_highspeed(card) ? "high speed " : "",
250 type);
251 } else {
252 printk(KERN_INFO "%s: new %s%s card at address %04x\n",
253 mmc_hostname(card->host),
254 mmc_card_highspeed(card) ? "high speed " : "",
255 type, card->rca);
256 }
233 257
234 card->dev.uevent_suppress = 1; 258 card->dev.uevent_suppress = 1;
235 259
@@ -261,8 +285,13 @@ int mmc_add_card(struct mmc_card *card)
261void mmc_remove_card(struct mmc_card *card) 285void mmc_remove_card(struct mmc_card *card)
262{ 286{
263 if (mmc_card_present(card)) { 287 if (mmc_card_present(card)) {
264 printk(KERN_INFO "%s: card %04x removed\n", 288 if (mmc_host_is_spi(card->host)) {
265 mmc_hostname(card->host), card->rca); 289 printk(KERN_INFO "%s: SPI card removed\n",
290 mmc_hostname(card->host));
291 } else {
292 printk(KERN_INFO "%s: card %04x removed\n",
293 mmc_hostname(card->host), card->rca);
294 }
266 295
267 if (card->host->bus_ops->sysfs_remove) 296 if (card->host->bus_ops->sysfs_remove)
268 card->host->bus_ops->sysfs_remove(card->host, card); 297 card->host->bus_ops->sysfs_remove(card->host, card);
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index bfd2ae5bd669..09435e0ec680 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -18,6 +18,7 @@
18#include <linux/delay.h> 18#include <linux/delay.h>
19#include <linux/pagemap.h> 19#include <linux/pagemap.h>
20#include <linux/err.h> 20#include <linux/err.h>
21#include <linux/leds.h>
21#include <asm/scatterlist.h> 22#include <asm/scatterlist.h>
22#include <linux/scatterlist.h> 23#include <linux/scatterlist.h>
23 24
@@ -29,16 +30,27 @@
29#include "core.h" 30#include "core.h"
30#include "bus.h" 31#include "bus.h"
31#include "host.h" 32#include "host.h"
33#include "sdio_bus.h"
32 34
33#include "mmc_ops.h" 35#include "mmc_ops.h"
34#include "sd_ops.h" 36#include "sd_ops.h"
37#include "sdio_ops.h"
35 38
36extern int mmc_attach_mmc(struct mmc_host *host, u32 ocr); 39extern int mmc_attach_mmc(struct mmc_host *host, u32 ocr);
37extern int mmc_attach_sd(struct mmc_host *host, u32 ocr); 40extern int mmc_attach_sd(struct mmc_host *host, u32 ocr);
41extern int mmc_attach_sdio(struct mmc_host *host, u32 ocr);
38 42
39static struct workqueue_struct *workqueue; 43static struct workqueue_struct *workqueue;
40 44
41/* 45/*
46 * Enabling software CRCs on the data blocks can be a significant (30%)
47 * performance cost, and for other reasons may not always be desired.
48 * So we allow it it to be disabled.
49 */
50int use_spi_crc = 1;
51module_param(use_spi_crc, bool, 0);
52
53/*
42 * Internal function. Schedule delayed work in the MMC work queue. 54 * Internal function. Schedule delayed work in the MMC work queue.
43 */ 55 */
44static int mmc_schedule_delayed_work(struct delayed_work *work, 56static int mmc_schedule_delayed_work(struct delayed_work *work,
@@ -68,6 +80,11 @@ void mmc_request_done(struct mmc_host *host, struct mmc_request *mrq)
68 struct mmc_command *cmd = mrq->cmd; 80 struct mmc_command *cmd = mrq->cmd;
69 int err = cmd->error; 81 int err = cmd->error;
70 82
83 if (err && cmd->retries && mmc_host_is_spi(host)) {
84 if (cmd->resp[0] & R1_SPI_ILLEGAL_COMMAND)
85 cmd->retries = 0;
86 }
87
71 if (err && cmd->retries) { 88 if (err && cmd->retries) {
72 pr_debug("%s: req failed (CMD%u): %d, retrying...\n", 89 pr_debug("%s: req failed (CMD%u): %d, retrying...\n",
73 mmc_hostname(host), cmd->opcode, err); 90 mmc_hostname(host), cmd->opcode, err);
@@ -76,6 +93,8 @@ void mmc_request_done(struct mmc_host *host, struct mmc_request *mrq)
76 cmd->error = 0; 93 cmd->error = 0;
77 host->ops->request(host, mrq); 94 host->ops->request(host, mrq);
78 } else { 95 } else {
96 led_trigger_event(host->led, LED_OFF);
97
79 pr_debug("%s: req done (CMD%u): %d: %08x %08x %08x %08x\n", 98 pr_debug("%s: req done (CMD%u): %d: %08x %08x %08x %08x\n",
80 mmc_hostname(host), cmd->opcode, err, 99 mmc_hostname(host), cmd->opcode, err,
81 cmd->resp[0], cmd->resp[1], 100 cmd->resp[0], cmd->resp[1],
@@ -118,7 +137,7 @@ mmc_start_request(struct mmc_host *host, struct mmc_request *mrq)
118 "tsac %d ms nsac %d\n", 137 "tsac %d ms nsac %d\n",
119 mmc_hostname(host), mrq->data->blksz, 138 mmc_hostname(host), mrq->data->blksz,
120 mrq->data->blocks, mrq->data->flags, 139 mrq->data->blocks, mrq->data->flags,
121 mrq->data->timeout_ns / 10000000, 140 mrq->data->timeout_ns / 1000000,
122 mrq->data->timeout_clks); 141 mrq->data->timeout_clks);
123 } 142 }
124 143
@@ -130,6 +149,8 @@ mmc_start_request(struct mmc_host *host, struct mmc_request *mrq)
130 149
131 WARN_ON(!host->claimed); 150 WARN_ON(!host->claimed);
132 151
152 led_trigger_event(host->led, LED_FULL);
153
133 mrq->cmd->error = 0; 154 mrq->cmd->error = 0;
134 mrq->cmd->mrq = mrq; 155 mrq->cmd->mrq = mrq;
135 if (mrq->data) { 156 if (mrq->data) {
@@ -199,7 +220,7 @@ int mmc_wait_for_cmd(struct mmc_host *host, struct mmc_command *cmd, int retries
199{ 220{
200 struct mmc_request mrq; 221 struct mmc_request mrq;
201 222
202 BUG_ON(!host->claimed); 223 WARN_ON(!host->claimed);
203 224
204 memset(&mrq, 0, sizeof(struct mmc_request)); 225 memset(&mrq, 0, sizeof(struct mmc_request));
205 226
@@ -220,17 +241,24 @@ EXPORT_SYMBOL(mmc_wait_for_cmd);
220 * mmc_set_data_timeout - set the timeout for a data command 241 * mmc_set_data_timeout - set the timeout for a data command
221 * @data: data phase for command 242 * @data: data phase for command
222 * @card: the MMC card associated with the data transfer 243 * @card: the MMC card associated with the data transfer
223 * @write: flag to differentiate reads from writes
224 * 244 *
225 * Computes the data timeout parameters according to the 245 * Computes the data timeout parameters according to the
226 * correct algorithm given the card type. 246 * correct algorithm given the card type.
227 */ 247 */
228void mmc_set_data_timeout(struct mmc_data *data, const struct mmc_card *card, 248void mmc_set_data_timeout(struct mmc_data *data, const struct mmc_card *card)
229 int write)
230{ 249{
231 unsigned int mult; 250 unsigned int mult;
232 251
233 /* 252 /*
253 * SDIO cards only define an upper 1 s limit on access.
254 */
255 if (mmc_card_sdio(card)) {
256 data->timeout_ns = 1000000000;
257 data->timeout_clks = 0;
258 return;
259 }
260
261 /*
234 * SD cards use a 100 multiplier rather than 10 262 * SD cards use a 100 multiplier rather than 10
235 */ 263 */
236 mult = mmc_card_sd(card) ? 100 : 10; 264 mult = mmc_card_sd(card) ? 100 : 10;
@@ -239,7 +267,7 @@ void mmc_set_data_timeout(struct mmc_data *data, const struct mmc_card *card,
239 * Scale up the multiplier (and therefore the timeout) by 267 * Scale up the multiplier (and therefore the timeout) by
240 * the r2w factor for writes. 268 * the r2w factor for writes.
241 */ 269 */
242 if (write) 270 if (data->flags & MMC_DATA_WRITE)
243 mult <<= card->csd.r2w_factor; 271 mult <<= card->csd.r2w_factor;
244 272
245 data->timeout_ns = card->csd.tacc_ns * mult; 273 data->timeout_ns = card->csd.tacc_ns * mult;
@@ -255,7 +283,7 @@ void mmc_set_data_timeout(struct mmc_data *data, const struct mmc_card *card,
255 timeout_us += data->timeout_clks * 1000 / 283 timeout_us += data->timeout_clks * 1000 /
256 (card->host->ios.clock / 1000); 284 (card->host->ios.clock / 1000);
257 285
258 if (write) 286 if (data->flags & MMC_DATA_WRITE)
259 limit_us = 250000; 287 limit_us = 250000;
260 else 288 else
261 limit_us = 100000; 289 limit_us = 100000;
@@ -272,15 +300,20 @@ void mmc_set_data_timeout(struct mmc_data *data, const struct mmc_card *card,
272EXPORT_SYMBOL(mmc_set_data_timeout); 300EXPORT_SYMBOL(mmc_set_data_timeout);
273 301
274/** 302/**
275 * mmc_claim_host - exclusively claim a host 303 * __mmc_claim_host - exclusively claim a host
276 * @host: mmc host to claim 304 * @host: mmc host to claim
305 * @abort: whether or not the operation should be aborted
277 * 306 *
278 * Claim a host for a set of operations. 307 * Claim a host for a set of operations. If @abort is non null and
308 * dereference a non-zero value then this will return prematurely with
309 * that non-zero value without acquiring the lock. Returns zero
310 * with the lock held otherwise.
279 */ 311 */
280void mmc_claim_host(struct mmc_host *host) 312int __mmc_claim_host(struct mmc_host *host, atomic_t *abort)
281{ 313{
282 DECLARE_WAITQUEUE(wait, current); 314 DECLARE_WAITQUEUE(wait, current);
283 unsigned long flags; 315 unsigned long flags;
316 int stop;
284 317
285 might_sleep(); 318 might_sleep();
286 319
@@ -288,19 +321,24 @@ void mmc_claim_host(struct mmc_host *host)
288 spin_lock_irqsave(&host->lock, flags); 321 spin_lock_irqsave(&host->lock, flags);
289 while (1) { 322 while (1) {
290 set_current_state(TASK_UNINTERRUPTIBLE); 323 set_current_state(TASK_UNINTERRUPTIBLE);
291 if (!host->claimed) 324 stop = abort ? atomic_read(abort) : 0;
325 if (stop || !host->claimed)
292 break; 326 break;
293 spin_unlock_irqrestore(&host->lock, flags); 327 spin_unlock_irqrestore(&host->lock, flags);
294 schedule(); 328 schedule();
295 spin_lock_irqsave(&host->lock, flags); 329 spin_lock_irqsave(&host->lock, flags);
296 } 330 }
297 set_current_state(TASK_RUNNING); 331 set_current_state(TASK_RUNNING);
298 host->claimed = 1; 332 if (!stop)
333 host->claimed = 1;
334 else
335 wake_up(&host->wq);
299 spin_unlock_irqrestore(&host->lock, flags); 336 spin_unlock_irqrestore(&host->lock, flags);
300 remove_wait_queue(&host->wq, &wait); 337 remove_wait_queue(&host->wq, &wait);
338 return stop;
301} 339}
302 340
303EXPORT_SYMBOL(mmc_claim_host); 341EXPORT_SYMBOL(__mmc_claim_host);
304 342
305/** 343/**
306 * mmc_release_host - release a host 344 * mmc_release_host - release a host
@@ -313,7 +351,7 @@ void mmc_release_host(struct mmc_host *host)
313{ 351{
314 unsigned long flags; 352 unsigned long flags;
315 353
316 BUG_ON(!host->claimed); 354 WARN_ON(!host->claimed);
317 355
318 spin_lock_irqsave(&host->lock, flags); 356 spin_lock_irqsave(&host->lock, flags);
319 host->claimed = 0; 357 host->claimed = 0;
@@ -433,19 +471,32 @@ static void mmc_power_up(struct mmc_host *host)
433 int bit = fls(host->ocr_avail) - 1; 471 int bit = fls(host->ocr_avail) - 1;
434 472
435 host->ios.vdd = bit; 473 host->ios.vdd = bit;
436 host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN; 474 if (mmc_host_is_spi(host)) {
437 host->ios.chip_select = MMC_CS_DONTCARE; 475 host->ios.chip_select = MMC_CS_HIGH;
476 host->ios.bus_mode = MMC_BUSMODE_PUSHPULL;
477 } else {
478 host->ios.chip_select = MMC_CS_DONTCARE;
479 host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN;
480 }
438 host->ios.power_mode = MMC_POWER_UP; 481 host->ios.power_mode = MMC_POWER_UP;
439 host->ios.bus_width = MMC_BUS_WIDTH_1; 482 host->ios.bus_width = MMC_BUS_WIDTH_1;
440 host->ios.timing = MMC_TIMING_LEGACY; 483 host->ios.timing = MMC_TIMING_LEGACY;
441 mmc_set_ios(host); 484 mmc_set_ios(host);
442 485
443 mmc_delay(1); 486 /*
487 * This delay should be sufficient to allow the power supply
488 * to reach the minimum voltage.
489 */
490 mmc_delay(2);
444 491
445 host->ios.clock = host->f_min; 492 host->ios.clock = host->f_min;
446 host->ios.power_mode = MMC_POWER_ON; 493 host->ios.power_mode = MMC_POWER_ON;
447 mmc_set_ios(host); 494 mmc_set_ios(host);
448 495
496 /*
497 * This delay must be at least 74 clock sizes, or 1 ms, or the
498 * time required to reach a stable voltage.
499 */
449 mmc_delay(2); 500 mmc_delay(2);
450} 501}
451 502
@@ -453,8 +504,10 @@ static void mmc_power_off(struct mmc_host *host)
453{ 504{
454 host->ios.clock = 0; 505 host->ios.clock = 0;
455 host->ios.vdd = 0; 506 host->ios.vdd = 0;
456 host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN; 507 if (!mmc_host_is_spi(host)) {
457 host->ios.chip_select = MMC_CS_DONTCARE; 508 host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN;
509 host->ios.chip_select = MMC_CS_DONTCARE;
510 }
458 host->ios.power_mode = MMC_POWER_OFF; 511 host->ios.power_mode = MMC_POWER_OFF;
459 host->ios.bus_width = MMC_BUS_WIDTH_1; 512 host->ios.bus_width = MMC_BUS_WIDTH_1;
460 host->ios.timing = MMC_TIMING_LEGACY; 513 host->ios.timing = MMC_TIMING_LEGACY;
@@ -511,7 +564,7 @@ void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops)
511 BUG_ON(!host); 564 BUG_ON(!host);
512 BUG_ON(!ops); 565 BUG_ON(!ops);
513 566
514 BUG_ON(!host->claimed); 567 WARN_ON(!host->claimed);
515 568
516 spin_lock_irqsave(&host->lock, flags); 569 spin_lock_irqsave(&host->lock, flags);
517 570
@@ -535,8 +588,8 @@ void mmc_detach_bus(struct mmc_host *host)
535 588
536 BUG_ON(!host); 589 BUG_ON(!host);
537 590
538 BUG_ON(!host->claimed); 591 WARN_ON(!host->claimed);
539 BUG_ON(!host->bus_ops); 592 WARN_ON(!host->bus_ops);
540 593
541 spin_lock_irqsave(&host->lock, flags); 594 spin_lock_irqsave(&host->lock, flags);
542 595
@@ -564,7 +617,7 @@ void mmc_detect_change(struct mmc_host *host, unsigned long delay)
564#ifdef CONFIG_MMC_DEBUG 617#ifdef CONFIG_MMC_DEBUG
565 unsigned long flags; 618 unsigned long flags;
566 spin_lock_irqsave(&host->lock, flags); 619 spin_lock_irqsave(&host->lock, flags);
567 BUG_ON(host->removed); 620 WARN_ON(host->removed);
568 spin_unlock_irqrestore(&host->lock, flags); 621 spin_unlock_irqrestore(&host->lock, flags);
569#endif 622#endif
570 623
@@ -597,24 +650,38 @@ void mmc_rescan(struct work_struct *work)
597 650
598 mmc_send_if_cond(host, host->ocr_avail); 651 mmc_send_if_cond(host, host->ocr_avail);
599 652
653 /*
654 * First we search for SDIO...
655 */
656 err = mmc_send_io_op_cond(host, 0, &ocr);
657 if (!err) {
658 if (mmc_attach_sdio(host, ocr))
659 mmc_power_off(host);
660 return;
661 }
662
663 /*
664 * ...then normal SD...
665 */
600 err = mmc_send_app_op_cond(host, 0, &ocr); 666 err = mmc_send_app_op_cond(host, 0, &ocr);
601 if (err == MMC_ERR_NONE) { 667 if (!err) {
602 if (mmc_attach_sd(host, ocr)) 668 if (mmc_attach_sd(host, ocr))
603 mmc_power_off(host); 669 mmc_power_off(host);
604 } else { 670 return;
605 /* 671 }
606 * If we fail to detect any SD cards then try 672
607 * searching for MMC cards. 673 /*
608 */ 674 * ...and finally MMC.
609 err = mmc_send_op_cond(host, 0, &ocr); 675 */
610 if (err == MMC_ERR_NONE) { 676 err = mmc_send_op_cond(host, 0, &ocr);
611 if (mmc_attach_mmc(host, ocr)) 677 if (!err) {
612 mmc_power_off(host); 678 if (mmc_attach_mmc(host, ocr))
613 } else {
614 mmc_power_off(host); 679 mmc_power_off(host);
615 mmc_release_host(host); 680 return;
616 }
617 } 681 }
682
683 mmc_release_host(host);
684 mmc_power_off(host);
618 } else { 685 } else {
619 if (host->bus_ops->detect && !host->bus_dead) 686 if (host->bus_ops->detect && !host->bus_dead)
620 host->bus_ops->detect(host); 687 host->bus_ops->detect(host);
@@ -725,22 +792,38 @@ static int __init mmc_init(void)
725 return -ENOMEM; 792 return -ENOMEM;
726 793
727 ret = mmc_register_bus(); 794 ret = mmc_register_bus();
728 if (ret == 0) { 795 if (ret)
729 ret = mmc_register_host_class(); 796 goto destroy_workqueue;
730 if (ret) 797
731 mmc_unregister_bus(); 798 ret = mmc_register_host_class();
732 } 799 if (ret)
800 goto unregister_bus;
801
802 ret = sdio_register_bus();
803 if (ret)
804 goto unregister_host_class;
805
806 return 0;
807
808unregister_host_class:
809 mmc_unregister_host_class();
810unregister_bus:
811 mmc_unregister_bus();
812destroy_workqueue:
813 destroy_workqueue(workqueue);
814
733 return ret; 815 return ret;
734} 816}
735 817
736static void __exit mmc_exit(void) 818static void __exit mmc_exit(void)
737{ 819{
820 sdio_unregister_bus();
738 mmc_unregister_host_class(); 821 mmc_unregister_host_class();
739 mmc_unregister_bus(); 822 mmc_unregister_bus();
740 destroy_workqueue(workqueue); 823 destroy_workqueue(workqueue);
741} 824}
742 825
743module_init(mmc_init); 826subsys_initcall(mmc_init);
744module_exit(mmc_exit); 827module_exit(mmc_exit);
745 828
746MODULE_LICENSE("GPL"); 829MODULE_LICENSE("GPL");
diff --git a/drivers/mmc/core/core.h b/drivers/mmc/core/core.h
index bb2774af9ea9..39daf2fb5dc4 100644
--- a/drivers/mmc/core/core.h
+++ b/drivers/mmc/core/core.h
@@ -48,5 +48,7 @@ void mmc_rescan(struct work_struct *work);
48void mmc_start_host(struct mmc_host *host); 48void mmc_start_host(struct mmc_host *host);
49void mmc_stop_host(struct mmc_host *host); 49void mmc_stop_host(struct mmc_host *host);
50 50
51extern int use_spi_crc;
52
51#endif 53#endif
52 54
diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c
index 2c7ce8f43a9a..64fbc9759a30 100644
--- a/drivers/mmc/core/host.c
+++ b/drivers/mmc/core/host.c
@@ -15,6 +15,7 @@
15#include <linux/err.h> 15#include <linux/err.h>
16#include <linux/idr.h> 16#include <linux/idr.h>
17#include <linux/pagemap.h> 17#include <linux/pagemap.h>
18#include <linux/leds.h>
18 19
19#include <linux/mmc/host.h> 20#include <linux/mmc/host.h>
20 21
@@ -100,6 +101,9 @@ int mmc_add_host(struct mmc_host *host)
100{ 101{
101 int err; 102 int err;
102 103
104 WARN_ON((host->caps & MMC_CAP_SDIO_IRQ) &&
105 !host->ops->enable_sdio_irq);
106
103 if (!idr_pre_get(&mmc_host_idr, GFP_KERNEL)) 107 if (!idr_pre_get(&mmc_host_idr, GFP_KERNEL))
104 return -ENOMEM; 108 return -ENOMEM;
105 109
@@ -112,6 +116,8 @@ int mmc_add_host(struct mmc_host *host)
112 snprintf(host->class_dev.bus_id, BUS_ID_SIZE, 116 snprintf(host->class_dev.bus_id, BUS_ID_SIZE,
113 "mmc%d", host->index); 117 "mmc%d", host->index);
114 118
119 led_trigger_register_simple(host->class_dev.bus_id, &host->led);
120
115 err = device_add(&host->class_dev); 121 err = device_add(&host->class_dev);
116 if (err) 122 if (err)
117 return err; 123 return err;
@@ -137,6 +143,8 @@ void mmc_remove_host(struct mmc_host *host)
137 143
138 device_del(&host->class_dev); 144 device_del(&host->class_dev);
139 145
146 led_trigger_unregister(host->led);
147
140 spin_lock(&mmc_host_lock); 148 spin_lock(&mmc_host_lock);
141 idr_remove(&mmc_host_idr, host->index); 149 idr_remove(&mmc_host_idr, host->index);
142 spin_unlock(&mmc_host_lock); 150 spin_unlock(&mmc_host_lock);
diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
index 21d7f48e1d4e..65fe28860f54 100644
--- a/drivers/mmc/core/mmc.c
+++ b/drivers/mmc/core/mmc.c
@@ -161,13 +161,12 @@ static int mmc_read_ext_csd(struct mmc_card *card)
161{ 161{
162 int err; 162 int err;
163 u8 *ext_csd; 163 u8 *ext_csd;
164 unsigned int ext_csd_struct;
164 165
165 BUG_ON(!card); 166 BUG_ON(!card);
166 167
167 err = MMC_ERR_FAILED;
168
169 if (card->csd.mmca_vsn < CSD_SPEC_VER_4) 168 if (card->csd.mmca_vsn < CSD_SPEC_VER_4)
170 return MMC_ERR_NONE; 169 return 0;
171 170
172 /* 171 /*
173 * As the ext_csd is so large and mostly unused, we don't store the 172 * As the ext_csd is so large and mostly unused, we don't store the
@@ -176,13 +175,19 @@ static int mmc_read_ext_csd(struct mmc_card *card)
176 ext_csd = kmalloc(512, GFP_KERNEL); 175 ext_csd = kmalloc(512, GFP_KERNEL);
177 if (!ext_csd) { 176 if (!ext_csd) {
178 printk(KERN_ERR "%s: could not allocate a buffer to " 177 printk(KERN_ERR "%s: could not allocate a buffer to "
179 "receive the ext_csd. mmc v4 cards will be " 178 "receive the ext_csd.\n", mmc_hostname(card->host));
180 "treated as v3.\n", mmc_hostname(card->host)); 179 return -ENOMEM;
181 return MMC_ERR_FAILED;
182 } 180 }
183 181
184 err = mmc_send_ext_csd(card, ext_csd); 182 err = mmc_send_ext_csd(card, ext_csd);
185 if (err != MMC_ERR_NONE) { 183 if (err) {
184 /*
185 * We all hosts that cannot perform the command
186 * to fail more gracefully
187 */
188 if (err != -EINVAL)
189 goto out;
190
186 /* 191 /*
187 * High capacity cards should have this "magic" size 192 * High capacity cards should have this "magic" size
188 * stored in their CSD. 193 * stored in their CSD.
@@ -197,18 +202,29 @@ static int mmc_read_ext_csd(struct mmc_card *card)
197 "EXT_CSD, performance might " 202 "EXT_CSD, performance might "
198 "suffer.\n", 203 "suffer.\n",
199 mmc_hostname(card->host)); 204 mmc_hostname(card->host));
200 err = MMC_ERR_NONE; 205 err = 0;
201 } 206 }
207
202 goto out; 208 goto out;
203 } 209 }
204 210
205 card->ext_csd.sectors = 211 ext_csd_struct = ext_csd[EXT_CSD_REV];
206 ext_csd[EXT_CSD_SEC_CNT + 0] << 0 | 212 if (ext_csd_struct > 2) {
207 ext_csd[EXT_CSD_SEC_CNT + 1] << 8 | 213 printk(KERN_ERR "%s: unrecognised EXT_CSD structure "
208 ext_csd[EXT_CSD_SEC_CNT + 2] << 16 | 214 "version %d\n", mmc_hostname(card->host),
209 ext_csd[EXT_CSD_SEC_CNT + 3] << 24; 215 ext_csd_struct);
210 if (card->ext_csd.sectors) 216 return -EINVAL;
211 mmc_card_set_blockaddr(card); 217 }
218
219 if (ext_csd_struct >= 2) {
220 card->ext_csd.sectors =
221 ext_csd[EXT_CSD_SEC_CNT + 0] << 0 |
222 ext_csd[EXT_CSD_SEC_CNT + 1] << 8 |
223 ext_csd[EXT_CSD_SEC_CNT + 2] << 16 |
224 ext_csd[EXT_CSD_SEC_CNT + 3] << 24;
225 if (card->ext_csd.sectors)
226 mmc_card_set_blockaddr(card);
227 }
212 228
213 switch (ext_csd[EXT_CSD_CARD_TYPE]) { 229 switch (ext_csd[EXT_CSD_CARD_TYPE]) {
214 case EXT_CSD_CARD_TYPE_52 | EXT_CSD_CARD_TYPE_26: 230 case EXT_CSD_CARD_TYPE_52 | EXT_CSD_CARD_TYPE_26:
@@ -246,7 +262,7 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
246 unsigned int max_dtr; 262 unsigned int max_dtr;
247 263
248 BUG_ON(!host); 264 BUG_ON(!host);
249 BUG_ON(!host->claimed); 265 WARN_ON(!host->claimed);
250 266
251 /* 267 /*
252 * Since we're changing the OCR value, we seem to 268 * Since we're changing the OCR value, we seem to
@@ -258,19 +274,33 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
258 274
259 /* The extra bit indicates that we support high capacity */ 275 /* The extra bit indicates that we support high capacity */
260 err = mmc_send_op_cond(host, ocr | (1 << 30), NULL); 276 err = mmc_send_op_cond(host, ocr | (1 << 30), NULL);
261 if (err != MMC_ERR_NONE) 277 if (err)
262 goto err; 278 goto err;
263 279
264 /* 280 /*
281 * For SPI, enable CRC as appropriate.
282 */
283 if (mmc_host_is_spi(host)) {
284 err = mmc_spi_set_crc(host, use_spi_crc);
285 if (err)
286 goto err;
287 }
288
289 /*
265 * Fetch CID from card. 290 * Fetch CID from card.
266 */ 291 */
267 err = mmc_all_send_cid(host, cid); 292 if (mmc_host_is_spi(host))
268 if (err != MMC_ERR_NONE) 293 err = mmc_send_cid(host, cid);
294 else
295 err = mmc_all_send_cid(host, cid);
296 if (err)
269 goto err; 297 goto err;
270 298
271 if (oldcard) { 299 if (oldcard) {
272 if (memcmp(cid, oldcard->raw_cid, sizeof(cid)) != 0) 300 if (memcmp(cid, oldcard->raw_cid, sizeof(cid)) != 0) {
301 err = -ENOENT;
273 goto err; 302 goto err;
303 }
274 304
275 card = oldcard; 305 card = oldcard;
276 } else { 306 } else {
@@ -278,8 +308,10 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
278 * Allocate card structure. 308 * Allocate card structure.
279 */ 309 */
280 card = mmc_alloc_card(host); 310 card = mmc_alloc_card(host);
281 if (IS_ERR(card)) 311 if (IS_ERR(card)) {
312 err = PTR_ERR(card);
282 goto err; 313 goto err;
314 }
283 315
284 card->type = MMC_TYPE_MMC; 316 card->type = MMC_TYPE_MMC;
285 card->rca = 1; 317 card->rca = 1;
@@ -287,43 +319,47 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
287 } 319 }
288 320
289 /* 321 /*
290 * Set card RCA. 322 * For native busses: set card RCA and quit open drain mode.
291 */ 323 */
292 err = mmc_set_relative_addr(card); 324 if (!mmc_host_is_spi(host)) {
293 if (err != MMC_ERR_NONE) 325 err = mmc_set_relative_addr(card);
294 goto free_card; 326 if (err)
327 goto free_card;
295 328
296 mmc_set_bus_mode(host, MMC_BUSMODE_PUSHPULL); 329 mmc_set_bus_mode(host, MMC_BUSMODE_PUSHPULL);
330 }
297 331
298 if (!oldcard) { 332 if (!oldcard) {
299 /* 333 /*
300 * Fetch CSD from card. 334 * Fetch CSD from card.
301 */ 335 */
302 err = mmc_send_csd(card, card->raw_csd); 336 err = mmc_send_csd(card, card->raw_csd);
303 if (err != MMC_ERR_NONE) 337 if (err)
304 goto free_card; 338 goto free_card;
305 339
306 err = mmc_decode_csd(card); 340 err = mmc_decode_csd(card);
307 if (err < 0) 341 if (err)
308 goto free_card; 342 goto free_card;
309 err = mmc_decode_cid(card); 343 err = mmc_decode_cid(card);
310 if (err < 0) 344 if (err)
311 goto free_card; 345 goto free_card;
312 } 346 }
313 347
314 /* 348 /*
315 * Select card, as all following commands rely on that. 349 * Select card, as all following commands rely on that.
316 */ 350 */
317 err = mmc_select_card(card); 351 if (!mmc_host_is_spi(host)) {
318 if (err != MMC_ERR_NONE) 352 err = mmc_select_card(card);
319 goto free_card; 353 if (err)
354 goto free_card;
355 }
320 356
321 if (!oldcard) { 357 if (!oldcard) {
322 /* 358 /*
323 * Fetch and process extened CSD. 359 * Fetch and process extended CSD.
324 */ 360 */
325 err = mmc_read_ext_csd(card); 361 err = mmc_read_ext_csd(card);
326 if (err != MMC_ERR_NONE) 362 if (err)
327 goto free_card; 363 goto free_card;
328 } 364 }
329 365
@@ -334,7 +370,7 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
334 (host->caps & MMC_CAP_MMC_HIGHSPEED)) { 370 (host->caps & MMC_CAP_MMC_HIGHSPEED)) {
335 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 371 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
336 EXT_CSD_HS_TIMING, 1); 372 EXT_CSD_HS_TIMING, 1);
337 if (err != MMC_ERR_NONE) 373 if (err)
338 goto free_card; 374 goto free_card;
339 375
340 mmc_card_set_highspeed(card); 376 mmc_card_set_highspeed(card);
@@ -363,7 +399,7 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
363 (host->caps & MMC_CAP_4_BIT_DATA)) { 399 (host->caps & MMC_CAP_4_BIT_DATA)) {
364 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, 400 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
365 EXT_CSD_BUS_WIDTH, EXT_CSD_BUS_WIDTH_4); 401 EXT_CSD_BUS_WIDTH, EXT_CSD_BUS_WIDTH_4);
366 if (err != MMC_ERR_NONE) 402 if (err)
367 goto free_card; 403 goto free_card;
368 404
369 mmc_set_bus_width(card->host, MMC_BUS_WIDTH_4); 405 mmc_set_bus_width(card->host, MMC_BUS_WIDTH_4);
@@ -372,14 +408,14 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
372 if (!oldcard) 408 if (!oldcard)
373 host->card = card; 409 host->card = card;
374 410
375 return MMC_ERR_NONE; 411 return 0;
376 412
377free_card: 413free_card:
378 if (!oldcard) 414 if (!oldcard)
379 mmc_remove_card(card); 415 mmc_remove_card(card);
380err: 416err:
381 417
382 return MMC_ERR_FAILED; 418 return err;
383} 419}
384 420
385/* 421/*
@@ -413,7 +449,7 @@ static void mmc_detect(struct mmc_host *host)
413 449
414 mmc_release_host(host); 450 mmc_release_host(host);
415 451
416 if (err != MMC_ERR_NONE) { 452 if (err) {
417 mmc_remove(host); 453 mmc_remove(host);
418 454
419 mmc_claim_host(host); 455 mmc_claim_host(host);
@@ -480,7 +516,8 @@ static void mmc_suspend(struct mmc_host *host)
480 BUG_ON(!host->card); 516 BUG_ON(!host->card);
481 517
482 mmc_claim_host(host); 518 mmc_claim_host(host);
483 mmc_deselect_cards(host); 519 if (!mmc_host_is_spi(host))
520 mmc_deselect_cards(host);
484 host->card->state &= ~MMC_STATE_HIGHSPEED; 521 host->card->state &= ~MMC_STATE_HIGHSPEED;
485 mmc_release_host(host); 522 mmc_release_host(host);
486} 523}
@@ -502,7 +539,7 @@ static void mmc_resume(struct mmc_host *host)
502 err = mmc_init_card(host, host->ocr, host->card); 539 err = mmc_init_card(host, host->ocr, host->card);
503 mmc_release_host(host); 540 mmc_release_host(host);
504 541
505 if (err != MMC_ERR_NONE) { 542 if (err) {
506 mmc_remove(host); 543 mmc_remove(host);
507 544
508 mmc_claim_host(host); 545 mmc_claim_host(host);
@@ -536,11 +573,20 @@ int mmc_attach_mmc(struct mmc_host *host, u32 ocr)
536 int err; 573 int err;
537 574
538 BUG_ON(!host); 575 BUG_ON(!host);
539 BUG_ON(!host->claimed); 576 WARN_ON(!host->claimed);
540 577
541 mmc_attach_bus(host, &mmc_ops); 578 mmc_attach_bus(host, &mmc_ops);
542 579
543 /* 580 /*
581 * We need to get OCR a different way for SPI.
582 */
583 if (mmc_host_is_spi(host)) {
584 err = mmc_spi_read_ocr(host, 1, &ocr);
585 if (err)
586 goto err;
587 }
588
589 /*
544 * Sanity check the voltages that the card claims to 590 * Sanity check the voltages that the card claims to
545 * support. 591 * support.
546 */ 592 */
@@ -565,7 +611,7 @@ int mmc_attach_mmc(struct mmc_host *host, u32 ocr)
565 * Detect and init the card. 611 * Detect and init the card.
566 */ 612 */
567 err = mmc_init_card(host, host->ocr, NULL); 613 err = mmc_init_card(host, host->ocr, NULL);
568 if (err != MMC_ERR_NONE) 614 if (err)
569 goto err; 615 goto err;
570 616
571 mmc_release_host(host); 617 mmc_release_host(host);
@@ -587,6 +633,6 @@ err:
587 printk(KERN_ERR "%s: error %d whilst initialising MMC card\n", 633 printk(KERN_ERR "%s: error %d whilst initialising MMC card\n",
588 mmc_hostname(host), err); 634 mmc_hostname(host), err);
589 635
590 return 0; 636 return err;
591} 637}
592 638
diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
index 913e75f00843..bf4bc6adcfef 100644
--- a/drivers/mmc/core/mmc_ops.c
+++ b/drivers/mmc/core/mmc_ops.c
@@ -40,10 +40,10 @@ static int _mmc_select_card(struct mmc_host *host, struct mmc_card *card)
40 } 40 }
41 41
42 err = mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES); 42 err = mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES);
43 if (err != MMC_ERR_NONE) 43 if (err)
44 return err; 44 return err;
45 45
46 return MMC_ERR_NONE; 46 return 0;
47} 47}
48 48
49int mmc_select_card(struct mmc_card *card) 49int mmc_select_card(struct mmc_card *card)
@@ -63,23 +63,36 @@ int mmc_go_idle(struct mmc_host *host)
63 int err; 63 int err;
64 struct mmc_command cmd; 64 struct mmc_command cmd;
65 65
66 mmc_set_chip_select(host, MMC_CS_HIGH); 66 /*
67 67 * Non-SPI hosts need to prevent chipselect going active during
68 mmc_delay(1); 68 * GO_IDLE; that would put chips into SPI mode. Remind them of
69 * that in case of hardware that won't pull up DAT3/nCS otherwise.
70 *
71 * SPI hosts ignore ios.chip_select; it's managed according to
72 * rules that must accomodate non-MMC slaves which this layer
73 * won't even know about.
74 */
75 if (!mmc_host_is_spi(host)) {
76 mmc_set_chip_select(host, MMC_CS_HIGH);
77 mmc_delay(1);
78 }
69 79
70 memset(&cmd, 0, sizeof(struct mmc_command)); 80 memset(&cmd, 0, sizeof(struct mmc_command));
71 81
72 cmd.opcode = MMC_GO_IDLE_STATE; 82 cmd.opcode = MMC_GO_IDLE_STATE;
73 cmd.arg = 0; 83 cmd.arg = 0;
74 cmd.flags = MMC_RSP_NONE | MMC_CMD_BC; 84 cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_NONE | MMC_CMD_BC;
75 85
76 err = mmc_wait_for_cmd(host, &cmd, 0); 86 err = mmc_wait_for_cmd(host, &cmd, 0);
77 87
78 mmc_delay(1); 88 mmc_delay(1);
79 89
80 mmc_set_chip_select(host, MMC_CS_DONTCARE); 90 if (!mmc_host_is_spi(host)) {
91 mmc_set_chip_select(host, MMC_CS_DONTCARE);
92 mmc_delay(1);
93 }
81 94
82 mmc_delay(1); 95 host->use_spi_crc = 0;
83 96
84 return err; 97 return err;
85} 98}
@@ -94,23 +107,33 @@ int mmc_send_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr)
94 memset(&cmd, 0, sizeof(struct mmc_command)); 107 memset(&cmd, 0, sizeof(struct mmc_command));
95 108
96 cmd.opcode = MMC_SEND_OP_COND; 109 cmd.opcode = MMC_SEND_OP_COND;
97 cmd.arg = ocr; 110 cmd.arg = mmc_host_is_spi(host) ? 0 : ocr;
98 cmd.flags = MMC_RSP_R3 | MMC_CMD_BCR; 111 cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R3 | MMC_CMD_BCR;
99 112
100 for (i = 100; i; i--) { 113 for (i = 100; i; i--) {
101 err = mmc_wait_for_cmd(host, &cmd, 0); 114 err = mmc_wait_for_cmd(host, &cmd, 0);
102 if (err != MMC_ERR_NONE) 115 if (err)
103 break; 116 break;
104 117
105 if (cmd.resp[0] & MMC_CARD_BUSY || ocr == 0) 118 /* if we're just probing, do a single pass */
119 if (ocr == 0)
106 break; 120 break;
107 121
108 err = MMC_ERR_TIMEOUT; 122 /* otherwise wait until reset completes */
123 if (mmc_host_is_spi(host)) {
124 if (!(cmd.resp[0] & R1_SPI_IDLE))
125 break;
126 } else {
127 if (cmd.resp[0] & MMC_CARD_BUSY)
128 break;
129 }
130
131 err = -ETIMEDOUT;
109 132
110 mmc_delay(10); 133 mmc_delay(10);
111 } 134 }
112 135
113 if (rocr) 136 if (rocr && !mmc_host_is_spi(host))
114 *rocr = cmd.resp[0]; 137 *rocr = cmd.resp[0];
115 138
116 return err; 139 return err;
@@ -131,12 +154,12 @@ int mmc_all_send_cid(struct mmc_host *host, u32 *cid)
131 cmd.flags = MMC_RSP_R2 | MMC_CMD_BCR; 154 cmd.flags = MMC_RSP_R2 | MMC_CMD_BCR;
132 155
133 err = mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES); 156 err = mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES);
134 if (err != MMC_ERR_NONE) 157 if (err)
135 return err; 158 return err;
136 159
137 memcpy(cid, cmd.resp, sizeof(u32) * 4); 160 memcpy(cid, cmd.resp, sizeof(u32) * 4);
138 161
139 return MMC_ERR_NONE; 162 return 0;
140} 163}
141 164
142int mmc_set_relative_addr(struct mmc_card *card) 165int mmc_set_relative_addr(struct mmc_card *card)
@@ -154,46 +177,52 @@ int mmc_set_relative_addr(struct mmc_card *card)
154 cmd.flags = MMC_RSP_R1 | MMC_CMD_AC; 177 cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
155 178
156 err = mmc_wait_for_cmd(card->host, &cmd, MMC_CMD_RETRIES); 179 err = mmc_wait_for_cmd(card->host, &cmd, MMC_CMD_RETRIES);
157 if (err != MMC_ERR_NONE) 180 if (err)
158 return err; 181 return err;
159 182
160 return MMC_ERR_NONE; 183 return 0;
161} 184}
162 185
163int mmc_send_csd(struct mmc_card *card, u32 *csd) 186static int
187mmc_send_cxd_native(struct mmc_host *host, u32 arg, u32 *cxd, int opcode)
164{ 188{
165 int err; 189 int err;
166 struct mmc_command cmd; 190 struct mmc_command cmd;
167 191
168 BUG_ON(!card); 192 BUG_ON(!host);
169 BUG_ON(!card->host); 193 BUG_ON(!cxd);
170 BUG_ON(!csd);
171 194
172 memset(&cmd, 0, sizeof(struct mmc_command)); 195 memset(&cmd, 0, sizeof(struct mmc_command));
173 196
174 cmd.opcode = MMC_SEND_CSD; 197 cmd.opcode = opcode;
175 cmd.arg = card->rca << 16; 198 cmd.arg = arg;
176 cmd.flags = MMC_RSP_R2 | MMC_CMD_AC; 199 cmd.flags = MMC_RSP_R2 | MMC_CMD_AC;
177 200
178 err = mmc_wait_for_cmd(card->host, &cmd, MMC_CMD_RETRIES); 201 err = mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES);
179 if (err != MMC_ERR_NONE) 202 if (err)
180 return err; 203 return err;
181 204
182 memcpy(csd, cmd.resp, sizeof(u32) * 4); 205 memcpy(cxd, cmd.resp, sizeof(u32) * 4);
183 206
184 return MMC_ERR_NONE; 207 return 0;
185} 208}
186 209
187int mmc_send_ext_csd(struct mmc_card *card, u8 *ext_csd) 210static int
211mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
212 u32 opcode, void *buf, unsigned len)
188{ 213{
189 struct mmc_request mrq; 214 struct mmc_request mrq;
190 struct mmc_command cmd; 215 struct mmc_command cmd;
191 struct mmc_data data; 216 struct mmc_data data;
192 struct scatterlist sg; 217 struct scatterlist sg;
218 void *data_buf;
193 219
194 BUG_ON(!card); 220 /* dma onto stack is unsafe/nonportable, but callers to this
195 BUG_ON(!card->host); 221 * routine normally provide temporary on-stack buffers ...
196 BUG_ON(!ext_csd); 222 */
223 data_buf = kmalloc(len, GFP_KERNEL);
224 if (data_buf == NULL)
225 return -ENOMEM;
197 226
198 memset(&mrq, 0, sizeof(struct mmc_request)); 227 memset(&mrq, 0, sizeof(struct mmc_request));
199 memset(&cmd, 0, sizeof(struct mmc_command)); 228 memset(&cmd, 0, sizeof(struct mmc_command));
@@ -202,28 +231,99 @@ int mmc_send_ext_csd(struct mmc_card *card, u8 *ext_csd)
202 mrq.cmd = &cmd; 231 mrq.cmd = &cmd;
203 mrq.data = &data; 232 mrq.data = &data;
204 233
205 cmd.opcode = MMC_SEND_EXT_CSD; 234 cmd.opcode = opcode;
206 cmd.arg = 0; 235 cmd.arg = 0;
207 cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC;
208 236
209 data.blksz = 512; 237 /* NOTE HACK: the MMC_RSP_SPI_R1 is always correct here, but we
238 * rely on callers to never use this with "native" calls for reading
239 * CSD or CID. Native versions of those commands use the R2 type,
240 * not R1 plus a data block.
241 */
242 cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
243
244 data.blksz = len;
210 data.blocks = 1; 245 data.blocks = 1;
211 data.flags = MMC_DATA_READ; 246 data.flags = MMC_DATA_READ;
212 data.sg = &sg; 247 data.sg = &sg;
213 data.sg_len = 1; 248 data.sg_len = 1;
214 249
215 sg_init_one(&sg, ext_csd, 512); 250 sg_init_one(&sg, data_buf, len);
216 251
217 mmc_set_data_timeout(&data, card, 0); 252 if (card)
253 mmc_set_data_timeout(&data, card);
218 254
219 mmc_wait_for_req(card->host, &mrq); 255 mmc_wait_for_req(host, &mrq);
220 256
221 if (cmd.error != MMC_ERR_NONE) 257 memcpy(buf, data_buf, len);
258 kfree(data_buf);
259
260 if (cmd.error)
222 return cmd.error; 261 return cmd.error;
223 if (data.error != MMC_ERR_NONE) 262 if (data.error)
224 return data.error; 263 return data.error;
225 264
226 return MMC_ERR_NONE; 265 return 0;
266}
267
268int mmc_send_csd(struct mmc_card *card, u32 *csd)
269{
270 if (!mmc_host_is_spi(card->host))
271 return mmc_send_cxd_native(card->host, card->rca << 16,
272 csd, MMC_SEND_CSD);
273
274 return mmc_send_cxd_data(card, card->host, MMC_SEND_CSD, csd, 16);
275}
276
277int mmc_send_cid(struct mmc_host *host, u32 *cid)
278{
279 if (!mmc_host_is_spi(host)) {
280 if (!host->card)
281 return -EINVAL;
282 return mmc_send_cxd_native(host, host->card->rca << 16,
283 cid, MMC_SEND_CID);
284 }
285
286 return mmc_send_cxd_data(NULL, host, MMC_SEND_CID, cid, 16);
287}
288
289int mmc_send_ext_csd(struct mmc_card *card, u8 *ext_csd)
290{
291 return mmc_send_cxd_data(card, card->host, MMC_SEND_EXT_CSD,
292 ext_csd, 512);
293}
294
295int mmc_spi_read_ocr(struct mmc_host *host, int highcap, u32 *ocrp)
296{
297 struct mmc_command cmd;
298 int err;
299
300 memset(&cmd, 0, sizeof(struct mmc_command));
301
302 cmd.opcode = MMC_SPI_READ_OCR;
303 cmd.arg = highcap ? (1 << 30) : 0;
304 cmd.flags = MMC_RSP_SPI_R3;
305
306 err = mmc_wait_for_cmd(host, &cmd, 0);
307
308 *ocrp = cmd.resp[1];
309 return err;
310}
311
312int mmc_spi_set_crc(struct mmc_host *host, int use_crc)
313{
314 struct mmc_command cmd;
315 int err;
316
317 memset(&cmd, 0, sizeof(struct mmc_command));
318
319 cmd.opcode = MMC_SPI_CRC_ON_OFF;
320 cmd.flags = MMC_RSP_SPI_R1;
321 cmd.arg = use_crc;
322
323 err = mmc_wait_for_cmd(host, &cmd, 0);
324 if (!err)
325 host->use_spi_crc = use_crc;
326 return err;
227} 327}
228 328
229int mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value) 329int mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value)
@@ -241,13 +341,13 @@ int mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value)
241 (index << 16) | 341 (index << 16) |
242 (value << 8) | 342 (value << 8) |
243 set; 343 set;
244 cmd.flags = MMC_RSP_R1B | MMC_CMD_AC; 344 cmd.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC;
245 345
246 err = mmc_wait_for_cmd(card->host, &cmd, MMC_CMD_RETRIES); 346 err = mmc_wait_for_cmd(card->host, &cmd, MMC_CMD_RETRIES);
247 if (err != MMC_ERR_NONE) 347 if (err)
248 return err; 348 return err;
249 349
250 return MMC_ERR_NONE; 350 return 0;
251} 351}
252 352
253int mmc_send_status(struct mmc_card *card, u32 *status) 353int mmc_send_status(struct mmc_card *card, u32 *status)
@@ -261,16 +361,20 @@ int mmc_send_status(struct mmc_card *card, u32 *status)
261 memset(&cmd, 0, sizeof(struct mmc_command)); 361 memset(&cmd, 0, sizeof(struct mmc_command));
262 362
263 cmd.opcode = MMC_SEND_STATUS; 363 cmd.opcode = MMC_SEND_STATUS;
264 cmd.arg = card->rca << 16; 364 if (!mmc_host_is_spi(card->host))
265 cmd.flags = MMC_RSP_R1 | MMC_CMD_AC; 365 cmd.arg = card->rca << 16;
366 cmd.flags = MMC_RSP_SPI_R2 | MMC_RSP_R1 | MMC_CMD_AC;
266 367
267 err = mmc_wait_for_cmd(card->host, &cmd, MMC_CMD_RETRIES); 368 err = mmc_wait_for_cmd(card->host, &cmd, MMC_CMD_RETRIES);
268 if (err != MMC_ERR_NONE) 369 if (err)
269 return err; 370 return err;
270 371
372 /* NOTE: callers are required to understand the difference
373 * between "native" and SPI format status words!
374 */
271 if (status) 375 if (status)
272 *status = cmd.resp[0]; 376 *status = cmd.resp[0];
273 377
274 return MMC_ERR_NONE; 378 return 0;
275} 379}
276 380
diff --git a/drivers/mmc/core/mmc_ops.h b/drivers/mmc/core/mmc_ops.h
index 76d09a93c5d6..17854bf7cf0d 100644
--- a/drivers/mmc/core/mmc_ops.h
+++ b/drivers/mmc/core/mmc_ops.h
@@ -22,6 +22,9 @@ int mmc_send_csd(struct mmc_card *card, u32 *csd);
22int mmc_send_ext_csd(struct mmc_card *card, u8 *ext_csd); 22int mmc_send_ext_csd(struct mmc_card *card, u8 *ext_csd);
23int mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value); 23int mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value);
24int mmc_send_status(struct mmc_card *card, u32 *status); 24int mmc_send_status(struct mmc_card *card, u32 *status);
25int mmc_send_cid(struct mmc_host *host, u32 *cid);
26int mmc_spi_read_ocr(struct mmc_host *host, int highcap, u32 *ocrp);
27int mmc_spi_set_crc(struct mmc_host *host, int use_crc);
25 28
26#endif 29#endif
27 30
diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c
index 1edc62b1e5c6..d1c1e0f592f1 100644
--- a/drivers/mmc/core/sd.c
+++ b/drivers/mmc/core/sd.c
@@ -166,8 +166,6 @@ static int mmc_decode_scr(struct mmc_card *card)
166 unsigned int scr_struct; 166 unsigned int scr_struct;
167 u32 resp[4]; 167 u32 resp[4];
168 168
169 BUG_ON(!mmc_card_sd(card));
170
171 resp[3] = card->raw_scr[1]; 169 resp[3] = card->raw_scr[1];
172 resp[2] = card->raw_scr[0]; 170 resp[2] = card->raw_scr[0];
173 171
@@ -193,30 +191,38 @@ static int mmc_read_switch(struct mmc_card *card)
193 u8 *status; 191 u8 *status;
194 192
195 if (card->scr.sda_vsn < SCR_SPEC_VER_1) 193 if (card->scr.sda_vsn < SCR_SPEC_VER_1)
196 return MMC_ERR_NONE; 194 return 0;
197 195
198 if (!(card->csd.cmdclass & CCC_SWITCH)) { 196 if (!(card->csd.cmdclass & CCC_SWITCH)) {
199 printk(KERN_WARNING "%s: card lacks mandatory switch " 197 printk(KERN_WARNING "%s: card lacks mandatory switch "
200 "function, performance might suffer.\n", 198 "function, performance might suffer.\n",
201 mmc_hostname(card->host)); 199 mmc_hostname(card->host));
202 return MMC_ERR_NONE; 200 return 0;
203 } 201 }
204 202
205 err = MMC_ERR_FAILED; 203 err = -EIO;
206 204
207 status = kmalloc(64, GFP_KERNEL); 205 status = kmalloc(64, GFP_KERNEL);
208 if (!status) { 206 if (!status) {
209 printk(KERN_ERR "%s: could not allocate a buffer for " 207 printk(KERN_ERR "%s: could not allocate a buffer for "
210 "switch capabilities.\n", mmc_hostname(card->host)); 208 "switch capabilities.\n", mmc_hostname(card->host));
211 return err; 209 return -ENOMEM;
212 } 210 }
213 211
214 err = mmc_sd_switch(card, 0, 0, 1, status); 212 err = mmc_sd_switch(card, 0, 0, 1, status);
215 if (err != MMC_ERR_NONE) { 213 if (err) {
214 /*
215 * We all hosts that cannot perform the command
216 * to fail more gracefully
217 */
218 if (err != -EINVAL)
219 goto out;
220
216 printk(KERN_WARNING "%s: problem reading switch " 221 printk(KERN_WARNING "%s: problem reading switch "
217 "capabilities, performance might suffer.\n", 222 "capabilities, performance might suffer.\n",
218 mmc_hostname(card->host)); 223 mmc_hostname(card->host));
219 err = MMC_ERR_NONE; 224 err = 0;
225
220 goto out; 226 goto out;
221 } 227 }
222 228
@@ -238,28 +244,28 @@ static int mmc_switch_hs(struct mmc_card *card)
238 u8 *status; 244 u8 *status;
239 245
240 if (card->scr.sda_vsn < SCR_SPEC_VER_1) 246 if (card->scr.sda_vsn < SCR_SPEC_VER_1)
241 return MMC_ERR_NONE; 247 return 0;
242 248
243 if (!(card->csd.cmdclass & CCC_SWITCH)) 249 if (!(card->csd.cmdclass & CCC_SWITCH))
244 return MMC_ERR_NONE; 250 return 0;
245 251
246 if (!(card->host->caps & MMC_CAP_SD_HIGHSPEED)) 252 if (!(card->host->caps & MMC_CAP_SD_HIGHSPEED))
247 return MMC_ERR_NONE; 253 return 0;
248 254
249 if (card->sw_caps.hs_max_dtr == 0) 255 if (card->sw_caps.hs_max_dtr == 0)
250 return MMC_ERR_NONE; 256 return 0;
251 257
252 err = MMC_ERR_FAILED; 258 err = -EIO;
253 259
254 status = kmalloc(64, GFP_KERNEL); 260 status = kmalloc(64, GFP_KERNEL);
255 if (!status) { 261 if (!status) {
256 printk(KERN_ERR "%s: could not allocate a buffer for " 262 printk(KERN_ERR "%s: could not allocate a buffer for "
257 "switch capabilities.\n", mmc_hostname(card->host)); 263 "switch capabilities.\n", mmc_hostname(card->host));
258 return err; 264 return -ENOMEM;
259 } 265 }
260 266
261 err = mmc_sd_switch(card, 1, 0, 1, status); 267 err = mmc_sd_switch(card, 1, 0, 1, status);
262 if (err != MMC_ERR_NONE) 268 if (err)
263 goto out; 269 goto out;
264 270
265 if ((status[16] & 0xF) != 1) { 271 if ((status[16] & 0xF) != 1) {
@@ -292,7 +298,7 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
292 unsigned int max_dtr; 298 unsigned int max_dtr;
293 299
294 BUG_ON(!host); 300 BUG_ON(!host);
295 BUG_ON(!host->claimed); 301 WARN_ON(!host->claimed);
296 302
297 /* 303 /*
298 * Since we're changing the OCR value, we seem to 304 * Since we're changing the OCR value, we seem to
@@ -309,23 +315,37 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
309 * block-addressed SDHC cards. 315 * block-addressed SDHC cards.
310 */ 316 */
311 err = mmc_send_if_cond(host, ocr); 317 err = mmc_send_if_cond(host, ocr);
312 if (err == MMC_ERR_NONE) 318 if (!err)
313 ocr |= 1 << 30; 319 ocr |= 1 << 30;
314 320
315 err = mmc_send_app_op_cond(host, ocr, NULL); 321 err = mmc_send_app_op_cond(host, ocr, NULL);
316 if (err != MMC_ERR_NONE) 322 if (err)
317 goto err; 323 goto err;
318 324
319 /* 325 /*
326 * For SPI, enable CRC as appropriate.
327 */
328 if (mmc_host_is_spi(host)) {
329 err = mmc_spi_set_crc(host, use_spi_crc);
330 if (err)
331 goto err;
332 }
333
334 /*
320 * Fetch CID from card. 335 * Fetch CID from card.
321 */ 336 */
322 err = mmc_all_send_cid(host, cid); 337 if (mmc_host_is_spi(host))
323 if (err != MMC_ERR_NONE) 338 err = mmc_send_cid(host, cid);
339 else
340 err = mmc_all_send_cid(host, cid);
341 if (err)
324 goto err; 342 goto err;
325 343
326 if (oldcard) { 344 if (oldcard) {
327 if (memcmp(cid, oldcard->raw_cid, sizeof(cid)) != 0) 345 if (memcmp(cid, oldcard->raw_cid, sizeof(cid)) != 0) {
346 err = -ENOENT;
328 goto err; 347 goto err;
348 }
329 349
330 card = oldcard; 350 card = oldcard;
331 } else { 351 } else {
@@ -333,32 +353,36 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
333 * Allocate card structure. 353 * Allocate card structure.
334 */ 354 */
335 card = mmc_alloc_card(host); 355 card = mmc_alloc_card(host);
336 if (IS_ERR(card)) 356 if (IS_ERR(card)) {
357 err = PTR_ERR(card);
337 goto err; 358 goto err;
359 }
338 360
339 card->type = MMC_TYPE_SD; 361 card->type = MMC_TYPE_SD;
340 memcpy(card->raw_cid, cid, sizeof(card->raw_cid)); 362 memcpy(card->raw_cid, cid, sizeof(card->raw_cid));
341 } 363 }
342 364
343 /* 365 /*
344 * Set card RCA. 366 * For native busses: get card RCA and quit open drain mode.
345 */ 367 */
346 err = mmc_send_relative_addr(host, &card->rca); 368 if (!mmc_host_is_spi(host)) {
347 if (err != MMC_ERR_NONE) 369 err = mmc_send_relative_addr(host, &card->rca);
348 goto free_card; 370 if (err)
371 goto free_card;
349 372
350 mmc_set_bus_mode(host, MMC_BUSMODE_PUSHPULL); 373 mmc_set_bus_mode(host, MMC_BUSMODE_PUSHPULL);
374 }
351 375
352 if (!oldcard) { 376 if (!oldcard) {
353 /* 377 /*
354 * Fetch CSD from card. 378 * Fetch CSD from card.
355 */ 379 */
356 err = mmc_send_csd(card, card->raw_csd); 380 err = mmc_send_csd(card, card->raw_csd);
357 if (err != MMC_ERR_NONE) 381 if (err)
358 goto free_card; 382 goto free_card;
359 383
360 err = mmc_decode_csd(card); 384 err = mmc_decode_csd(card);
361 if (err < 0) 385 if (err)
362 goto free_card; 386 goto free_card;
363 387
364 mmc_decode_cid(card); 388 mmc_decode_cid(card);
@@ -367,16 +391,18 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
367 /* 391 /*
368 * Select card, as all following commands rely on that. 392 * Select card, as all following commands rely on that.
369 */ 393 */
370 err = mmc_select_card(card); 394 if (!mmc_host_is_spi(host)) {
371 if (err != MMC_ERR_NONE) 395 err = mmc_select_card(card);
372 goto free_card; 396 if (err)
397 goto free_card;
398 }
373 399
374 if (!oldcard) { 400 if (!oldcard) {
375 /* 401 /*
376 * Fetch SCR from card. 402 * Fetch SCR from card.
377 */ 403 */
378 err = mmc_app_send_scr(card, card->raw_scr); 404 err = mmc_app_send_scr(card, card->raw_scr);
379 if (err != MMC_ERR_NONE) 405 if (err)
380 goto free_card; 406 goto free_card;
381 407
382 err = mmc_decode_scr(card); 408 err = mmc_decode_scr(card);
@@ -387,7 +413,7 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
387 * Fetch switch information from card. 413 * Fetch switch information from card.
388 */ 414 */
389 err = mmc_read_switch(card); 415 err = mmc_read_switch(card);
390 if (err != MMC_ERR_NONE) 416 if (err)
391 goto free_card; 417 goto free_card;
392 } 418 }
393 419
@@ -395,7 +421,7 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
395 * Attempt to change to high-speed (if supported) 421 * Attempt to change to high-speed (if supported)
396 */ 422 */
397 err = mmc_switch_hs(card); 423 err = mmc_switch_hs(card);
398 if (err != MMC_ERR_NONE) 424 if (err)
399 goto free_card; 425 goto free_card;
400 426
401 /* 427 /*
@@ -418,7 +444,7 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
418 if ((host->caps & MMC_CAP_4_BIT_DATA) && 444 if ((host->caps & MMC_CAP_4_BIT_DATA) &&
419 (card->scr.bus_widths & SD_SCR_BUS_WIDTH_4)) { 445 (card->scr.bus_widths & SD_SCR_BUS_WIDTH_4)) {
420 err = mmc_app_set_bus_width(card, MMC_BUS_WIDTH_4); 446 err = mmc_app_set_bus_width(card, MMC_BUS_WIDTH_4);
421 if (err != MMC_ERR_NONE) 447 if (err)
422 goto free_card; 448 goto free_card;
423 449
424 mmc_set_bus_width(host, MMC_BUS_WIDTH_4); 450 mmc_set_bus_width(host, MMC_BUS_WIDTH_4);
@@ -442,14 +468,14 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
442 if (!oldcard) 468 if (!oldcard)
443 host->card = card; 469 host->card = card;
444 470
445 return MMC_ERR_NONE; 471 return 0;
446 472
447free_card: 473free_card:
448 if (!oldcard) 474 if (!oldcard)
449 mmc_remove_card(card); 475 mmc_remove_card(card);
450err: 476err:
451 477
452 return MMC_ERR_FAILED; 478 return err;
453} 479}
454 480
455/* 481/*
@@ -483,7 +509,7 @@ static void mmc_sd_detect(struct mmc_host *host)
483 509
484 mmc_release_host(host); 510 mmc_release_host(host);
485 511
486 if (err != MMC_ERR_NONE) { 512 if (err) {
487 mmc_sd_remove(host); 513 mmc_sd_remove(host);
488 514
489 mmc_claim_host(host); 515 mmc_claim_host(host);
@@ -552,7 +578,8 @@ static void mmc_sd_suspend(struct mmc_host *host)
552 BUG_ON(!host->card); 578 BUG_ON(!host->card);
553 579
554 mmc_claim_host(host); 580 mmc_claim_host(host);
555 mmc_deselect_cards(host); 581 if (!mmc_host_is_spi(host))
582 mmc_deselect_cards(host);
556 host->card->state &= ~MMC_STATE_HIGHSPEED; 583 host->card->state &= ~MMC_STATE_HIGHSPEED;
557 mmc_release_host(host); 584 mmc_release_host(host);
558} 585}
@@ -574,7 +601,7 @@ static void mmc_sd_resume(struct mmc_host *host)
574 err = mmc_sd_init_card(host, host->ocr, host->card); 601 err = mmc_sd_init_card(host, host->ocr, host->card);
575 mmc_release_host(host); 602 mmc_release_host(host);
576 603
577 if (err != MMC_ERR_NONE) { 604 if (err) {
578 mmc_sd_remove(host); 605 mmc_sd_remove(host);
579 606
580 mmc_claim_host(host); 607 mmc_claim_host(host);
@@ -608,11 +635,22 @@ int mmc_attach_sd(struct mmc_host *host, u32 ocr)
608 int err; 635 int err;
609 636
610 BUG_ON(!host); 637 BUG_ON(!host);
611 BUG_ON(!host->claimed); 638 WARN_ON(!host->claimed);
612 639
613 mmc_attach_bus(host, &mmc_sd_ops); 640 mmc_attach_bus(host, &mmc_sd_ops);
614 641
615 /* 642 /*
643 * We need to get OCR a different way for SPI.
644 */
645 if (mmc_host_is_spi(host)) {
646 mmc_go_idle(host);
647
648 err = mmc_spi_read_ocr(host, 0, &ocr);
649 if (err)
650 goto err;
651 }
652
653 /*
616 * Sanity check the voltages that the card claims to 654 * Sanity check the voltages that the card claims to
617 * support. 655 * support.
618 */ 656 */
@@ -644,7 +682,7 @@ int mmc_attach_sd(struct mmc_host *host, u32 ocr)
644 * Detect and init the card. 682 * Detect and init the card.
645 */ 683 */
646 err = mmc_sd_init_card(host, host->ocr, NULL); 684 err = mmc_sd_init_card(host, host->ocr, NULL);
647 if (err != MMC_ERR_NONE) 685 if (err)
648 goto err; 686 goto err;
649 687
650 mmc_release_host(host); 688 mmc_release_host(host);
@@ -666,6 +704,6 @@ err:
666 printk(KERN_ERR "%s: error %d whilst initialising SD card\n", 704 printk(KERN_ERR "%s: error %d whilst initialising SD card\n",
667 mmc_hostname(host), err); 705 mmc_hostname(host), err);
668 706
669 return 0; 707 return err;
670} 708}
671 709
diff --git a/drivers/mmc/core/sd_ops.c b/drivers/mmc/core/sd_ops.c
index 342f340ebc25..ee4029a24efd 100644
--- a/drivers/mmc/core/sd_ops.c
+++ b/drivers/mmc/core/sd_ops.c
@@ -33,21 +33,21 @@ static int mmc_app_cmd(struct mmc_host *host, struct mmc_card *card)
33 33
34 if (card) { 34 if (card) {
35 cmd.arg = card->rca << 16; 35 cmd.arg = card->rca << 16;
36 cmd.flags = MMC_RSP_R1 | MMC_CMD_AC; 36 cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC;
37 } else { 37 } else {
38 cmd.arg = 0; 38 cmd.arg = 0;
39 cmd.flags = MMC_RSP_R1 | MMC_CMD_BCR; 39 cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_BCR;
40 } 40 }
41 41
42 err = mmc_wait_for_cmd(host, &cmd, 0); 42 err = mmc_wait_for_cmd(host, &cmd, 0);
43 if (err != MMC_ERR_NONE) 43 if (err)
44 return err; 44 return err;
45 45
46 /* Check that card supported application commands */ 46 /* Check that card supported application commands */
47 if (!(cmd.resp[0] & R1_APP_CMD)) 47 if (!mmc_host_is_spi(host) && !(cmd.resp[0] & R1_APP_CMD))
48 return MMC_ERR_FAILED; 48 return -EOPNOTSUPP;
49 49
50 return MMC_ERR_NONE; 50 return 0;
51} 51}
52 52
53/** 53/**
@@ -73,7 +73,7 @@ int mmc_wait_for_app_cmd(struct mmc_host *host, struct mmc_card *card,
73 BUG_ON(!cmd); 73 BUG_ON(!cmd);
74 BUG_ON(retries < 0); 74 BUG_ON(retries < 0);
75 75
76 err = MMC_ERR_INVALID; 76 err = -EIO;
77 77
78 /* 78 /*
79 * We have to resend MMC_APP_CMD for each attempt so 79 * We have to resend MMC_APP_CMD for each attempt so
@@ -83,8 +83,14 @@ int mmc_wait_for_app_cmd(struct mmc_host *host, struct mmc_card *card,
83 memset(&mrq, 0, sizeof(struct mmc_request)); 83 memset(&mrq, 0, sizeof(struct mmc_request));
84 84
85 err = mmc_app_cmd(host, card); 85 err = mmc_app_cmd(host, card);
86 if (err != MMC_ERR_NONE) 86 if (err) {
87 /* no point in retrying; no APP commands allowed */
88 if (mmc_host_is_spi(host)) {
89 if (cmd->resp[0] & R1_SPI_ILLEGAL_COMMAND)
90 break;
91 }
87 continue; 92 continue;
93 }
88 94
89 memset(&mrq, 0, sizeof(struct mmc_request)); 95 memset(&mrq, 0, sizeof(struct mmc_request));
90 96
@@ -97,8 +103,14 @@ int mmc_wait_for_app_cmd(struct mmc_host *host, struct mmc_card *card,
97 mmc_wait_for_req(host, &mrq); 103 mmc_wait_for_req(host, &mrq);
98 104
99 err = cmd->error; 105 err = cmd->error;
100 if (cmd->error == MMC_ERR_NONE) 106 if (!cmd->error)
101 break; 107 break;
108
109 /* no point in retrying illegal APP commands */
110 if (mmc_host_is_spi(host)) {
111 if (cmd->resp[0] & R1_SPI_ILLEGAL_COMMAND)
112 break;
113 }
102 } 114 }
103 115
104 return err; 116 return err;
@@ -127,14 +139,14 @@ int mmc_app_set_bus_width(struct mmc_card *card, int width)
127 cmd.arg = SD_BUS_WIDTH_4; 139 cmd.arg = SD_BUS_WIDTH_4;
128 break; 140 break;
129 default: 141 default:
130 return MMC_ERR_INVALID; 142 return -EINVAL;
131 } 143 }
132 144
133 err = mmc_wait_for_app_cmd(card->host, card, &cmd, MMC_CMD_RETRIES); 145 err = mmc_wait_for_app_cmd(card->host, card, &cmd, MMC_CMD_RETRIES);
134 if (err != MMC_ERR_NONE) 146 if (err)
135 return err; 147 return err;
136 148
137 return MMC_ERR_NONE; 149 return 0;
138} 150}
139 151
140int mmc_send_app_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr) 152int mmc_send_app_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr)
@@ -147,23 +159,36 @@ int mmc_send_app_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr)
147 memset(&cmd, 0, sizeof(struct mmc_command)); 159 memset(&cmd, 0, sizeof(struct mmc_command));
148 160
149 cmd.opcode = SD_APP_OP_COND; 161 cmd.opcode = SD_APP_OP_COND;
150 cmd.arg = ocr; 162 if (mmc_host_is_spi(host))
151 cmd.flags = MMC_RSP_R3 | MMC_CMD_BCR; 163 cmd.arg = ocr & (1 << 30); /* SPI only defines one bit */
164 else
165 cmd.arg = ocr;
166 cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R3 | MMC_CMD_BCR;
152 167
153 for (i = 100; i; i--) { 168 for (i = 100; i; i--) {
154 err = mmc_wait_for_app_cmd(host, NULL, &cmd, MMC_CMD_RETRIES); 169 err = mmc_wait_for_app_cmd(host, NULL, &cmd, MMC_CMD_RETRIES);
155 if (err != MMC_ERR_NONE) 170 if (err)
156 break; 171 break;
157 172
158 if (cmd.resp[0] & MMC_CARD_BUSY || ocr == 0) 173 /* if we're just probing, do a single pass */
174 if (ocr == 0)
159 break; 175 break;
160 176
161 err = MMC_ERR_TIMEOUT; 177 /* otherwise wait until reset completes */
178 if (mmc_host_is_spi(host)) {
179 if (!(cmd.resp[0] & R1_SPI_IDLE))
180 break;
181 } else {
182 if (cmd.resp[0] & MMC_CARD_BUSY)
183 break;
184 }
185
186 err = -ETIMEDOUT;
162 187
163 mmc_delay(10); 188 mmc_delay(10);
164 } 189 }
165 190
166 if (rocr) 191 if (rocr && !mmc_host_is_spi(host))
167 *rocr = cmd.resp[0]; 192 *rocr = cmd.resp[0];
168 193
169 return err; 194 return err;
@@ -174,6 +199,7 @@ int mmc_send_if_cond(struct mmc_host *host, u32 ocr)
174 struct mmc_command cmd; 199 struct mmc_command cmd;
175 int err; 200 int err;
176 static const u8 test_pattern = 0xAA; 201 static const u8 test_pattern = 0xAA;
202 u8 result_pattern;
177 203
178 /* 204 /*
179 * To support SD 2.0 cards, we must always invoke SD_SEND_IF_COND 205 * To support SD 2.0 cards, we must always invoke SD_SEND_IF_COND
@@ -182,16 +208,21 @@ int mmc_send_if_cond(struct mmc_host *host, u32 ocr)
182 */ 208 */
183 cmd.opcode = SD_SEND_IF_COND; 209 cmd.opcode = SD_SEND_IF_COND;
184 cmd.arg = ((ocr & 0xFF8000) != 0) << 8 | test_pattern; 210 cmd.arg = ((ocr & 0xFF8000) != 0) << 8 | test_pattern;
185 cmd.flags = MMC_RSP_R7 | MMC_CMD_BCR; 211 cmd.flags = MMC_RSP_SPI_R7 | MMC_RSP_R7 | MMC_CMD_BCR;
186 212
187 err = mmc_wait_for_cmd(host, &cmd, 0); 213 err = mmc_wait_for_cmd(host, &cmd, 0);
188 if (err != MMC_ERR_NONE) 214 if (err)
189 return err; 215 return err;
190 216
191 if ((cmd.resp[0] & 0xFF) != test_pattern) 217 if (mmc_host_is_spi(host))
192 return MMC_ERR_FAILED; 218 result_pattern = cmd.resp[1] & 0xFF;
219 else
220 result_pattern = cmd.resp[0] & 0xFF;
221
222 if (result_pattern != test_pattern)
223 return -EIO;
193 224
194 return MMC_ERR_NONE; 225 return 0;
195} 226}
196 227
197int mmc_send_relative_addr(struct mmc_host *host, unsigned int *rca) 228int mmc_send_relative_addr(struct mmc_host *host, unsigned int *rca)
@@ -209,12 +240,12 @@ int mmc_send_relative_addr(struct mmc_host *host, unsigned int *rca)
209 cmd.flags = MMC_RSP_R6 | MMC_CMD_BCR; 240 cmd.flags = MMC_RSP_R6 | MMC_CMD_BCR;
210 241
211 err = mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES); 242 err = mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES);
212 if (err != MMC_ERR_NONE) 243 if (err)
213 return err; 244 return err;
214 245
215 *rca = cmd.resp[0] >> 16; 246 *rca = cmd.resp[0] >> 16;
216 247
217 return MMC_ERR_NONE; 248 return 0;
218} 249}
219 250
220int mmc_app_send_scr(struct mmc_card *card, u32 *scr) 251int mmc_app_send_scr(struct mmc_card *card, u32 *scr)
@@ -229,8 +260,10 @@ int mmc_app_send_scr(struct mmc_card *card, u32 *scr)
229 BUG_ON(!card->host); 260 BUG_ON(!card->host);
230 BUG_ON(!scr); 261 BUG_ON(!scr);
231 262
263 /* NOTE: caller guarantees scr is heap-allocated */
264
232 err = mmc_app_cmd(card->host, card); 265 err = mmc_app_cmd(card->host, card);
233 if (err != MMC_ERR_NONE) 266 if (err)
234 return err; 267 return err;
235 268
236 memset(&mrq, 0, sizeof(struct mmc_request)); 269 memset(&mrq, 0, sizeof(struct mmc_request));
@@ -242,7 +275,7 @@ int mmc_app_send_scr(struct mmc_card *card, u32 *scr)
242 275
243 cmd.opcode = SD_APP_SEND_SCR; 276 cmd.opcode = SD_APP_SEND_SCR;
244 cmd.arg = 0; 277 cmd.arg = 0;
245 cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC; 278 cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
246 279
247 data.blksz = 8; 280 data.blksz = 8;
248 data.blocks = 1; 281 data.blocks = 1;
@@ -252,19 +285,19 @@ int mmc_app_send_scr(struct mmc_card *card, u32 *scr)
252 285
253 sg_init_one(&sg, scr, 8); 286 sg_init_one(&sg, scr, 8);
254 287
255 mmc_set_data_timeout(&data, card, 0); 288 mmc_set_data_timeout(&data, card);
256 289
257 mmc_wait_for_req(card->host, &mrq); 290 mmc_wait_for_req(card->host, &mrq);
258 291
259 if (cmd.error != MMC_ERR_NONE) 292 if (cmd.error)
260 return cmd.error; 293 return cmd.error;
261 if (data.error != MMC_ERR_NONE) 294 if (data.error)
262 return data.error; 295 return data.error;
263 296
264 scr[0] = ntohl(scr[0]); 297 scr[0] = ntohl(scr[0]);
265 scr[1] = ntohl(scr[1]); 298 scr[1] = ntohl(scr[1]);
266 299
267 return MMC_ERR_NONE; 300 return 0;
268} 301}
269 302
270int mmc_sd_switch(struct mmc_card *card, int mode, int group, 303int mmc_sd_switch(struct mmc_card *card, int mode, int group,
@@ -278,6 +311,8 @@ int mmc_sd_switch(struct mmc_card *card, int mode, int group,
278 BUG_ON(!card); 311 BUG_ON(!card);
279 BUG_ON(!card->host); 312 BUG_ON(!card->host);
280 313
314 /* NOTE: caller guarantees resp is heap-allocated */
315
281 mode = !!mode; 316 mode = !!mode;
282 value &= 0xF; 317 value &= 0xF;
283 318
@@ -292,7 +327,7 @@ int mmc_sd_switch(struct mmc_card *card, int mode, int group,
292 cmd.arg = mode << 31 | 0x00FFFFFF; 327 cmd.arg = mode << 31 | 0x00FFFFFF;
293 cmd.arg &= ~(0xF << (group * 4)); 328 cmd.arg &= ~(0xF << (group * 4));
294 cmd.arg |= value << (group * 4); 329 cmd.arg |= value << (group * 4);
295 cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC; 330 cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
296 331
297 data.blksz = 64; 332 data.blksz = 64;
298 data.blocks = 1; 333 data.blocks = 1;
@@ -302,15 +337,15 @@ int mmc_sd_switch(struct mmc_card *card, int mode, int group,
302 337
303 sg_init_one(&sg, resp, 64); 338 sg_init_one(&sg, resp, 64);
304 339
305 mmc_set_data_timeout(&data, card, 0); 340 mmc_set_data_timeout(&data, card);
306 341
307 mmc_wait_for_req(card->host, &mrq); 342 mmc_wait_for_req(card->host, &mrq);
308 343
309 if (cmd.error != MMC_ERR_NONE) 344 if (cmd.error)
310 return cmd.error; 345 return cmd.error;
311 if (data.error != MMC_ERR_NONE) 346 if (data.error)
312 return data.error; 347 return data.error;
313 348
314 return MMC_ERR_NONE; 349 return 0;
315} 350}
316 351
diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c
new file mode 100644
index 000000000000..87a50f456efc
--- /dev/null
+++ b/drivers/mmc/core/sdio.c
@@ -0,0 +1,395 @@
1/*
2 * linux/drivers/mmc/sdio.c
3 *
4 * Copyright 2006-2007 Pierre Ossman
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 (at
9 * your option) any later version.
10 */
11
12#include <linux/err.h>
13
14#include <linux/mmc/host.h>
15#include <linux/mmc/card.h>
16#include <linux/mmc/sdio.h>
17#include <linux/mmc/sdio_func.h>
18
19#include "core.h"
20#include "bus.h"
21#include "sdio_bus.h"
22#include "mmc_ops.h"
23#include "sd_ops.h"
24#include "sdio_ops.h"
25#include "sdio_cis.h"
26
27static int sdio_read_fbr(struct sdio_func *func)
28{
29 int ret;
30 unsigned char data;
31
32 ret = mmc_io_rw_direct(func->card, 0, 0,
33 SDIO_FBR_BASE(func->num) + SDIO_FBR_STD_IF, 0, &data);
34 if (ret)
35 goto out;
36
37 data &= 0x0f;
38
39 if (data == 0x0f) {
40 ret = mmc_io_rw_direct(func->card, 0, 0,
41 SDIO_FBR_BASE(func->num) + SDIO_FBR_STD_IF_EXT, 0, &data);
42 if (ret)
43 goto out;
44 }
45
46 func->class = data;
47
48out:
49 return ret;
50}
51
52static int sdio_init_func(struct mmc_card *card, unsigned int fn)
53{
54 int ret;
55 struct sdio_func *func;
56
57 BUG_ON(fn > SDIO_MAX_FUNCS);
58
59 func = sdio_alloc_func(card);
60 if (IS_ERR(func))
61 return PTR_ERR(func);
62
63 func->num = fn;
64
65 ret = sdio_read_fbr(func);
66 if (ret)
67 goto fail;
68
69 ret = sdio_read_func_cis(func);
70 if (ret)
71 goto fail;
72
73 card->sdio_func[fn - 1] = func;
74
75 return 0;
76
77fail:
78 /*
79 * It is okay to remove the function here even though we hold
80 * the host lock as we haven't registered the device yet.
81 */
82 sdio_remove_func(func);
83 return ret;
84}
85
86static int sdio_read_cccr(struct mmc_card *card)
87{
88 int ret;
89 int cccr_vsn;
90 unsigned char data;
91
92 memset(&card->cccr, 0, sizeof(struct sdio_cccr));
93
94 ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_CCCR, 0, &data);
95 if (ret)
96 goto out;
97
98 cccr_vsn = data & 0x0f;
99
100 if (cccr_vsn > SDIO_CCCR_REV_1_20) {
101 printk(KERN_ERR "%s: unrecognised CCCR structure version %d\n",
102 mmc_hostname(card->host), cccr_vsn);
103 return -EINVAL;
104 }
105
106 card->cccr.sdio_vsn = (data & 0xf0) >> 4;
107
108 ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_CAPS, 0, &data);
109 if (ret)
110 goto out;
111
112 if (data & SDIO_CCCR_CAP_SMB)
113 card->cccr.multi_block = 1;
114 if (data & SDIO_CCCR_CAP_LSC)
115 card->cccr.low_speed = 1;
116 if (data & SDIO_CCCR_CAP_4BLS)
117 card->cccr.wide_bus = 1;
118
119 if (cccr_vsn >= SDIO_CCCR_REV_1_10) {
120 ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_POWER, 0, &data);
121 if (ret)
122 goto out;
123
124 if (data & SDIO_POWER_SMPC)
125 card->cccr.high_power = 1;
126 }
127
128 if (cccr_vsn >= SDIO_CCCR_REV_1_20) {
129 ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_SPEED, 0, &data);
130 if (ret)
131 goto out;
132
133 if (data & SDIO_SPEED_SHS)
134 card->cccr.high_speed = 1;
135 }
136
137out:
138 return ret;
139}
140
141static int sdio_enable_wide(struct mmc_card *card)
142{
143 int ret;
144 u8 ctrl;
145
146 if (!(card->host->caps & MMC_CAP_4_BIT_DATA))
147 return 0;
148
149 if (card->cccr.low_speed && !card->cccr.wide_bus)
150 return 0;
151
152 ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_IF, 0, &ctrl);
153 if (ret)
154 return ret;
155
156 ctrl |= SDIO_BUS_WIDTH_4BIT;
157
158 ret = mmc_io_rw_direct(card, 1, 0, SDIO_CCCR_IF, ctrl, NULL);
159 if (ret)
160 return ret;
161
162 mmc_set_bus_width(card->host, MMC_BUS_WIDTH_4);
163
164 return 0;
165}
166
167/*
168 * Host is being removed. Free up the current card.
169 */
170static void mmc_sdio_remove(struct mmc_host *host)
171{
172 int i;
173
174 BUG_ON(!host);
175 BUG_ON(!host->card);
176
177 for (i = 0;i < host->card->sdio_funcs;i++) {
178 if (host->card->sdio_func[i]) {
179 sdio_remove_func(host->card->sdio_func[i]);
180 host->card->sdio_func[i] = NULL;
181 }
182 }
183
184 mmc_remove_card(host->card);
185 host->card = NULL;
186}
187
188/*
189 * Card detection callback from host.
190 */
191static void mmc_sdio_detect(struct mmc_host *host)
192{
193 int err;
194
195 BUG_ON(!host);
196 BUG_ON(!host->card);
197
198 mmc_claim_host(host);
199
200 /*
201 * Just check if our card has been removed.
202 */
203 err = mmc_select_card(host->card);
204
205 mmc_release_host(host);
206
207 if (err) {
208 mmc_sdio_remove(host);
209
210 mmc_claim_host(host);
211 mmc_detach_bus(host);
212 mmc_release_host(host);
213 }
214}
215
216
217static const struct mmc_bus_ops mmc_sdio_ops = {
218 .remove = mmc_sdio_remove,
219 .detect = mmc_sdio_detect,
220};
221
222
223/*
224 * Starting point for SDIO card init.
225 */
226int mmc_attach_sdio(struct mmc_host *host, u32 ocr)
227{
228 int err;
229 int i, funcs;
230 struct mmc_card *card;
231
232 BUG_ON(!host);
233 WARN_ON(!host->claimed);
234
235 mmc_attach_bus(host, &mmc_sdio_ops);
236
237 /*
238 * Sanity check the voltages that the card claims to
239 * support.
240 */
241 if (ocr & 0x7F) {
242 printk(KERN_WARNING "%s: card claims to support voltages "
243 "below the defined range. These will be ignored.\n",
244 mmc_hostname(host));
245 ocr &= ~0x7F;
246 }
247
248 if (ocr & MMC_VDD_165_195) {
249 printk(KERN_WARNING "%s: SDIO card claims to support the "
250 "incompletely defined 'low voltage range'. This "
251 "will be ignored.\n", mmc_hostname(host));
252 ocr &= ~MMC_VDD_165_195;
253 }
254
255 host->ocr = mmc_select_voltage(host, ocr);
256
257 /*
258 * Can we support the voltage(s) of the card(s)?
259 */
260 if (!host->ocr) {
261 err = -EINVAL;
262 goto err;
263 }
264
265 /*
266 * Inform the card of the voltage
267 */
268 err = mmc_send_io_op_cond(host, host->ocr, &ocr);
269 if (err)
270 goto err;
271
272 /*
273 * For SPI, enable CRC as appropriate.
274 */
275 if (mmc_host_is_spi(host)) {
276 err = mmc_spi_set_crc(host, use_spi_crc);
277 if (err)
278 goto err;
279 }
280
281 /*
282 * The number of functions on the card is encoded inside
283 * the ocr.
284 */
285 funcs = (ocr & 0x70000000) >> 28;
286
287 /*
288 * Allocate card structure.
289 */
290 card = mmc_alloc_card(host);
291 if (IS_ERR(card)) {
292 err = PTR_ERR(card);
293 goto err;
294 }
295
296 card->type = MMC_TYPE_SDIO;
297 card->sdio_funcs = funcs;
298
299 host->card = card;
300
301 /*
302 * For native busses: set card RCA and quit open drain mode.
303 */
304 if (!mmc_host_is_spi(host)) {
305 err = mmc_send_relative_addr(host, &card->rca);
306 if (err)
307 goto remove;
308
309 mmc_set_bus_mode(host, MMC_BUSMODE_PUSHPULL);
310 }
311
312 /*
313 * Select card, as all following commands rely on that.
314 */
315 if (!mmc_host_is_spi(host)) {
316 err = mmc_select_card(card);
317 if (err)
318 goto remove;
319 }
320
321 /*
322 * Read the common registers.
323 */
324 err = sdio_read_cccr(card);
325 if (err)
326 goto remove;
327
328 /*
329 * Read the common CIS tuples.
330 */
331 err = sdio_read_common_cis(card);
332 if (err)
333 goto remove;
334
335 /*
336 * No support for high-speed yet, so just set
337 * the card's maximum speed.
338 */
339 mmc_set_clock(host, card->cis.max_dtr);
340
341 /*
342 * Switch to wider bus (if supported).
343 */
344 err = sdio_enable_wide(card);
345 if (err)
346 goto remove;
347
348 /*
349 * Initialize (but don't add) all present functions.
350 */
351 for (i = 0;i < funcs;i++) {
352 err = sdio_init_func(host->card, i + 1);
353 if (err)
354 goto remove;
355 }
356
357 mmc_release_host(host);
358
359 /*
360 * First add the card to the driver model...
361 */
362 err = mmc_add_card(host->card);
363 if (err)
364 goto remove_added;
365
366 /*
367 * ...then the SDIO functions.
368 */
369 for (i = 0;i < funcs;i++) {
370 err = sdio_add_func(host->card->sdio_func[i]);
371 if (err)
372 goto remove_added;
373 }
374
375 return 0;
376
377
378remove_added:
379 /* Remove without lock if the device has been added. */
380 mmc_sdio_remove(host);
381 mmc_claim_host(host);
382remove:
383 /* And with lock if it hasn't been added. */
384 if (host->card)
385 mmc_sdio_remove(host);
386err:
387 mmc_detach_bus(host);
388 mmc_release_host(host);
389
390 printk(KERN_ERR "%s: error %d whilst initialising SDIO card\n",
391 mmc_hostname(host), err);
392
393 return err;
394}
395
diff --git a/drivers/mmc/core/sdio_bus.c b/drivers/mmc/core/sdio_bus.c
new file mode 100644
index 000000000000..0713a8c71e54
--- /dev/null
+++ b/drivers/mmc/core/sdio_bus.c
@@ -0,0 +1,270 @@
1/*
2 * linux/drivers/mmc/core/sdio_bus.c
3 *
4 * Copyright 2007 Pierre Ossman
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 (at
9 * your option) any later version.
10 *
11 * SDIO function driver model
12 */
13
14#include <linux/device.h>
15#include <linux/err.h>
16
17#include <linux/mmc/card.h>
18#include <linux/mmc/sdio_func.h>
19
20#include "sdio_cis.h"
21#include "sdio_bus.h"
22
23#define dev_to_sdio_func(d) container_of(d, struct sdio_func, dev)
24#define to_sdio_driver(d) container_of(d, struct sdio_driver, drv)
25
26/* show configuration fields */
27#define sdio_config_attr(field, format_string) \
28static ssize_t \
29field##_show(struct device *dev, struct device_attribute *attr, char *buf) \
30{ \
31 struct sdio_func *func; \
32 \
33 func = dev_to_sdio_func (dev); \
34 return sprintf (buf, format_string, func->field); \
35}
36
37sdio_config_attr(class, "0x%02x\n");
38sdio_config_attr(vendor, "0x%04x\n");
39sdio_config_attr(device, "0x%04x\n");
40
41static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, char *buf)
42{
43 struct sdio_func *func = dev_to_sdio_func (dev);
44
45 return sprintf(buf, "sdio:c%02Xv%04Xd%04X\n",
46 func->class, func->vendor, func->device);
47}
48
49static struct device_attribute sdio_dev_attrs[] = {
50 __ATTR_RO(class),
51 __ATTR_RO(vendor),
52 __ATTR_RO(device),
53 __ATTR_RO(modalias),
54 __ATTR_NULL,
55};
56
57static const struct sdio_device_id *sdio_match_one(struct sdio_func *func,
58 const struct sdio_device_id *id)
59{
60 if (id->class != (__u8)SDIO_ANY_ID && id->class != func->class)
61 return NULL;
62 if (id->vendor != (__u16)SDIO_ANY_ID && id->vendor != func->vendor)
63 return NULL;
64 if (id->device != (__u16)SDIO_ANY_ID && id->device != func->device)
65 return NULL;
66 return id;
67}
68
69static const struct sdio_device_id *sdio_match_device(struct sdio_func *func,
70 struct sdio_driver *sdrv)
71{
72 const struct sdio_device_id *ids;
73
74 ids = sdrv->id_table;
75
76 if (ids) {
77 while (ids->class || ids->vendor || ids->device) {
78 if (sdio_match_one(func, ids))
79 return ids;
80 ids++;
81 }
82 }
83
84 return NULL;
85}
86
87static int sdio_bus_match(struct device *dev, struct device_driver *drv)
88{
89 struct sdio_func *func = dev_to_sdio_func(dev);
90 struct sdio_driver *sdrv = to_sdio_driver(drv);
91
92 if (sdio_match_device(func, sdrv))
93 return 1;
94
95 return 0;
96}
97
98static int
99sdio_bus_uevent(struct device *dev, char **envp, int num_envp, char *buf,
100 int buf_size)
101{
102 struct sdio_func *func = dev_to_sdio_func(dev);
103 int i = 0, length = 0;
104
105 if (add_uevent_var(envp, num_envp, &i,
106 buf, buf_size, &length,
107 "SDIO_CLASS=%02X", func->class))
108 return -ENOMEM;
109
110 if (add_uevent_var(envp, num_envp, &i,
111 buf, buf_size, &length,
112 "SDIO_ID=%04X:%04X", func->vendor, func->device))
113 return -ENOMEM;
114
115 if (add_uevent_var(envp, num_envp, &i,
116 buf, buf_size, &length,
117 "MODALIAS=sdio:c%02Xv%04Xd%04X",
118 func->class, func->vendor, func->device))
119 return -ENOMEM;
120
121 envp[i] = NULL;
122
123 return 0;
124}
125
126static int sdio_bus_probe(struct device *dev)
127{
128 struct sdio_driver *drv = to_sdio_driver(dev->driver);
129 struct sdio_func *func = dev_to_sdio_func(dev);
130 const struct sdio_device_id *id;
131 int ret;
132
133 id = sdio_match_device(func, drv);
134 if (!id)
135 return -ENODEV;
136
137 /* Set the default block size so the driver is sure it's something
138 * sensible. */
139 sdio_claim_host(func);
140 ret = sdio_set_block_size(func, 0);
141 sdio_release_host(func);
142 if (ret)
143 return ret;
144
145 return drv->probe(func, id);
146}
147
148static int sdio_bus_remove(struct device *dev)
149{
150 struct sdio_driver *drv = to_sdio_driver(dev->driver);
151 struct sdio_func *func = dev_to_sdio_func(dev);
152
153 drv->remove(func);
154
155 if (func->irq_handler) {
156 printk(KERN_WARNING "WARNING: driver %s did not remove "
157 "its interrupt handler!\n", drv->name);
158 sdio_claim_host(func);
159 sdio_release_irq(func);
160 sdio_release_host(func);
161 }
162
163 return 0;
164}
165
166static struct bus_type sdio_bus_type = {
167 .name = "sdio",
168 .dev_attrs = sdio_dev_attrs,
169 .match = sdio_bus_match,
170 .uevent = sdio_bus_uevent,
171 .probe = sdio_bus_probe,
172 .remove = sdio_bus_remove,
173};
174
175int sdio_register_bus(void)
176{
177 return bus_register(&sdio_bus_type);
178}
179
180void sdio_unregister_bus(void)
181{
182 bus_unregister(&sdio_bus_type);
183}
184
185/**
186 * sdio_register_driver - register a function driver
187 * @drv: SDIO function driver
188 */
189int sdio_register_driver(struct sdio_driver *drv)
190{
191 drv->drv.name = drv->name;
192 drv->drv.bus = &sdio_bus_type;
193 return driver_register(&drv->drv);
194}
195EXPORT_SYMBOL_GPL(sdio_register_driver);
196
197/**
198 * sdio_unregister_driver - unregister a function driver
199 * @drv: SDIO function driver
200 */
201void sdio_unregister_driver(struct sdio_driver *drv)
202{
203 drv->drv.bus = &sdio_bus_type;
204 driver_unregister(&drv->drv);
205}
206EXPORT_SYMBOL_GPL(sdio_unregister_driver);
207
208static void sdio_release_func(struct device *dev)
209{
210 struct sdio_func *func = dev_to_sdio_func(dev);
211
212 sdio_free_func_cis(func);
213
214 if (func->info)
215 kfree(func->info);
216
217 kfree(func);
218}
219
220/*
221 * Allocate and initialise a new SDIO function structure.
222 */
223struct sdio_func *sdio_alloc_func(struct mmc_card *card)
224{
225 struct sdio_func *func;
226
227 func = kzalloc(sizeof(struct sdio_func), GFP_KERNEL);
228 if (!func)
229 return ERR_PTR(-ENOMEM);
230
231 func->card = card;
232
233 device_initialize(&func->dev);
234
235 func->dev.parent = &card->dev;
236 func->dev.bus = &sdio_bus_type;
237 func->dev.release = sdio_release_func;
238
239 return func;
240}
241
242/*
243 * Register a new SDIO function with the driver model.
244 */
245int sdio_add_func(struct sdio_func *func)
246{
247 int ret;
248
249 snprintf(func->dev.bus_id, sizeof(func->dev.bus_id),
250 "%s:%d", mmc_card_id(func->card), func->num);
251
252 ret = device_add(&func->dev);
253 if (ret == 0)
254 sdio_func_set_present(func);
255
256 return ret;
257}
258
259/*
260 * Unregister a SDIO function with the driver model, and
261 * (eventually) free it.
262 */
263void sdio_remove_func(struct sdio_func *func)
264{
265 if (sdio_func_present(func))
266 device_del(&func->dev);
267
268 put_device(&func->dev);
269}
270
diff --git a/drivers/mmc/core/sdio_bus.h b/drivers/mmc/core/sdio_bus.h
new file mode 100644
index 000000000000..567a76821ba7
--- /dev/null
+++ b/drivers/mmc/core/sdio_bus.h
@@ -0,0 +1,22 @@
1/*
2 * linux/drivers/mmc/core/sdio_bus.h
3 *
4 * Copyright 2007 Pierre Ossman
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 (at
9 * your option) any later version.
10 */
11#ifndef _MMC_CORE_SDIO_BUS_H
12#define _MMC_CORE_SDIO_BUS_H
13
14struct sdio_func *sdio_alloc_func(struct mmc_card *card);
15int sdio_add_func(struct sdio_func *func);
16void sdio_remove_func(struct sdio_func *func);
17
18int sdio_register_bus(void);
19void sdio_unregister_bus(void);
20
21#endif
22
diff --git a/drivers/mmc/core/sdio_cis.c b/drivers/mmc/core/sdio_cis.c
new file mode 100644
index 000000000000..d5e51b1c7b3f
--- /dev/null
+++ b/drivers/mmc/core/sdio_cis.c
@@ -0,0 +1,346 @@
1/*
2 * linux/drivers/mmc/core/sdio_cis.c
3 *
4 * Author: Nicolas Pitre
5 * Created: June 11, 2007
6 * Copyright: MontaVista Software Inc.
7 *
8 * Copyright 2007 Pierre Ossman
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or (at
13 * your option) any later version.
14 */
15
16#include <linux/kernel.h>
17
18#include <linux/mmc/host.h>
19#include <linux/mmc/card.h>
20#include <linux/mmc/sdio.h>
21#include <linux/mmc/sdio_func.h>
22
23#include "sdio_cis.h"
24#include "sdio_ops.h"
25
26static int cistpl_vers_1(struct mmc_card *card, struct sdio_func *func,
27 const unsigned char *buf, unsigned size)
28{
29 unsigned i, nr_strings;
30 char **buffer, *string;
31
32 buf += 2;
33 size -= 2;
34
35 nr_strings = 0;
36 for (i = 0; i < size; i++) {
37 if (buf[i] == 0xff)
38 break;
39 if (buf[i] == 0)
40 nr_strings++;
41 }
42
43 if (buf[i-1] != '\0') {
44 printk(KERN_WARNING "SDIO: ignoring broken CISTPL_VERS_1\n");
45 return 0;
46 }
47
48 size = i;
49
50 buffer = kzalloc(sizeof(char*) * nr_strings + size, GFP_KERNEL);
51 if (!buffer)
52 return -ENOMEM;
53
54 string = (char*)(buffer + nr_strings);
55
56 for (i = 0; i < nr_strings; i++) {
57 buffer[i] = string;
58 strcpy(string, buf);
59 string += strlen(string) + 1;
60 buf += strlen(buf) + 1;
61 }
62
63 if (func) {
64 func->num_info = nr_strings;
65 func->info = (const char**)buffer;
66 } else {
67 card->num_info = nr_strings;
68 card->info = (const char**)buffer;
69 }
70
71 return 0;
72}
73
74static int cistpl_manfid(struct mmc_card *card, struct sdio_func *func,
75 const unsigned char *buf, unsigned size)
76{
77 unsigned int vendor, device;
78
79 /* TPLMID_MANF */
80 vendor = buf[0] | (buf[1] << 8);
81
82 /* TPLMID_CARD */
83 device = buf[2] | (buf[3] << 8);
84
85 if (func) {
86 func->vendor = vendor;
87 func->device = device;
88 } else {
89 card->cis.vendor = vendor;
90 card->cis.device = device;
91 }
92
93 return 0;
94}
95
96static const unsigned char speed_val[16] =
97 { 0, 10, 12, 13, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 70, 80 };
98static const unsigned int speed_unit[8] =
99 { 10000, 100000, 1000000, 10000000, 0, 0, 0, 0 };
100
101static int cistpl_funce_common(struct mmc_card *card,
102 const unsigned char *buf, unsigned size)
103{
104 if (size < 0x04 || buf[0] != 0)
105 return -EINVAL;
106
107 /* TPLFE_FN0_BLK_SIZE */
108 card->cis.blksize = buf[1] | (buf[2] << 8);
109
110 /* TPLFE_MAX_TRAN_SPEED */
111 card->cis.max_dtr = speed_val[(buf[3] >> 3) & 15] *
112 speed_unit[buf[3] & 7];
113
114 return 0;
115}
116
117static int cistpl_funce_func(struct sdio_func *func,
118 const unsigned char *buf, unsigned size)
119{
120 unsigned vsn;
121 unsigned min_size;
122
123 vsn = func->card->cccr.sdio_vsn;
124 min_size = (vsn == SDIO_SDIO_REV_1_00) ? 28 : 42;
125
126 if (size < min_size || buf[0] != 1)
127 return -EINVAL;
128
129 /* TPLFE_MAX_BLK_SIZE */
130 func->max_blksize = buf[12] | (buf[13] << 8);
131
132 return 0;
133}
134
135static int cistpl_funce(struct mmc_card *card, struct sdio_func *func,
136 const unsigned char *buf, unsigned size)
137{
138 int ret;
139
140 /*
141 * There should be two versions of the CISTPL_FUNCE tuple,
142 * one for the common CIS (function 0) and a version used by
143 * the individual function's CIS (1-7). Yet, the later has a
144 * different length depending on the SDIO spec version.
145 */
146 if (func)
147 ret = cistpl_funce_func(func, buf, size);
148 else
149 ret = cistpl_funce_common(card, buf, size);
150
151 if (ret) {
152 printk(KERN_ERR "%s: bad CISTPL_FUNCE size %u "
153 "type %u\n", mmc_hostname(card->host), size, buf[0]);
154 return ret;
155 }
156
157 return 0;
158}
159
160typedef int (tpl_parse_t)(struct mmc_card *, struct sdio_func *,
161 const unsigned char *, unsigned);
162
163struct cis_tpl {
164 unsigned char code;
165 unsigned char min_size;
166 tpl_parse_t *parse;
167};
168
169static const struct cis_tpl cis_tpl_list[] = {
170 { 0x15, 3, cistpl_vers_1 },
171 { 0x20, 4, cistpl_manfid },
172 { 0x21, 2, /* cistpl_funcid */ },
173 { 0x22, 0, cistpl_funce },
174};
175
176static int sdio_read_cis(struct mmc_card *card, struct sdio_func *func)
177{
178 int ret;
179 struct sdio_func_tuple *this, **prev;
180 unsigned i, ptr = 0;
181
182 /*
183 * Note that this works for the common CIS (function number 0) as
184 * well as a function's CIS * since SDIO_CCCR_CIS and SDIO_FBR_CIS
185 * have the same offset.
186 */
187 for (i = 0; i < 3; i++) {
188 unsigned char x, fn;
189
190 if (func)
191 fn = func->num;
192 else
193 fn = 0;
194
195 ret = mmc_io_rw_direct(card, 0, 0,
196 SDIO_FBR_BASE(fn) + SDIO_FBR_CIS + i, 0, &x);
197 if (ret)
198 return ret;
199 ptr |= x << (i * 8);
200 }
201
202 if (func)
203 prev = &func->tuples;
204 else
205 prev = &card->tuples;
206
207 BUG_ON(*prev);
208
209 do {
210 unsigned char tpl_code, tpl_link;
211
212 ret = mmc_io_rw_direct(card, 0, 0, ptr++, 0, &tpl_code);
213 if (ret)
214 break;
215
216 /* 0xff means we're done */
217 if (tpl_code == 0xff)
218 break;
219
220 ret = mmc_io_rw_direct(card, 0, 0, ptr++, 0, &tpl_link);
221 if (ret)
222 break;
223
224 this = kmalloc(sizeof(*this) + tpl_link, GFP_KERNEL);
225 if (!this)
226 return -ENOMEM;
227
228 for (i = 0; i < tpl_link; i++) {
229 ret = mmc_io_rw_direct(card, 0, 0,
230 ptr + i, 0, &this->data[i]);
231 if (ret)
232 break;
233 }
234 if (ret) {
235 kfree(this);
236 break;
237 }
238
239 for (i = 0; i < ARRAY_SIZE(cis_tpl_list); i++)
240 if (cis_tpl_list[i].code == tpl_code)
241 break;
242 if (i >= ARRAY_SIZE(cis_tpl_list)) {
243 /* this tuple is unknown to the core */
244 this->next = NULL;
245 this->code = tpl_code;
246 this->size = tpl_link;
247 *prev = this;
248 prev = &this->next;
249 printk(KERN_DEBUG
250 "%s: queuing CIS tuple 0x%02x length %u\n",
251 mmc_hostname(card->host), tpl_code, tpl_link);
252 } else {
253 const struct cis_tpl *tpl = cis_tpl_list + i;
254 if (tpl_link < tpl->min_size) {
255 printk(KERN_ERR
256 "%s: bad CIS tuple 0x%02x (length = %u, expected >= %u)\n",
257 mmc_hostname(card->host),
258 tpl_code, tpl_link, tpl->min_size);
259 ret = -EINVAL;
260 } else if (tpl->parse) {
261 ret = tpl->parse(card, func,
262 this->data, tpl_link);
263 }
264 kfree(this);
265 }
266
267 ptr += tpl_link;
268 } while (!ret);
269
270 /*
271 * Link in all unknown tuples found in the common CIS so that
272 * drivers don't have to go digging in two places.
273 */
274 if (func)
275 *prev = card->tuples;
276
277 return ret;
278}
279
280int sdio_read_common_cis(struct mmc_card *card)
281{
282 return sdio_read_cis(card, NULL);
283}
284
285void sdio_free_common_cis(struct mmc_card *card)
286{
287 struct sdio_func_tuple *tuple, *victim;
288
289 tuple = card->tuples;
290
291 while (tuple) {
292 victim = tuple;
293 tuple = tuple->next;
294 kfree(victim);
295 }
296
297 card->tuples = NULL;
298}
299
300int sdio_read_func_cis(struct sdio_func *func)
301{
302 int ret;
303
304 ret = sdio_read_cis(func->card, func);
305 if (ret)
306 return ret;
307
308 /*
309 * Since we've linked to tuples in the card structure,
310 * we must make sure we have a reference to it.
311 */
312 get_device(&func->card->dev);
313
314 /*
315 * Vendor/device id is optional for function CIS, so
316 * copy it from the card structure as needed.
317 */
318 if (func->vendor == 0) {
319 func->vendor = func->card->cis.vendor;
320 func->device = func->card->cis.device;
321 }
322
323 return 0;
324}
325
326void sdio_free_func_cis(struct sdio_func *func)
327{
328 struct sdio_func_tuple *tuple, *victim;
329
330 tuple = func->tuples;
331
332 while (tuple && tuple != func->card->tuples) {
333 victim = tuple;
334 tuple = tuple->next;
335 kfree(victim);
336 }
337
338 func->tuples = NULL;
339
340 /*
341 * We have now removed the link to the tuples in the
342 * card structure, so remove the reference.
343 */
344 put_device(&func->card->dev);
345}
346
diff --git a/drivers/mmc/core/sdio_cis.h b/drivers/mmc/core/sdio_cis.h
new file mode 100644
index 000000000000..4d903c2e425e
--- /dev/null
+++ b/drivers/mmc/core/sdio_cis.h
@@ -0,0 +1,23 @@
1/*
2 * linux/drivers/mmc/core/sdio_cis.h
3 *
4 * Author: Nicolas Pitre
5 * Created: June 11, 2007
6 * Copyright: MontaVista Software Inc.
7 *
8 * 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
10 * the Free Software Foundation; either version 2 of the License, or (at
11 * your option) any later version.
12 */
13
14#ifndef _MMC_SDIO_CIS_H
15#define _MMC_SDIO_CIS_H
16
17int sdio_read_common_cis(struct mmc_card *card);
18void sdio_free_common_cis(struct mmc_card *card);
19
20int sdio_read_func_cis(struct sdio_func *func);
21void sdio_free_func_cis(struct sdio_func *func);
22
23#endif
diff --git a/drivers/mmc/core/sdio_io.c b/drivers/mmc/core/sdio_io.c
new file mode 100644
index 000000000000..625b92ce9cef
--- /dev/null
+++ b/drivers/mmc/core/sdio_io.c
@@ -0,0 +1,548 @@
1/*
2 * linux/drivers/mmc/core/sdio_io.c
3 *
4 * Copyright 2007 Pierre Ossman
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 (at
9 * your option) any later version.
10 */
11
12#include <linux/mmc/host.h>
13#include <linux/mmc/card.h>
14#include <linux/mmc/sdio.h>
15#include <linux/mmc/sdio_func.h>
16
17#include "sdio_ops.h"
18
19/**
20 * sdio_claim_host - exclusively claim a bus for a certain SDIO function
21 * @func: SDIO function that will be accessed
22 *
23 * Claim a bus for a set of operations. The SDIO function given
24 * is used to figure out which bus is relevant.
25 */
26void sdio_claim_host(struct sdio_func *func)
27{
28 BUG_ON(!func);
29 BUG_ON(!func->card);
30
31 mmc_claim_host(func->card->host);
32}
33EXPORT_SYMBOL_GPL(sdio_claim_host);
34
35/**
36 * sdio_release_host - release a bus for a certain SDIO function
37 * @func: SDIO function that was accessed
38 *
39 * Release a bus, allowing others to claim the bus for their
40 * operations.
41 */
42void sdio_release_host(struct sdio_func *func)
43{
44 BUG_ON(!func);
45 BUG_ON(!func->card);
46
47 mmc_release_host(func->card->host);
48}
49EXPORT_SYMBOL_GPL(sdio_release_host);
50
51/**
52 * sdio_enable_func - enables a SDIO function for usage
53 * @func: SDIO function to enable
54 *
55 * Powers up and activates a SDIO function so that register
56 * access is possible.
57 */
58int sdio_enable_func(struct sdio_func *func)
59{
60 int ret;
61 unsigned char reg;
62 unsigned long timeout;
63
64 BUG_ON(!func);
65 BUG_ON(!func->card);
66
67 pr_debug("SDIO: Enabling device %s...\n", sdio_func_id(func));
68
69 ret = mmc_io_rw_direct(func->card, 0, 0, SDIO_CCCR_IOEx, 0, &reg);
70 if (ret)
71 goto err;
72
73 reg |= 1 << func->num;
74
75 ret = mmc_io_rw_direct(func->card, 1, 0, SDIO_CCCR_IOEx, reg, NULL);
76 if (ret)
77 goto err;
78
79 /*
80 * FIXME: This should timeout based on information in the CIS,
81 * but we don't have card to parse that yet.
82 */
83 timeout = jiffies + HZ;
84
85 while (1) {
86 ret = mmc_io_rw_direct(func->card, 0, 0, SDIO_CCCR_IORx, 0, &reg);
87 if (ret)
88 goto err;
89 if (reg & (1 << func->num))
90 break;
91 ret = -ETIME;
92 if (time_after(jiffies, timeout))
93 goto err;
94 }
95
96 pr_debug("SDIO: Enabled device %s\n", sdio_func_id(func));
97
98 return 0;
99
100err:
101 pr_debug("SDIO: Failed to enable device %s\n", sdio_func_id(func));
102 return ret;
103}
104EXPORT_SYMBOL_GPL(sdio_enable_func);
105
106/**
107 * sdio_disable_func - disable a SDIO function
108 * @func: SDIO function to disable
109 *
110 * Powers down and deactivates a SDIO function. Register access
111 * to this function will fail until the function is reenabled.
112 */
113int sdio_disable_func(struct sdio_func *func)
114{
115 int ret;
116 unsigned char reg;
117
118 BUG_ON(!func);
119 BUG_ON(!func->card);
120
121 pr_debug("SDIO: Disabling device %s...\n", sdio_func_id(func));
122
123 ret = mmc_io_rw_direct(func->card, 0, 0, SDIO_CCCR_IOEx, 0, &reg);
124 if (ret)
125 goto err;
126
127 reg &= ~(1 << func->num);
128
129 ret = mmc_io_rw_direct(func->card, 1, 0, SDIO_CCCR_IOEx, reg, NULL);
130 if (ret)
131 goto err;
132
133 pr_debug("SDIO: Disabled device %s\n", sdio_func_id(func));
134
135 return 0;
136
137err:
138 pr_debug("SDIO: Failed to disable device %s\n", sdio_func_id(func));
139 return -EIO;
140}
141EXPORT_SYMBOL_GPL(sdio_disable_func);
142
143/**
144 * sdio_set_block_size - set the block size of an SDIO function
145 * @func: SDIO function to change
146 * @blksz: new block size or 0 to use the default.
147 *
148 * The default block size is the largest supported by both the function
149 * and the host, with a maximum of 512 to ensure that arbitrarily sized
150 * data transfer use the optimal (least) number of commands.
151 *
152 * A driver may call this to override the default block size set by the
153 * core. This can be used to set a block size greater than the maximum
154 * that reported by the card; it is the driver's responsibility to ensure
155 * it uses a value that the card supports.
156 *
157 * Returns 0 on success, -EINVAL if the host does not support the
158 * requested block size, or -EIO (etc.) if one of the resultant FBR block
159 * size register writes failed.
160 *
161 */
162int sdio_set_block_size(struct sdio_func *func, unsigned blksz)
163{
164 int ret;
165
166 if (blksz > func->card->host->max_blk_size)
167 return -EINVAL;
168
169 if (blksz == 0) {
170 blksz = min(min(
171 func->max_blksize,
172 func->card->host->max_blk_size),
173 512u);
174 }
175
176 ret = mmc_io_rw_direct(func->card, 1, 0,
177 SDIO_FBR_BASE(func->num) + SDIO_FBR_BLKSIZE,
178 blksz & 0xff, NULL);
179 if (ret)
180 return ret;
181 ret = mmc_io_rw_direct(func->card, 1, 0,
182 SDIO_FBR_BASE(func->num) + SDIO_FBR_BLKSIZE + 1,
183 (blksz >> 8) & 0xff, NULL);
184 if (ret)
185 return ret;
186 func->cur_blksize = blksz;
187 return 0;
188}
189
190EXPORT_SYMBOL_GPL(sdio_set_block_size);
191
192/* Split an arbitrarily sized data transfer into several
193 * IO_RW_EXTENDED commands. */
194static int sdio_io_rw_ext_helper(struct sdio_func *func, int write,
195 unsigned addr, int incr_addr, u8 *buf, unsigned size)
196{
197 unsigned remainder = size;
198 unsigned max_blocks;
199 int ret;
200
201 /* Do the bulk of the transfer using block mode (if supported). */
202 if (func->card->cccr.multi_block) {
203 /* Blocks per command is limited by host count, host transfer
204 * size (we only use a single sg entry) and the maximum for
205 * IO_RW_EXTENDED of 511 blocks. */
206 max_blocks = min(min(
207 func->card->host->max_blk_count,
208 func->card->host->max_seg_size / func->cur_blksize),
209 511u);
210
211 while (remainder > func->cur_blksize) {
212 unsigned blocks;
213
214 blocks = remainder / func->cur_blksize;
215 if (blocks > max_blocks)
216 blocks = max_blocks;
217 size = blocks * func->cur_blksize;
218
219 ret = mmc_io_rw_extended(func->card, write,
220 func->num, addr, incr_addr, buf,
221 blocks, func->cur_blksize);
222 if (ret)
223 return ret;
224
225 remainder -= size;
226 buf += size;
227 if (incr_addr)
228 addr += size;
229 }
230 }
231
232 /* Write the remainder using byte mode. */
233 while (remainder > 0) {
234 size = remainder;
235 if (size > func->cur_blksize)
236 size = func->cur_blksize;
237 if (size > 512)
238 size = 512; /* maximum size for byte mode */
239
240 ret = mmc_io_rw_extended(func->card, write, func->num, addr,
241 incr_addr, buf, 1, size);
242 if (ret)
243 return ret;
244
245 remainder -= size;
246 buf += size;
247 if (incr_addr)
248 addr += size;
249 }
250 return 0;
251}
252
253/**
254 * sdio_readb - read a single byte from a SDIO function
255 * @func: SDIO function to access
256 * @addr: address to read
257 * @err_ret: optional status value from transfer
258 *
259 * Reads a single byte from the address space of a given SDIO
260 * function. If there is a problem reading the address, 0xff
261 * is returned and @err_ret will contain the error code.
262 */
263unsigned char sdio_readb(struct sdio_func *func, unsigned int addr,
264 int *err_ret)
265{
266 int ret;
267 unsigned char val;
268
269 BUG_ON(!func);
270
271 if (err_ret)
272 *err_ret = 0;
273
274 ret = mmc_io_rw_direct(func->card, 0, func->num, addr, 0, &val);
275 if (ret) {
276 if (err_ret)
277 *err_ret = ret;
278 return 0xFF;
279 }
280
281 return val;
282}
283EXPORT_SYMBOL_GPL(sdio_readb);
284
285/**
286 * sdio_writeb - write a single byte to a SDIO function
287 * @func: SDIO function to access
288 * @b: byte to write
289 * @addr: address to write to
290 * @err_ret: optional status value from transfer
291 *
292 * Writes a single byte to the address space of a given SDIO
293 * function. @err_ret will contain the status of the actual
294 * transfer.
295 */
296void sdio_writeb(struct sdio_func *func, unsigned char b, unsigned int addr,
297 int *err_ret)
298{
299 int ret;
300
301 BUG_ON(!func);
302
303 ret = mmc_io_rw_direct(func->card, 1, func->num, addr, b, NULL);
304 if (err_ret)
305 *err_ret = ret;
306}
307EXPORT_SYMBOL_GPL(sdio_writeb);
308
309/**
310 * sdio_memcpy_fromio - read a chunk of memory from a SDIO function
311 * @func: SDIO function to access
312 * @dst: buffer to store the data
313 * @addr: address to begin reading from
314 * @count: number of bytes to read
315 *
316 * Reads from the address space of a given SDIO function. Return
317 * value indicates if the transfer succeeded or not.
318 */
319int sdio_memcpy_fromio(struct sdio_func *func, void *dst,
320 unsigned int addr, int count)
321{
322 return sdio_io_rw_ext_helper(func, 0, addr, 1, dst, count);
323}
324EXPORT_SYMBOL_GPL(sdio_memcpy_fromio);
325
326/**
327 * sdio_memcpy_toio - write a chunk of memory to a SDIO function
328 * @func: SDIO function to access
329 * @addr: address to start writing to
330 * @src: buffer that contains the data to write
331 * @count: number of bytes to write
332 *
333 * Writes to the address space of a given SDIO function. Return
334 * value indicates if the transfer succeeded or not.
335 */
336int sdio_memcpy_toio(struct sdio_func *func, unsigned int addr,
337 void *src, int count)
338{
339 return sdio_io_rw_ext_helper(func, 1, addr, 1, src, count);
340}
341EXPORT_SYMBOL_GPL(sdio_memcpy_toio);
342
343/**
344 * sdio_readsb - read from a FIFO on a SDIO function
345 * @func: SDIO function to access
346 * @dst: buffer to store the data
347 * @addr: address of (single byte) FIFO
348 * @count: number of bytes to read
349 *
350 * Reads from the specified FIFO of a given SDIO function. Return
351 * value indicates if the transfer succeeded or not.
352 */
353int sdio_readsb(struct sdio_func *func, void *dst, unsigned int addr,
354 int count)
355{
356 return sdio_io_rw_ext_helper(func, 0, addr, 0, dst, count);
357}
358
359EXPORT_SYMBOL_GPL(sdio_readsb);
360
361/**
362 * sdio_writesb - write to a FIFO of a SDIO function
363 * @func: SDIO function to access
364 * @addr: address of (single byte) FIFO
365 * @src: buffer that contains the data to write
366 * @count: number of bytes to write
367 *
368 * Writes to the specified FIFO of a given SDIO function. Return
369 * value indicates if the transfer succeeded or not.
370 */
371int sdio_writesb(struct sdio_func *func, unsigned int addr, void *src,
372 int count)
373{
374 return sdio_io_rw_ext_helper(func, 1, addr, 0, src, count);
375}
376EXPORT_SYMBOL_GPL(sdio_writesb);
377
378/**
379 * sdio_readw - read a 16 bit integer from a SDIO function
380 * @func: SDIO function to access
381 * @addr: address to read
382 * @err_ret: optional status value from transfer
383 *
384 * Reads a 16 bit integer from the address space of a given SDIO
385 * function. If there is a problem reading the address, 0xffff
386 * is returned and @err_ret will contain the error code.
387 */
388unsigned short sdio_readw(struct sdio_func *func, unsigned int addr,
389 int *err_ret)
390{
391 int ret;
392
393 if (err_ret)
394 *err_ret = 0;
395
396 ret = sdio_memcpy_fromio(func, func->tmpbuf, addr, 2);
397 if (ret) {
398 if (err_ret)
399 *err_ret = ret;
400 return 0xFFFF;
401 }
402
403 return le16_to_cpu(*(u16*)func->tmpbuf);
404}
405EXPORT_SYMBOL_GPL(sdio_readw);
406
407/**
408 * sdio_writew - write a 16 bit integer to a SDIO function
409 * @func: SDIO function to access
410 * @b: integer to write
411 * @addr: address to write to
412 * @err_ret: optional status value from transfer
413 *
414 * Writes a 16 bit integer to the address space of a given SDIO
415 * function. @err_ret will contain the status of the actual
416 * transfer.
417 */
418void sdio_writew(struct sdio_func *func, unsigned short b, unsigned int addr,
419 int *err_ret)
420{
421 int ret;
422
423 *(u16*)func->tmpbuf = cpu_to_le16(b);
424
425 ret = sdio_memcpy_toio(func, addr, func->tmpbuf, 2);
426 if (err_ret)
427 *err_ret = ret;
428}
429EXPORT_SYMBOL_GPL(sdio_writew);
430
431/**
432 * sdio_readl - read a 32 bit integer from a SDIO function
433 * @func: SDIO function to access
434 * @addr: address to read
435 * @err_ret: optional status value from transfer
436 *
437 * Reads a 32 bit integer from the address space of a given SDIO
438 * function. If there is a problem reading the address,
439 * 0xffffffff is returned and @err_ret will contain the error
440 * code.
441 */
442unsigned long sdio_readl(struct sdio_func *func, unsigned int addr,
443 int *err_ret)
444{
445 int ret;
446
447 if (err_ret)
448 *err_ret = 0;
449
450 ret = sdio_memcpy_fromio(func, func->tmpbuf, addr, 4);
451 if (ret) {
452 if (err_ret)
453 *err_ret = ret;
454 return 0xFFFFFFFF;
455 }
456
457 return le32_to_cpu(*(u32*)func->tmpbuf);
458}
459EXPORT_SYMBOL_GPL(sdio_readl);
460
461/**
462 * sdio_writel - write a 32 bit integer to a SDIO function
463 * @func: SDIO function to access
464 * @b: integer to write
465 * @addr: address to write to
466 * @err_ret: optional status value from transfer
467 *
468 * Writes a 32 bit integer to the address space of a given SDIO
469 * function. @err_ret will contain the status of the actual
470 * transfer.
471 */
472void sdio_writel(struct sdio_func *func, unsigned long b, unsigned int addr,
473 int *err_ret)
474{
475 int ret;
476
477 *(u32*)func->tmpbuf = cpu_to_le32(b);
478
479 ret = sdio_memcpy_toio(func, addr, func->tmpbuf, 4);
480 if (err_ret)
481 *err_ret = ret;
482}
483EXPORT_SYMBOL_GPL(sdio_writel);
484
485/**
486 * sdio_f0_readb - read a single byte from SDIO function 0
487 * @func: an SDIO function of the card
488 * @addr: address to read
489 * @err_ret: optional status value from transfer
490 *
491 * Reads a single byte from the address space of SDIO function 0.
492 * If there is a problem reading the address, 0xff is returned
493 * and @err_ret will contain the error code.
494 */
495unsigned char sdio_f0_readb(struct sdio_func *func, unsigned int addr,
496 int *err_ret)
497{
498 int ret;
499 unsigned char val;
500
501 BUG_ON(!func);
502
503 if (err_ret)
504 *err_ret = 0;
505
506 ret = mmc_io_rw_direct(func->card, 0, 0, addr, 0, &val);
507 if (ret) {
508 if (err_ret)
509 *err_ret = ret;
510 return 0xFF;
511 }
512
513 return val;
514}
515EXPORT_SYMBOL_GPL(sdio_f0_readb);
516
517/**
518 * sdio_f0_writeb - write a single byte to SDIO function 0
519 * @func: an SDIO function of the card
520 * @b: byte to write
521 * @addr: address to write to
522 * @err_ret: optional status value from transfer
523 *
524 * Writes a single byte to the address space of SDIO function 0.
525 * @err_ret will contain the status of the actual transfer.
526 *
527 * Only writes to the vendor specific CCCR registers (0xF0 -
528 * 0xFF) are permiited; @err_ret will be set to -EINVAL for *
529 * writes outside this range.
530 */
531void sdio_f0_writeb(struct sdio_func *func, unsigned char b, unsigned int addr,
532 int *err_ret)
533{
534 int ret;
535
536 BUG_ON(!func);
537
538 if (addr < 0xF0 || addr > 0xFF) {
539 if (err_ret)
540 *err_ret = -EINVAL;
541 return;
542 }
543
544 ret = mmc_io_rw_direct(func->card, 1, 0, addr, b, NULL);
545 if (err_ret)
546 *err_ret = ret;
547}
548EXPORT_SYMBOL_GPL(sdio_f0_writeb);
diff --git a/drivers/mmc/core/sdio_irq.c b/drivers/mmc/core/sdio_irq.c
new file mode 100644
index 000000000000..3bd3021f5e80
--- /dev/null
+++ b/drivers/mmc/core/sdio_irq.c
@@ -0,0 +1,267 @@
1/*
2 * linux/drivers/mmc/core/sdio_irq.c
3 *
4 * Author: Nicolas Pitre
5 * Created: June 18, 2007
6 * Copyright: MontaVista Software Inc.
7 *
8 * 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
10 * the Free Software Foundation; either version 2 of the License, or (at
11 * your option) any later version.
12 */
13
14#include <linux/kernel.h>
15#include <linux/sched.h>
16#include <linux/kthread.h>
17#include <linux/wait.h>
18#include <linux/delay.h>
19
20#include <linux/mmc/core.h>
21#include <linux/mmc/host.h>
22#include <linux/mmc/card.h>
23#include <linux/mmc/sdio.h>
24#include <linux/mmc/sdio_func.h>
25
26#include "sdio_ops.h"
27
28static int process_sdio_pending_irqs(struct mmc_card *card)
29{
30 int i, ret, count;
31 unsigned char pending;
32
33 ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_INTx, 0, &pending);
34 if (ret) {
35 printk(KERN_DEBUG "%s: error %d reading SDIO_CCCR_INTx\n",
36 mmc_card_id(card), ret);
37 return ret;
38 }
39
40 count = 0;
41 for (i = 1; i <= 7; i++) {
42 if (pending & (1 << i)) {
43 struct sdio_func *func = card->sdio_func[i - 1];
44 if (!func) {
45 printk(KERN_WARNING "%s: pending IRQ for "
46 "non-existant function\n",
47 mmc_card_id(card));
48 ret = -EINVAL;
49 } else if (func->irq_handler) {
50 func->irq_handler(func);
51 count++;
52 } else {
53 printk(KERN_WARNING "%s: pending IRQ with no handler\n",
54 sdio_func_id(func));
55 ret = -EINVAL;
56 }
57 }
58 }
59
60 if (count)
61 return count;
62
63 return ret;
64}
65
66static int sdio_irq_thread(void *_host)
67{
68 struct mmc_host *host = _host;
69 struct sched_param param = { .sched_priority = 1 };
70 unsigned long period, idle_period;
71 int ret;
72
73 sched_setscheduler(current, SCHED_FIFO, &param);
74
75 /*
76 * We want to allow for SDIO cards to work even on non SDIO
77 * aware hosts. One thing that non SDIO host cannot do is
78 * asynchronous notification of pending SDIO card interrupts
79 * hence we poll for them in that case.
80 */
81 idle_period = msecs_to_jiffies(10);
82 period = (host->caps & MMC_CAP_SDIO_IRQ) ?
83 MAX_SCHEDULE_TIMEOUT : idle_period;
84
85 pr_debug("%s: IRQ thread started (poll period = %lu jiffies)\n",
86 mmc_hostname(host), period);
87
88 do {
89 /*
90 * We claim the host here on drivers behalf for a couple
91 * reasons:
92 *
93 * 1) it is already needed to retrieve the CCCR_INTx;
94 * 2) we want the driver(s) to clear the IRQ condition ASAP;
95 * 3) we need to control the abort condition locally.
96 *
97 * Just like traditional hard IRQ handlers, we expect SDIO
98 * IRQ handlers to be quick and to the point, so that the
99 * holding of the host lock does not cover too much work
100 * that doesn't require that lock to be held.
101 */
102 ret = __mmc_claim_host(host, &host->sdio_irq_thread_abort);
103 if (ret)
104 break;
105 ret = process_sdio_pending_irqs(host->card);
106 mmc_release_host(host);
107
108 /*
109 * Give other threads a chance to run in the presence of
110 * errors. FIXME: determine if due to card removal and
111 * possibly exit this thread if so.
112 */
113 if (ret < 0)
114 ssleep(1);
115
116 /*
117 * Adaptive polling frequency based on the assumption
118 * that an interrupt will be closely followed by more.
119 * This has a substantial benefit for network devices.
120 */
121 if (!(host->caps & MMC_CAP_SDIO_IRQ)) {
122 if (ret > 0)
123 period /= 2;
124 else {
125 period++;
126 if (period > idle_period)
127 period = idle_period;
128 }
129 }
130
131 set_task_state(current, TASK_INTERRUPTIBLE);
132 if (host->caps & MMC_CAP_SDIO_IRQ)
133 host->ops->enable_sdio_irq(host, 1);
134 if (!kthread_should_stop())
135 schedule_timeout(period);
136 set_task_state(current, TASK_RUNNING);
137 } while (!kthread_should_stop());
138
139 if (host->caps & MMC_CAP_SDIO_IRQ)
140 host->ops->enable_sdio_irq(host, 0);
141
142 pr_debug("%s: IRQ thread exiting with code %d\n",
143 mmc_hostname(host), ret);
144
145 return ret;
146}
147
148static int sdio_card_irq_get(struct mmc_card *card)
149{
150 struct mmc_host *host = card->host;
151
152 WARN_ON(!host->claimed);
153
154 if (!host->sdio_irqs++) {
155 atomic_set(&host->sdio_irq_thread_abort, 0);
156 host->sdio_irq_thread =
157 kthread_run(sdio_irq_thread, host, "ksdiorqd");
158 if (IS_ERR(host->sdio_irq_thread)) {
159 int err = PTR_ERR(host->sdio_irq_thread);
160 host->sdio_irqs--;
161 return err;
162 }
163 }
164
165 return 0;
166}
167
168static int sdio_card_irq_put(struct mmc_card *card)
169{
170 struct mmc_host *host = card->host;
171
172 WARN_ON(!host->claimed);
173 BUG_ON(host->sdio_irqs < 1);
174
175 if (!--host->sdio_irqs) {
176 atomic_set(&host->sdio_irq_thread_abort, 1);
177 kthread_stop(host->sdio_irq_thread);
178 }
179
180 return 0;
181}
182
183/**
184 * sdio_claim_irq - claim the IRQ for a SDIO function
185 * @func: SDIO function
186 * @handler: IRQ handler callback
187 *
188 * Claim and activate the IRQ for the given SDIO function. The provided
189 * handler will be called when that IRQ is asserted. The host is always
190 * claimed already when the handler is called so the handler must not
191 * call sdio_claim_host() nor sdio_release_host().
192 */
193int sdio_claim_irq(struct sdio_func *func, sdio_irq_handler_t *handler)
194{
195 int ret;
196 unsigned char reg;
197
198 BUG_ON(!func);
199 BUG_ON(!func->card);
200
201 pr_debug("SDIO: Enabling IRQ for %s...\n", sdio_func_id(func));
202
203 if (func->irq_handler) {
204 pr_debug("SDIO: IRQ for %s already in use.\n", sdio_func_id(func));
205 return -EBUSY;
206 }
207
208 ret = mmc_io_rw_direct(func->card, 0, 0, SDIO_CCCR_IENx, 0, &reg);
209 if (ret)
210 return ret;
211
212 reg |= 1 << func->num;
213
214 reg |= 1; /* Master interrupt enable */
215
216 ret = mmc_io_rw_direct(func->card, 1, 0, SDIO_CCCR_IENx, reg, NULL);
217 if (ret)
218 return ret;
219
220 func->irq_handler = handler;
221 ret = sdio_card_irq_get(func->card);
222 if (ret)
223 func->irq_handler = NULL;
224
225 return ret;
226}
227EXPORT_SYMBOL_GPL(sdio_claim_irq);
228
229/**
230 * sdio_release_irq - release the IRQ for a SDIO function
231 * @func: SDIO function
232 *
233 * Disable and release the IRQ for the given SDIO function.
234 */
235int sdio_release_irq(struct sdio_func *func)
236{
237 int ret;
238 unsigned char reg;
239
240 BUG_ON(!func);
241 BUG_ON(!func->card);
242
243 pr_debug("SDIO: Disabling IRQ for %s...\n", sdio_func_id(func));
244
245 if (func->irq_handler) {
246 func->irq_handler = NULL;
247 sdio_card_irq_put(func->card);
248 }
249
250 ret = mmc_io_rw_direct(func->card, 0, 0, SDIO_CCCR_IENx, 0, &reg);
251 if (ret)
252 return ret;
253
254 reg &= ~(1 << func->num);
255
256 /* Disable master interrupt with the last function interrupt */
257 if (!(reg & 0xFE))
258 reg = 0;
259
260 ret = mmc_io_rw_direct(func->card, 1, 0, SDIO_CCCR_IENx, reg, NULL);
261 if (ret)
262 return ret;
263
264 return 0;
265}
266EXPORT_SYMBOL_GPL(sdio_release_irq);
267
diff --git a/drivers/mmc/core/sdio_ops.c b/drivers/mmc/core/sdio_ops.c
new file mode 100644
index 000000000000..4d289b275031
--- /dev/null
+++ b/drivers/mmc/core/sdio_ops.c
@@ -0,0 +1,176 @@
1/*
2 * linux/drivers/mmc/sdio_ops.c
3 *
4 * Copyright 2006-2007 Pierre Ossman
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 (at
9 * your option) any later version.
10 */
11
12#include <asm/scatterlist.h>
13#include <linux/scatterlist.h>
14
15#include <linux/mmc/host.h>
16#include <linux/mmc/card.h>
17#include <linux/mmc/mmc.h>
18#include <linux/mmc/sdio.h>
19
20#include "core.h"
21
22int mmc_send_io_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr)
23{
24 struct mmc_command cmd;
25 int i, err = 0;
26
27 BUG_ON(!host);
28
29 memset(&cmd, 0, sizeof(struct mmc_command));
30
31 cmd.opcode = SD_IO_SEND_OP_COND;
32 cmd.arg = ocr;
33 cmd.flags = MMC_RSP_SPI_R4 | MMC_RSP_R4 | MMC_CMD_BCR;
34
35 for (i = 100; i; i--) {
36 err = mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES);
37 if (err)
38 break;
39
40 /* if we're just probing, do a single pass */
41 if (ocr == 0)
42 break;
43
44 /* otherwise wait until reset completes */
45 if (mmc_host_is_spi(host)) {
46 /*
47 * Both R1_SPI_IDLE and MMC_CARD_BUSY indicate
48 * an initialized card under SPI, but some cards
49 * (Marvell's) only behave when looking at this
50 * one.
51 */
52 if (cmd.resp[1] & MMC_CARD_BUSY)
53 break;
54 } else {
55 if (cmd.resp[0] & MMC_CARD_BUSY)
56 break;
57 }
58
59 err = -ETIMEDOUT;
60
61 mmc_delay(10);
62 }
63
64 if (rocr)
65 *rocr = cmd.resp[mmc_host_is_spi(host) ? 1 : 0];
66
67 return err;
68}
69
70int mmc_io_rw_direct(struct mmc_card *card, int write, unsigned fn,
71 unsigned addr, u8 in, u8* out)
72{
73 struct mmc_command cmd;
74 int err;
75
76 BUG_ON(!card);
77 BUG_ON(fn > 7);
78
79 memset(&cmd, 0, sizeof(struct mmc_command));
80
81 cmd.opcode = SD_IO_RW_DIRECT;
82 cmd.arg = write ? 0x80000000 : 0x00000000;
83 cmd.arg |= fn << 28;
84 cmd.arg |= (write && out) ? 0x08000000 : 0x00000000;
85 cmd.arg |= addr << 9;
86 cmd.arg |= in;
87 cmd.flags = MMC_RSP_SPI_R5 | MMC_RSP_R5 | MMC_CMD_AC;
88
89 err = mmc_wait_for_cmd(card->host, &cmd, 0);
90 if (err)
91 return err;
92
93 if (mmc_host_is_spi(card->host)) {
94 /* host driver already reported errors */
95 } else {
96 if (cmd.resp[0] & R5_ERROR)
97 return -EIO;
98 if (cmd.resp[0] & R5_FUNCTION_NUMBER)
99 return -EINVAL;
100 if (cmd.resp[0] & R5_OUT_OF_RANGE)
101 return -ERANGE;
102 }
103
104 if (out) {
105 if (mmc_host_is_spi(card->host))
106 *out = (cmd.resp[0] >> 8) & 0xFF;
107 else
108 *out = cmd.resp[0] & 0xFF;
109 }
110
111 return 0;
112}
113
114int mmc_io_rw_extended(struct mmc_card *card, int write, unsigned fn,
115 unsigned addr, int incr_addr, u8 *buf, unsigned blocks, unsigned blksz)
116{
117 struct mmc_request mrq;
118 struct mmc_command cmd;
119 struct mmc_data data;
120 struct scatterlist sg;
121
122 BUG_ON(!card);
123 BUG_ON(fn > 7);
124 BUG_ON(blocks == 1 && blksz > 512);
125 WARN_ON(blocks == 0);
126 WARN_ON(blksz == 0);
127
128 memset(&mrq, 0, sizeof(struct mmc_request));
129 memset(&cmd, 0, sizeof(struct mmc_command));
130 memset(&data, 0, sizeof(struct mmc_data));
131
132 mrq.cmd = &cmd;
133 mrq.data = &data;
134
135 cmd.opcode = SD_IO_RW_EXTENDED;
136 cmd.arg = write ? 0x80000000 : 0x00000000;
137 cmd.arg |= fn << 28;
138 cmd.arg |= incr_addr ? 0x04000000 : 0x00000000;
139 cmd.arg |= addr << 9;
140 if (blocks == 1 && blksz <= 512)
141 cmd.arg |= (blksz == 512) ? 0 : blksz; /* byte mode */
142 else
143 cmd.arg |= 0x08000000 | blocks; /* block mode */
144 cmd.flags = MMC_RSP_SPI_R5 | MMC_RSP_R5 | MMC_CMD_ADTC;
145
146 data.blksz = blksz;
147 data.blocks = blocks;
148 data.flags = write ? MMC_DATA_WRITE : MMC_DATA_READ;
149 data.sg = &sg;
150 data.sg_len = 1;
151
152 sg_init_one(&sg, buf, blksz * blocks);
153
154 mmc_set_data_timeout(&data, card);
155
156 mmc_wait_for_req(card->host, &mrq);
157
158 if (cmd.error)
159 return cmd.error;
160 if (data.error)
161 return data.error;
162
163 if (mmc_host_is_spi(card->host)) {
164 /* host driver already reported errors */
165 } else {
166 if (cmd.resp[0] & R5_ERROR)
167 return -EIO;
168 if (cmd.resp[0] & R5_FUNCTION_NUMBER)
169 return -EINVAL;
170 if (cmd.resp[0] & R5_OUT_OF_RANGE)
171 return -ERANGE;
172 }
173
174 return 0;
175}
176
diff --git a/drivers/mmc/core/sdio_ops.h b/drivers/mmc/core/sdio_ops.h
new file mode 100644
index 000000000000..e2e74b0d17d8
--- /dev/null
+++ b/drivers/mmc/core/sdio_ops.h
@@ -0,0 +1,22 @@
1/*
2 * linux/drivers/mmc/sdio_ops.c
3 *
4 * Copyright 2006-2007 Pierre Ossman
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 (at
9 * your option) any later version.
10 */
11
12#ifndef _MMC_SDIO_OPS_H
13#define _MMC_SDIO_OPS_H
14
15int mmc_send_io_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr);
16int mmc_io_rw_direct(struct mmc_card *card, int write, unsigned fn,
17 unsigned addr, u8 in, u8* out);
18int mmc_io_rw_extended(struct mmc_card *card, int write, unsigned fn,
19 unsigned addr, int incr_addr, u8 *buf, unsigned blocks, unsigned blksz);
20
21#endif
22
diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig
index e23082fe88d0..5fef6783c716 100644
--- a/drivers/mmc/host/Kconfig
+++ b/drivers/mmc/host/Kconfig
@@ -35,6 +35,23 @@ config MMC_SDHCI
35 35
36 If unsure, say N. 36 If unsure, say N.
37 37
38config MMC_RICOH_MMC
39 tristate "Ricoh MMC Controller Disabler (EXPERIMENTAL)"
40 depends on PCI && EXPERIMENTAL && MMC_SDHCI
41 help
42 This selects the disabler for the Ricoh MMC Controller. This
43 proprietary controller is unnecessary because the SDHCI driver
44 supports MMC cards on the SD controller, but if it is not
45 disabled, it will steal the MMC cards away - rendering them
46 useless. It is safe to select this driver even if you don't
47 have a Ricoh based card reader.
48
49
50 To compile this driver as a module, choose M here:
51 the module will be called ricoh_mmc.
52
53 If unsure, say Y.
54
38config MMC_OMAP 55config MMC_OMAP
39 tristate "TI OMAP Multimedia Card Interface support" 56 tristate "TI OMAP Multimedia Card Interface support"
40 depends on ARCH_OMAP 57 depends on ARCH_OMAP
@@ -100,3 +117,16 @@ config MMC_TIFM_SD
100 To compile this driver as a module, choose M here: the 117 To compile this driver as a module, choose M here: the
101 module will be called tifm_sd. 118 module will be called tifm_sd.
102 119
120config MMC_SPI
121 tristate "MMC/SD over SPI (EXPERIMENTAL)"
122 depends on MMC && SPI_MASTER && !HIGHMEM && EXPERIMENTAL
123 select CRC7
124 select CRC_ITU_T
125 help
126 Some systems accss MMC/SD cards using a SPI controller instead of
127 using a "native" MMC/SD controller. This has a disadvantage of
128 being relatively high overhead, but a compensating advantage of
129 working on many systems without dedicated MMC/SD controllers.
130
131 If unsure, or if your system has no SPI master driver, say N.
132
diff --git a/drivers/mmc/host/Makefile b/drivers/mmc/host/Makefile
index 6685f64345b4..3877c87e6da2 100644
--- a/drivers/mmc/host/Makefile
+++ b/drivers/mmc/host/Makefile
@@ -10,9 +10,11 @@ obj-$(CONFIG_MMC_ARMMMCI) += mmci.o
10obj-$(CONFIG_MMC_PXA) += pxamci.o 10obj-$(CONFIG_MMC_PXA) += pxamci.o
11obj-$(CONFIG_MMC_IMX) += imxmmc.o 11obj-$(CONFIG_MMC_IMX) += imxmmc.o
12obj-$(CONFIG_MMC_SDHCI) += sdhci.o 12obj-$(CONFIG_MMC_SDHCI) += sdhci.o
13obj-$(CONFIG_MMC_RICOH_MMC) += ricoh_mmc.o
13obj-$(CONFIG_MMC_WBSD) += wbsd.o 14obj-$(CONFIG_MMC_WBSD) += wbsd.o
14obj-$(CONFIG_MMC_AU1X) += au1xmmc.o 15obj-$(CONFIG_MMC_AU1X) += au1xmmc.o
15obj-$(CONFIG_MMC_OMAP) += omap.o 16obj-$(CONFIG_MMC_OMAP) += omap.o
16obj-$(CONFIG_MMC_AT91) += at91_mci.o 17obj-$(CONFIG_MMC_AT91) += at91_mci.o
17obj-$(CONFIG_MMC_TIFM_SD) += tifm_sd.o 18obj-$(CONFIG_MMC_TIFM_SD) += tifm_sd.o
19obj-$(CONFIG_MMC_SPI) += mmc_spi.o
18 20
diff --git a/drivers/mmc/host/at91_mci.c b/drivers/mmc/host/at91_mci.c
index 955ea60583b5..6ba98a49612d 100644
--- a/drivers/mmc/host/at91_mci.c
+++ b/drivers/mmc/host/at91_mci.c
@@ -328,7 +328,7 @@ static void at91_mci_handle_transmitted(struct at91mci_host *host)
328 data = cmd->data; 328 data = cmd->data;
329 if (!data) return; 329 if (!data) return;
330 330
331 if (cmd->data->flags & MMC_DATA_MULTI) { 331 if (cmd->data->blocks > 1) {
332 pr_debug("multiple write : wait for BLKE...\n"); 332 pr_debug("multiple write : wait for BLKE...\n");
333 at91_mci_write(host, AT91_MCI_IER, AT91_MCI_BLKE); 333 at91_mci_write(host, AT91_MCI_IER, AT91_MCI_BLKE);
334 } else 334 } else
@@ -428,6 +428,14 @@ static void at91_mci_send_command(struct at91mci_host *host, struct mmc_command
428 } 428 }
429 429
430 if (data) { 430 if (data) {
431
432 if ( data->blksz & 0x3 ) {
433 pr_debug("Unsupported block size\n");
434 cmd->error = -EINVAL;
435 mmc_request_done(host->mmc, host->request);
436 return;
437 }
438
431 block_length = data->blksz; 439 block_length = data->blksz;
432 blocks = data->blocks; 440 blocks = data->blocks;
433 441
@@ -439,7 +447,7 @@ static void at91_mci_send_command(struct at91mci_host *host, struct mmc_command
439 447
440 if (data->flags & MMC_DATA_STREAM) 448 if (data->flags & MMC_DATA_STREAM)
441 cmdr |= AT91_MCI_TRTYP_STREAM; 449 cmdr |= AT91_MCI_TRTYP_STREAM;
442 if (data->flags & MMC_DATA_MULTI) 450 if (data->blocks > 1)
443 cmdr |= AT91_MCI_TRTYP_MULTIPLE; 451 cmdr |= AT91_MCI_TRTYP_MULTIPLE;
444 } 452 }
445 else { 453 else {
@@ -577,24 +585,22 @@ static void at91_mci_completed_command(struct at91mci_host *host)
577 AT91_MCI_RENDE | AT91_MCI_RTOE | AT91_MCI_DCRCE | 585 AT91_MCI_RENDE | AT91_MCI_RTOE | AT91_MCI_DCRCE |
578 AT91_MCI_DTOE | AT91_MCI_OVRE | AT91_MCI_UNRE)) { 586 AT91_MCI_DTOE | AT91_MCI_OVRE | AT91_MCI_UNRE)) {
579 if ((status & AT91_MCI_RCRCE) && !(mmc_resp_type(cmd) & MMC_RSP_CRC)) { 587 if ((status & AT91_MCI_RCRCE) && !(mmc_resp_type(cmd) & MMC_RSP_CRC)) {
580 cmd->error = MMC_ERR_NONE; 588 cmd->error = 0;
581 } 589 }
582 else { 590 else {
583 if (status & (AT91_MCI_RTOE | AT91_MCI_DTOE)) 591 if (status & (AT91_MCI_RTOE | AT91_MCI_DTOE))
584 cmd->error = MMC_ERR_TIMEOUT; 592 cmd->error = -ETIMEDOUT;
585 else if (status & (AT91_MCI_RCRCE | AT91_MCI_DCRCE)) 593 else if (status & (AT91_MCI_RCRCE | AT91_MCI_DCRCE))
586 cmd->error = MMC_ERR_BADCRC; 594 cmd->error = -EILSEQ;
587 else if (status & (AT91_MCI_OVRE | AT91_MCI_UNRE))
588 cmd->error = MMC_ERR_FIFO;
589 else 595 else
590 cmd->error = MMC_ERR_FAILED; 596 cmd->error = -EIO;
591 597
592 pr_debug("Error detected and set to %d (cmd = %d, retries = %d)\n", 598 pr_debug("Error detected and set to %d (cmd = %d, retries = %d)\n",
593 cmd->error, cmd->opcode, cmd->retries); 599 cmd->error, cmd->opcode, cmd->retries);
594 } 600 }
595 } 601 }
596 else 602 else
597 cmd->error = MMC_ERR_NONE; 603 cmd->error = 0;
598 604
599 at91_mci_process_next(host); 605 at91_mci_process_next(host);
600} 606}
@@ -836,7 +842,6 @@ static int __init at91_mci_probe(struct platform_device *pdev)
836 mmc->f_min = 375000; 842 mmc->f_min = 375000;
837 mmc->f_max = 25000000; 843 mmc->f_max = 25000000;
838 mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34; 844 mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
839 mmc->caps = MMC_CAP_BYTEBLOCK;
840 845
841 mmc->max_blk_size = 4095; 846 mmc->max_blk_size = 4095;
842 mmc->max_blk_count = mmc->max_req_size; 847 mmc->max_blk_count = mmc->max_req_size;
diff --git a/drivers/mmc/host/au1xmmc.c b/drivers/mmc/host/au1xmmc.c
index 34c99d4ea041..92c4d0dfee43 100644
--- a/drivers/mmc/host/au1xmmc.c
+++ b/drivers/mmc/host/au1xmmc.c
@@ -186,7 +186,7 @@ static void au1xmmc_tasklet_finish(unsigned long param)
186} 186}
187 187
188static int au1xmmc_send_command(struct au1xmmc_host *host, int wait, 188static int au1xmmc_send_command(struct au1xmmc_host *host, int wait,
189 struct mmc_command *cmd, unsigned int flags) 189 struct mmc_command *cmd, struct mmc_data *data)
190{ 190{
191 u32 mmccmd = (cmd->opcode << SD_CMD_CI_SHIFT); 191 u32 mmccmd = (cmd->opcode << SD_CMD_CI_SHIFT);
192 192
@@ -208,19 +208,21 @@ static int au1xmmc_send_command(struct au1xmmc_host *host, int wait,
208 default: 208 default:
209 printk(KERN_INFO "au1xmmc: unhandled response type %02x\n", 209 printk(KERN_INFO "au1xmmc: unhandled response type %02x\n",
210 mmc_resp_type(cmd)); 210 mmc_resp_type(cmd));
211 return MMC_ERR_INVALID; 211 return -EINVAL;
212 } 212 }
213 213
214 if (flags & MMC_DATA_READ) { 214 if (data) {
215 if (flags & MMC_DATA_MULTI) 215 if (flags & MMC_DATA_READ) {
216 mmccmd |= SD_CMD_CT_4; 216 if (data->blocks > 1)
217 else 217 mmccmd |= SD_CMD_CT_4;
218 mmccmd |= SD_CMD_CT_2; 218 else
219 } else if (flags & MMC_DATA_WRITE) { 219 mmccmd |= SD_CMD_CT_2;
220 if (flags & MMC_DATA_MULTI) 220 } else if (flags & MMC_DATA_WRITE) {
221 mmccmd |= SD_CMD_CT_3; 221 if (data->blocks > 1)
222 else 222 mmccmd |= SD_CMD_CT_3;
223 mmccmd |= SD_CMD_CT_1; 223 else
224 mmccmd |= SD_CMD_CT_1;
225 }
224 } 226 }
225 227
226 au_writel(cmd->arg, HOST_CMDARG(host)); 228 au_writel(cmd->arg, HOST_CMDARG(host));
@@ -253,7 +255,7 @@ static int au1xmmc_send_command(struct au1xmmc_host *host, int wait,
253 IRQ_ON(host, SD_CONFIG_CR); 255 IRQ_ON(host, SD_CONFIG_CR);
254 } 256 }
255 257
256 return MMC_ERR_NONE; 258 return 0;
257} 259}
258 260
259static void au1xmmc_data_complete(struct au1xmmc_host *host, u32 status) 261static void au1xmmc_data_complete(struct au1xmmc_host *host, u32 status)
@@ -278,7 +280,7 @@ static void au1xmmc_data_complete(struct au1xmmc_host *host, u32 status)
278 while((host->flags & HOST_F_XMIT) && (status & SD_STATUS_DB)) 280 while((host->flags & HOST_F_XMIT) && (status & SD_STATUS_DB))
279 status = au_readl(HOST_STATUS(host)); 281 status = au_readl(HOST_STATUS(host));
280 282
281 data->error = MMC_ERR_NONE; 283 data->error = 0;
282 dma_unmap_sg(mmc_dev(host->mmc), data->sg, data->sg_len, host->dma.dir); 284 dma_unmap_sg(mmc_dev(host->mmc), data->sg, data->sg_len, host->dma.dir);
283 285
284 /* Process any errors */ 286 /* Process any errors */
@@ -288,14 +290,14 @@ static void au1xmmc_data_complete(struct au1xmmc_host *host, u32 status)
288 crc |= ((status & 0x07) == 0x02) ? 0 : 1; 290 crc |= ((status & 0x07) == 0x02) ? 0 : 1;
289 291
290 if (crc) 292 if (crc)
291 data->error = MMC_ERR_BADCRC; 293 data->error = -EILSEQ;
292 294
293 /* Clear the CRC bits */ 295 /* Clear the CRC bits */
294 au_writel(SD_STATUS_WC | SD_STATUS_RC, HOST_STATUS(host)); 296 au_writel(SD_STATUS_WC | SD_STATUS_RC, HOST_STATUS(host));
295 297
296 data->bytes_xfered = 0; 298 data->bytes_xfered = 0;
297 299
298 if (data->error == MMC_ERR_NONE) { 300 if (!data->error) {
299 if (host->flags & HOST_F_DMA) { 301 if (host->flags & HOST_F_DMA) {
300 u32 chan = DMA_CHANNEL(host); 302 u32 chan = DMA_CHANNEL(host);
301 303
@@ -475,7 +477,7 @@ static void au1xmmc_cmd_complete(struct au1xmmc_host *host, u32 status)
475 return; 477 return;
476 478
477 cmd = mrq->cmd; 479 cmd = mrq->cmd;
478 cmd->error = MMC_ERR_NONE; 480 cmd->error = 0;
479 481
480 if (cmd->flags & MMC_RSP_PRESENT) { 482 if (cmd->flags & MMC_RSP_PRESENT) {
481 if (cmd->flags & MMC_RSP_136) { 483 if (cmd->flags & MMC_RSP_136) {
@@ -512,11 +514,11 @@ static void au1xmmc_cmd_complete(struct au1xmmc_host *host, u32 status)
512 /* Figure out errors */ 514 /* Figure out errors */
513 515
514 if (status & (SD_STATUS_SC | SD_STATUS_WC | SD_STATUS_RC)) 516 if (status & (SD_STATUS_SC | SD_STATUS_WC | SD_STATUS_RC))
515 cmd->error = MMC_ERR_BADCRC; 517 cmd->error = -EILSEQ;
516 518
517 trans = host->flags & (HOST_F_XMIT | HOST_F_RECV); 519 trans = host->flags & (HOST_F_XMIT | HOST_F_RECV);
518 520
519 if (!trans || cmd->error != MMC_ERR_NONE) { 521 if (!trans || cmd->error) {
520 522
521 IRQ_OFF(host, SD_CONFIG_TH | SD_CONFIG_RA|SD_CONFIG_RF); 523 IRQ_OFF(host, SD_CONFIG_TH | SD_CONFIG_RA|SD_CONFIG_RF);
522 tasklet_schedule(&host->finish_task); 524 tasklet_schedule(&host->finish_task);
@@ -589,7 +591,7 @@ au1xmmc_prepare_data(struct au1xmmc_host *host, struct mmc_data *data)
589 data->sg_len, host->dma.dir); 591 data->sg_len, host->dma.dir);
590 592
591 if (host->dma.len == 0) 593 if (host->dma.len == 0)
592 return MMC_ERR_TIMEOUT; 594 return -ETIMEDOUT;
593 595
594 au_writel(data->blksz - 1, HOST_BLKSIZE(host)); 596 au_writel(data->blksz - 1, HOST_BLKSIZE(host));
595 597
@@ -640,11 +642,11 @@ au1xmmc_prepare_data(struct au1xmmc_host *host, struct mmc_data *data)
640 //IRQ_ON(host, SD_CONFIG_RA|SD_CONFIG_RF); 642 //IRQ_ON(host, SD_CONFIG_RA|SD_CONFIG_RF);
641 } 643 }
642 644
643 return MMC_ERR_NONE; 645 return 0;
644 646
645 dataerr: 647 dataerr:
646 dma_unmap_sg(mmc_dev(host->mmc),data->sg,data->sg_len,host->dma.dir); 648 dma_unmap_sg(mmc_dev(host->mmc),data->sg,data->sg_len,host->dma.dir);
647 return MMC_ERR_TIMEOUT; 649 return -ETIMEDOUT;
648} 650}
649 651
650/* static void au1xmmc_request 652/* static void au1xmmc_request
@@ -656,7 +658,7 @@ static void au1xmmc_request(struct mmc_host* mmc, struct mmc_request* mrq)
656 658
657 struct au1xmmc_host *host = mmc_priv(mmc); 659 struct au1xmmc_host *host = mmc_priv(mmc);
658 unsigned int flags = 0; 660 unsigned int flags = 0;
659 int ret = MMC_ERR_NONE; 661 int ret = 0;
660 662
661 WARN_ON(irqs_disabled()); 663 WARN_ON(irqs_disabled());
662 WARN_ON(host->status != HOST_S_IDLE); 664 WARN_ON(host->status != HOST_S_IDLE);
@@ -672,10 +674,10 @@ static void au1xmmc_request(struct mmc_host* mmc, struct mmc_request* mrq)
672 ret = au1xmmc_prepare_data(host, mrq->data); 674 ret = au1xmmc_prepare_data(host, mrq->data);
673 } 675 }
674 676
675 if (ret == MMC_ERR_NONE) 677 if (!ret)
676 ret = au1xmmc_send_command(host, 0, mrq->cmd, flags); 678 ret = au1xmmc_send_command(host, 0, mrq->cmd, mrq->data);
677 679
678 if (ret != MMC_ERR_NONE) { 680 if (ret) {
679 mrq->cmd->error = ret; 681 mrq->cmd->error = ret;
680 au1xmmc_finish_request(host); 682 au1xmmc_finish_request(host);
681 } 683 }
@@ -764,10 +766,10 @@ static irqreturn_t au1xmmc_irq(int irq, void *dev_id)
764 766
765 if (host->mrq && (status & STATUS_TIMEOUT)) { 767 if (host->mrq && (status & STATUS_TIMEOUT)) {
766 if (status & SD_STATUS_RAT) 768 if (status & SD_STATUS_RAT)
767 host->mrq->cmd->error = MMC_ERR_TIMEOUT; 769 host->mrq->cmd->error = -ETIMEDOUT;
768 770
769 else if (status & SD_STATUS_DT) 771 else if (status & SD_STATUS_DT)
770 host->mrq->data->error = MMC_ERR_TIMEOUT; 772 host->mrq->data->error = -ETIMEDOUT;
771 773
772 /* In PIO mode, interrupts might still be enabled */ 774 /* In PIO mode, interrupts might still be enabled */
773 IRQ_OFF(host, SD_CONFIG_NE | SD_CONFIG_TH); 775 IRQ_OFF(host, SD_CONFIG_NE | SD_CONFIG_TH);
diff --git a/drivers/mmc/host/imxmmc.c b/drivers/mmc/host/imxmmc.c
index 54bfc9f25596..6ebc41e7592c 100644
--- a/drivers/mmc/host/imxmmc.c
+++ b/drivers/mmc/host/imxmmc.c
@@ -428,11 +428,11 @@ static int imxmci_finish_data(struct imxmci_host *host, unsigned int stat)
428 if ( stat & STATUS_ERR_MASK ) { 428 if ( stat & STATUS_ERR_MASK ) {
429 dev_dbg(mmc_dev(host->mmc), "request failed. status: 0x%08x\n",stat); 429 dev_dbg(mmc_dev(host->mmc), "request failed. status: 0x%08x\n",stat);
430 if(stat & (STATUS_CRC_READ_ERR | STATUS_CRC_WRITE_ERR)) 430 if(stat & (STATUS_CRC_READ_ERR | STATUS_CRC_WRITE_ERR))
431 data->error = MMC_ERR_BADCRC; 431 data->error = -EILSEQ;
432 else if(stat & STATUS_TIME_OUT_READ) 432 else if(stat & STATUS_TIME_OUT_READ)
433 data->error = MMC_ERR_TIMEOUT; 433 data->error = -ETIMEDOUT;
434 else 434 else
435 data->error = MMC_ERR_FAILED; 435 data->error = -EIO;
436 } else { 436 } else {
437 data->bytes_xfered = host->dma_size; 437 data->bytes_xfered = host->dma_size;
438 } 438 }
@@ -458,10 +458,10 @@ static int imxmci_cmd_done(struct imxmci_host *host, unsigned int stat)
458 458
459 if (stat & STATUS_TIME_OUT_RESP) { 459 if (stat & STATUS_TIME_OUT_RESP) {
460 dev_dbg(mmc_dev(host->mmc), "CMD TIMEOUT\n"); 460 dev_dbg(mmc_dev(host->mmc), "CMD TIMEOUT\n");
461 cmd->error = MMC_ERR_TIMEOUT; 461 cmd->error = -ETIMEDOUT;
462 } else if (stat & STATUS_RESP_CRC_ERR && cmd->flags & MMC_RSP_CRC) { 462 } else if (stat & STATUS_RESP_CRC_ERR && cmd->flags & MMC_RSP_CRC) {
463 dev_dbg(mmc_dev(host->mmc), "cmd crc error\n"); 463 dev_dbg(mmc_dev(host->mmc), "cmd crc error\n");
464 cmd->error = MMC_ERR_BADCRC; 464 cmd->error = -EILSEQ;
465 } 465 }
466 466
467 if(cmd->flags & MMC_RSP_PRESENT) { 467 if(cmd->flags & MMC_RSP_PRESENT) {
@@ -482,7 +482,7 @@ static int imxmci_cmd_done(struct imxmci_host *host, unsigned int stat)
482 dev_dbg(mmc_dev(host->mmc), "RESP 0x%08x, 0x%08x, 0x%08x, 0x%08x, error %d\n", 482 dev_dbg(mmc_dev(host->mmc), "RESP 0x%08x, 0x%08x, 0x%08x, 0x%08x, error %d\n",
483 cmd->resp[0], cmd->resp[1], cmd->resp[2], cmd->resp[3], cmd->error); 483 cmd->resp[0], cmd->resp[1], cmd->resp[2], cmd->resp[3], cmd->error);
484 484
485 if (data && (cmd->error == MMC_ERR_NONE) && !(stat & STATUS_ERR_MASK)) { 485 if (data && !cmd->error && !(stat & STATUS_ERR_MASK)) {
486 if (host->req->data->flags & MMC_DATA_WRITE) { 486 if (host->req->data->flags & MMC_DATA_WRITE) {
487 487
488 /* Wait for FIFO to be empty before starting DMA write */ 488 /* Wait for FIFO to be empty before starting DMA write */
@@ -491,7 +491,7 @@ static int imxmci_cmd_done(struct imxmci_host *host, unsigned int stat)
491 if(imxmci_busy_wait_for_status(host, &stat, 491 if(imxmci_busy_wait_for_status(host, &stat,
492 STATUS_APPL_BUFF_FE, 492 STATUS_APPL_BUFF_FE,
493 40, "imxmci_cmd_done DMA WR") < 0) { 493 40, "imxmci_cmd_done DMA WR") < 0) {
494 cmd->error = MMC_ERR_FIFO; 494 cmd->error = -EIO;
495 imxmci_finish_data(host, stat); 495 imxmci_finish_data(host, stat);
496 if(host->req) 496 if(host->req)
497 imxmci_finish_request(host, host->req); 497 imxmci_finish_request(host, host->req);
@@ -884,9 +884,21 @@ static void imxmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
884 } 884 }
885} 885}
886 886
887static int imxmci_get_ro(struct mmc_host *mmc)
888{
889 struct imxmci_host *host = mmc_priv(mmc);
890
891 if (host->pdata && host->pdata->get_ro)
892 return host->pdata->get_ro(mmc_dev(mmc));
893 /* Host doesn't support read only detection so assume writeable */
894 return 0;
895}
896
897
887static const struct mmc_host_ops imxmci_ops = { 898static const struct mmc_host_ops imxmci_ops = {
888 .request = imxmci_request, 899 .request = imxmci_request,
889 .set_ios = imxmci_set_ios, 900 .set_ios = imxmci_set_ios,
901 .get_ro = imxmci_get_ro,
890}; 902};
891 903
892static struct resource *platform_device_resource(struct platform_device *dev, unsigned int mask, int nr) 904static struct resource *platform_device_resource(struct platform_device *dev, unsigned int mask, int nr)
@@ -913,7 +925,7 @@ static void imxmci_check_status(unsigned long data)
913{ 925{
914 struct imxmci_host *host = (struct imxmci_host *)data; 926 struct imxmci_host *host = (struct imxmci_host *)data;
915 927
916 if( host->pdata->card_present() != host->present ) { 928 if( host->pdata->card_present(mmc_dev(host->mmc)) != host->present ) {
917 host->present ^= 1; 929 host->present ^= 1;
918 dev_info(mmc_dev(host->mmc), "card %s\n", 930 dev_info(mmc_dev(host->mmc), "card %s\n",
919 host->present ? "inserted" : "removed"); 931 host->present ? "inserted" : "removed");
@@ -963,7 +975,7 @@ static int imxmci_probe(struct platform_device *pdev)
963 mmc->f_min = 150000; 975 mmc->f_min = 150000;
964 mmc->f_max = CLK_RATE/2; 976 mmc->f_max = CLK_RATE/2;
965 mmc->ocr_avail = MMC_VDD_32_33; 977 mmc->ocr_avail = MMC_VDD_32_33;
966 mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_BYTEBLOCK; 978 mmc->caps = MMC_CAP_4_BIT_DATA;
967 979
968 /* MMC core transfer sizes tunable parameters */ 980 /* MMC core transfer sizes tunable parameters */
969 mmc->max_hw_segs = 64; 981 mmc->max_hw_segs = 64;
@@ -1022,7 +1034,7 @@ static int imxmci_probe(struct platform_device *pdev)
1022 if (ret) 1034 if (ret)
1023 goto out; 1035 goto out;
1024 1036
1025 host->present = host->pdata->card_present(); 1037 host->present = host->pdata->card_present(mmc_dev(mmc));
1026 init_timer(&host->timer); 1038 init_timer(&host->timer);
1027 host->timer.data = (unsigned long)host; 1039 host->timer.data = (unsigned long)host;
1028 host->timer.function = imxmci_check_status; 1040 host->timer.function = imxmci_check_status;
diff --git a/drivers/mmc/host/mmc_spi.c b/drivers/mmc/host/mmc_spi.c
new file mode 100644
index 000000000000..f30327bba6f6
--- /dev/null
+++ b/drivers/mmc/host/mmc_spi.c
@@ -0,0 +1,1408 @@
1/*
2 * mmc_spi.c - Access SD/MMC cards through SPI master controllers
3 *
4 * (C) Copyright 2005, Intec Automation,
5 * Mike Lavender (mike@steroidmicros)
6 * (C) Copyright 2006-2007, David Brownell
7 * (C) Copyright 2007, Axis Communications,
8 * Hans-Peter Nilsson (hp@axis.com)
9 * (C) Copyright 2007, ATRON electronic GmbH,
10 * Jan Nikitenko <jan.nikitenko@gmail.com>
11 *
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 */
27#include <linux/hrtimer.h>
28#include <linux/delay.h>
29#include <linux/blkdev.h>
30#include <linux/dma-mapping.h>
31#include <linux/crc7.h>
32#include <linux/crc-itu-t.h>
33
34#include <linux/mmc/host.h>
35#include <linux/mmc/mmc.h> /* for R1_SPI_* bit values */
36
37#include <linux/spi/spi.h>
38#include <linux/spi/mmc_spi.h>
39
40#include <asm/unaligned.h>
41
42
43/* NOTES:
44 *
45 * - For now, we won't try to interoperate with a real mmc/sd/sdio
46 * controller, although some of them do have hardware support for
47 * SPI protocol. The main reason for such configs would be mmc-ish
48 * cards like DataFlash, which don't support that "native" protocol.
49 *
50 * We don't have a "DataFlash/MMC/SD/SDIO card slot" abstraction to
51 * switch between driver stacks, and in any case if "native" mode
52 * is available, it will be faster and hence preferable.
53 *
54 * - MMC depends on a different chipselect management policy than the
55 * SPI interface currently supports for shared bus segments: it needs
56 * to issue multiple spi_message requests with the chipselect active,
57 * using the results of one message to decide the next one to issue.
58 *
59 * Pending updates to the programming interface, this driver expects
60 * that it not share the bus with other drivers (precluding conflicts).
61 *
62 * - We tell the controller to keep the chipselect active from the
63 * beginning of an mmc_host_ops.request until the end. So beware
64 * of SPI controller drivers that mis-handle the cs_change flag!
65 *
66 * However, many cards seem OK with chipselect flapping up/down
67 * during that time ... at least on unshared bus segments.
68 */
69
70
71/*
72 * Local protocol constants, internal to data block protocols.
73 */
74
75/* Response tokens used to ack each block written: */
76#define SPI_MMC_RESPONSE_CODE(x) ((x) & 0x1f)
77#define SPI_RESPONSE_ACCEPTED ((2 << 1)|1)
78#define SPI_RESPONSE_CRC_ERR ((5 << 1)|1)
79#define SPI_RESPONSE_WRITE_ERR ((6 << 1)|1)
80
81/* Read and write blocks start with these tokens and end with crc;
82 * on error, read tokens act like a subset of R2_SPI_* values.
83 */
84#define SPI_TOKEN_SINGLE 0xfe /* single block r/w, multiblock read */
85#define SPI_TOKEN_MULTI_WRITE 0xfc /* multiblock write */
86#define SPI_TOKEN_STOP_TRAN 0xfd /* terminate multiblock write */
87
88#define MMC_SPI_BLOCKSIZE 512
89
90
91/* These fixed timeouts come from the latest SD specs, which say to ignore
92 * the CSD values. The R1B value is for card erase (e.g. the "I forgot the
93 * card's password" scenario); it's mostly applied to STOP_TRANSMISSION after
94 * reads which takes nowhere near that long. Older cards may be able to use
95 * shorter timeouts ... but why bother?
96 */
97#define readblock_timeout ktime_set(0, 100 * 1000 * 1000)
98#define writeblock_timeout ktime_set(0, 250 * 1000 * 1000)
99#define r1b_timeout ktime_set(3, 0)
100
101
102/****************************************************************************/
103
104/*
105 * Local Data Structures
106 */
107
108/* "scratch" is per-{command,block} data exchanged with the card */
109struct scratch {
110 u8 status[29];
111 u8 data_token;
112 __be16 crc_val;
113};
114
115struct mmc_spi_host {
116 struct mmc_host *mmc;
117 struct spi_device *spi;
118
119 unsigned char power_mode;
120 u16 powerup_msecs;
121
122 struct mmc_spi_platform_data *pdata;
123
124 /* for bulk data transfers */
125 struct spi_transfer token, t, crc, early_status;
126 struct spi_message m;
127
128 /* for status readback */
129 struct spi_transfer status;
130 struct spi_message readback;
131
132 /* underlying DMA-aware controller, or null */
133 struct device *dma_dev;
134
135 /* buffer used for commands and for message "overhead" */
136 struct scratch *data;
137 dma_addr_t data_dma;
138
139 /* Specs say to write ones most of the time, even when the card
140 * has no need to read its input data; and many cards won't care.
141 * This is our source of those ones.
142 */
143 void *ones;
144 dma_addr_t ones_dma;
145};
146
147
148/****************************************************************************/
149
150/*
151 * MMC-over-SPI protocol glue, used by the MMC stack interface
152 */
153
154static inline int mmc_cs_off(struct mmc_spi_host *host)
155{
156 /* chipselect will always be inactive after setup() */
157 return spi_setup(host->spi);
158}
159
160static int
161mmc_spi_readbytes(struct mmc_spi_host *host, unsigned len)
162{
163 int status;
164
165 if (len > sizeof(*host->data)) {
166 WARN_ON(1);
167 return -EIO;
168 }
169
170 host->status.len = len;
171
172 if (host->dma_dev)
173 dma_sync_single_for_device(host->dma_dev,
174 host->data_dma, sizeof(*host->data),
175 DMA_FROM_DEVICE);
176
177 status = spi_sync(host->spi, &host->readback);
178 if (status == 0)
179 status = host->readback.status;
180
181 if (host->dma_dev)
182 dma_sync_single_for_cpu(host->dma_dev,
183 host->data_dma, sizeof(*host->data),
184 DMA_FROM_DEVICE);
185
186 return status;
187}
188
189static int
190mmc_spi_skip(struct mmc_spi_host *host, ktime_t timeout, unsigned n, u8 byte)
191{
192 u8 *cp = host->data->status;
193
194 timeout = ktime_add(timeout, ktime_get());
195
196 while (1) {
197 int status;
198 unsigned i;
199
200 status = mmc_spi_readbytes(host, n);
201 if (status < 0)
202 return status;
203
204 for (i = 0; i < n; i++) {
205 if (cp[i] != byte)
206 return cp[i];
207 }
208
209 /* REVISIT investigate msleep() to avoid busy-wait I/O
210 * in at least some cases.
211 */
212 if (ktime_to_ns(ktime_sub(ktime_get(), timeout)) > 0)
213 break;
214 }
215 return -ETIMEDOUT;
216}
217
218static inline int
219mmc_spi_wait_unbusy(struct mmc_spi_host *host, ktime_t timeout)
220{
221 return mmc_spi_skip(host, timeout, sizeof(host->data->status), 0);
222}
223
224static int mmc_spi_readtoken(struct mmc_spi_host *host)
225{
226 return mmc_spi_skip(host, readblock_timeout, 1, 0xff);
227}
228
229
230/*
231 * Note that for SPI, cmd->resp[0] is not the same data as "native" protocol
232 * hosts return! The low byte holds R1_SPI bits. The next byte may hold
233 * R2_SPI bits ... for SEND_STATUS, or after data read errors.
234 *
235 * cmd->resp[1] holds any four-byte response, for R3 (READ_OCR) and on
236 * newer cards R7 (IF_COND).
237 */
238
239static char *maptype(struct mmc_command *cmd)
240{
241 switch (mmc_spi_resp_type(cmd)) {
242 case MMC_RSP_SPI_R1: return "R1";
243 case MMC_RSP_SPI_R1B: return "R1B";
244 case MMC_RSP_SPI_R2: return "R2/R5";
245 case MMC_RSP_SPI_R3: return "R3/R4/R7";
246 default: return "?";
247 }
248}
249
250/* return zero, else negative errno after setting cmd->error */
251static int mmc_spi_response_get(struct mmc_spi_host *host,
252 struct mmc_command *cmd, int cs_on)
253{
254 u8 *cp = host->data->status;
255 u8 *end = cp + host->t.len;
256 int value = 0;
257 char tag[32];
258
259 snprintf(tag, sizeof(tag), " ... CMD%d response SPI_%s",
260 cmd->opcode, maptype(cmd));
261
262 /* Except for data block reads, the whole response will already
263 * be stored in the scratch buffer. It's somewhere after the
264 * command and the first byte we read after it. We ignore that
265 * first byte. After STOP_TRANSMISSION command it may include
266 * two data bits, but otherwise it's all ones.
267 */
268 cp += 8;
269 while (cp < end && *cp == 0xff)
270 cp++;
271
272 /* Data block reads (R1 response types) may need more data... */
273 if (cp == end) {
274 unsigned i;
275
276 cp = host->data->status;
277
278 /* Card sends N(CR) (== 1..8) bytes of all-ones then one
279 * status byte ... and we already scanned 2 bytes.
280 *
281 * REVISIT block read paths use nasty byte-at-a-time I/O
282 * so it can always DMA directly into the target buffer.
283 * It'd probably be better to memcpy() the first chunk and
284 * avoid extra i/o calls...
285 */
286 for (i = 2; i < 9; i++) {
287 value = mmc_spi_readbytes(host, 1);
288 if (value < 0)
289 goto done;
290 if (*cp != 0xff)
291 goto checkstatus;
292 }
293 value = -ETIMEDOUT;
294 goto done;
295 }
296
297checkstatus:
298 if (*cp & 0x80) {
299 dev_dbg(&host->spi->dev, "%s: INVALID RESPONSE, %02x\n",
300 tag, *cp);
301 value = -EBADR;
302 goto done;
303 }
304
305 cmd->resp[0] = *cp++;
306 cmd->error = 0;
307
308 /* Status byte: the entire seven-bit R1 response. */
309 if (cmd->resp[0] != 0) {
310 if ((R1_SPI_PARAMETER | R1_SPI_ADDRESS
311 | R1_SPI_ILLEGAL_COMMAND)
312 & cmd->resp[0])
313 value = -EINVAL;
314 else if (R1_SPI_COM_CRC & cmd->resp[0])
315 value = -EILSEQ;
316 else if ((R1_SPI_ERASE_SEQ | R1_SPI_ERASE_RESET)
317 & cmd->resp[0])
318 value = -EIO;
319 /* else R1_SPI_IDLE, "it's resetting" */
320 }
321
322 switch (mmc_spi_resp_type(cmd)) {
323
324 /* SPI R1B == R1 + busy; STOP_TRANSMISSION (for multiblock reads)
325 * and less-common stuff like various erase operations.
326 */
327 case MMC_RSP_SPI_R1B:
328 /* maybe we read all the busy tokens already */
329 while (cp < end && *cp == 0)
330 cp++;
331 if (cp == end)
332 mmc_spi_wait_unbusy(host, r1b_timeout);
333 break;
334
335 /* SPI R2 == R1 + second status byte; SEND_STATUS
336 * SPI R5 == R1 + data byte; IO_RW_DIRECT
337 */
338 case MMC_RSP_SPI_R2:
339 cmd->resp[0] |= *cp << 8;
340 break;
341
342 /* SPI R3, R4, or R7 == R1 + 4 bytes */
343 case MMC_RSP_SPI_R3:
344 cmd->resp[1] = be32_to_cpu(get_unaligned((u32 *)cp));
345 break;
346
347 /* SPI R1 == just one status byte */
348 case MMC_RSP_SPI_R1:
349 break;
350
351 default:
352 dev_dbg(&host->spi->dev, "bad response type %04x\n",
353 mmc_spi_resp_type(cmd));
354 if (value >= 0)
355 value = -EINVAL;
356 goto done;
357 }
358
359 if (value < 0)
360 dev_dbg(&host->spi->dev, "%s: resp %04x %08x\n",
361 tag, cmd->resp[0], cmd->resp[1]);
362
363 /* disable chipselect on errors and some success cases */
364 if (value >= 0 && cs_on)
365 return value;
366done:
367 if (value < 0)
368 cmd->error = value;
369 mmc_cs_off(host);
370 return value;
371}
372
373/* Issue command and read its response.
374 * Returns zero on success, negative for error.
375 *
376 * On error, caller must cope with mmc core retry mechanism. That
377 * means immediate low-level resubmit, which affects the bus lock...
378 */
379static int
380mmc_spi_command_send(struct mmc_spi_host *host,
381 struct mmc_request *mrq,
382 struct mmc_command *cmd, int cs_on)
383{
384 struct scratch *data = host->data;
385 u8 *cp = data->status;
386 u32 arg = cmd->arg;
387 int status;
388 struct spi_transfer *t;
389
390 /* We can handle most commands (except block reads) in one full
391 * duplex I/O operation before either starting the next transfer
392 * (data block or command) or else deselecting the card.
393 *
394 * First, write 7 bytes:
395 * - an all-ones byte to ensure the card is ready
396 * - opcode byte (plus start and transmission bits)
397 * - four bytes of big-endian argument
398 * - crc7 (plus end bit) ... always computed, it's cheap
399 *
400 * We init the whole buffer to all-ones, which is what we need
401 * to write while we're reading (later) response data.
402 */
403 memset(cp++, 0xff, sizeof(data->status));
404
405 *cp++ = 0x40 | cmd->opcode;
406 *cp++ = (u8)(arg >> 24);
407 *cp++ = (u8)(arg >> 16);
408 *cp++ = (u8)(arg >> 8);
409 *cp++ = (u8)arg;
410 *cp++ = (crc7(0, &data->status[1], 5) << 1) | 0x01;
411
412 /* Then, read up to 13 bytes (while writing all-ones):
413 * - N(CR) (== 1..8) bytes of all-ones
414 * - status byte (for all response types)
415 * - the rest of the response, either:
416 * + nothing, for R1 or R1B responses
417 * + second status byte, for R2 responses
418 * + four data bytes, for R3 and R7 responses
419 *
420 * Finally, read some more bytes ... in the nice cases we know in
421 * advance how many, and reading 1 more is always OK:
422 * - N(EC) (== 0..N) bytes of all-ones, before deselect/finish
423 * - N(RC) (== 1..N) bytes of all-ones, before next command
424 * - N(WR) (== 1..N) bytes of all-ones, before data write
425 *
426 * So in those cases one full duplex I/O of at most 21 bytes will
427 * handle the whole command, leaving the card ready to receive a
428 * data block or new command. We do that whenever we can, shaving
429 * CPU and IRQ costs (especially when using DMA or FIFOs).
430 *
431 * There are two other cases, where it's not generally practical
432 * to rely on a single I/O:
433 *
434 * - R1B responses need at least N(EC) bytes of all-zeroes.
435 *
436 * In this case we can *try* to fit it into one I/O, then
437 * maybe read more data later.
438 *
439 * - Data block reads are more troublesome, since a variable
440 * number of padding bytes precede the token and data.
441 * + N(CX) (== 0..8) bytes of all-ones, before CSD or CID
442 * + N(AC) (== 1..many) bytes of all-ones
443 *
444 * In this case we currently only have minimal speedups here:
445 * when N(CR) == 1 we can avoid I/O in response_get().
446 */
447 if (cs_on && (mrq->data->flags & MMC_DATA_READ)) {
448 cp += 2; /* min(N(CR)) + status */
449 /* R1 */
450 } else {
451 cp += 10; /* max(N(CR)) + status + min(N(RC),N(WR)) */
452 if (cmd->flags & MMC_RSP_SPI_S2) /* R2/R5 */
453 cp++;
454 else if (cmd->flags & MMC_RSP_SPI_B4) /* R3/R4/R7 */
455 cp += 4;
456 else if (cmd->flags & MMC_RSP_BUSY) /* R1B */
457 cp = data->status + sizeof(data->status);
458 /* else: R1 (most commands) */
459 }
460
461 dev_dbg(&host->spi->dev, " mmc_spi: CMD%d, resp %s\n",
462 cmd->opcode, maptype(cmd));
463
464 /* send command, leaving chipselect active */
465 spi_message_init(&host->m);
466
467 t = &host->t;
468 memset(t, 0, sizeof(*t));
469 t->tx_buf = t->rx_buf = data->status;
470 t->tx_dma = t->rx_dma = host->data_dma;
471 t->len = cp - data->status;
472 t->cs_change = 1;
473 spi_message_add_tail(t, &host->m);
474
475 if (host->dma_dev) {
476 host->m.is_dma_mapped = 1;
477 dma_sync_single_for_device(host->dma_dev,
478 host->data_dma, sizeof(*host->data),
479 DMA_BIDIRECTIONAL);
480 }
481 status = spi_sync(host->spi, &host->m);
482 if (status == 0)
483 status = host->m.status;
484
485 if (host->dma_dev)
486 dma_sync_single_for_cpu(host->dma_dev,
487 host->data_dma, sizeof(*host->data),
488 DMA_BIDIRECTIONAL);
489 if (status < 0) {
490 dev_dbg(&host->spi->dev, " ... write returned %d\n", status);
491 cmd->error = status;
492 return status;
493 }
494
495 /* after no-data commands and STOP_TRANSMISSION, chipselect off */
496 return mmc_spi_response_get(host, cmd, cs_on);
497}
498
499/* Build data message with up to four separate transfers. For TX, we
500 * start by writing the data token. And in most cases, we finish with
501 * a status transfer.
502 *
503 * We always provide TX data for data and CRC. The MMC/SD protocol
504 * requires us to write ones; but Linux defaults to writing zeroes;
505 * so we explicitly initialize it to all ones on RX paths.
506 *
507 * We also handle DMA mapping, so the underlying SPI controller does
508 * not need to (re)do it for each message.
509 */
510static void
511mmc_spi_setup_data_message(
512 struct mmc_spi_host *host,
513 int multiple,
514 enum dma_data_direction direction)
515{
516 struct spi_transfer *t;
517 struct scratch *scratch = host->data;
518 dma_addr_t dma = host->data_dma;
519
520 spi_message_init(&host->m);
521 if (dma)
522 host->m.is_dma_mapped = 1;
523
524 /* for reads, readblock() skips 0xff bytes before finding
525 * the token; for writes, this transfer issues that token.
526 */
527 if (direction == DMA_TO_DEVICE) {
528 t = &host->token;
529 memset(t, 0, sizeof(*t));
530 t->len = 1;
531 if (multiple)
532 scratch->data_token = SPI_TOKEN_MULTI_WRITE;
533 else
534 scratch->data_token = SPI_TOKEN_SINGLE;
535 t->tx_buf = &scratch->data_token;
536 if (dma)
537 t->tx_dma = dma + offsetof(struct scratch, data_token);
538 spi_message_add_tail(t, &host->m);
539 }
540
541 /* Body of transfer is buffer, then CRC ...
542 * either TX-only, or RX with TX-ones.
543 */
544 t = &host->t;
545 memset(t, 0, sizeof(*t));
546 t->tx_buf = host->ones;
547 t->tx_dma = host->ones_dma;
548 /* length and actual buffer info are written later */
549 spi_message_add_tail(t, &host->m);
550
551 t = &host->crc;
552 memset(t, 0, sizeof(*t));
553 t->len = 2;
554 if (direction == DMA_TO_DEVICE) {
555 /* the actual CRC may get written later */
556 t->tx_buf = &scratch->crc_val;
557 if (dma)
558 t->tx_dma = dma + offsetof(struct scratch, crc_val);
559 } else {
560 t->tx_buf = host->ones;
561 t->tx_dma = host->ones_dma;
562 t->rx_buf = &scratch->crc_val;
563 if (dma)
564 t->rx_dma = dma + offsetof(struct scratch, crc_val);
565 }
566 spi_message_add_tail(t, &host->m);
567
568 /*
569 * A single block read is followed by N(EC) [0+] all-ones bytes
570 * before deselect ... don't bother.
571 *
572 * Multiblock reads are followed by N(AC) [1+] all-ones bytes before
573 * the next block is read, or a STOP_TRANSMISSION is issued. We'll
574 * collect that single byte, so readblock() doesn't need to.
575 *
576 * For a write, the one-byte data response follows immediately, then
577 * come zero or more busy bytes, then N(WR) [1+] all-ones bytes.
578 * Then single block reads may deselect, and multiblock ones issue
579 * the next token (next data block, or STOP_TRAN). We can try to
580 * minimize I/O ops by using a single read to collect end-of-busy.
581 */
582 if (multiple || direction == DMA_TO_DEVICE) {
583 t = &host->early_status;
584 memset(t, 0, sizeof(*t));
585 t->len = (direction == DMA_TO_DEVICE)
586 ? sizeof(scratch->status)
587 : 1;
588 t->tx_buf = host->ones;
589 t->tx_dma = host->ones_dma;
590 t->rx_buf = scratch->status;
591 if (dma)
592 t->rx_dma = dma + offsetof(struct scratch, status);
593 t->cs_change = 1;
594 spi_message_add_tail(t, &host->m);
595 }
596}
597
598/*
599 * Write one block:
600 * - caller handled preceding N(WR) [1+] all-ones bytes
601 * - data block
602 * + token
603 * + data bytes
604 * + crc16
605 * - an all-ones byte ... card writes a data-response byte
606 * - followed by N(EC) [0+] all-ones bytes, card writes zero/'busy'
607 *
608 * Return negative errno, else success.
609 */
610static int
611mmc_spi_writeblock(struct mmc_spi_host *host, struct spi_transfer *t)
612{
613 struct spi_device *spi = host->spi;
614 int status, i;
615 struct scratch *scratch = host->data;
616
617 if (host->mmc->use_spi_crc)
618 scratch->crc_val = cpu_to_be16(
619 crc_itu_t(0, t->tx_buf, t->len));
620 if (host->dma_dev)
621 dma_sync_single_for_device(host->dma_dev,
622 host->data_dma, sizeof(*scratch),
623 DMA_BIDIRECTIONAL);
624
625 status = spi_sync(spi, &host->m);
626 if (status == 0)
627 status = host->m.status;
628
629 if (status != 0) {
630 dev_dbg(&spi->dev, "write error (%d)\n", status);
631 return status;
632 }
633
634 if (host->dma_dev)
635 dma_sync_single_for_cpu(host->dma_dev,
636 host->data_dma, sizeof(*scratch),
637 DMA_BIDIRECTIONAL);
638
639 /*
640 * Get the transmission data-response reply. It must follow
641 * immediately after the data block we transferred. This reply
642 * doesn't necessarily tell whether the write operation succeeded;
643 * it just says if the transmission was ok and whether *earlier*
644 * writes succeeded; see the standard.
645 */
646 switch (SPI_MMC_RESPONSE_CODE(scratch->status[0])) {
647 case SPI_RESPONSE_ACCEPTED:
648 status = 0;
649 break;
650 case SPI_RESPONSE_CRC_ERR:
651 /* host shall then issue MMC_STOP_TRANSMISSION */
652 status = -EILSEQ;
653 break;
654 case SPI_RESPONSE_WRITE_ERR:
655 /* host shall then issue MMC_STOP_TRANSMISSION,
656 * and should MMC_SEND_STATUS to sort it out
657 */
658 status = -EIO;
659 break;
660 default:
661 status = -EPROTO;
662 break;
663 }
664 if (status != 0) {
665 dev_dbg(&spi->dev, "write error %02x (%d)\n",
666 scratch->status[0], status);
667 return status;
668 }
669
670 t->tx_buf += t->len;
671 if (host->dma_dev)
672 t->tx_dma += t->len;
673
674 /* Return when not busy. If we didn't collect that status yet,
675 * we'll need some more I/O.
676 */
677 for (i = 1; i < sizeof(scratch->status); i++) {
678 if (scratch->status[i] != 0)
679 return 0;
680 }
681 return mmc_spi_wait_unbusy(host, writeblock_timeout);
682}
683
684/*
685 * Read one block:
686 * - skip leading all-ones bytes ... either
687 * + N(AC) [1..f(clock,CSD)] usually, else
688 * + N(CX) [0..8] when reading CSD or CID
689 * - data block
690 * + token ... if error token, no data or crc
691 * + data bytes
692 * + crc16
693 *
694 * After single block reads, we're done; N(EC) [0+] all-ones bytes follow
695 * before dropping chipselect.
696 *
697 * For multiblock reads, caller either reads the next block or issues a
698 * STOP_TRANSMISSION command.
699 */
700static int
701mmc_spi_readblock(struct mmc_spi_host *host, struct spi_transfer *t)
702{
703 struct spi_device *spi = host->spi;
704 int status;
705 struct scratch *scratch = host->data;
706
707 /* At least one SD card sends an all-zeroes byte when N(CX)
708 * applies, before the all-ones bytes ... just cope with that.
709 */
710 status = mmc_spi_readbytes(host, 1);
711 if (status < 0)
712 return status;
713 status = scratch->status[0];
714 if (status == 0xff || status == 0)
715 status = mmc_spi_readtoken(host);
716
717 if (status == SPI_TOKEN_SINGLE) {
718 if (host->dma_dev) {
719 dma_sync_single_for_device(host->dma_dev,
720 host->data_dma, sizeof(*scratch),
721 DMA_BIDIRECTIONAL);
722 dma_sync_single_for_device(host->dma_dev,
723 t->rx_dma, t->len,
724 DMA_FROM_DEVICE);
725 }
726
727 status = spi_sync(spi, &host->m);
728 if (status == 0)
729 status = host->m.status;
730
731 if (host->dma_dev) {
732 dma_sync_single_for_cpu(host->dma_dev,
733 host->data_dma, sizeof(*scratch),
734 DMA_BIDIRECTIONAL);
735 dma_sync_single_for_cpu(host->dma_dev,
736 t->rx_dma, t->len,
737 DMA_FROM_DEVICE);
738 }
739
740 } else {
741 dev_dbg(&spi->dev, "read error %02x (%d)\n", status, status);
742
743 /* we've read extra garbage, timed out, etc */
744 if (status < 0)
745 return status;
746
747 /* low four bits are an R2 subset, fifth seems to be
748 * vendor specific ... map them all to generic error..
749 */
750 return -EIO;
751 }
752
753 if (host->mmc->use_spi_crc) {
754 u16 crc = crc_itu_t(0, t->rx_buf, t->len);
755
756 be16_to_cpus(&scratch->crc_val);
757 if (scratch->crc_val != crc) {
758 dev_dbg(&spi->dev, "read - crc error: crc_val=0x%04x, "
759 "computed=0x%04x len=%d\n",
760 scratch->crc_val, crc, t->len);
761 return -EILSEQ;
762 }
763 }
764
765 t->rx_buf += t->len;
766 if (host->dma_dev)
767 t->rx_dma += t->len;
768
769 return 0;
770}
771
772/*
773 * An MMC/SD data stage includes one or more blocks, optional CRCs,
774 * and inline handshaking. That handhaking makes it unlike most
775 * other SPI protocol stacks.
776 */
777static void
778mmc_spi_data_do(struct mmc_spi_host *host, struct mmc_command *cmd,
779 struct mmc_data *data, u32 blk_size)
780{
781 struct spi_device *spi = host->spi;
782 struct device *dma_dev = host->dma_dev;
783 struct spi_transfer *t;
784 enum dma_data_direction direction;
785 struct scatterlist *sg;
786 unsigned n_sg;
787 int multiple = (data->blocks > 1);
788
789 if (data->flags & MMC_DATA_READ)
790 direction = DMA_FROM_DEVICE;
791 else
792 direction = DMA_TO_DEVICE;
793 mmc_spi_setup_data_message(host, multiple, direction);
794 t = &host->t;
795
796 /* Handle scatterlist segments one at a time, with synch for
797 * each 512-byte block
798 */
799 for (sg = data->sg, n_sg = data->sg_len; n_sg; n_sg--, sg++) {
800 int status = 0;
801 dma_addr_t dma_addr = 0;
802 void *kmap_addr;
803 unsigned length = sg->length;
804 enum dma_data_direction dir = direction;
805
806 /* set up dma mapping for controller drivers that might
807 * use DMA ... though they may fall back to PIO
808 */
809 if (dma_dev) {
810 /* never invalidate whole *shared* pages ... */
811 if ((sg->offset != 0 || length != PAGE_SIZE)
812 && dir == DMA_FROM_DEVICE)
813 dir = DMA_BIDIRECTIONAL;
814
815 dma_addr = dma_map_page(dma_dev, sg->page, 0,
816 PAGE_SIZE, dir);
817 if (direction == DMA_TO_DEVICE)
818 t->tx_dma = dma_addr + sg->offset;
819 else
820 t->rx_dma = dma_addr + sg->offset;
821 }
822
823 /* allow pio too; we don't allow highmem */
824 kmap_addr = kmap(sg->page);
825 if (direction == DMA_TO_DEVICE)
826 t->tx_buf = kmap_addr + sg->offset;
827 else
828 t->rx_buf = kmap_addr + sg->offset;
829
830 /* transfer each block, and update request status */
831 while (length) {
832 t->len = min(length, blk_size);
833
834 dev_dbg(&host->spi->dev,
835 " mmc_spi: %s block, %d bytes\n",
836 (direction == DMA_TO_DEVICE)
837 ? "write"
838 : "read",
839 t->len);
840
841 if (direction == DMA_TO_DEVICE)
842 status = mmc_spi_writeblock(host, t);
843 else
844 status = mmc_spi_readblock(host, t);
845 if (status < 0)
846 break;
847
848 data->bytes_xfered += t->len;
849 length -= t->len;
850
851 if (!multiple)
852 break;
853 }
854
855 /* discard mappings */
856 if (direction == DMA_FROM_DEVICE)
857 flush_kernel_dcache_page(sg->page);
858 kunmap(sg->page);
859 if (dma_dev)
860 dma_unmap_page(dma_dev, dma_addr, PAGE_SIZE, dir);
861
862 if (status < 0) {
863 data->error = status;
864 dev_dbg(&spi->dev, "%s status %d\n",
865 (direction == DMA_TO_DEVICE)
866 ? "write" : "read",
867 status);
868 break;
869 }
870 }
871
872 /* NOTE some docs describe an MMC-only SET_BLOCK_COUNT (CMD23) that
873 * can be issued before multiblock writes. Unlike its more widely
874 * documented analogue for SD cards (SET_WR_BLK_ERASE_COUNT, ACMD23),
875 * that can affect the STOP_TRAN logic. Complete (and current)
876 * MMC specs should sort that out before Linux starts using CMD23.
877 */
878 if (direction == DMA_TO_DEVICE && multiple) {
879 struct scratch *scratch = host->data;
880 int tmp;
881 const unsigned statlen = sizeof(scratch->status);
882
883 dev_dbg(&spi->dev, " mmc_spi: STOP_TRAN\n");
884
885 /* Tweak the per-block message we set up earlier by morphing
886 * it to hold single buffer with the token followed by some
887 * all-ones bytes ... skip N(BR) (0..1), scan the rest for
888 * "not busy any longer" status, and leave chip selected.
889 */
890 INIT_LIST_HEAD(&host->m.transfers);
891 list_add(&host->early_status.transfer_list,
892 &host->m.transfers);
893
894 memset(scratch->status, 0xff, statlen);
895 scratch->status[0] = SPI_TOKEN_STOP_TRAN;
896
897 host->early_status.tx_buf = host->early_status.rx_buf;
898 host->early_status.tx_dma = host->early_status.rx_dma;
899 host->early_status.len = statlen;
900
901 if (host->dma_dev)
902 dma_sync_single_for_device(host->dma_dev,
903 host->data_dma, sizeof(*scratch),
904 DMA_BIDIRECTIONAL);
905
906 tmp = spi_sync(spi, &host->m);
907 if (tmp == 0)
908 tmp = host->m.status;
909
910 if (host->dma_dev)
911 dma_sync_single_for_cpu(host->dma_dev,
912 host->data_dma, sizeof(*scratch),
913 DMA_BIDIRECTIONAL);
914
915 if (tmp < 0) {
916 if (!data->error)
917 data->error = tmp;
918 return;
919 }
920
921 /* Ideally we collected "not busy" status with one I/O,
922 * avoiding wasteful byte-at-a-time scanning... but more
923 * I/O is often needed.
924 */
925 for (tmp = 2; tmp < statlen; tmp++) {
926 if (scratch->status[tmp] != 0)
927 return;
928 }
929 tmp = mmc_spi_wait_unbusy(host, writeblock_timeout);
930 if (tmp < 0 && !data->error)
931 data->error = tmp;
932 }
933}
934
935/****************************************************************************/
936
937/*
938 * MMC driver implementation -- the interface to the MMC stack
939 */
940
941static void mmc_spi_request(struct mmc_host *mmc, struct mmc_request *mrq)
942{
943 struct mmc_spi_host *host = mmc_priv(mmc);
944 int status = -EINVAL;
945
946#ifdef DEBUG
947 /* MMC core and layered drivers *MUST* issue SPI-aware commands */
948 {
949 struct mmc_command *cmd;
950 int invalid = 0;
951
952 cmd = mrq->cmd;
953 if (!mmc_spi_resp_type(cmd)) {
954 dev_dbg(&host->spi->dev, "bogus command\n");
955 cmd->error = -EINVAL;
956 invalid = 1;
957 }
958
959 cmd = mrq->stop;
960 if (cmd && !mmc_spi_resp_type(cmd)) {
961 dev_dbg(&host->spi->dev, "bogus STOP command\n");
962 cmd->error = -EINVAL;
963 invalid = 1;
964 }
965
966 if (invalid) {
967 dump_stack();
968 mmc_request_done(host->mmc, mrq);
969 return;
970 }
971 }
972#endif
973
974 /* issue command; then optionally data and stop */
975 status = mmc_spi_command_send(host, mrq, mrq->cmd, mrq->data != NULL);
976 if (status == 0 && mrq->data) {
977 mmc_spi_data_do(host, mrq->cmd, mrq->data, mrq->data->blksz);
978 if (mrq->stop)
979 status = mmc_spi_command_send(host, mrq, mrq->stop, 0);
980 else
981 mmc_cs_off(host);
982 }
983
984 mmc_request_done(host->mmc, mrq);
985}
986
987/* See Section 6.4.1, in SD "Simplified Physical Layer Specification 2.0"
988 *
989 * NOTE that here we can't know that the card has just been powered up;
990 * not all MMC/SD sockets support power switching.
991 *
992 * FIXME when the card is still in SPI mode, e.g. from a previous kernel,
993 * this doesn't seem to do the right thing at all...
994 */
995static void mmc_spi_initsequence(struct mmc_spi_host *host)
996{
997 /* Try to be very sure any previous command has completed;
998 * wait till not-busy, skip debris from any old commands.
999 */
1000 mmc_spi_wait_unbusy(host, r1b_timeout);
1001 mmc_spi_readbytes(host, 10);
1002
1003 /*
1004 * Do a burst with chipselect active-high. We need to do this to
1005 * meet the requirement of 74 clock cycles with both chipselect
1006 * and CMD (MOSI) high before CMD0 ... after the card has been
1007 * powered up to Vdd(min), and so is ready to take commands.
1008 *
1009 * Some cards are particularly needy of this (e.g. Viking "SD256")
1010 * while most others don't seem to care.
1011 *
1012 * Note that this is one of the places MMC/SD plays games with the
1013 * SPI protocol. Another is that when chipselect is released while
1014 * the card returns BUSY status, the clock must issue several cycles
1015 * with chipselect high before the card will stop driving its output.
1016 */
1017 host->spi->mode |= SPI_CS_HIGH;
1018 if (spi_setup(host->spi) != 0) {
1019 /* Just warn; most cards work without it. */
1020 dev_warn(&host->spi->dev,
1021 "can't change chip-select polarity\n");
1022 host->spi->mode &= ~SPI_CS_HIGH;
1023 } else {
1024 mmc_spi_readbytes(host, 18);
1025
1026 host->spi->mode &= ~SPI_CS_HIGH;
1027 if (spi_setup(host->spi) != 0) {
1028 /* Wot, we can't get the same setup we had before? */
1029 dev_err(&host->spi->dev,
1030 "can't restore chip-select polarity\n");
1031 }
1032 }
1033}
1034
1035static char *mmc_powerstring(u8 power_mode)
1036{
1037 switch (power_mode) {
1038 case MMC_POWER_OFF: return "off";
1039 case MMC_POWER_UP: return "up";
1040 case MMC_POWER_ON: return "on";
1041 }
1042 return "?";
1043}
1044
1045static void mmc_spi_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1046{
1047 struct mmc_spi_host *host = mmc_priv(mmc);
1048
1049 if (host->power_mode != ios->power_mode) {
1050 int canpower;
1051
1052 canpower = host->pdata && host->pdata->setpower;
1053
1054 dev_dbg(&host->spi->dev, "mmc_spi: power %s (%d)%s\n",
1055 mmc_powerstring(ios->power_mode),
1056 ios->vdd,
1057 canpower ? ", can switch" : "");
1058
1059 /* switch power on/off if possible, accounting for
1060 * max 250msec powerup time if needed.
1061 */
1062 if (canpower) {
1063 switch (ios->power_mode) {
1064 case MMC_POWER_OFF:
1065 case MMC_POWER_UP:
1066 host->pdata->setpower(&host->spi->dev,
1067 ios->vdd);
1068 if (ios->power_mode == MMC_POWER_UP)
1069 msleep(host->powerup_msecs);
1070 }
1071 }
1072
1073 /* See 6.4.1 in the simplified SD card physical spec 2.0 */
1074 if (ios->power_mode == MMC_POWER_ON)
1075 mmc_spi_initsequence(host);
1076
1077 /* If powering down, ground all card inputs to avoid power
1078 * delivery from data lines! On a shared SPI bus, this
1079 * will probably be temporary; 6.4.2 of the simplified SD
1080 * spec says this must last at least 1msec.
1081 *
1082 * - Clock low means CPOL 0, e.g. mode 0
1083 * - MOSI low comes from writing zero
1084 * - Chipselect is usually active low...
1085 */
1086 if (canpower && ios->power_mode == MMC_POWER_OFF) {
1087 int mres;
1088
1089 host->spi->mode &= ~(SPI_CPOL|SPI_CPHA);
1090 mres = spi_setup(host->spi);
1091 if (mres < 0)
1092 dev_dbg(&host->spi->dev,
1093 "switch to SPI mode 0 failed\n");
1094
1095 if (spi_w8r8(host->spi, 0x00) < 0)
1096 dev_dbg(&host->spi->dev,
1097 "put spi signals to low failed\n");
1098
1099 /*
1100 * Now clock should be low due to spi mode 0;
1101 * MOSI should be low because of written 0x00;
1102 * chipselect should be low (it is active low)
1103 * power supply is off, so now MMC is off too!
1104 *
1105 * FIXME no, chipselect can be high since the
1106 * device is inactive and SPI_CS_HIGH is clear...
1107 */
1108 msleep(10);
1109 if (mres == 0) {
1110 host->spi->mode |= (SPI_CPOL|SPI_CPHA);
1111 mres = spi_setup(host->spi);
1112 if (mres < 0)
1113 dev_dbg(&host->spi->dev,
1114 "switch back to SPI mode 3"
1115 " failed\n");
1116 }
1117 }
1118
1119 host->power_mode = ios->power_mode;
1120 }
1121
1122 if (host->spi->max_speed_hz != ios->clock && ios->clock != 0) {
1123 int status;
1124
1125 host->spi->max_speed_hz = ios->clock;
1126 status = spi_setup(host->spi);
1127 dev_dbg(&host->spi->dev,
1128 "mmc_spi: clock to %d Hz, %d\n",
1129 host->spi->max_speed_hz, status);
1130 }
1131}
1132
1133static int mmc_spi_get_ro(struct mmc_host *mmc)
1134{
1135 struct mmc_spi_host *host = mmc_priv(mmc);
1136
1137 if (host->pdata && host->pdata->get_ro)
1138 return host->pdata->get_ro(mmc->parent);
1139 /* board doesn't support read only detection; assume writeable */
1140 return 0;
1141}
1142
1143
1144static const struct mmc_host_ops mmc_spi_ops = {
1145 .request = mmc_spi_request,
1146 .set_ios = mmc_spi_set_ios,
1147 .get_ro = mmc_spi_get_ro,
1148};
1149
1150
1151/****************************************************************************/
1152
1153/*
1154 * SPI driver implementation
1155 */
1156
1157static irqreturn_t
1158mmc_spi_detect_irq(int irq, void *mmc)
1159{
1160 struct mmc_spi_host *host = mmc_priv(mmc);
1161 u16 delay_msec = max(host->pdata->detect_delay, (u16)100);
1162
1163 mmc_detect_change(mmc, msecs_to_jiffies(delay_msec));
1164 return IRQ_HANDLED;
1165}
1166
1167static int mmc_spi_probe(struct spi_device *spi)
1168{
1169 void *ones;
1170 struct mmc_host *mmc;
1171 struct mmc_spi_host *host;
1172 int status;
1173
1174 /* MMC and SD specs only seem to care that sampling is on the
1175 * rising edge ... meaning SPI modes 0 or 3. So either SPI mode
1176 * should be legit. We'll use mode 0 since it seems to be a
1177 * bit less troublesome on some hardware ... unclear why.
1178 */
1179 spi->mode = SPI_MODE_0;
1180 spi->bits_per_word = 8;
1181
1182 status = spi_setup(spi);
1183 if (status < 0) {
1184 dev_dbg(&spi->dev, "needs SPI mode %02x, %d KHz; %d\n",
1185 spi->mode, spi->max_speed_hz / 1000,
1186 status);
1187 return status;
1188 }
1189
1190 /* We can use the bus safely iff nobody else will interfere with
1191 * us. That is, either we have the experimental exclusive access
1192 * primitives ... or else there's nobody to share it with.
1193 */
1194 if (spi->master->num_chipselect > 1) {
1195 struct device *parent = spi->dev.parent;
1196
1197 /* If there are multiple devices on this bus, we
1198 * can't proceed.
1199 */
1200 spin_lock(&parent->klist_children.k_lock);
1201 if (parent->klist_children.k_list.next
1202 != parent->klist_children.k_list.prev)
1203 status = -EMLINK;
1204 else
1205 status = 0;
1206 spin_unlock(&parent->klist_children.k_lock);
1207 if (status < 0) {
1208 dev_err(&spi->dev, "can't share SPI bus\n");
1209 return status;
1210 }
1211
1212 /* REVISIT we can't guarantee another device won't
1213 * be added later. It's uncommon though ... for now,
1214 * work as if this is safe.
1215 */
1216 dev_warn(&spi->dev, "ASSUMING unshared SPI bus!\n");
1217 }
1218
1219 /* We need a supply of ones to transmit. This is the only time
1220 * the CPU touches these, so cache coherency isn't a concern.
1221 *
1222 * NOTE if many systems use more than one MMC-over-SPI connector
1223 * it'd save some memory to share this. That's evidently rare.
1224 */
1225 status = -ENOMEM;
1226 ones = kmalloc(MMC_SPI_BLOCKSIZE, GFP_KERNEL);
1227 if (!ones)
1228 goto nomem;
1229 memset(ones, 0xff, MMC_SPI_BLOCKSIZE);
1230
1231 mmc = mmc_alloc_host(sizeof(*host), &spi->dev);
1232 if (!mmc)
1233 goto nomem;
1234
1235 mmc->ops = &mmc_spi_ops;
1236 mmc->max_blk_size = MMC_SPI_BLOCKSIZE;
1237
1238 /* As long as we keep track of the number of successfully
1239 * transmitted blocks, we're good for multiwrite.
1240 */
1241 mmc->caps = MMC_CAP_SPI | MMC_CAP_MULTIWRITE;
1242
1243 /* SPI doesn't need the lowspeed device identification thing for
1244 * MMC or SD cards, since it never comes up in open drain mode.
1245 * That's good; some SPI masters can't handle very low speeds!
1246 *
1247 * However, low speed SDIO cards need not handle over 400 KHz;
1248 * that's the only reason not to use a few MHz for f_min (until
1249 * the upper layer reads the target frequency from the CSD).
1250 */
1251 mmc->f_min = 400000;
1252 mmc->f_max = spi->max_speed_hz;
1253
1254 host = mmc_priv(mmc);
1255 host->mmc = mmc;
1256 host->spi = spi;
1257
1258 host->ones = ones;
1259
1260 /* Platform data is used to hook up things like card sensing
1261 * and power switching gpios.
1262 */
1263 host->pdata = spi->dev.platform_data;
1264 if (host->pdata)
1265 mmc->ocr_avail = host->pdata->ocr_mask;
1266 if (!mmc->ocr_avail) {
1267 dev_warn(&spi->dev, "ASSUMING 3.2-3.4 V slot power\n");
1268 mmc->ocr_avail = MMC_VDD_32_33|MMC_VDD_33_34;
1269 }
1270 if (host->pdata && host->pdata->setpower) {
1271 host->powerup_msecs = host->pdata->powerup_msecs;
1272 if (!host->powerup_msecs || host->powerup_msecs > 250)
1273 host->powerup_msecs = 250;
1274 }
1275
1276 dev_set_drvdata(&spi->dev, mmc);
1277
1278 /* preallocate dma buffers */
1279 host->data = kmalloc(sizeof(*host->data), GFP_KERNEL);
1280 if (!host->data)
1281 goto fail_nobuf1;
1282
1283 if (spi->master->cdev.dev->dma_mask) {
1284 struct device *dev = spi->master->cdev.dev;
1285
1286 host->dma_dev = dev;
1287 host->ones_dma = dma_map_single(dev, ones,
1288 MMC_SPI_BLOCKSIZE, DMA_TO_DEVICE);
1289 host->data_dma = dma_map_single(dev, host->data,
1290 sizeof(*host->data), DMA_BIDIRECTIONAL);
1291
1292 /* REVISIT in theory those map operations can fail... */
1293
1294 dma_sync_single_for_cpu(host->dma_dev,
1295 host->data_dma, sizeof(*host->data),
1296 DMA_BIDIRECTIONAL);
1297 }
1298
1299 /* setup message for status/busy readback */
1300 spi_message_init(&host->readback);
1301 host->readback.is_dma_mapped = (host->dma_dev != NULL);
1302
1303 spi_message_add_tail(&host->status, &host->readback);
1304 host->status.tx_buf = host->ones;
1305 host->status.tx_dma = host->ones_dma;
1306 host->status.rx_buf = &host->data->status;
1307 host->status.rx_dma = host->data_dma + offsetof(struct scratch, status);
1308 host->status.cs_change = 1;
1309
1310 /* register card detect irq */
1311 if (host->pdata && host->pdata->init) {
1312 status = host->pdata->init(&spi->dev, mmc_spi_detect_irq, mmc);
1313 if (status != 0)
1314 goto fail_glue_init;
1315 }
1316
1317 status = mmc_add_host(mmc);
1318 if (status != 0)
1319 goto fail_add_host;
1320
1321 dev_info(&spi->dev, "SD/MMC host %s%s%s%s\n",
1322 mmc->class_dev.bus_id,
1323 host->dma_dev ? "" : ", no DMA",
1324 (host->pdata && host->pdata->get_ro)
1325 ? "" : ", no WP",
1326 (host->pdata && host->pdata->setpower)
1327 ? "" : ", no poweroff");
1328 return 0;
1329
1330fail_add_host:
1331 mmc_remove_host (mmc);
1332fail_glue_init:
1333 if (host->dma_dev)
1334 dma_unmap_single(host->dma_dev, host->data_dma,
1335 sizeof(*host->data), DMA_BIDIRECTIONAL);
1336 kfree(host->data);
1337
1338fail_nobuf1:
1339 mmc_free_host(mmc);
1340 dev_set_drvdata(&spi->dev, NULL);
1341
1342nomem:
1343 kfree(ones);
1344 return status;
1345}
1346
1347
1348static int __devexit mmc_spi_remove(struct spi_device *spi)
1349{
1350 struct mmc_host *mmc = dev_get_drvdata(&spi->dev);
1351 struct mmc_spi_host *host;
1352
1353 if (mmc) {
1354 host = mmc_priv(mmc);
1355
1356 /* prevent new mmc_detect_change() calls */
1357 if (host->pdata && host->pdata->exit)
1358 host->pdata->exit(&spi->dev, mmc);
1359
1360 mmc_remove_host(mmc);
1361
1362 if (host->dma_dev) {
1363 dma_unmap_single(host->dma_dev, host->ones_dma,
1364 MMC_SPI_BLOCKSIZE, DMA_TO_DEVICE);
1365 dma_unmap_single(host->dma_dev, host->data_dma,
1366 sizeof(*host->data), DMA_BIDIRECTIONAL);
1367 }
1368
1369 kfree(host->data);
1370 kfree(host->ones);
1371
1372 spi->max_speed_hz = mmc->f_max;
1373 mmc_free_host(mmc);
1374 dev_set_drvdata(&spi->dev, NULL);
1375 }
1376 return 0;
1377}
1378
1379
1380static struct spi_driver mmc_spi_driver = {
1381 .driver = {
1382 .name = "mmc_spi",
1383 .bus = &spi_bus_type,
1384 .owner = THIS_MODULE,
1385 },
1386 .probe = mmc_spi_probe,
1387 .remove = __devexit_p(mmc_spi_remove),
1388};
1389
1390
1391static int __init mmc_spi_init(void)
1392{
1393 return spi_register_driver(&mmc_spi_driver);
1394}
1395module_init(mmc_spi_init);
1396
1397
1398static void __exit mmc_spi_exit(void)
1399{
1400 spi_unregister_driver(&mmc_spi_driver);
1401}
1402module_exit(mmc_spi_exit);
1403
1404
1405MODULE_AUTHOR("Mike Lavender, David Brownell, "
1406 "Hans-Peter Nilsson, Jan Nikitenko");
1407MODULE_DESCRIPTION("SPI SD/MMC host driver");
1408MODULE_LICENSE("GPL");
diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
index be730c0a0352..d0eb0a2abf4d 100644
--- a/drivers/mmc/host/mmci.c
+++ b/drivers/mmc/host/mmci.c
@@ -16,6 +16,7 @@
16#include <linux/delay.h> 16#include <linux/delay.h>
17#include <linux/err.h> 17#include <linux/err.h>
18#include <linux/highmem.h> 18#include <linux/highmem.h>
19#include <linux/log2.h>
19#include <linux/mmc/host.h> 20#include <linux/mmc/host.h>
20#include <linux/amba/bus.h> 21#include <linux/amba/bus.h>
21#include <linux/clk.h> 22#include <linux/clk.h>
@@ -154,11 +155,11 @@ mmci_data_irq(struct mmci_host *host, struct mmc_data *data,
154 } 155 }
155 if (status & (MCI_DATACRCFAIL|MCI_DATATIMEOUT|MCI_TXUNDERRUN|MCI_RXOVERRUN)) { 156 if (status & (MCI_DATACRCFAIL|MCI_DATATIMEOUT|MCI_TXUNDERRUN|MCI_RXOVERRUN)) {
156 if (status & MCI_DATACRCFAIL) 157 if (status & MCI_DATACRCFAIL)
157 data->error = MMC_ERR_BADCRC; 158 data->error = -EILSEQ;
158 else if (status & MCI_DATATIMEOUT) 159 else if (status & MCI_DATATIMEOUT)
159 data->error = MMC_ERR_TIMEOUT; 160 data->error = -ETIMEDOUT;
160 else if (status & (MCI_TXUNDERRUN|MCI_RXOVERRUN)) 161 else if (status & (MCI_TXUNDERRUN|MCI_RXOVERRUN))
161 data->error = MMC_ERR_FIFO; 162 data->error = -EIO;
162 status |= MCI_DATAEND; 163 status |= MCI_DATAEND;
163 164
164 /* 165 /*
@@ -193,12 +194,12 @@ mmci_cmd_irq(struct mmci_host *host, struct mmc_command *cmd,
193 cmd->resp[3] = readl(base + MMCIRESPONSE3); 194 cmd->resp[3] = readl(base + MMCIRESPONSE3);
194 195
195 if (status & MCI_CMDTIMEOUT) { 196 if (status & MCI_CMDTIMEOUT) {
196 cmd->error = MMC_ERR_TIMEOUT; 197 cmd->error = -ETIMEDOUT;
197 } else if (status & MCI_CMDCRCFAIL && cmd->flags & MMC_RSP_CRC) { 198 } else if (status & MCI_CMDCRCFAIL && cmd->flags & MMC_RSP_CRC) {
198 cmd->error = MMC_ERR_BADCRC; 199 cmd->error = -EILSEQ;
199 } 200 }
200 201
201 if (!cmd->data || cmd->error != MMC_ERR_NONE) { 202 if (!cmd->data || cmd->error) {
202 if (host->data) 203 if (host->data)
203 mmci_stop_data(host); 204 mmci_stop_data(host);
204 mmci_request_end(host, cmd->mrq); 205 mmci_request_end(host, cmd->mrq);
@@ -391,6 +392,14 @@ static void mmci_request(struct mmc_host *mmc, struct mmc_request *mrq)
391 392
392 WARN_ON(host->mrq != NULL); 393 WARN_ON(host->mrq != NULL);
393 394
395 if (mrq->data && !is_power_of_2(mrq->data->blksz)) {
396 printk(KERN_ERR "%s: Unsupported block size (%d bytes)\n",
397 mmc_hostname(mmc), mrq->data->blksz);
398 mrq->cmd->error = -EINVAL;
399 mmc_request_done(mmc, mrq);
400 return;
401 }
402
394 spin_lock_irq(&host->lock); 403 spin_lock_irq(&host->lock);
395 404
396 host->mrq = mrq; 405 host->mrq = mrq;
diff --git a/drivers/mmc/host/omap.c b/drivers/mmc/host/omap.c
index 0cf97edc5f58..60a67dfcda6a 100644
--- a/drivers/mmc/host/omap.c
+++ b/drivers/mmc/host/omap.c
@@ -263,7 +263,7 @@ mmc_omap_xfer_done(struct mmc_omap_host *host, struct mmc_data *data)
263 enum dma_data_direction dma_data_dir; 263 enum dma_data_direction dma_data_dir;
264 264
265 BUG_ON(host->dma_ch < 0); 265 BUG_ON(host->dma_ch < 0);
266 if (data->error != MMC_ERR_NONE) 266 if (data->error)
267 omap_stop_dma(host->dma_ch); 267 omap_stop_dma(host->dma_ch);
268 /* Release DMA channel lazily */ 268 /* Release DMA channel lazily */
269 mod_timer(&host->dma_timer, jiffies + HZ); 269 mod_timer(&host->dma_timer, jiffies + HZ);
@@ -368,7 +368,7 @@ mmc_omap_cmd_done(struct mmc_omap_host *host, struct mmc_command *cmd)
368 } 368 }
369 } 369 }
370 370
371 if (host->data == NULL || cmd->error != MMC_ERR_NONE) { 371 if (host->data == NULL || cmd->error) {
372 host->mrq = NULL; 372 host->mrq = NULL;
373 clk_disable(host->fclk); 373 clk_disable(host->fclk);
374 mmc_request_done(host->mmc, cmd->mrq); 374 mmc_request_done(host->mmc, cmd->mrq);
@@ -475,14 +475,14 @@ static irqreturn_t mmc_omap_irq(int irq, void *dev_id)
475 if (status & OMAP_MMC_STAT_DATA_TOUT) { 475 if (status & OMAP_MMC_STAT_DATA_TOUT) {
476 dev_dbg(mmc_dev(host->mmc), "data timeout\n"); 476 dev_dbg(mmc_dev(host->mmc), "data timeout\n");
477 if (host->data) { 477 if (host->data) {
478 host->data->error |= MMC_ERR_TIMEOUT; 478 host->data->error = -ETIMEDOUT;
479 transfer_error = 1; 479 transfer_error = 1;
480 } 480 }
481 } 481 }
482 482
483 if (status & OMAP_MMC_STAT_DATA_CRC) { 483 if (status & OMAP_MMC_STAT_DATA_CRC) {
484 if (host->data) { 484 if (host->data) {
485 host->data->error |= MMC_ERR_BADCRC; 485 host->data->error = -EILSEQ;
486 dev_dbg(mmc_dev(host->mmc), 486 dev_dbg(mmc_dev(host->mmc),
487 "data CRC error, bytes left %d\n", 487 "data CRC error, bytes left %d\n",
488 host->total_bytes_left); 488 host->total_bytes_left);
@@ -504,7 +504,7 @@ static irqreturn_t mmc_omap_irq(int irq, void *dev_id)
504 dev_err(mmc_dev(host->mmc), 504 dev_err(mmc_dev(host->mmc),
505 "command timeout, CMD %d\n", 505 "command timeout, CMD %d\n",
506 host->cmd->opcode); 506 host->cmd->opcode);
507 host->cmd->error = MMC_ERR_TIMEOUT; 507 host->cmd->error = -ETIMEDOUT;
508 end_command = 1; 508 end_command = 1;
509 } 509 }
510 } 510 }
@@ -514,7 +514,7 @@ static irqreturn_t mmc_omap_irq(int irq, void *dev_id)
514 dev_err(mmc_dev(host->mmc), 514 dev_err(mmc_dev(host->mmc),
515 "command CRC error (CMD%d, arg 0x%08x)\n", 515 "command CRC error (CMD%d, arg 0x%08x)\n",
516 host->cmd->opcode, host->cmd->arg); 516 host->cmd->opcode, host->cmd->arg);
517 host->cmd->error = MMC_ERR_BADCRC; 517 host->cmd->error = -EILSEQ;
518 end_command = 1; 518 end_command = 1;
519 } else 519 } else
520 dev_err(mmc_dev(host->mmc), 520 dev_err(mmc_dev(host->mmc),
diff --git a/drivers/mmc/host/pxamci.c b/drivers/mmc/host/pxamci.c
index ff960334b337..657901eecfce 100644
--- a/drivers/mmc/host/pxamci.c
+++ b/drivers/mmc/host/pxamci.c
@@ -142,6 +142,10 @@ static void pxamci_setup_data(struct pxamci_host *host, struct mmc_data *data)
142 host->dma_dir); 142 host->dma_dir);
143 143
144 for (i = 0; i < host->dma_len; i++) { 144 for (i = 0; i < host->dma_len; i++) {
145 unsigned int length = sg_dma_len(&data->sg[i]);
146 host->sg_cpu[i].dcmd = dcmd | length;
147 if (length & 31 && !(data->flags & MMC_DATA_READ))
148 host->sg_cpu[i].dcmd |= DCMD_ENDIRQEN;
145 if (data->flags & MMC_DATA_READ) { 149 if (data->flags & MMC_DATA_READ) {
146 host->sg_cpu[i].dsadr = host->res->start + MMC_RXFIFO; 150 host->sg_cpu[i].dsadr = host->res->start + MMC_RXFIFO;
147 host->sg_cpu[i].dtadr = sg_dma_address(&data->sg[i]); 151 host->sg_cpu[i].dtadr = sg_dma_address(&data->sg[i]);
@@ -149,7 +153,6 @@ static void pxamci_setup_data(struct pxamci_host *host, struct mmc_data *data)
149 host->sg_cpu[i].dsadr = sg_dma_address(&data->sg[i]); 153 host->sg_cpu[i].dsadr = sg_dma_address(&data->sg[i]);
150 host->sg_cpu[i].dtadr = host->res->start + MMC_TXFIFO; 154 host->sg_cpu[i].dtadr = host->res->start + MMC_TXFIFO;
151 } 155 }
152 host->sg_cpu[i].dcmd = dcmd | sg_dma_len(&data->sg[i]);
153 host->sg_cpu[i].ddadr = host->sg_dma + (i + 1) * 156 host->sg_cpu[i].ddadr = host->sg_dma + (i + 1) *
154 sizeof(struct pxa_dma_desc); 157 sizeof(struct pxa_dma_desc);
155 } 158 }
@@ -226,7 +229,7 @@ static int pxamci_cmd_done(struct pxamci_host *host, unsigned int stat)
226 } 229 }
227 230
228 if (stat & STAT_TIME_OUT_RESPONSE) { 231 if (stat & STAT_TIME_OUT_RESPONSE) {
229 cmd->error = MMC_ERR_TIMEOUT; 232 cmd->error = -ETIMEDOUT;
230 } else if (stat & STAT_RES_CRC_ERR && cmd->flags & MMC_RSP_CRC) { 233 } else if (stat & STAT_RES_CRC_ERR && cmd->flags & MMC_RSP_CRC) {
231#ifdef CONFIG_PXA27x 234#ifdef CONFIG_PXA27x
232 /* 235 /*
@@ -239,11 +242,11 @@ static int pxamci_cmd_done(struct pxamci_host *host, unsigned int stat)
239 pr_debug("ignoring CRC from command %d - *risky*\n", cmd->opcode); 242 pr_debug("ignoring CRC from command %d - *risky*\n", cmd->opcode);
240 } else 243 } else
241#endif 244#endif
242 cmd->error = MMC_ERR_BADCRC; 245 cmd->error = -EILSEQ;
243 } 246 }
244 247
245 pxamci_disable_irq(host, END_CMD_RES); 248 pxamci_disable_irq(host, END_CMD_RES);
246 if (host->data && cmd->error == MMC_ERR_NONE) { 249 if (host->data && !cmd->error) {
247 pxamci_enable_irq(host, DATA_TRAN_DONE); 250 pxamci_enable_irq(host, DATA_TRAN_DONE);
248 } else { 251 } else {
249 pxamci_finish_request(host, host->mrq); 252 pxamci_finish_request(host, host->mrq);
@@ -264,9 +267,9 @@ static int pxamci_data_done(struct pxamci_host *host, unsigned int stat)
264 host->dma_dir); 267 host->dma_dir);
265 268
266 if (stat & STAT_READ_TIME_OUT) 269 if (stat & STAT_READ_TIME_OUT)
267 data->error = MMC_ERR_TIMEOUT; 270 data->error = -ETIMEDOUT;
268 else if (stat & (STAT_CRC_READ_ERROR|STAT_CRC_WRITE_ERROR)) 271 else if (stat & (STAT_CRC_READ_ERROR|STAT_CRC_WRITE_ERROR))
269 data->error = MMC_ERR_BADCRC; 272 data->error = -EILSEQ;
270 273
271 /* 274 /*
272 * There appears to be a hardware design bug here. There seems to 275 * There appears to be a hardware design bug here. There seems to
@@ -274,7 +277,7 @@ static int pxamci_data_done(struct pxamci_host *host, unsigned int stat)
274 * This means that if there was an error on any block, we mark all 277 * This means that if there was an error on any block, we mark all
275 * data blocks as being in error. 278 * data blocks as being in error.
276 */ 279 */
277 if (data->error == MMC_ERR_NONE) 280 if (!data->error)
278 data->bytes_xfered = data->blocks * data->blksz; 281 data->bytes_xfered = data->blocks * data->blksz;
279 else 282 else
280 data->bytes_xfered = 0; 283 data->bytes_xfered = 0;
@@ -284,7 +287,7 @@ static int pxamci_data_done(struct pxamci_host *host, unsigned int stat)
284 host->data = NULL; 287 host->data = NULL;
285 if (host->mrq->stop) { 288 if (host->mrq->stop) {
286 pxamci_stop_clock(host); 289 pxamci_stop_clock(host);
287 pxamci_start_cmd(host, host->mrq->stop, 0); 290 pxamci_start_cmd(host, host->mrq->stop, host->cmdat);
288 } else { 291 } else {
289 pxamci_finish_request(host, host->mrq); 292 pxamci_finish_request(host, host->mrq);
290 } 293 }
@@ -298,7 +301,7 @@ static irqreturn_t pxamci_irq(int irq, void *devid)
298 unsigned int ireg; 301 unsigned int ireg;
299 int handled = 0; 302 int handled = 0;
300 303
301 ireg = readl(host->base + MMC_I_REG); 304 ireg = readl(host->base + MMC_I_REG) & ~readl(host->base + MMC_I_MASK);
302 305
303 if (ireg) { 306 if (ireg) {
304 unsigned stat = readl(host->base + MMC_STAT); 307 unsigned stat = readl(host->base + MMC_STAT);
@@ -309,6 +312,10 @@ static irqreturn_t pxamci_irq(int irq, void *devid)
309 handled |= pxamci_cmd_done(host, stat); 312 handled |= pxamci_cmd_done(host, stat);
310 if (ireg & DATA_TRAN_DONE) 313 if (ireg & DATA_TRAN_DONE)
311 handled |= pxamci_data_done(host, stat); 314 handled |= pxamci_data_done(host, stat);
315 if (ireg & SDIO_INT) {
316 mmc_signal_sdio_irq(host->mmc);
317 handled = 1;
318 }
312 } 319 }
313 320
314 return IRQ_RETVAL(handled); 321 return IRQ_RETVAL(handled);
@@ -382,20 +389,46 @@ static void pxamci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
382 host->cmdat |= CMDAT_INIT; 389 host->cmdat |= CMDAT_INIT;
383 } 390 }
384 391
392 if (ios->bus_width == MMC_BUS_WIDTH_4)
393 host->cmdat |= CMDAT_SD_4DAT;
394 else
395 host->cmdat &= ~CMDAT_SD_4DAT;
396
385 pr_debug("PXAMCI: clkrt = %x cmdat = %x\n", 397 pr_debug("PXAMCI: clkrt = %x cmdat = %x\n",
386 host->clkrt, host->cmdat); 398 host->clkrt, host->cmdat);
387} 399}
388 400
401static void pxamci_enable_sdio_irq(struct mmc_host *host, int enable)
402{
403 struct pxamci_host *pxa_host = mmc_priv(host);
404
405 if (enable)
406 pxamci_enable_irq(pxa_host, SDIO_INT);
407 else
408 pxamci_disable_irq(pxa_host, SDIO_INT);
409}
410
389static const struct mmc_host_ops pxamci_ops = { 411static const struct mmc_host_ops pxamci_ops = {
390 .request = pxamci_request, 412 .request = pxamci_request,
391 .get_ro = pxamci_get_ro, 413 .get_ro = pxamci_get_ro,
392 .set_ios = pxamci_set_ios, 414 .set_ios = pxamci_set_ios,
415 .enable_sdio_irq = pxamci_enable_sdio_irq,
393}; 416};
394 417
395static void pxamci_dma_irq(int dma, void *devid) 418static void pxamci_dma_irq(int dma, void *devid)
396{ 419{
397 printk(KERN_ERR "DMA%d: IRQ???\n", dma); 420 struct pxamci_host *host = devid;
398 DCSR(dma) = DCSR_STARTINTR|DCSR_ENDINTR|DCSR_BUSERR; 421 int dcsr = DCSR(dma);
422 DCSR(dma) = dcsr & ~DCSR_STOPIRQEN;
423
424 if (dcsr & DCSR_ENDINTR) {
425 writel(BUF_PART_FULL, host->base + MMC_PRTBUF);
426 } else {
427 printk(KERN_ERR "%s: DMA error on channel %d (DCSR=%#x)\n",
428 mmc_hostname(host->mmc), dma, dcsr);
429 host->data->error = -EIO;
430 pxamci_data_done(host, 0);
431 }
399} 432}
400 433
401static irqreturn_t pxamci_detect_irq(int irq, void *devid) 434static irqreturn_t pxamci_detect_irq(int irq, void *devid)
@@ -444,9 +477,9 @@ static int pxamci_probe(struct platform_device *pdev)
444 mmc->max_seg_size = PAGE_SIZE; 477 mmc->max_seg_size = PAGE_SIZE;
445 478
446 /* 479 /*
447 * Block length register is 10 bits. 480 * Block length register is only 10 bits before PXA27x.
448 */ 481 */
449 mmc->max_blk_size = 1023; 482 mmc->max_blk_size = (cpu_is_pxa21x() || cpu_is_pxa25x()) ? 1023 : 2048;
450 483
451 /* 484 /*
452 * Block count register is 16 bits. 485 * Block count register is 16 bits.
@@ -460,6 +493,12 @@ static int pxamci_probe(struct platform_device *pdev)
460 mmc->ocr_avail = host->pdata ? 493 mmc->ocr_avail = host->pdata ?
461 host->pdata->ocr_mask : 494 host->pdata->ocr_mask :
462 MMC_VDD_32_33|MMC_VDD_33_34; 495 MMC_VDD_32_33|MMC_VDD_33_34;
496 mmc->caps = 0;
497 host->cmdat = 0;
498 if (!cpu_is_pxa21x() && !cpu_is_pxa25x()) {
499 mmc->caps |= MMC_CAP_4_BIT_DATA | MMC_CAP_SDIO_IRQ;
500 host->cmdat |= CMDAT_SDIO_INT_EN;
501 }
463 502
464 host->sg_cpu = dma_alloc_coherent(&pdev->dev, PAGE_SIZE, &host->sg_dma, GFP_KERNEL); 503 host->sg_cpu = dma_alloc_coherent(&pdev->dev, PAGE_SIZE, &host->sg_dma, GFP_KERNEL);
465 if (!host->sg_cpu) { 504 if (!host->sg_cpu) {
diff --git a/drivers/mmc/host/pxamci.h b/drivers/mmc/host/pxamci.h
index df17c281278a..3153e779d46a 100644
--- a/drivers/mmc/host/pxamci.h
+++ b/drivers/mmc/host/pxamci.h
@@ -25,6 +25,8 @@
25#define SPI_EN (1 << 0) 25#define SPI_EN (1 << 0)
26 26
27#define MMC_CMDAT 0x0010 27#define MMC_CMDAT 0x0010
28#define CMDAT_SDIO_INT_EN (1 << 11)
29#define CMDAT_SD_4DAT (1 << 8)
28#define CMDAT_DMAEN (1 << 7) 30#define CMDAT_DMAEN (1 << 7)
29#define CMDAT_INIT (1 << 6) 31#define CMDAT_INIT (1 << 6)
30#define CMDAT_BUSY (1 << 5) 32#define CMDAT_BUSY (1 << 5)
diff --git a/drivers/mmc/host/ricoh_mmc.c b/drivers/mmc/host/ricoh_mmc.c
new file mode 100644
index 000000000000..1e8704533bc5
--- /dev/null
+++ b/drivers/mmc/host/ricoh_mmc.c
@@ -0,0 +1,151 @@
1/*
2 * ricoh_mmc.c - Dummy driver to disable the Rioch MMC controller.
3 *
4 * Copyright (C) 2007 Philip Langdale, All Rights Reserved.
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 (at
9 * your option) any later version.
10 */
11
12/*
13 * This is a conceptually ridiculous driver, but it is required by the way
14 * the Ricoh multi-function R5C832 works. This chip implements firewire
15 * and four different memory card controllers. Two of those controllers are
16 * an SDHCI controller and a proprietary MMC controller. The linux SDHCI
17 * driver supports MMC cards but the chip detects MMC cards in hardware
18 * and directs them to the MMC controller - so the SDHCI driver never sees
19 * them. To get around this, we must disable the useless MMC controller.
20 * At that point, the SDHCI controller will start seeing them. As a bonus,
21 * a detection event occurs immediately, even if the MMC card is already
22 * in the reader.
23 *
24 * The relevant registers live on the firewire function, so this is unavoidably
25 * ugly. Such is life.
26 */
27
28#include <linux/pci.h>
29
30#define DRIVER_NAME "ricoh-mmc"
31
32static const struct pci_device_id pci_ids[] __devinitdata = {
33 {
34 .vendor = PCI_VENDOR_ID_RICOH,
35 .device = PCI_DEVICE_ID_RICOH_R5C843,
36 .subvendor = PCI_ANY_ID,
37 .subdevice = PCI_ANY_ID,
38 },
39 { /* end: all zeroes */ },
40};
41
42MODULE_DEVICE_TABLE(pci, pci_ids);
43
44static int __devinit ricoh_mmc_probe(struct pci_dev *pdev,
45 const struct pci_device_id *ent)
46{
47 u8 rev;
48
49 struct pci_dev *fw_dev = NULL;
50
51 BUG_ON(pdev == NULL);
52 BUG_ON(ent == NULL);
53
54 pci_read_config_byte(pdev, PCI_CLASS_REVISION, &rev);
55
56 printk(KERN_INFO DRIVER_NAME
57 ": Ricoh MMC controller found at %s [%04x:%04x] (rev %x)\n",
58 pci_name(pdev), (int)pdev->vendor, (int)pdev->device,
59 (int)rev);
60
61 while ((fw_dev = pci_get_device(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_R5C832, fw_dev))) {
62 if (PCI_SLOT(pdev->devfn) == PCI_SLOT(fw_dev->devfn) &&
63 pdev->bus == fw_dev->bus) {
64 u8 write_enable;
65 u8 disable;
66
67 pci_read_config_byte(fw_dev, 0xCB, &disable);
68 if (disable & 0x02) {
69 printk(KERN_INFO DRIVER_NAME
70 ": Controller already disabled. Nothing to do.\n");
71 return -ENODEV;
72 }
73
74 pci_read_config_byte(fw_dev, 0xCA, &write_enable);
75 pci_write_config_byte(fw_dev, 0xCA, 0x57);
76 pci_write_config_byte(fw_dev, 0xCB, disable | 0x02);
77 pci_write_config_byte(fw_dev, 0xCA, write_enable);
78
79 pci_set_drvdata(pdev, fw_dev);
80
81 printk(KERN_INFO DRIVER_NAME
82 ": Controller is now disabled.\n");
83
84 break;
85 }
86 }
87
88 if (pci_get_drvdata(pdev) == NULL) {
89 printk(KERN_WARNING DRIVER_NAME
90 ": Main firewire function not found. Cannot disable controller.\n");
91 return -ENODEV;
92 }
93
94 return 0;
95}
96
97static void __devexit ricoh_mmc_remove(struct pci_dev *pdev)
98{
99 u8 write_enable;
100 u8 disable;
101 struct pci_dev *fw_dev = NULL;
102
103 fw_dev = pci_get_drvdata(pdev);
104 BUG_ON(fw_dev == NULL);
105
106 pci_read_config_byte(fw_dev, 0xCA, &write_enable);
107 pci_read_config_byte(fw_dev, 0xCB, &disable);
108 pci_write_config_byte(fw_dev, 0xCA, 0x57);
109 pci_write_config_byte(fw_dev, 0xCB, disable & ~0x02);
110 pci_write_config_byte(fw_dev, 0xCA, write_enable);
111
112 printk(KERN_INFO DRIVER_NAME
113 ": Controller is now re-enabled.\n");
114
115 pci_set_drvdata(pdev, NULL);
116}
117
118static struct pci_driver ricoh_mmc_driver = {
119 .name = DRIVER_NAME,
120 .id_table = pci_ids,
121 .probe = ricoh_mmc_probe,
122 .remove = __devexit_p(ricoh_mmc_remove),
123};
124
125/*****************************************************************************\
126 * *
127 * Driver init/exit *
128 * *
129\*****************************************************************************/
130
131static int __init ricoh_mmc_drv_init(void)
132{
133 printk(KERN_INFO DRIVER_NAME
134 ": Ricoh MMC Controller disabling driver\n");
135 printk(KERN_INFO DRIVER_NAME ": Copyright(c) Philip Langdale\n");
136
137 return pci_register_driver(&ricoh_mmc_driver);
138}
139
140static void __exit ricoh_mmc_drv_exit(void)
141{
142 pci_unregister_driver(&ricoh_mmc_driver);
143}
144
145module_init(ricoh_mmc_drv_init);
146module_exit(ricoh_mmc_drv_exit);
147
148MODULE_AUTHOR("Philip Langdale <philipl@alumni.utexas.net>");
149MODULE_DESCRIPTION("Ricoh MMC Controller disabling driver");
150MODULE_LICENSE("GPL");
151
diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index 20a7d89e01ba..b397121b947d 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -25,8 +25,6 @@
25#define DBG(f, x...) \ 25#define DBG(f, x...) \
26 pr_debug(DRIVER_NAME " [%s()]: " f, __func__,## x) 26 pr_debug(DRIVER_NAME " [%s()]: " f, __func__,## x)
27 27
28static unsigned int debug_nodma = 0;
29static unsigned int debug_forcedma = 0;
30static unsigned int debug_quirks = 0; 28static unsigned int debug_quirks = 0;
31 29
32#define SDHCI_QUIRK_CLOCK_BEFORE_RESET (1<<0) 30#define SDHCI_QUIRK_CLOCK_BEFORE_RESET (1<<0)
@@ -35,6 +33,7 @@ static unsigned int debug_quirks = 0;
35#define SDHCI_QUIRK_NO_CARD_NO_RESET (1<<2) 33#define SDHCI_QUIRK_NO_CARD_NO_RESET (1<<2)
36#define SDHCI_QUIRK_SINGLE_POWER_WRITE (1<<3) 34#define SDHCI_QUIRK_SINGLE_POWER_WRITE (1<<3)
37#define SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS (1<<4) 35#define SDHCI_QUIRK_RESET_CMD_DATA_ON_IOS (1<<4)
36#define SDHCI_QUIRK_BROKEN_DMA (1<<5)
38 37
39static const struct pci_device_id pci_ids[] __devinitdata = { 38static const struct pci_device_id pci_ids[] __devinitdata = {
40 { 39 {
@@ -68,7 +67,8 @@ static const struct pci_device_id pci_ids[] __devinitdata = {
68 .device = PCI_DEVICE_ID_ENE_CB712_SD, 67 .device = PCI_DEVICE_ID_ENE_CB712_SD,
69 .subvendor = PCI_ANY_ID, 68 .subvendor = PCI_ANY_ID,
70 .subdevice = PCI_ANY_ID, 69 .subdevice = PCI_ANY_ID,
71 .driver_data = SDHCI_QUIRK_SINGLE_POWER_WRITE, 70 .driver_data = SDHCI_QUIRK_SINGLE_POWER_WRITE |
71 SDHCI_QUIRK_BROKEN_DMA,
72 }, 72 },
73 73
74 { 74 {
@@ -76,7 +76,8 @@ static const struct pci_device_id pci_ids[] __devinitdata = {
76 .device = PCI_DEVICE_ID_ENE_CB712_SD_2, 76 .device = PCI_DEVICE_ID_ENE_CB712_SD_2,
77 .subvendor = PCI_ANY_ID, 77 .subvendor = PCI_ANY_ID,
78 .subdevice = PCI_ANY_ID, 78 .subdevice = PCI_ANY_ID,
79 .driver_data = SDHCI_QUIRK_SINGLE_POWER_WRITE, 79 .driver_data = SDHCI_QUIRK_SINGLE_POWER_WRITE |
80 SDHCI_QUIRK_BROKEN_DMA,
80 }, 81 },
81 82
82 { 83 {
@@ -132,7 +133,7 @@ static void sdhci_dumpregs(struct sdhci_host *host)
132 readb(host->ioaddr + SDHCI_POWER_CONTROL), 133 readb(host->ioaddr + SDHCI_POWER_CONTROL),
133 readb(host->ioaddr + SDHCI_BLOCK_GAP_CONTROL)); 134 readb(host->ioaddr + SDHCI_BLOCK_GAP_CONTROL));
134 printk(KERN_DEBUG DRIVER_NAME ": Wake-up: 0x%08x | Clock: 0x%08x\n", 135 printk(KERN_DEBUG DRIVER_NAME ": Wake-up: 0x%08x | Clock: 0x%08x\n",
135 readb(host->ioaddr + SDHCI_WALK_UP_CONTROL), 136 readb(host->ioaddr + SDHCI_WAKE_UP_CONTROL),
136 readw(host->ioaddr + SDHCI_CLOCK_CONTROL)); 137 readw(host->ioaddr + SDHCI_CLOCK_CONTROL));
137 printk(KERN_DEBUG DRIVER_NAME ": Timeout: 0x%08x | Int stat: 0x%08x\n", 138 printk(KERN_DEBUG DRIVER_NAME ": Timeout: 0x%08x | Int stat: 0x%08x\n",
138 readb(host->ioaddr + SDHCI_TIMEOUT_CONTROL), 139 readb(host->ioaddr + SDHCI_TIMEOUT_CONTROL),
@@ -481,16 +482,16 @@ static void sdhci_finish_data(struct sdhci_host *host)
481 * Controller doesn't count down when in single block mode. 482 * Controller doesn't count down when in single block mode.
482 */ 483 */
483 if (data->blocks == 1) 484 if (data->blocks == 1)
484 blocks = (data->error == MMC_ERR_NONE) ? 0 : 1; 485 blocks = (data->error == 0) ? 0 : 1;
485 else 486 else
486 blocks = readw(host->ioaddr + SDHCI_BLOCK_COUNT); 487 blocks = readw(host->ioaddr + SDHCI_BLOCK_COUNT);
487 data->bytes_xfered = data->blksz * (data->blocks - blocks); 488 data->bytes_xfered = data->blksz * (data->blocks - blocks);
488 489
489 if ((data->error == MMC_ERR_NONE) && blocks) { 490 if (!data->error && blocks) {
490 printk(KERN_ERR "%s: Controller signalled completion even " 491 printk(KERN_ERR "%s: Controller signalled completion even "
491 "though there were blocks left.\n", 492 "though there were blocks left.\n",
492 mmc_hostname(host->mmc)); 493 mmc_hostname(host->mmc));
493 data->error = MMC_ERR_FAILED; 494 data->error = -EIO;
494 } 495 }
495 496
496 if (data->stop) { 497 if (data->stop) {
@@ -498,7 +499,7 @@ static void sdhci_finish_data(struct sdhci_host *host)
498 * The controller needs a reset of internal state machines 499 * The controller needs a reset of internal state machines
499 * upon error conditions. 500 * upon error conditions.
500 */ 501 */
501 if (data->error != MMC_ERR_NONE) { 502 if (data->error) {
502 sdhci_reset(host, SDHCI_RESET_CMD); 503 sdhci_reset(host, SDHCI_RESET_CMD);
503 sdhci_reset(host, SDHCI_RESET_DATA); 504 sdhci_reset(host, SDHCI_RESET_DATA);
504 } 505 }
@@ -533,7 +534,7 @@ static void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)
533 printk(KERN_ERR "%s: Controller never released " 534 printk(KERN_ERR "%s: Controller never released "
534 "inhibit bit(s).\n", mmc_hostname(host->mmc)); 535 "inhibit bit(s).\n", mmc_hostname(host->mmc));
535 sdhci_dumpregs(host); 536 sdhci_dumpregs(host);
536 cmd->error = MMC_ERR_FAILED; 537 cmd->error = -EIO;
537 tasklet_schedule(&host->finish_tasklet); 538 tasklet_schedule(&host->finish_tasklet);
538 return; 539 return;
539 } 540 }
@@ -554,7 +555,7 @@ static void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)
554 if ((cmd->flags & MMC_RSP_136) && (cmd->flags & MMC_RSP_BUSY)) { 555 if ((cmd->flags & MMC_RSP_136) && (cmd->flags & MMC_RSP_BUSY)) {
555 printk(KERN_ERR "%s: Unsupported response type!\n", 556 printk(KERN_ERR "%s: Unsupported response type!\n",
556 mmc_hostname(host->mmc)); 557 mmc_hostname(host->mmc));
557 cmd->error = MMC_ERR_INVALID; 558 cmd->error = -EINVAL;
558 tasklet_schedule(&host->finish_tasklet); 559 tasklet_schedule(&host->finish_tasklet);
559 return; 560 return;
560 } 561 }
@@ -601,7 +602,7 @@ static void sdhci_finish_command(struct sdhci_host *host)
601 } 602 }
602 } 603 }
603 604
604 host->cmd->error = MMC_ERR_NONE; 605 host->cmd->error = 0;
605 606
606 if (host->data && host->data_early) 607 if (host->data && host->data_early)
607 sdhci_finish_data(host); 608 sdhci_finish_data(host);
@@ -722,7 +723,7 @@ static void sdhci_request(struct mmc_host *mmc, struct mmc_request *mrq)
722 host->mrq = mrq; 723 host->mrq = mrq;
723 724
724 if (!(readl(host->ioaddr + SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT)) { 725 if (!(readl(host->ioaddr + SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT)) {
725 host->mrq->cmd->error = MMC_ERR_TIMEOUT; 726 host->mrq->cmd->error = -ENOMEDIUM;
726 tasklet_schedule(&host->finish_tasklet); 727 tasklet_schedule(&host->finish_tasklet);
727 } else 728 } else
728 sdhci_send_command(host, mrq->cmd); 729 sdhci_send_command(host, mrq->cmd);
@@ -800,10 +801,35 @@ static int sdhci_get_ro(struct mmc_host *mmc)
800 return !(present & SDHCI_WRITE_PROTECT); 801 return !(present & SDHCI_WRITE_PROTECT);
801} 802}
802 803
804static void sdhci_enable_sdio_irq(struct mmc_host *mmc, int enable)
805{
806 struct sdhci_host *host;
807 unsigned long flags;
808 u32 ier;
809
810 host = mmc_priv(mmc);
811
812 spin_lock_irqsave(&host->lock, flags);
813
814 ier = readl(host->ioaddr + SDHCI_INT_ENABLE);
815
816 ier &= ~SDHCI_INT_CARD_INT;
817 if (enable)
818 ier |= SDHCI_INT_CARD_INT;
819
820 writel(ier, host->ioaddr + SDHCI_INT_ENABLE);
821 writel(ier, host->ioaddr + SDHCI_SIGNAL_ENABLE);
822
823 mmiowb();
824
825 spin_unlock_irqrestore(&host->lock, flags);
826}
827
803static const struct mmc_host_ops sdhci_ops = { 828static const struct mmc_host_ops sdhci_ops = {
804 .request = sdhci_request, 829 .request = sdhci_request,
805 .set_ios = sdhci_set_ios, 830 .set_ios = sdhci_set_ios,
806 .get_ro = sdhci_get_ro, 831 .get_ro = sdhci_get_ro,
832 .enable_sdio_irq = sdhci_enable_sdio_irq,
807}; 833};
808 834
809/*****************************************************************************\ 835/*****************************************************************************\
@@ -831,7 +857,7 @@ static void sdhci_tasklet_card(unsigned long param)
831 sdhci_reset(host, SDHCI_RESET_CMD); 857 sdhci_reset(host, SDHCI_RESET_CMD);
832 sdhci_reset(host, SDHCI_RESET_DATA); 858 sdhci_reset(host, SDHCI_RESET_DATA);
833 859
834 host->mrq->cmd->error = MMC_ERR_FAILED; 860 host->mrq->cmd->error = -ENOMEDIUM;
835 tasklet_schedule(&host->finish_tasklet); 861 tasklet_schedule(&host->finish_tasklet);
836 } 862 }
837 } 863 }
@@ -859,9 +885,9 @@ static void sdhci_tasklet_finish(unsigned long param)
859 * The controller needs a reset of internal state machines 885 * The controller needs a reset of internal state machines
860 * upon error conditions. 886 * upon error conditions.
861 */ 887 */
862 if ((mrq->cmd->error != MMC_ERR_NONE) || 888 if (mrq->cmd->error ||
863 (mrq->data && ((mrq->data->error != MMC_ERR_NONE) || 889 (mrq->data && (mrq->data->error ||
864 (mrq->data->stop && (mrq->data->stop->error != MMC_ERR_NONE))))) { 890 (mrq->data->stop && mrq->data->stop->error)))) {
865 891
866 /* Some controllers need this kick or reset won't work here */ 892 /* Some controllers need this kick or reset won't work here */
867 if (host->chip->quirks & SDHCI_QUIRK_CLOCK_BEFORE_RESET) { 893 if (host->chip->quirks & SDHCI_QUIRK_CLOCK_BEFORE_RESET) {
@@ -906,13 +932,13 @@ static void sdhci_timeout_timer(unsigned long data)
906 sdhci_dumpregs(host); 932 sdhci_dumpregs(host);
907 933
908 if (host->data) { 934 if (host->data) {
909 host->data->error = MMC_ERR_TIMEOUT; 935 host->data->error = -ETIMEDOUT;
910 sdhci_finish_data(host); 936 sdhci_finish_data(host);
911 } else { 937 } else {
912 if (host->cmd) 938 if (host->cmd)
913 host->cmd->error = MMC_ERR_TIMEOUT; 939 host->cmd->error = -ETIMEDOUT;
914 else 940 else
915 host->mrq->cmd->error = MMC_ERR_TIMEOUT; 941 host->mrq->cmd->error = -ETIMEDOUT;
916 942
917 tasklet_schedule(&host->finish_tasklet); 943 tasklet_schedule(&host->finish_tasklet);
918 } 944 }
@@ -941,13 +967,12 @@ static void sdhci_cmd_irq(struct sdhci_host *host, u32 intmask)
941 } 967 }
942 968
943 if (intmask & SDHCI_INT_TIMEOUT) 969 if (intmask & SDHCI_INT_TIMEOUT)
944 host->cmd->error = MMC_ERR_TIMEOUT; 970 host->cmd->error = -ETIMEDOUT;
945 else if (intmask & SDHCI_INT_CRC) 971 else if (intmask & (SDHCI_INT_CRC | SDHCI_INT_END_BIT |
946 host->cmd->error = MMC_ERR_BADCRC; 972 SDHCI_INT_INDEX))
947 else if (intmask & (SDHCI_INT_END_BIT | SDHCI_INT_INDEX)) 973 host->cmd->error = -EILSEQ;
948 host->cmd->error = MMC_ERR_FAILED;
949 974
950 if (host->cmd->error != MMC_ERR_NONE) 975 if (host->cmd->error)
951 tasklet_schedule(&host->finish_tasklet); 976 tasklet_schedule(&host->finish_tasklet);
952 else if (intmask & SDHCI_INT_RESPONSE) 977 else if (intmask & SDHCI_INT_RESPONSE)
953 sdhci_finish_command(host); 978 sdhci_finish_command(host);
@@ -974,13 +999,11 @@ static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)
974 } 999 }
975 1000
976 if (intmask & SDHCI_INT_DATA_TIMEOUT) 1001 if (intmask & SDHCI_INT_DATA_TIMEOUT)
977 host->data->error = MMC_ERR_TIMEOUT; 1002 host->data->error = -ETIMEDOUT;
978 else if (intmask & SDHCI_INT_DATA_CRC) 1003 else if (intmask & (SDHCI_INT_DATA_CRC | SDHCI_INT_DATA_END_BIT))
979 host->data->error = MMC_ERR_BADCRC; 1004 host->data->error = -EILSEQ;
980 else if (intmask & SDHCI_INT_DATA_END_BIT)
981 host->data->error = MMC_ERR_FAILED;
982 1005
983 if (host->data->error != MMC_ERR_NONE) 1006 if (host->data->error)
984 sdhci_finish_data(host); 1007 sdhci_finish_data(host);
985 else { 1008 else {
986 if (intmask & (SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL)) 1009 if (intmask & (SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL))
@@ -1015,6 +1038,7 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id)
1015 irqreturn_t result; 1038 irqreturn_t result;
1016 struct sdhci_host* host = dev_id; 1039 struct sdhci_host* host = dev_id;
1017 u32 intmask; 1040 u32 intmask;
1041 int cardint = 0;
1018 1042
1019 spin_lock(&host->lock); 1043 spin_lock(&host->lock);
1020 1044
@@ -1059,6 +1083,11 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id)
1059 1083
1060 intmask &= ~SDHCI_INT_BUS_POWER; 1084 intmask &= ~SDHCI_INT_BUS_POWER;
1061 1085
1086 if (intmask & SDHCI_INT_CARD_INT)
1087 cardint = 1;
1088
1089 intmask &= ~SDHCI_INT_CARD_INT;
1090
1062 if (intmask) { 1091 if (intmask) {
1063 printk(KERN_ERR "%s: Unexpected interrupt 0x%08x.\n", 1092 printk(KERN_ERR "%s: Unexpected interrupt 0x%08x.\n",
1064 mmc_hostname(host->mmc), intmask); 1093 mmc_hostname(host->mmc), intmask);
@@ -1073,6 +1102,12 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id)
1073out: 1102out:
1074 spin_unlock(&host->lock); 1103 spin_unlock(&host->lock);
1075 1104
1105 /*
1106 * We have to delay this as it calls back into the driver.
1107 */
1108 if (cardint)
1109 mmc_signal_sdio_irq(host->mmc);
1110
1076 return result; 1111 return result;
1077} 1112}
1078 1113
@@ -1258,20 +1293,26 @@ static int __devinit sdhci_probe_slot(struct pci_dev *pdev, int slot)
1258 1293
1259 caps = readl(host->ioaddr + SDHCI_CAPABILITIES); 1294 caps = readl(host->ioaddr + SDHCI_CAPABILITIES);
1260 1295
1261 if (debug_nodma) 1296 if (chip->quirks & SDHCI_QUIRK_FORCE_DMA)
1262 DBG("DMA forced off\n");
1263 else if (debug_forcedma) {
1264 DBG("DMA forced on\n");
1265 host->flags |= SDHCI_USE_DMA;
1266 } else if (chip->quirks & SDHCI_QUIRK_FORCE_DMA)
1267 host->flags |= SDHCI_USE_DMA; 1297 host->flags |= SDHCI_USE_DMA;
1268 else if ((pdev->class & 0x0000FF) != PCI_SDHCI_IFDMA)
1269 DBG("Controller doesn't have DMA interface\n");
1270 else if (!(caps & SDHCI_CAN_DO_DMA)) 1298 else if (!(caps & SDHCI_CAN_DO_DMA))
1271 DBG("Controller doesn't have DMA capability\n"); 1299 DBG("Controller doesn't have DMA capability\n");
1272 else 1300 else
1273 host->flags |= SDHCI_USE_DMA; 1301 host->flags |= SDHCI_USE_DMA;
1274 1302
1303 if ((chip->quirks & SDHCI_QUIRK_BROKEN_DMA) &&
1304 (host->flags & SDHCI_USE_DMA)) {
1305 DBG("Disabling DMA as it is marked broken");
1306 host->flags &= ~SDHCI_USE_DMA;
1307 }
1308
1309 if (((pdev->class & 0x0000FF) != PCI_SDHCI_IFDMA) &&
1310 (host->flags & SDHCI_USE_DMA)) {
1311 printk(KERN_WARNING "%s: Will use DMA "
1312 "mode even though HW doesn't fully "
1313 "claim to support it.\n", host->slot_descr);
1314 }
1315
1275 if (host->flags & SDHCI_USE_DMA) { 1316 if (host->flags & SDHCI_USE_DMA) {
1276 if (pci_set_dma_mask(pdev, DMA_32BIT_MASK)) { 1317 if (pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
1277 printk(KERN_WARNING "%s: No suitable DMA available. " 1318 printk(KERN_WARNING "%s: No suitable DMA available. "
@@ -1312,7 +1353,7 @@ static int __devinit sdhci_probe_slot(struct pci_dev *pdev, int slot)
1312 mmc->ops = &sdhci_ops; 1353 mmc->ops = &sdhci_ops;
1313 mmc->f_min = host->max_clk / 256; 1354 mmc->f_min = host->max_clk / 256;
1314 mmc->f_max = host->max_clk; 1355 mmc->f_max = host->max_clk;
1315 mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_MULTIWRITE | MMC_CAP_BYTEBLOCK; 1356 mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_MULTIWRITE | MMC_CAP_SDIO_IRQ;
1316 1357
1317 if (caps & SDHCI_CAN_DO_HISPD) 1358 if (caps & SDHCI_CAN_DO_HISPD)
1318 mmc->caps |= MMC_CAP_SD_HIGHSPEED; 1359 mmc->caps |= MMC_CAP_SD_HIGHSPEED;
@@ -1565,14 +1606,10 @@ static void __exit sdhci_drv_exit(void)
1565module_init(sdhci_drv_init); 1606module_init(sdhci_drv_init);
1566module_exit(sdhci_drv_exit); 1607module_exit(sdhci_drv_exit);
1567 1608
1568module_param(debug_nodma, uint, 0444);
1569module_param(debug_forcedma, uint, 0444);
1570module_param(debug_quirks, uint, 0444); 1609module_param(debug_quirks, uint, 0444);
1571 1610
1572MODULE_AUTHOR("Pierre Ossman <drzeus@drzeus.cx>"); 1611MODULE_AUTHOR("Pierre Ossman <drzeus@drzeus.cx>");
1573MODULE_DESCRIPTION("Secure Digital Host Controller Interface driver"); 1612MODULE_DESCRIPTION("Secure Digital Host Controller Interface driver");
1574MODULE_LICENSE("GPL"); 1613MODULE_LICENSE("GPL");
1575 1614
1576MODULE_PARM_DESC(debug_nodma, "Forcefully disable DMA transfers. (default 0)");
1577MODULE_PARM_DESC(debug_forcedma, "Forcefully enable DMA transfers. (default 0)");
1578MODULE_PARM_DESC(debug_quirks, "Force certain quirks."); 1615MODULE_PARM_DESC(debug_quirks, "Force certain quirks.");
diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h
index e28987d6d2eb..05195ea900f4 100644
--- a/drivers/mmc/host/sdhci.h
+++ b/drivers/mmc/host/sdhci.h
@@ -81,7 +81,7 @@
81 81
82#define SDHCI_BLOCK_GAP_CONTROL 0x2A 82#define SDHCI_BLOCK_GAP_CONTROL 0x2A
83 83
84#define SDHCI_WALK_UP_CONTROL 0x2B 84#define SDHCI_WAKE_UP_CONTROL 0x2B
85 85
86#define SDHCI_CLOCK_CONTROL 0x2C 86#define SDHCI_CLOCK_CONTROL 0x2C
87#define SDHCI_DIVIDER_SHIFT 8 87#define SDHCI_DIVIDER_SHIFT 8
diff --git a/drivers/mmc/host/tifm_sd.c b/drivers/mmc/host/tifm_sd.c
index 8b736e968447..9b904795eb77 100644
--- a/drivers/mmc/host/tifm_sd.c
+++ b/drivers/mmc/host/tifm_sd.c
@@ -16,6 +16,7 @@
16#include <linux/mmc/host.h> 16#include <linux/mmc/host.h>
17#include <linux/highmem.h> 17#include <linux/highmem.h>
18#include <linux/scatterlist.h> 18#include <linux/scatterlist.h>
19#include <linux/log2.h>
19#include <asm/io.h> 20#include <asm/io.h>
20 21
21#define DRIVER_NAME "tifm_sd" 22#define DRIVER_NAME "tifm_sd"
@@ -404,14 +405,14 @@ static void tifm_sd_check_status(struct tifm_sd *host)
404 struct tifm_dev *sock = host->dev; 405 struct tifm_dev *sock = host->dev;
405 struct mmc_command *cmd = host->req->cmd; 406 struct mmc_command *cmd = host->req->cmd;
406 407
407 if (cmd->error != MMC_ERR_NONE) 408 if (cmd->error)
408 goto finish_request; 409 goto finish_request;
409 410
410 if (!(host->cmd_flags & CMD_READY)) 411 if (!(host->cmd_flags & CMD_READY))
411 return; 412 return;
412 413
413 if (cmd->data) { 414 if (cmd->data) {
414 if (cmd->data->error != MMC_ERR_NONE) { 415 if (cmd->data->error) {
415 if ((host->cmd_flags & SCMD_ACTIVE) 416 if ((host->cmd_flags & SCMD_ACTIVE)
416 && !(host->cmd_flags & SCMD_READY)) 417 && !(host->cmd_flags & SCMD_READY))
417 return; 418 return;
@@ -504,7 +505,7 @@ static void tifm_sd_card_event(struct tifm_dev *sock)
504{ 505{
505 struct tifm_sd *host; 506 struct tifm_sd *host;
506 unsigned int host_status = 0; 507 unsigned int host_status = 0;
507 int cmd_error = MMC_ERR_NONE; 508 int cmd_error = 0;
508 struct mmc_command *cmd = NULL; 509 struct mmc_command *cmd = NULL;
509 unsigned long flags; 510 unsigned long flags;
510 511
@@ -521,15 +522,15 @@ static void tifm_sd_card_event(struct tifm_dev *sock)
521 writel(host_status & TIFM_MMCSD_ERRMASK, 522 writel(host_status & TIFM_MMCSD_ERRMASK,
522 sock->addr + SOCK_MMCSD_STATUS); 523 sock->addr + SOCK_MMCSD_STATUS);
523 if (host_status & TIFM_MMCSD_CTO) 524 if (host_status & TIFM_MMCSD_CTO)
524 cmd_error = MMC_ERR_TIMEOUT; 525 cmd_error = -ETIMEDOUT;
525 else if (host_status & TIFM_MMCSD_CCRC) 526 else if (host_status & TIFM_MMCSD_CCRC)
526 cmd_error = MMC_ERR_BADCRC; 527 cmd_error = -EILSEQ;
527 528
528 if (cmd->data) { 529 if (cmd->data) {
529 if (host_status & TIFM_MMCSD_DTO) 530 if (host_status & TIFM_MMCSD_DTO)
530 cmd->data->error = MMC_ERR_TIMEOUT; 531 cmd->data->error = -ETIMEDOUT;
531 else if (host_status & TIFM_MMCSD_DCRC) 532 else if (host_status & TIFM_MMCSD_DCRC)
532 cmd->data->error = MMC_ERR_BADCRC; 533 cmd->data->error = -EILSEQ;
533 } 534 }
534 535
535 writel(TIFM_FIFO_INT_SETALL, 536 writel(TIFM_FIFO_INT_SETALL,
@@ -626,14 +627,21 @@ static void tifm_sd_request(struct mmc_host *mmc, struct mmc_request *mrq)
626 627
627 spin_lock_irqsave(&sock->lock, flags); 628 spin_lock_irqsave(&sock->lock, flags);
628 if (host->eject) { 629 if (host->eject) {
629 spin_unlock_irqrestore(&sock->lock, flags); 630 mrq->cmd->error = -ENOMEDIUM;
630 goto err_out; 631 goto err_out;
631 } 632 }
632 633
633 if (host->req) { 634 if (host->req) {
634 printk(KERN_ERR "%s : unfinished request detected\n", 635 printk(KERN_ERR "%s : unfinished request detected\n",
635 sock->dev.bus_id); 636 sock->dev.bus_id);
636 spin_unlock_irqrestore(&sock->lock, flags); 637 mrq->cmd->error = -ETIMEDOUT;
638 goto err_out;
639 }
640
641 if (mrq->data && !is_power_of_2(mrq->data->blksz)) {
642 printk(KERN_ERR "%s: Unsupported block size (%d bytes)\n",
643 sock->dev.bus_id, mrq->data->blksz);
644 mrq->cmd->error = -EINVAL;
637 goto err_out; 645 goto err_out;
638 } 646 }
639 647
@@ -722,7 +730,7 @@ static void tifm_sd_request(struct mmc_host *mmc, struct mmc_request *mrq)
722 return; 730 return;
723 731
724err_out: 732err_out:
725 mrq->cmd->error = MMC_ERR_TIMEOUT; 733 spin_unlock_irqrestore(&sock->lock, flags);
726 mmc_request_done(mmc, mrq); 734 mmc_request_done(mmc, mrq);
727} 735}
728 736
@@ -1012,9 +1020,9 @@ static void tifm_sd_remove(struct tifm_dev *sock)
1012 writel(TIFM_FIFO_INT_SETALL, 1020 writel(TIFM_FIFO_INT_SETALL,
1013 sock->addr + SOCK_DMA_FIFO_INT_ENABLE_CLEAR); 1021 sock->addr + SOCK_DMA_FIFO_INT_ENABLE_CLEAR);
1014 writel(0, sock->addr + SOCK_DMA_FIFO_INT_ENABLE_SET); 1022 writel(0, sock->addr + SOCK_DMA_FIFO_INT_ENABLE_SET);
1015 host->req->cmd->error = MMC_ERR_TIMEOUT; 1023 host->req->cmd->error = -ENOMEDIUM;
1016 if (host->req->stop) 1024 if (host->req->stop)
1017 host->req->stop->error = MMC_ERR_TIMEOUT; 1025 host->req->stop->error = -ENOMEDIUM;
1018 tasklet_schedule(&host->finish_tasklet); 1026 tasklet_schedule(&host->finish_tasklet);
1019 } 1027 }
1020 spin_unlock_irqrestore(&sock->lock, flags); 1028 spin_unlock_irqrestore(&sock->lock, flags);
diff --git a/drivers/mmc/host/wbsd.c b/drivers/mmc/host/wbsd.c
index 9bf2a877113b..80db11c05f2a 100644
--- a/drivers/mmc/host/wbsd.c
+++ b/drivers/mmc/host/wbsd.c
@@ -317,7 +317,7 @@ static inline void wbsd_get_short_reply(struct wbsd_host *host,
317 * Correct response type? 317 * Correct response type?
318 */ 318 */
319 if (wbsd_read_index(host, WBSD_IDX_RSPLEN) != WBSD_RSP_SHORT) { 319 if (wbsd_read_index(host, WBSD_IDX_RSPLEN) != WBSD_RSP_SHORT) {
320 cmd->error = MMC_ERR_INVALID; 320 cmd->error = -EILSEQ;
321 return; 321 return;
322 } 322 }
323 323
@@ -337,7 +337,7 @@ static inline void wbsd_get_long_reply(struct wbsd_host *host,
337 * Correct response type? 337 * Correct response type?
338 */ 338 */
339 if (wbsd_read_index(host, WBSD_IDX_RSPLEN) != WBSD_RSP_LONG) { 339 if (wbsd_read_index(host, WBSD_IDX_RSPLEN) != WBSD_RSP_LONG) {
340 cmd->error = MMC_ERR_INVALID; 340 cmd->error = -EILSEQ;
341 return; 341 return;
342 } 342 }
343 343
@@ -372,7 +372,7 @@ static void wbsd_send_command(struct wbsd_host *host, struct mmc_command *cmd)
372 for (i = 3; i >= 0; i--) 372 for (i = 3; i >= 0; i--)
373 outb((cmd->arg >> (i * 8)) & 0xff, host->base + WBSD_CMDR); 373 outb((cmd->arg >> (i * 8)) & 0xff, host->base + WBSD_CMDR);
374 374
375 cmd->error = MMC_ERR_NONE; 375 cmd->error = 0;
376 376
377 /* 377 /*
378 * Wait for the request to complete. 378 * Wait for the request to complete.
@@ -392,13 +392,13 @@ static void wbsd_send_command(struct wbsd_host *host, struct mmc_command *cmd)
392 392
393 /* Card removed? */ 393 /* Card removed? */
394 if (isr & WBSD_INT_CARD) 394 if (isr & WBSD_INT_CARD)
395 cmd->error = MMC_ERR_TIMEOUT; 395 cmd->error = -ENOMEDIUM;
396 /* Timeout? */ 396 /* Timeout? */
397 else if (isr & WBSD_INT_TIMEOUT) 397 else if (isr & WBSD_INT_TIMEOUT)
398 cmd->error = MMC_ERR_TIMEOUT; 398 cmd->error = -ETIMEDOUT;
399 /* CRC? */ 399 /* CRC? */
400 else if ((cmd->flags & MMC_RSP_CRC) && (isr & WBSD_INT_CRC)) 400 else if ((cmd->flags & MMC_RSP_CRC) && (isr & WBSD_INT_CRC))
401 cmd->error = MMC_ERR_BADCRC; 401 cmd->error = -EILSEQ;
402 /* All ok */ 402 /* All ok */
403 else { 403 else {
404 if (cmd->flags & MMC_RSP_136) 404 if (cmd->flags & MMC_RSP_136)
@@ -585,7 +585,7 @@ static void wbsd_prepare_data(struct wbsd_host *host, struct mmc_data *data)
585 ((blksize >> 4) & 0xF0) | WBSD_DATA_WIDTH); 585 ((blksize >> 4) & 0xF0) | WBSD_DATA_WIDTH);
586 wbsd_write_index(host, WBSD_IDX_PBSLSB, blksize & 0xFF); 586 wbsd_write_index(host, WBSD_IDX_PBSLSB, blksize & 0xFF);
587 } else { 587 } else {
588 data->error = MMC_ERR_INVALID; 588 data->error = -EINVAL;
589 return; 589 return;
590 } 590 }
591 591
@@ -607,7 +607,7 @@ static void wbsd_prepare_data(struct wbsd_host *host, struct mmc_data *data)
607 */ 607 */
608 BUG_ON(size > 0x10000); 608 BUG_ON(size > 0x10000);
609 if (size > 0x10000) { 609 if (size > 0x10000) {
610 data->error = MMC_ERR_INVALID; 610 data->error = -EINVAL;
611 return; 611 return;
612 } 612 }
613 613
@@ -669,7 +669,7 @@ static void wbsd_prepare_data(struct wbsd_host *host, struct mmc_data *data)
669 } 669 }
670 } 670 }
671 671
672 data->error = MMC_ERR_NONE; 672 data->error = 0;
673} 673}
674 674
675static void wbsd_finish_data(struct wbsd_host *host, struct mmc_data *data) 675static void wbsd_finish_data(struct wbsd_host *host, struct mmc_data *data)
@@ -724,8 +724,8 @@ static void wbsd_finish_data(struct wbsd_host *host, struct mmc_data *data)
724 "%d bytes left.\n", 724 "%d bytes left.\n",
725 mmc_hostname(host->mmc), count); 725 mmc_hostname(host->mmc), count);
726 726
727 if (data->error == MMC_ERR_NONE) 727 if (!data->error)
728 data->error = MMC_ERR_FAILED; 728 data->error = -EIO;
729 } else { 729 } else {
730 /* 730 /*
731 * Transfer data from DMA buffer to 731 * Transfer data from DMA buffer to
@@ -735,7 +735,7 @@ static void wbsd_finish_data(struct wbsd_host *host, struct mmc_data *data)
735 wbsd_dma_to_sg(host, data); 735 wbsd_dma_to_sg(host, data);
736 } 736 }
737 737
738 if (data->error != MMC_ERR_NONE) { 738 if (data->error) {
739 if (data->bytes_xfered) 739 if (data->bytes_xfered)
740 data->bytes_xfered -= data->blksz; 740 data->bytes_xfered -= data->blksz;
741 } 741 }
@@ -767,11 +767,10 @@ static void wbsd_request(struct mmc_host *mmc, struct mmc_request *mrq)
767 host->mrq = mrq; 767 host->mrq = mrq;
768 768
769 /* 769 /*
770 * If there is no card in the slot then 770 * Check that there is actually a card in the slot.
771 * timeout immediatly.
772 */ 771 */
773 if (!(host->flags & WBSD_FCARD_PRESENT)) { 772 if (!(host->flags & WBSD_FCARD_PRESENT)) {
774 cmd->error = MMC_ERR_TIMEOUT; 773 cmd->error = -ENOMEDIUM;
775 goto done; 774 goto done;
776 } 775 }
777 776
@@ -807,7 +806,7 @@ static void wbsd_request(struct mmc_host *mmc, struct mmc_request *mrq)
807 "supported by this controller.\n", 806 "supported by this controller.\n",
808 mmc_hostname(host->mmc), cmd->opcode); 807 mmc_hostname(host->mmc), cmd->opcode);
809#endif 808#endif
810 cmd->error = MMC_ERR_INVALID; 809 cmd->error = -EINVAL;
811 810
812 goto done; 811 goto done;
813 }; 812 };
@@ -819,7 +818,7 @@ static void wbsd_request(struct mmc_host *mmc, struct mmc_request *mrq)
819 if (cmd->data) { 818 if (cmd->data) {
820 wbsd_prepare_data(host, cmd->data); 819 wbsd_prepare_data(host, cmd->data);
821 820
822 if (cmd->data->error != MMC_ERR_NONE) 821 if (cmd->data->error)
823 goto done; 822 goto done;
824 } 823 }
825 824
@@ -830,7 +829,7 @@ static void wbsd_request(struct mmc_host *mmc, struct mmc_request *mrq)
830 * will be finished after the data has 829 * will be finished after the data has
831 * transfered. 830 * transfered.
832 */ 831 */
833 if (cmd->data && (cmd->error == MMC_ERR_NONE)) { 832 if (cmd->data && !cmd->error) {
834 /* 833 /*
835 * Dirty fix for hardware bug. 834 * Dirty fix for hardware bug.
836 */ 835 */
@@ -1033,7 +1032,7 @@ static void wbsd_tasklet_card(unsigned long param)
1033 mmc_hostname(host->mmc)); 1032 mmc_hostname(host->mmc));
1034 wbsd_reset(host); 1033 wbsd_reset(host);
1035 1034
1036 host->mrq->cmd->error = MMC_ERR_FAILED; 1035 host->mrq->cmd->error = -ENOMEDIUM;
1037 tasklet_schedule(&host->finish_tasklet); 1036 tasklet_schedule(&host->finish_tasklet);
1038 } 1037 }
1039 1038
@@ -1097,7 +1096,7 @@ static void wbsd_tasklet_crc(unsigned long param)
1097 1096
1098 DBGF("CRC error\n"); 1097 DBGF("CRC error\n");
1099 1098
1100 data->error = MMC_ERR_BADCRC; 1099 data->error = -EILSEQ;
1101 1100
1102 tasklet_schedule(&host->finish_tasklet); 1101 tasklet_schedule(&host->finish_tasklet);
1103 1102
@@ -1121,7 +1120,7 @@ static void wbsd_tasklet_timeout(unsigned long param)
1121 1120
1122 DBGF("Timeout\n"); 1121 DBGF("Timeout\n");
1123 1122
1124 data->error = MMC_ERR_TIMEOUT; 1123 data->error = -ETIMEDOUT;
1125 1124
1126 tasklet_schedule(&host->finish_tasklet); 1125 tasklet_schedule(&host->finish_tasklet);
1127 1126
@@ -1220,7 +1219,7 @@ static int __devinit wbsd_alloc_mmc(struct device *dev)
1220 mmc->f_min = 375000; 1219 mmc->f_min = 375000;
1221 mmc->f_max = 24000000; 1220 mmc->f_max = 24000000;
1222 mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34; 1221 mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
1223 mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_MULTIWRITE | MMC_CAP_BYTEBLOCK; 1222 mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_MULTIWRITE;
1224 1223
1225 spin_lock_init(&host->lock); 1224 spin_lock_init(&host->lock);
1226 1225
diff --git a/drivers/pci/hotplug/cpqphp_core.c b/drivers/pci/hotplug/cpqphp_core.c
index d590a99930fa..2305cc450a45 100644
--- a/drivers/pci/hotplug/cpqphp_core.c
+++ b/drivers/pci/hotplug/cpqphp_core.c
@@ -45,7 +45,7 @@
45 45
46#include "cpqphp.h" 46#include "cpqphp.h"
47#include "cpqphp_nvram.h" 47#include "cpqphp_nvram.h"
48#include "../../../arch/i386/pci/pci.h" /* horrible hack showing how processor dependent we are... */ 48#include "../../../arch/x86/pci/pci.h" /* horrible hack showing how processor dependent we are... */
49 49
50 50
51/* Global variables */ 51/* Global variables */
diff --git a/drivers/pci/hotplug/cpqphp_pci.c b/drivers/pci/hotplug/cpqphp_pci.c
index fc7c74d72595..3f6cd20e95d2 100644
--- a/drivers/pci/hotplug/cpqphp_pci.c
+++ b/drivers/pci/hotplug/cpqphp_pci.c
@@ -37,7 +37,7 @@
37#include "../pci.h" 37#include "../pci.h"
38#include "cpqphp.h" 38#include "cpqphp.h"
39#include "cpqphp_nvram.h" 39#include "cpqphp_nvram.h"
40#include "../../../arch/i386/pci/pci.h" /* horrible hack showing how processor dependent we are... */ 40#include "../../../arch/x86/pci/pci.h" /* horrible hack showing how processor dependent we are... */
41 41
42 42
43u8 cpqhp_nic_irq; 43u8 cpqhp_nic_irq;
diff --git a/drivers/pci/hotplug/ibmphp_core.c b/drivers/pci/hotplug/ibmphp_core.c
index 0316eeaaeb29..a90c28d0c69d 100644
--- a/drivers/pci/hotplug/ibmphp_core.c
+++ b/drivers/pci/hotplug/ibmphp_core.c
@@ -35,7 +35,7 @@
35#include <linux/delay.h> 35#include <linux/delay.h>
36#include <linux/wait.h> 36#include <linux/wait.h>
37#include "../pci.h" 37#include "../pci.h"
38#include "../../../arch/i386/pci/pci.h" /* for struct irq_routing_table */ 38#include "../../../arch/x86/pci/pci.h" /* for struct irq_routing_table */
39#include "ibmphp.h" 39#include "ibmphp.h"
40 40
41#define attn_on(sl) ibmphp_hpc_writeslot (sl, HPC_SLOT_ATTNON) 41#define attn_on(sl) ibmphp_hpc_writeslot (sl, HPC_SLOT_ATTNON)
diff --git a/drivers/s390/block/dasd_diag.c b/drivers/s390/block/dasd_diag.c
index d32c60dbdd82..571320ab9e1a 100644
--- a/drivers/s390/block/dasd_diag.c
+++ b/drivers/s390/block/dasd_diag.c
@@ -472,14 +472,13 @@ dasd_diag_build_cp(struct dasd_device * device, struct request *req)
472 struct dasd_ccw_req *cqr; 472 struct dasd_ccw_req *cqr;
473 struct dasd_diag_req *dreq; 473 struct dasd_diag_req *dreq;
474 struct dasd_diag_bio *dbio; 474 struct dasd_diag_bio *dbio;
475 struct bio *bio; 475 struct req_iterator iter;
476 struct bio_vec *bv; 476 struct bio_vec *bv;
477 char *dst; 477 char *dst;
478 unsigned int count, datasize; 478 unsigned int count, datasize;
479 sector_t recid, first_rec, last_rec; 479 sector_t recid, first_rec, last_rec;
480 unsigned int blksize, off; 480 unsigned int blksize, off;
481 unsigned char rw_cmd; 481 unsigned char rw_cmd;
482 int i;
483 482
484 if (rq_data_dir(req) == READ) 483 if (rq_data_dir(req) == READ)
485 rw_cmd = MDSK_READ_REQ; 484 rw_cmd = MDSK_READ_REQ;
@@ -493,13 +492,11 @@ dasd_diag_build_cp(struct dasd_device * device, struct request *req)
493 last_rec = (req->sector + req->nr_sectors - 1) >> device->s2b_shift; 492 last_rec = (req->sector + req->nr_sectors - 1) >> device->s2b_shift;
494 /* Check struct bio and count the number of blocks for the request. */ 493 /* Check struct bio and count the number of blocks for the request. */
495 count = 0; 494 count = 0;
496 rq_for_each_bio(bio, req) { 495 rq_for_each_segment(bv, req, iter) {
497 bio_for_each_segment(bv, bio, i) { 496 if (bv->bv_len & (blksize - 1))
498 if (bv->bv_len & (blksize - 1)) 497 /* Fba can only do full blocks. */
499 /* Fba can only do full blocks. */ 498 return ERR_PTR(-EINVAL);
500 return ERR_PTR(-EINVAL); 499 count += bv->bv_len >> (device->s2b_shift + 9);
501 count += bv->bv_len >> (device->s2b_shift + 9);
502 }
503 } 500 }
504 /* Paranoia. */ 501 /* Paranoia. */
505 if (count != last_rec - first_rec + 1) 502 if (count != last_rec - first_rec + 1)
@@ -516,18 +513,16 @@ dasd_diag_build_cp(struct dasd_device * device, struct request *req)
516 dreq->block_count = count; 513 dreq->block_count = count;
517 dbio = dreq->bio; 514 dbio = dreq->bio;
518 recid = first_rec; 515 recid = first_rec;
519 rq_for_each_bio(bio, req) { 516 rq_for_each_segment(bv, req, iter) {
520 bio_for_each_segment(bv, bio, i) { 517 dst = page_address(bv->bv_page) + bv->bv_offset;
521 dst = page_address(bv->bv_page) + bv->bv_offset; 518 for (off = 0; off < bv->bv_len; off += blksize) {
522 for (off = 0; off < bv->bv_len; off += blksize) { 519 memset(dbio, 0, sizeof (struct dasd_diag_bio));
523 memset(dbio, 0, sizeof (struct dasd_diag_bio)); 520 dbio->type = rw_cmd;
524 dbio->type = rw_cmd; 521 dbio->block_number = recid + 1;
525 dbio->block_number = recid + 1; 522 dbio->buffer = dst;
526 dbio->buffer = dst; 523 dbio++;
527 dbio++; 524 dst += blksize;
528 dst += blksize; 525 recid++;
529 recid++;
530 }
531 } 526 }
532 } 527 }
533 cqr->retries = DIAG_MAX_RETRIES; 528 cqr->retries = DIAG_MAX_RETRIES;
diff --git a/drivers/s390/block/dasd_eckd.c b/drivers/s390/block/dasd_eckd.c
index ea63ba7828f9..44adf8496bda 100644
--- a/drivers/s390/block/dasd_eckd.c
+++ b/drivers/s390/block/dasd_eckd.c
@@ -1176,7 +1176,7 @@ dasd_eckd_build_cp(struct dasd_device * device, struct request *req)
1176 struct LO_eckd_data *LO_data; 1176 struct LO_eckd_data *LO_data;
1177 struct dasd_ccw_req *cqr; 1177 struct dasd_ccw_req *cqr;
1178 struct ccw1 *ccw; 1178 struct ccw1 *ccw;
1179 struct bio *bio; 1179 struct req_iterator iter;
1180 struct bio_vec *bv; 1180 struct bio_vec *bv;
1181 char *dst; 1181 char *dst;
1182 unsigned int blksize, blk_per_trk, off; 1182 unsigned int blksize, blk_per_trk, off;
@@ -1185,7 +1185,6 @@ dasd_eckd_build_cp(struct dasd_device * device, struct request *req)
1185 sector_t first_trk, last_trk; 1185 sector_t first_trk, last_trk;
1186 unsigned int first_offs, last_offs; 1186 unsigned int first_offs, last_offs;
1187 unsigned char cmd, rcmd; 1187 unsigned char cmd, rcmd;
1188 int i;
1189 1188
1190 private = (struct dasd_eckd_private *) device->private; 1189 private = (struct dasd_eckd_private *) device->private;
1191 if (rq_data_dir(req) == READ) 1190 if (rq_data_dir(req) == READ)
@@ -1206,18 +1205,15 @@ dasd_eckd_build_cp(struct dasd_device * device, struct request *req)
1206 /* Check struct bio and count the number of blocks for the request. */ 1205 /* Check struct bio and count the number of blocks for the request. */
1207 count = 0; 1206 count = 0;
1208 cidaw = 0; 1207 cidaw = 0;
1209 rq_for_each_bio(bio, req) { 1208 rq_for_each_segment(bv, req, iter) {
1210 bio_for_each_segment(bv, bio, i) { 1209 if (bv->bv_len & (blksize - 1))
1211 if (bv->bv_len & (blksize - 1)) 1210 /* Eckd can only do full blocks. */
1212 /* Eckd can only do full blocks. */ 1211 return ERR_PTR(-EINVAL);
1213 return ERR_PTR(-EINVAL); 1212 count += bv->bv_len >> (device->s2b_shift + 9);
1214 count += bv->bv_len >> (device->s2b_shift + 9);
1215#if defined(CONFIG_64BIT) 1213#if defined(CONFIG_64BIT)
1216 if (idal_is_needed (page_address(bv->bv_page), 1214 if (idal_is_needed (page_address(bv->bv_page), bv->bv_len))
1217 bv->bv_len)) 1215 cidaw += bv->bv_len >> (device->s2b_shift + 9);
1218 cidaw += bv->bv_len >> (device->s2b_shift + 9);
1219#endif 1216#endif
1220 }
1221 } 1217 }
1222 /* Paranoia. */ 1218 /* Paranoia. */
1223 if (count != last_rec - first_rec + 1) 1219 if (count != last_rec - first_rec + 1)
@@ -1257,7 +1253,7 @@ dasd_eckd_build_cp(struct dasd_device * device, struct request *req)
1257 locate_record(ccw++, LO_data++, first_trk, first_offs + 1, 1253 locate_record(ccw++, LO_data++, first_trk, first_offs + 1,
1258 last_rec - recid + 1, cmd, device, blksize); 1254 last_rec - recid + 1, cmd, device, blksize);
1259 } 1255 }
1260 rq_for_each_bio(bio, req) bio_for_each_segment(bv, bio, i) { 1256 rq_for_each_segment(bv, req, iter) {
1261 dst = page_address(bv->bv_page) + bv->bv_offset; 1257 dst = page_address(bv->bv_page) + bv->bv_offset;
1262 if (dasd_page_cache) { 1258 if (dasd_page_cache) {
1263 char *copy = kmem_cache_alloc(dasd_page_cache, 1259 char *copy = kmem_cache_alloc(dasd_page_cache,
@@ -1328,12 +1324,12 @@ dasd_eckd_free_cp(struct dasd_ccw_req *cqr, struct request *req)
1328{ 1324{
1329 struct dasd_eckd_private *private; 1325 struct dasd_eckd_private *private;
1330 struct ccw1 *ccw; 1326 struct ccw1 *ccw;
1331 struct bio *bio; 1327 struct req_iterator iter;
1332 struct bio_vec *bv; 1328 struct bio_vec *bv;
1333 char *dst, *cda; 1329 char *dst, *cda;
1334 unsigned int blksize, blk_per_trk, off; 1330 unsigned int blksize, blk_per_trk, off;
1335 sector_t recid; 1331 sector_t recid;
1336 int i, status; 1332 int status;
1337 1333
1338 if (!dasd_page_cache) 1334 if (!dasd_page_cache)
1339 goto out; 1335 goto out;
@@ -1346,7 +1342,7 @@ dasd_eckd_free_cp(struct dasd_ccw_req *cqr, struct request *req)
1346 ccw++; 1342 ccw++;
1347 if (private->uses_cdl == 0 || recid > 2*blk_per_trk) 1343 if (private->uses_cdl == 0 || recid > 2*blk_per_trk)
1348 ccw++; 1344 ccw++;
1349 rq_for_each_bio(bio, req) bio_for_each_segment(bv, bio, i) { 1345 rq_for_each_segment(bv, req, iter) {
1350 dst = page_address(bv->bv_page) + bv->bv_offset; 1346 dst = page_address(bv->bv_page) + bv->bv_offset;
1351 for (off = 0; off < bv->bv_len; off += blksize) { 1347 for (off = 0; off < bv->bv_len; off += blksize) {
1352 /* Skip locate record. */ 1348 /* Skip locate record. */
diff --git a/drivers/s390/block/dasd_fba.c b/drivers/s390/block/dasd_fba.c
index da16ead8aff2..1d95822e0b8e 100644
--- a/drivers/s390/block/dasd_fba.c
+++ b/drivers/s390/block/dasd_fba.c
@@ -234,14 +234,13 @@ dasd_fba_build_cp(struct dasd_device * device, struct request *req)
234 struct LO_fba_data *LO_data; 234 struct LO_fba_data *LO_data;
235 struct dasd_ccw_req *cqr; 235 struct dasd_ccw_req *cqr;
236 struct ccw1 *ccw; 236 struct ccw1 *ccw;
237 struct bio *bio; 237 struct req_iterator iter;
238 struct bio_vec *bv; 238 struct bio_vec *bv;
239 char *dst; 239 char *dst;
240 int count, cidaw, cplength, datasize; 240 int count, cidaw, cplength, datasize;
241 sector_t recid, first_rec, last_rec; 241 sector_t recid, first_rec, last_rec;
242 unsigned int blksize, off; 242 unsigned int blksize, off;
243 unsigned char cmd; 243 unsigned char cmd;
244 int i;
245 244
246 private = (struct dasd_fba_private *) device->private; 245 private = (struct dasd_fba_private *) device->private;
247 if (rq_data_dir(req) == READ) { 246 if (rq_data_dir(req) == READ) {
@@ -257,18 +256,15 @@ dasd_fba_build_cp(struct dasd_device * device, struct request *req)
257 /* Check struct bio and count the number of blocks for the request. */ 256 /* Check struct bio and count the number of blocks for the request. */
258 count = 0; 257 count = 0;
259 cidaw = 0; 258 cidaw = 0;
260 rq_for_each_bio(bio, req) { 259 rq_for_each_segment(bv, req, iter) {
261 bio_for_each_segment(bv, bio, i) { 260 if (bv->bv_len & (blksize - 1))
262 if (bv->bv_len & (blksize - 1)) 261 /* Fba can only do full blocks. */
263 /* Fba can only do full blocks. */ 262 return ERR_PTR(-EINVAL);
264 return ERR_PTR(-EINVAL); 263 count += bv->bv_len >> (device->s2b_shift + 9);
265 count += bv->bv_len >> (device->s2b_shift + 9);
266#if defined(CONFIG_64BIT) 264#if defined(CONFIG_64BIT)
267 if (idal_is_needed (page_address(bv->bv_page), 265 if (idal_is_needed (page_address(bv->bv_page), bv->bv_len))
268 bv->bv_len)) 266 cidaw += bv->bv_len / blksize;
269 cidaw += bv->bv_len / blksize;
270#endif 267#endif
271 }
272 } 268 }
273 /* Paranoia. */ 269 /* Paranoia. */
274 if (count != last_rec - first_rec + 1) 270 if (count != last_rec - first_rec + 1)
@@ -304,7 +300,7 @@ dasd_fba_build_cp(struct dasd_device * device, struct request *req)
304 locate_record(ccw++, LO_data++, rq_data_dir(req), 0, count); 300 locate_record(ccw++, LO_data++, rq_data_dir(req), 0, count);
305 } 301 }
306 recid = first_rec; 302 recid = first_rec;
307 rq_for_each_bio(bio, req) bio_for_each_segment(bv, bio, i) { 303 rq_for_each_segment(bv, req, iter) {
308 dst = page_address(bv->bv_page) + bv->bv_offset; 304 dst = page_address(bv->bv_page) + bv->bv_offset;
309 if (dasd_page_cache) { 305 if (dasd_page_cache) {
310 char *copy = kmem_cache_alloc(dasd_page_cache, 306 char *copy = kmem_cache_alloc(dasd_page_cache,
@@ -359,11 +355,11 @@ dasd_fba_free_cp(struct dasd_ccw_req *cqr, struct request *req)
359{ 355{
360 struct dasd_fba_private *private; 356 struct dasd_fba_private *private;
361 struct ccw1 *ccw; 357 struct ccw1 *ccw;
362 struct bio *bio; 358 struct req_iterator iter;
363 struct bio_vec *bv; 359 struct bio_vec *bv;
364 char *dst, *cda; 360 char *dst, *cda;
365 unsigned int blksize, off; 361 unsigned int blksize, off;
366 int i, status; 362 int status;
367 363
368 if (!dasd_page_cache) 364 if (!dasd_page_cache)
369 goto out; 365 goto out;
@@ -374,7 +370,7 @@ dasd_fba_free_cp(struct dasd_ccw_req *cqr, struct request *req)
374 ccw++; 370 ccw++;
375 if (private->rdc_data.mode.bits.data_chain != 0) 371 if (private->rdc_data.mode.bits.data_chain != 0)
376 ccw++; 372 ccw++;
377 rq_for_each_bio(bio, req) bio_for_each_segment(bv, bio, i) { 373 rq_for_each_segment(bv, req, iter) {
378 dst = page_address(bv->bv_page) + bv->bv_offset; 374 dst = page_address(bv->bv_page) + bv->bv_offset;
379 for (off = 0; off < bv->bv_len; off += blksize) { 375 for (off = 0; off < bv->bv_len; off += blksize) {
380 /* Skip locate record. */ 376 /* Skip locate record. */
diff --git a/drivers/s390/block/dcssblk.c b/drivers/s390/block/dcssblk.c
index 4d8798bacf97..859f870552e3 100644
--- a/drivers/s390/block/dcssblk.c
+++ b/drivers/s390/block/dcssblk.c
@@ -674,10 +674,10 @@ dcssblk_make_request(struct request_queue *q, struct bio *bio)
674 } 674 }
675 bytes_done += bvec->bv_len; 675 bytes_done += bvec->bv_len;
676 } 676 }
677 bio_endio(bio, bytes_done, 0); 677 bio_endio(bio, 0);
678 return 0; 678 return 0;
679fail: 679fail:
680 bio_io_error(bio, bio->bi_size); 680 bio_io_error(bio);
681 return 0; 681 return 0;
682} 682}
683 683
diff --git a/drivers/s390/block/xpram.c b/drivers/s390/block/xpram.c
index 354a060e5bec..0fbacc8b1063 100644
--- a/drivers/s390/block/xpram.c
+++ b/drivers/s390/block/xpram.c
@@ -230,12 +230,10 @@ static int xpram_make_request(struct request_queue *q, struct bio *bio)
230 } 230 }
231 } 231 }
232 set_bit(BIO_UPTODATE, &bio->bi_flags); 232 set_bit(BIO_UPTODATE, &bio->bi_flags);
233 bytes = bio->bi_size; 233 bio_end_io(bio, 0);
234 bio->bi_size = 0;
235 bio->bi_end_io(bio, bytes, 0);
236 return 0; 234 return 0;
237fail: 235fail:
238 bio_io_error(bio, bio->bi_size); 236 bio_io_error(bio);
239 return 0; 237 return 0;
240} 238}
241 239
diff --git a/drivers/s390/char/tape_34xx.c b/drivers/s390/char/tape_34xx.c
index 80e7a537e7d2..5b47e9cce75f 100644
--- a/drivers/s390/char/tape_34xx.c
+++ b/drivers/s390/char/tape_34xx.c
@@ -1134,21 +1134,18 @@ tape_34xx_bread(struct tape_device *device, struct request *req)
1134{ 1134{
1135 struct tape_request *request; 1135 struct tape_request *request;
1136 struct ccw1 *ccw; 1136 struct ccw1 *ccw;
1137 int count = 0, i; 1137 int count = 0;
1138 unsigned off; 1138 unsigned off;
1139 char *dst; 1139 char *dst;
1140 struct bio_vec *bv; 1140 struct bio_vec *bv;
1141 struct bio *bio; 1141 struct req_iterator iter;
1142 struct tape_34xx_block_id * start_block; 1142 struct tape_34xx_block_id * start_block;
1143 1143
1144 DBF_EVENT(6, "xBREDid:"); 1144 DBF_EVENT(6, "xBREDid:");
1145 1145
1146 /* Count the number of blocks for the request. */ 1146 /* Count the number of blocks for the request. */
1147 rq_for_each_bio(bio, req) { 1147 rq_for_each_segment(bv, req, iter)
1148 bio_for_each_segment(bv, bio, i) { 1148 count += bv->bv_len >> (TAPEBLOCK_HSEC_S2B + 9);
1149 count += bv->bv_len >> (TAPEBLOCK_HSEC_S2B + 9);
1150 }
1151 }
1152 1149
1153 /* Allocate the ccw request. */ 1150 /* Allocate the ccw request. */
1154 request = tape_alloc_request(3+count+1, 8); 1151 request = tape_alloc_request(3+count+1, 8);
@@ -1175,18 +1172,15 @@ tape_34xx_bread(struct tape_device *device, struct request *req)
1175 ccw = tape_ccw_cc(ccw, NOP, 0, NULL); 1172 ccw = tape_ccw_cc(ccw, NOP, 0, NULL);
1176 ccw = tape_ccw_cc(ccw, NOP, 0, NULL); 1173 ccw = tape_ccw_cc(ccw, NOP, 0, NULL);
1177 1174
1178 rq_for_each_bio(bio, req) { 1175 rq_for_each_segment(bv, req, iter) {
1179 bio_for_each_segment(bv, bio, i) { 1176 dst = kmap(bv->bv_page) + bv->bv_offset;
1180 dst = kmap(bv->bv_page) + bv->bv_offset; 1177 for (off = 0; off < bv->bv_len; off += TAPEBLOCK_HSEC_SIZE) {
1181 for (off = 0; off < bv->bv_len; 1178 ccw->flags = CCW_FLAG_CC;
1182 off += TAPEBLOCK_HSEC_SIZE) { 1179 ccw->cmd_code = READ_FORWARD;
1183 ccw->flags = CCW_FLAG_CC; 1180 ccw->count = TAPEBLOCK_HSEC_SIZE;
1184 ccw->cmd_code = READ_FORWARD; 1181 set_normalized_cda(ccw, (void*) __pa(dst));
1185 ccw->count = TAPEBLOCK_HSEC_SIZE; 1182 ccw++;
1186 set_normalized_cda(ccw, (void*) __pa(dst)); 1183 dst += TAPEBLOCK_HSEC_SIZE;
1187 ccw++;
1188 dst += TAPEBLOCK_HSEC_SIZE;
1189 }
1190 } 1184 }
1191 } 1185 }
1192 1186
diff --git a/drivers/s390/char/tape_3590.c b/drivers/s390/char/tape_3590.c
index 7e2b2ab49264..9f244c591eeb 100644
--- a/drivers/s390/char/tape_3590.c
+++ b/drivers/s390/char/tape_3590.c
@@ -623,21 +623,19 @@ tape_3590_bread(struct tape_device *device, struct request *req)
623{ 623{
624 struct tape_request *request; 624 struct tape_request *request;
625 struct ccw1 *ccw; 625 struct ccw1 *ccw;
626 int count = 0, start_block, i; 626 int count = 0, start_block;
627 unsigned off; 627 unsigned off;
628 char *dst; 628 char *dst;
629 struct bio_vec *bv; 629 struct bio_vec *bv;
630 struct bio *bio; 630 struct req_iterator iter;
631 631
632 DBF_EVENT(6, "xBREDid:"); 632 DBF_EVENT(6, "xBREDid:");
633 start_block = req->sector >> TAPEBLOCK_HSEC_S2B; 633 start_block = req->sector >> TAPEBLOCK_HSEC_S2B;
634 DBF_EVENT(6, "start_block = %i\n", start_block); 634 DBF_EVENT(6, "start_block = %i\n", start_block);
635 635
636 rq_for_each_bio(bio, req) { 636 rq_for_each_segment(bv, req, iter)
637 bio_for_each_segment(bv, bio, i) { 637 count += bv->bv_len >> (TAPEBLOCK_HSEC_S2B + 9);
638 count += bv->bv_len >> (TAPEBLOCK_HSEC_S2B + 9); 638
639 }
640 }
641 request = tape_alloc_request(2 + count + 1, 4); 639 request = tape_alloc_request(2 + count + 1, 4);
642 if (IS_ERR(request)) 640 if (IS_ERR(request))
643 return request; 641 return request;
@@ -653,21 +651,18 @@ tape_3590_bread(struct tape_device *device, struct request *req)
653 */ 651 */
654 ccw = tape_ccw_cc(ccw, NOP, 0, NULL); 652 ccw = tape_ccw_cc(ccw, NOP, 0, NULL);
655 653
656 rq_for_each_bio(bio, req) { 654 rq_for_each_segment(bv, req, iter) {
657 bio_for_each_segment(bv, bio, i) { 655 dst = page_address(bv->bv_page) + bv->bv_offset;
658 dst = page_address(bv->bv_page) + bv->bv_offset; 656 for (off = 0; off < bv->bv_len; off += TAPEBLOCK_HSEC_SIZE) {
659 for (off = 0; off < bv->bv_len; 657 ccw->flags = CCW_FLAG_CC;
660 off += TAPEBLOCK_HSEC_SIZE) { 658 ccw->cmd_code = READ_FORWARD;
661 ccw->flags = CCW_FLAG_CC; 659 ccw->count = TAPEBLOCK_HSEC_SIZE;
662 ccw->cmd_code = READ_FORWARD; 660 set_normalized_cda(ccw, (void *) __pa(dst));
663 ccw->count = TAPEBLOCK_HSEC_SIZE; 661 ccw++;
664 set_normalized_cda(ccw, (void *) __pa(dst)); 662 dst += TAPEBLOCK_HSEC_SIZE;
665 ccw++;
666 dst += TAPEBLOCK_HSEC_SIZE;
667 }
668 if (off > bv->bv_len)
669 BUG();
670 } 663 }
664 if (off > bv->bv_len)
665 BUG();
671 } 666 }
672 ccw = tape_ccw_end(ccw, NOP, 0, NULL); 667 ccw = tape_ccw_end(ccw, NOP, 0, NULL);
673 DBF_EVENT(6, "xBREDccwg\n"); 668 DBF_EVENT(6, "xBREDccwg\n");
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index a417a6ff9f97..604f4d717933 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -263,25 +263,12 @@ static int scsi_merge_bio(struct request *rq, struct bio *bio)
263 bio->bi_rw |= (1 << BIO_RW); 263 bio->bi_rw |= (1 << BIO_RW);
264 blk_queue_bounce(q, &bio); 264 blk_queue_bounce(q, &bio);
265 265
266 if (!rq->bio) 266 return blk_rq_append_bio(q, rq, bio);
267 blk_rq_bio_prep(q, rq, bio);
268 else if (!ll_back_merge_fn(q, rq, bio))
269 return -EINVAL;
270 else {
271 rq->biotail->bi_next = bio;
272 rq->biotail = bio;
273 }
274
275 return 0;
276} 267}
277 268
278static int scsi_bi_endio(struct bio *bio, unsigned int bytes_done, int error) 269static void scsi_bi_endio(struct bio *bio, int error)
279{ 270{
280 if (bio->bi_size)
281 return 1;
282
283 bio_put(bio); 271 bio_put(bio);
284 return 0;
285} 272}
286 273
287/** 274/**
@@ -337,7 +324,7 @@ static int scsi_req_map_sg(struct request *rq, struct scatterlist *sgl,
337 if (bio->bi_vcnt >= nr_vecs) { 324 if (bio->bi_vcnt >= nr_vecs) {
338 err = scsi_merge_bio(rq, bio); 325 err = scsi_merge_bio(rq, bio);
339 if (err) { 326 if (err) {
340 bio_endio(bio, bio->bi_size, 0); 327 bio_endio(bio, 0);
341 goto free_bios; 328 goto free_bios;
342 } 329 }
343 bio = NULL; 330 bio = NULL;
@@ -359,7 +346,7 @@ free_bios:
359 /* 346 /*
360 * call endio instead of bio_put incase it was bounced 347 * call endio instead of bio_put incase it was bounced
361 */ 348 */
362 bio_endio(bio, bio->bi_size, 0); 349 bio_endio(bio, 0);
363 } 350 }
364 351
365 return err; 352 return err;
diff --git a/drivers/serial/bfin_5xx.c b/drivers/serial/bfin_5xx.c
index 66c92bc36f3d..6f475b609864 100644
--- a/drivers/serial/bfin_5xx.c
+++ b/drivers/serial/bfin_5xx.c
@@ -86,10 +86,8 @@ static void bfin_serial_stop_tx(struct uart_port *port)
86{ 86{
87 struct bfin_serial_port *uart = (struct bfin_serial_port *)port; 87 struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
88 88
89#ifdef CONFIG_BF54x
90 while (!(UART_GET_LSR(uart) & TEMT)) 89 while (!(UART_GET_LSR(uart) & TEMT))
91 continue; 90 continue;
92#endif
93 91
94#ifdef CONFIG_SERIAL_BFIN_DMA 92#ifdef CONFIG_SERIAL_BFIN_DMA
95 disable_dma(uart->tx_dma_channel); 93 disable_dma(uart->tx_dma_channel);
@@ -128,8 +126,8 @@ static void bfin_serial_start_tx(struct uart_port *port)
128 ier = UART_GET_IER(uart); 126 ier = UART_GET_IER(uart);
129 ier |= ETBEI; 127 ier |= ETBEI;
130 UART_PUT_IER(uart, ier); 128 UART_PUT_IER(uart, ier);
131 bfin_serial_tx_chars(uart);
132#endif 129#endif
130 bfin_serial_tx_chars(uart);
133#endif 131#endif
134} 132}
135 133
@@ -139,18 +137,21 @@ static void bfin_serial_start_tx(struct uart_port *port)
139static void bfin_serial_stop_rx(struct uart_port *port) 137static void bfin_serial_stop_rx(struct uart_port *port)
140{ 138{
141 struct bfin_serial_port *uart = (struct bfin_serial_port *)port; 139 struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
140#ifdef CONFIG_KGDB_UART
141 if (uart->port.line != CONFIG_KGDB_UART_PORT) {
142#endif
142#ifdef CONFIG_BF54x 143#ifdef CONFIG_BF54x
143 UART_CLEAR_IER(uart, ERBFI); 144 UART_CLEAR_IER(uart, ERBFI);
144#else 145#else
145 unsigned short ier; 146 unsigned short ier;
146 147
147 ier = UART_GET_IER(uart); 148 ier = UART_GET_IER(uart);
148#ifdef CONFIG_KGDB_UART
149 if (uart->port.line != CONFIG_KGDB_UART_PORT)
150#endif
151 ier &= ~ERBFI; 149 ier &= ~ERBFI;
152 UART_PUT_IER(uart, ier); 150 UART_PUT_IER(uart, ier);
153#endif 151#endif
152#ifdef CONFIG_KGDB_UART
153 }
154#endif
154} 155}
155 156
156/* 157/*
@@ -173,12 +174,15 @@ void kgdb_put_debug_char(int chr)
173 uart = &bfin_serial_ports[CONFIG_KGDB_UART_PORT]; 174 uart = &bfin_serial_ports[CONFIG_KGDB_UART_PORT];
174 175
175 while (!(UART_GET_LSR(uart) & THRE)) { 176 while (!(UART_GET_LSR(uart) & THRE)) {
176 __builtin_bfin_ssync(); 177 SSYNC();
177 } 178 }
179
180#ifndef CONFIG_BF54x
178 UART_PUT_LCR(uart, UART_GET_LCR(uart)&(~DLAB)); 181 UART_PUT_LCR(uart, UART_GET_LCR(uart)&(~DLAB));
179 __builtin_bfin_ssync(); 182 SSYNC();
183#endif
180 UART_PUT_CHAR(uart, (unsigned char)chr); 184 UART_PUT_CHAR(uart, (unsigned char)chr);
181 __builtin_bfin_ssync(); 185 SSYNC();
182} 186}
183 187
184int kgdb_get_debug_char(void) 188int kgdb_get_debug_char(void)
@@ -192,12 +196,14 @@ int kgdb_get_debug_char(void)
192 uart = &bfin_serial_ports[CONFIG_KGDB_UART_PORT]; 196 uart = &bfin_serial_ports[CONFIG_KGDB_UART_PORT];
193 197
194 while(!(UART_GET_LSR(uart) & DR)) { 198 while(!(UART_GET_LSR(uart) & DR)) {
195 __builtin_bfin_ssync(); 199 SSYNC();
196 } 200 }
201#ifndef CONFIG_BF54x
197 UART_PUT_LCR(uart, UART_GET_LCR(uart)&(~DLAB)); 202 UART_PUT_LCR(uart, UART_GET_LCR(uart)&(~DLAB));
198 __builtin_bfin_ssync(); 203 SSYNC();
204#endif
199 chr = UART_GET_CHAR(uart); 205 chr = UART_GET_CHAR(uart);
200 __builtin_bfin_ssync(); 206 SSYNC();
201 207
202 return chr; 208 return chr;
203} 209}
@@ -225,12 +231,10 @@ static void bfin_serial_rx_chars(struct bfin_serial_port *uart)
225{ 231{
226 struct tty_struct *tty = uart->port.info->tty; 232 struct tty_struct *tty = uart->port.info->tty;
227 unsigned int status, ch, flg; 233 unsigned int status, ch, flg;
234 static int in_break = 0;
228#ifdef CONFIG_KGDB_UART 235#ifdef CONFIG_KGDB_UART
229 struct pt_regs *regs = get_irq_regs(); 236 struct pt_regs *regs = get_irq_regs();
230#endif 237#endif
231#ifdef BF533_FAMILY
232 static int in_break = 0;
233#endif
234 238
235 status = UART_GET_LSR(uart); 239 status = UART_GET_LSR(uart);
236 ch = UART_GET_CHAR(uart); 240 ch = UART_GET_CHAR(uart);
@@ -256,29 +260,30 @@ static void bfin_serial_rx_chars(struct bfin_serial_port *uart)
256 } 260 }
257 } 261 }
258#endif 262#endif
259 263
260#ifdef BF533_FAMILY 264 if (ANOMALY_05000230) {
261 /* The BF533 family of processors have a nice misbehavior where 265 /* The BF533 family of processors have a nice misbehavior where
262 * they continuously generate characters for a "single" break. 266 * they continuously generate characters for a "single" break.
263 * We have to basically ignore this flood until the "next" valid 267 * We have to basically ignore this flood until the "next" valid
264 * character comes across. All other Blackfin families operate 268 * character comes across. All other Blackfin families operate
265 * properly though. 269 * properly though.
266 */ 270 * Note: While Anomaly 05000230 does not directly address this,
267 if (in_break) { 271 * the changes that went in for it also fixed this issue.
268 if (ch != 0) { 272 */
269 in_break = 0; 273 if (in_break) {
270 ch = UART_GET_CHAR(uart); 274 if (ch != 0) {
271 if (bfin_revid() < 5) 275 in_break = 0;
276 ch = UART_GET_CHAR(uart);
277 if (bfin_revid() < 5)
278 return;
279 } else
272 return; 280 return;
273 } else 281 }
274 return;
275 } 282 }
276#endif
277 283
278 if (status & BI) { 284 if (status & BI) {
279#ifdef BF533_FAMILY 285 if (ANOMALY_05000230)
280 in_break = 1; 286 in_break = 1;
281#endif
282 uart->port.icount.brk++; 287 uart->port.icount.brk++;
283 if (uart_handle_break(&uart->port)) 288 if (uart_handle_break(&uart->port))
284 goto ignore_char; 289 goto ignore_char;
@@ -697,17 +702,19 @@ static int bfin_serial_startup(struct uart_port *port)
697 uart->rx_dma_timer.expires = jiffies + DMA_RX_FLUSH_JIFFIES; 702 uart->rx_dma_timer.expires = jiffies + DMA_RX_FLUSH_JIFFIES;
698 add_timer(&(uart->rx_dma_timer)); 703 add_timer(&(uart->rx_dma_timer));
699#else 704#else
705 if (request_irq(uart->port.irq, bfin_serial_rx_int, IRQF_DISABLED,
706 "BFIN_UART_RX", uart)) {
700# ifdef CONFIG_KGDB_UART 707# ifdef CONFIG_KGDB_UART
701 if (uart->port.line != CONFIG_KGDB_UART_PORT && request_irq 708 if (uart->port.line != CONFIG_KGDB_UART_PORT) {
702# else
703 if (request_irq
704# endif 709# endif
705 (uart->port.irq, bfin_serial_rx_int, IRQF_DISABLED,
706 "BFIN_UART_RX", uart)) {
707 printk(KERN_NOTICE "Unable to attach BlackFin UART RX interrupt\n"); 710 printk(KERN_NOTICE "Unable to attach BlackFin UART RX interrupt\n");
708 return -EBUSY; 711 return -EBUSY;
712# ifdef CONFIG_KGDB_UART
713 }
714# endif
709 } 715 }
710 716
717
711 if (request_irq 718 if (request_irq
712 (uart->port.irq+1, bfin_serial_tx_int, IRQF_DISABLED, 719 (uart->port.irq+1, bfin_serial_tx_int, IRQF_DISABLED,
713 "BFIN_UART_TX", uart)) { 720 "BFIN_UART_TX", uart)) {
@@ -962,30 +969,6 @@ static void __init bfin_serial_init_ports(void)
962} 969}
963 970
964#ifdef CONFIG_SERIAL_BFIN_CONSOLE 971#ifdef CONFIG_SERIAL_BFIN_CONSOLE
965static void bfin_serial_console_putchar(struct uart_port *port, int ch)
966{
967 struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
968 while (!(UART_GET_LSR(uart) & THRE))
969 barrier();
970 UART_PUT_CHAR(uart, ch);
971 SSYNC();
972}
973
974/*
975 * Interrupts are disabled on entering
976 */
977static void
978bfin_serial_console_write(struct console *co, const char *s, unsigned int count)
979{
980 struct bfin_serial_port *uart = &bfin_serial_ports[co->index];
981 int flags = 0;
982
983 spin_lock_irqsave(&uart->port.lock, flags);
984 uart_console_write(&uart->port, s, count, bfin_serial_console_putchar);
985 spin_unlock_irqrestore(&uart->port.lock, flags);
986
987}
988
989/* 972/*
990 * If the port was already initialised (eg, by a boot loader), 973 * If the port was already initialised (eg, by a boot loader),
991 * try to determine the current setup. 974 * try to determine the current setup.
@@ -1038,19 +1021,25 @@ bfin_serial_console_get_options(struct bfin_serial_port *uart, int *baud,
1038 } 1021 }
1039 pr_debug("%s:baud = %d, parity = %c, bits= %d\n", __FUNCTION__, *baud, *parity, *bits); 1022 pr_debug("%s:baud = %d, parity = %c, bits= %d\n", __FUNCTION__, *baud, *parity, *bits);
1040} 1023}
1024#endif
1025
1026#if defined(CONFIG_SERIAL_BFIN_CONSOLE) || defined(CONFIG_EARLY_PRINTK)
1027static struct uart_driver bfin_serial_reg;
1041 1028
1042static int __init 1029static int __init
1043bfin_serial_console_setup(struct console *co, char *options) 1030bfin_serial_console_setup(struct console *co, char *options)
1044{ 1031{
1045 struct bfin_serial_port *uart; 1032 struct bfin_serial_port *uart;
1033# ifdef CONFIG_SERIAL_BFIN_CONSOLE
1046 int baud = 57600; 1034 int baud = 57600;
1047 int bits = 8; 1035 int bits = 8;
1048 int parity = 'n'; 1036 int parity = 'n';
1049#ifdef CONFIG_SERIAL_BFIN_CTSRTS 1037# ifdef CONFIG_SERIAL_BFIN_CTSRTS
1050 int flow = 'r'; 1038 int flow = 'r';
1051#else 1039# else
1052 int flow = 'n'; 1040 int flow = 'n';
1053#endif 1041# endif
1042# endif
1054 1043
1055 /* 1044 /*
1056 * Check whether an invalid uart number has been specified, and 1045 * Check whether an invalid uart number has been specified, and
@@ -1061,15 +1050,45 @@ bfin_serial_console_setup(struct console *co, char *options)
1061 co->index = 0; 1050 co->index = 0;
1062 uart = &bfin_serial_ports[co->index]; 1051 uart = &bfin_serial_ports[co->index];
1063 1052
1053# ifdef CONFIG_SERIAL_BFIN_CONSOLE
1064 if (options) 1054 if (options)
1065 uart_parse_options(options, &baud, &parity, &bits, &flow); 1055 uart_parse_options(options, &baud, &parity, &bits, &flow);
1066 else 1056 else
1067 bfin_serial_console_get_options(uart, &baud, &parity, &bits); 1057 bfin_serial_console_get_options(uart, &baud, &parity, &bits);
1068 1058
1069 return uart_set_options(&uart->port, co, baud, parity, bits, flow); 1059 return uart_set_options(&uart->port, co, baud, parity, bits, flow);
1060# else
1061 return 0;
1062# endif
1063}
1064#endif /* defined (CONFIG_SERIAL_BFIN_CONSOLE) ||
1065 defined (CONFIG_EARLY_PRINTK) */
1066
1067#ifdef CONFIG_SERIAL_BFIN_CONSOLE
1068static void bfin_serial_console_putchar(struct uart_port *port, int ch)
1069{
1070 struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
1071 while (!(UART_GET_LSR(uart) & THRE))
1072 barrier();
1073 UART_PUT_CHAR(uart, ch);
1074 SSYNC();
1075}
1076
1077/*
1078 * Interrupts are disabled on entering
1079 */
1080static void
1081bfin_serial_console_write(struct console *co, const char *s, unsigned int count)
1082{
1083 struct bfin_serial_port *uart = &bfin_serial_ports[co->index];
1084 int flags = 0;
1085
1086 spin_lock_irqsave(&uart->port.lock, flags);
1087 uart_console_write(&uart->port, s, count, bfin_serial_console_putchar);
1088 spin_unlock_irqrestore(&uart->port.lock, flags);
1089
1070} 1090}
1071 1091
1072static struct uart_driver bfin_serial_reg;
1073static struct console bfin_serial_console = { 1092static struct console bfin_serial_console = {
1074 .name = BFIN_SERIAL_NAME, 1093 .name = BFIN_SERIAL_NAME,
1075 .write = bfin_serial_console_write, 1094 .write = bfin_serial_console_write,
@@ -1095,7 +1114,64 @@ console_initcall(bfin_serial_rs_console_init);
1095#define BFIN_SERIAL_CONSOLE &bfin_serial_console 1114#define BFIN_SERIAL_CONSOLE &bfin_serial_console
1096#else 1115#else
1097#define BFIN_SERIAL_CONSOLE NULL 1116#define BFIN_SERIAL_CONSOLE NULL
1098#endif 1117#endif /* CONFIG_SERIAL_BFIN_CONSOLE */
1118
1119
1120#ifdef CONFIG_EARLY_PRINTK
1121static __init void early_serial_putc(struct uart_port *port, int ch)
1122{
1123 unsigned timeout = 0xffff;
1124 struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
1125
1126 while ((!(UART_GET_LSR(uart) & THRE)) && --timeout)
1127 cpu_relax();
1128 UART_PUT_CHAR(uart, ch);
1129}
1130
1131static __init void early_serial_write(struct console *con, const char *s,
1132 unsigned int n)
1133{
1134 struct bfin_serial_port *uart = &bfin_serial_ports[con->index];
1135 unsigned int i;
1136
1137 for (i = 0; i < n; i++, s++) {
1138 if (*s == '\n')
1139 early_serial_putc(&uart->port, '\r');
1140 early_serial_putc(&uart->port, *s);
1141 }
1142}
1143
1144static struct __init console bfin_early_serial_console = {
1145 .name = "early_BFuart",
1146 .write = early_serial_write,
1147 .device = uart_console_device,
1148 .flags = CON_PRINTBUFFER,
1149 .setup = bfin_serial_console_setup,
1150 .index = -1,
1151 .data = &bfin_serial_reg,
1152};
1153
1154struct console __init *bfin_earlyserial_init(unsigned int port,
1155 unsigned int cflag)
1156{
1157 struct bfin_serial_port *uart;
1158 struct ktermios t;
1159
1160 if (port == -1 || port >= nr_ports)
1161 port = 0;
1162 bfin_serial_init_ports();
1163 bfin_early_serial_console.index = port;
1164 uart = &bfin_serial_ports[port];
1165 t.c_cflag = cflag;
1166 t.c_iflag = 0;
1167 t.c_oflag = 0;
1168 t.c_lflag = ICANON;
1169 t.c_line = port;
1170 bfin_serial_set_termios(&uart->port, &t, &t);
1171 return &bfin_early_serial_console;
1172}
1173
1174#endif /* CONFIG_SERIAL_BFIN_CONSOLE */
1099 1175
1100static struct uart_driver bfin_serial_reg = { 1176static struct uart_driver bfin_serial_reg = {
1101 .owner = THIS_MODULE, 1177 .owner = THIS_MODULE,
@@ -1182,7 +1258,7 @@ static int __init bfin_serial_init(void)
1182 int ret; 1258 int ret;
1183#ifdef CONFIG_KGDB_UART 1259#ifdef CONFIG_KGDB_UART
1184 struct bfin_serial_port *uart = &bfin_serial_ports[CONFIG_KGDB_UART_PORT]; 1260 struct bfin_serial_port *uart = &bfin_serial_ports[CONFIG_KGDB_UART_PORT];
1185 struct termios t; 1261 struct ktermios t;
1186#endif 1262#endif
1187 1263
1188 pr_info("Serial: Blackfin serial driver\n"); 1264 pr_info("Serial: Blackfin serial driver\n");
@@ -1199,11 +1275,15 @@ static int __init bfin_serial_init(void)
1199 } 1275 }
1200#ifdef CONFIG_KGDB_UART 1276#ifdef CONFIG_KGDB_UART
1201 if (uart->port.cons->index != CONFIG_KGDB_UART_PORT) { 1277 if (uart->port.cons->index != CONFIG_KGDB_UART_PORT) {
1202 request_irq(uart->port.irq, bfin_serial_int, 1278 request_irq(uart->port.irq, bfin_serial_rx_int,
1203 IRQF_DISABLED, "BFIN_UART_RX", uart); 1279 IRQF_DISABLED, "BFIN_UART_RX", uart);
1204 pr_info("Request irq for kgdb uart port\n"); 1280 pr_info("Request irq for kgdb uart port\n");
1281#ifdef CONFIG_BF54x
1282 UART_SET_IER(uart, ERBFI);
1283#else
1205 UART_PUT_IER(uart, UART_GET_IER(uart) | ERBFI); 1284 UART_PUT_IER(uart, UART_GET_IER(uart) | ERBFI);
1206 __builtin_bfin_ssync(); 1285#endif
1286 SSYNC();
1207 t.c_cflag = CS8|B57600; 1287 t.c_cflag = CS8|B57600;
1208 t.c_iflag = 0; 1288 t.c_iflag = 0;
1209 t.c_oflag = 0; 1289 t.c_oflag = 0;
diff --git a/fs/bio.c b/fs/bio.c
index 29a44c1b64c6..5f604f269dfa 100644
--- a/fs/bio.c
+++ b/fs/bio.c
@@ -798,13 +798,9 @@ void bio_unmap_user(struct bio *bio)
798 bio_put(bio); 798 bio_put(bio);
799} 799}
800 800
801static int bio_map_kern_endio(struct bio *bio, unsigned int bytes_done, int err) 801static void bio_map_kern_endio(struct bio *bio, int err)
802{ 802{
803 if (bio->bi_size)
804 return 1;
805
806 bio_put(bio); 803 bio_put(bio);
807 return 0;
808} 804}
809 805
810 806
@@ -1002,34 +998,26 @@ void bio_check_pages_dirty(struct bio *bio)
1002/** 998/**
1003 * bio_endio - end I/O on a bio 999 * bio_endio - end I/O on a bio
1004 * @bio: bio 1000 * @bio: bio
1005 * @bytes_done: number of bytes completed
1006 * @error: error, if any 1001 * @error: error, if any
1007 * 1002 *
1008 * Description: 1003 * Description:
1009 * bio_endio() will end I/O on @bytes_done number of bytes. This may be 1004 * bio_endio() will end I/O on the whole bio. bio_endio() is the
1010 * just a partial part of the bio, or it may be the whole bio. bio_endio() 1005 * preferred way to end I/O on a bio, it takes care of clearing
1011 * is the preferred way to end I/O on a bio, it takes care of decrementing 1006 * BIO_UPTODATE on error. @error is 0 on success, and and one of the
1012 * bi_size and clearing BIO_UPTODATE on error. @error is 0 on success, and 1007 * established -Exxxx (-EIO, for instance) error values in case
1013 * and one of the established -Exxxx (-EIO, for instance) error values in 1008 * something went wrong. Noone should call bi_end_io() directly on a
1014 * case something went wrong. Noone should call bi_end_io() directly on 1009 * bio unless they own it and thus know that it has an end_io
1015 * a bio unless they own it and thus know that it has an end_io function. 1010 * function.
1016 **/ 1011 **/
1017void bio_endio(struct bio *bio, unsigned int bytes_done, int error) 1012void bio_endio(struct bio *bio, int error)
1018{ 1013{
1019 if (error) 1014 if (error)
1020 clear_bit(BIO_UPTODATE, &bio->bi_flags); 1015 clear_bit(BIO_UPTODATE, &bio->bi_flags);
1021 1016 else if (!test_bit(BIO_UPTODATE, &bio->bi_flags))
1022 if (unlikely(bytes_done > bio->bi_size)) { 1017 error = -EIO;
1023 printk("%s: want %u bytes done, only %u left\n", __FUNCTION__,
1024 bytes_done, bio->bi_size);
1025 bytes_done = bio->bi_size;
1026 }
1027
1028 bio->bi_size -= bytes_done;
1029 bio->bi_sector += (bytes_done >> 9);
1030 1018
1031 if (bio->bi_end_io) 1019 if (bio->bi_end_io)
1032 bio->bi_end_io(bio, bytes_done, error); 1020 bio->bi_end_io(bio, error);
1033} 1021}
1034 1022
1035void bio_pair_release(struct bio_pair *bp) 1023void bio_pair_release(struct bio_pair *bp)
@@ -1037,37 +1025,29 @@ void bio_pair_release(struct bio_pair *bp)
1037 if (atomic_dec_and_test(&bp->cnt)) { 1025 if (atomic_dec_and_test(&bp->cnt)) {
1038 struct bio *master = bp->bio1.bi_private; 1026 struct bio *master = bp->bio1.bi_private;
1039 1027
1040 bio_endio(master, master->bi_size, bp->error); 1028 bio_endio(master, bp->error);
1041 mempool_free(bp, bp->bio2.bi_private); 1029 mempool_free(bp, bp->bio2.bi_private);
1042 } 1030 }
1043} 1031}
1044 1032
1045static int bio_pair_end_1(struct bio * bi, unsigned int done, int err) 1033static void bio_pair_end_1(struct bio *bi, int err)
1046{ 1034{
1047 struct bio_pair *bp = container_of(bi, struct bio_pair, bio1); 1035 struct bio_pair *bp = container_of(bi, struct bio_pair, bio1);
1048 1036
1049 if (err) 1037 if (err)
1050 bp->error = err; 1038 bp->error = err;
1051 1039
1052 if (bi->bi_size)
1053 return 1;
1054
1055 bio_pair_release(bp); 1040 bio_pair_release(bp);
1056 return 0;
1057} 1041}
1058 1042
1059static int bio_pair_end_2(struct bio * bi, unsigned int done, int err) 1043static void bio_pair_end_2(struct bio *bi, int err)
1060{ 1044{
1061 struct bio_pair *bp = container_of(bi, struct bio_pair, bio2); 1045 struct bio_pair *bp = container_of(bi, struct bio_pair, bio2);
1062 1046
1063 if (err) 1047 if (err)
1064 bp->error = err; 1048 bp->error = err;
1065 1049
1066 if (bi->bi_size)
1067 return 1;
1068
1069 bio_pair_release(bp); 1050 bio_pair_release(bp);
1070 return 0;
1071} 1051}
1072 1052
1073/* 1053/*
diff --git a/fs/block_dev.c b/fs/block_dev.c
index 2980eabe5779..6339a30879b7 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -172,7 +172,7 @@ blkdev_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov,
172} 172}
173 173
174#if 0 174#if 0
175static int blk_end_aio(struct bio *bio, unsigned int bytes_done, int error) 175static void blk_end_aio(struct bio *bio, int error)
176{ 176{
177 struct kiocb *iocb = bio->bi_private; 177 struct kiocb *iocb = bio->bi_private;
178 atomic_t *bio_count = &iocb->ki_bio_count; 178 atomic_t *bio_count = &iocb->ki_bio_count;
diff --git a/fs/buffer.c b/fs/buffer.c
index 0e5ec371ce72..75b51dfa5e03 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -2634,13 +2634,10 @@ sector_t generic_block_bmap(struct address_space *mapping, sector_t block,
2634 return tmp.b_blocknr; 2634 return tmp.b_blocknr;
2635} 2635}
2636 2636
2637static int end_bio_bh_io_sync(struct bio *bio, unsigned int bytes_done, int err) 2637static void end_bio_bh_io_sync(struct bio *bio, int err)
2638{ 2638{
2639 struct buffer_head *bh = bio->bi_private; 2639 struct buffer_head *bh = bio->bi_private;
2640 2640
2641 if (bio->bi_size)
2642 return 1;
2643
2644 if (err == -EOPNOTSUPP) { 2641 if (err == -EOPNOTSUPP) {
2645 set_bit(BIO_EOPNOTSUPP, &bio->bi_flags); 2642 set_bit(BIO_EOPNOTSUPP, &bio->bi_flags);
2646 set_bit(BH_Eopnotsupp, &bh->b_state); 2643 set_bit(BH_Eopnotsupp, &bh->b_state);
@@ -2648,7 +2645,6 @@ static int end_bio_bh_io_sync(struct bio *bio, unsigned int bytes_done, int err)
2648 2645
2649 bh->b_end_io(bh, test_bit(BIO_UPTODATE, &bio->bi_flags)); 2646 bh->b_end_io(bh, test_bit(BIO_UPTODATE, &bio->bi_flags));
2650 bio_put(bio); 2647 bio_put(bio);
2651 return 0;
2652} 2648}
2653 2649
2654int submit_bh(int rw, struct buffer_head * bh) 2650int submit_bh(int rw, struct buffer_head * bh)
diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
index 37310b0e8107..b9e3357bcc2e 100644
--- a/fs/compat_ioctl.c
+++ b/fs/compat_ioctl.c
@@ -21,7 +21,6 @@
21#include <linux/if.h> 21#include <linux/if.h>
22#include <linux/if_bridge.h> 22#include <linux/if_bridge.h>
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/hdreg.h>
25#include <linux/raid/md.h> 24#include <linux/raid/md.h>
26#include <linux/kd.h> 25#include <linux/kd.h>
27#include <linux/dirent.h> 26#include <linux/dirent.h>
@@ -33,12 +32,10 @@
33#include <linux/vt.h> 32#include <linux/vt.h>
34#include <linux/fs.h> 33#include <linux/fs.h>
35#include <linux/file.h> 34#include <linux/file.h>
36#include <linux/fd.h>
37#include <linux/ppp_defs.h> 35#include <linux/ppp_defs.h>
38#include <linux/if_ppp.h> 36#include <linux/if_ppp.h>
39#include <linux/if_pppox.h> 37#include <linux/if_pppox.h>
40#include <linux/mtio.h> 38#include <linux/mtio.h>
41#include <linux/cdrom.h>
42#include <linux/auto_fs.h> 39#include <linux/auto_fs.h>
43#include <linux/auto_fs4.h> 40#include <linux/auto_fs4.h>
44#include <linux/tty.h> 41#include <linux/tty.h>
@@ -48,7 +45,6 @@
48#include <linux/netdevice.h> 45#include <linux/netdevice.h>
49#include <linux/raw.h> 46#include <linux/raw.h>
50#include <linux/smb_fs.h> 47#include <linux/smb_fs.h>
51#include <linux/blkpg.h>
52#include <linux/blkdev.h> 48#include <linux/blkdev.h>
53#include <linux/elevator.h> 49#include <linux/elevator.h>
54#include <linux/rtc.h> 50#include <linux/rtc.h>
@@ -62,7 +58,6 @@
62#include <linux/i2c-dev.h> 58#include <linux/i2c-dev.h>
63#include <linux/wireless.h> 59#include <linux/wireless.h>
64#include <linux/atalk.h> 60#include <linux/atalk.h>
65#include <linux/blktrace_api.h>
66#include <linux/loop.h> 61#include <linux/loop.h>
67 62
68#include <net/bluetooth/bluetooth.h> 63#include <net/bluetooth/bluetooth.h>
@@ -668,53 +663,6 @@ out:
668#endif 663#endif
669 664
670#ifdef CONFIG_BLOCK 665#ifdef CONFIG_BLOCK
671struct hd_geometry32 {
672 unsigned char heads;
673 unsigned char sectors;
674 unsigned short cylinders;
675 u32 start;
676};
677
678static int hdio_getgeo(unsigned int fd, unsigned int cmd, unsigned long arg)
679{
680 mm_segment_t old_fs = get_fs();
681 struct hd_geometry geo;
682 struct hd_geometry32 __user *ugeo;
683 int err;
684
685 set_fs (KERNEL_DS);
686 err = sys_ioctl(fd, HDIO_GETGEO, (unsigned long)&geo);
687 set_fs (old_fs);
688 ugeo = compat_ptr(arg);
689 if (!err) {
690 err = copy_to_user (ugeo, &geo, 4);
691 err |= __put_user (geo.start, &ugeo->start);
692 if (err)
693 err = -EFAULT;
694 }
695 return err;
696}
697
698static int hdio_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
699{
700 mm_segment_t old_fs = get_fs();
701 unsigned long kval;
702 unsigned int __user *uvp;
703 int error;
704
705 set_fs(KERNEL_DS);
706 error = sys_ioctl(fd, cmd, (long)&kval);
707 set_fs(old_fs);
708
709 if(error == 0) {
710 uvp = compat_ptr(arg);
711 if(put_user(kval, uvp))
712 error = -EFAULT;
713 }
714 return error;
715}
716
717
718typedef struct sg_io_hdr32 { 666typedef struct sg_io_hdr32 {
719 compat_int_t interface_id; /* [i] 'S' for SCSI generic (required) */ 667 compat_int_t interface_id; /* [i] 'S' for SCSI generic (required) */
720 compat_int_t dxfer_direction; /* [i] data transfer direction */ 668 compat_int_t dxfer_direction; /* [i] data transfer direction */
@@ -1089,108 +1037,6 @@ static int mt_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1089 return err ? -EFAULT: 0; 1037 return err ? -EFAULT: 0;
1090} 1038}
1091 1039
1092struct cdrom_read_audio32 {
1093 union cdrom_addr addr;
1094 u8 addr_format;
1095 compat_int_t nframes;
1096 compat_caddr_t buf;
1097};
1098
1099struct cdrom_generic_command32 {
1100 unsigned char cmd[CDROM_PACKET_SIZE];
1101 compat_caddr_t buffer;
1102 compat_uint_t buflen;
1103 compat_int_t stat;
1104 compat_caddr_t sense;
1105 unsigned char data_direction;
1106 compat_int_t quiet;
1107 compat_int_t timeout;
1108 compat_caddr_t reserved[1];
1109};
1110
1111static int cdrom_do_read_audio(unsigned int fd, unsigned int cmd, unsigned long arg)
1112{
1113 struct cdrom_read_audio __user *cdread_audio;
1114 struct cdrom_read_audio32 __user *cdread_audio32;
1115 __u32 data;
1116 void __user *datap;
1117
1118 cdread_audio = compat_alloc_user_space(sizeof(*cdread_audio));
1119 cdread_audio32 = compat_ptr(arg);
1120
1121 if (copy_in_user(&cdread_audio->addr,
1122 &cdread_audio32->addr,
1123 (sizeof(*cdread_audio32) -
1124 sizeof(compat_caddr_t))))
1125 return -EFAULT;
1126
1127 if (get_user(data, &cdread_audio32->buf))
1128 return -EFAULT;
1129 datap = compat_ptr(data);
1130 if (put_user(datap, &cdread_audio->buf))
1131 return -EFAULT;
1132
1133 return sys_ioctl(fd, cmd, (unsigned long) cdread_audio);
1134}
1135
1136static int cdrom_do_generic_command(unsigned int fd, unsigned int cmd, unsigned long arg)
1137{
1138 struct cdrom_generic_command __user *cgc;
1139 struct cdrom_generic_command32 __user *cgc32;
1140 u32 data;
1141 unsigned char dir;
1142 int itmp;
1143
1144 cgc = compat_alloc_user_space(sizeof(*cgc));
1145 cgc32 = compat_ptr(arg);
1146
1147 if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
1148 get_user(data, &cgc32->buffer) ||
1149 put_user(compat_ptr(data), &cgc->buffer) ||
1150 copy_in_user(&cgc->buflen, &cgc32->buflen,
1151 (sizeof(unsigned int) + sizeof(int))) ||
1152 get_user(data, &cgc32->sense) ||
1153 put_user(compat_ptr(data), &cgc->sense) ||
1154 get_user(dir, &cgc32->data_direction) ||
1155 put_user(dir, &cgc->data_direction) ||
1156 get_user(itmp, &cgc32->quiet) ||
1157 put_user(itmp, &cgc->quiet) ||
1158 get_user(itmp, &cgc32->timeout) ||
1159 put_user(itmp, &cgc->timeout) ||
1160 get_user(data, &cgc32->reserved[0]) ||
1161 put_user(compat_ptr(data), &cgc->reserved[0]))
1162 return -EFAULT;
1163
1164 return sys_ioctl(fd, cmd, (unsigned long) cgc);
1165}
1166
1167static int cdrom_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1168{
1169 int err;
1170
1171 switch(cmd) {
1172 case CDROMREADAUDIO:
1173 err = cdrom_do_read_audio(fd, cmd, arg);
1174 break;
1175
1176 case CDROM_SEND_PACKET:
1177 err = cdrom_do_generic_command(fd, cmd, arg);
1178 break;
1179
1180 default:
1181 do {
1182 static int count;
1183 if (++count <= 20)
1184 printk("cdrom_ioctl: Unknown cmd fd(%d) "
1185 "cmd(%08x) arg(%08x)\n",
1186 (int)fd, (unsigned int)cmd, (unsigned int)arg);
1187 } while(0);
1188 err = -EINVAL;
1189 break;
1190 };
1191
1192 return err;
1193}
1194#endif /* CONFIG_BLOCK */ 1040#endif /* CONFIG_BLOCK */
1195 1041
1196#ifdef CONFIG_VT 1042#ifdef CONFIG_VT
@@ -1536,71 +1382,11 @@ ret_einval(unsigned int fd, unsigned int cmd, unsigned long arg)
1536 return -EINVAL; 1382 return -EINVAL;
1537} 1383}
1538 1384
1539#ifdef CONFIG_BLOCK
1540static int broken_blkgetsize(unsigned int fd, unsigned int cmd, unsigned long arg)
1541{
1542 /* The mkswap binary hard codes it to Intel value :-((( */
1543 return w_long(fd, BLKGETSIZE, arg);
1544}
1545
1546struct blkpg_ioctl_arg32 {
1547 compat_int_t op;
1548 compat_int_t flags;
1549 compat_int_t datalen;
1550 compat_caddr_t data;
1551};
1552
1553static int blkpg_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1554{
1555 struct blkpg_ioctl_arg32 __user *ua32 = compat_ptr(arg);
1556 struct blkpg_ioctl_arg __user *a = compat_alloc_user_space(sizeof(*a));
1557 compat_caddr_t udata;
1558 compat_int_t n;
1559 int err;
1560
1561 err = get_user(n, &ua32->op);
1562 err |= put_user(n, &a->op);
1563 err |= get_user(n, &ua32->flags);
1564 err |= put_user(n, &a->flags);
1565 err |= get_user(n, &ua32->datalen);
1566 err |= put_user(n, &a->datalen);
1567 err |= get_user(udata, &ua32->data);
1568 err |= put_user(compat_ptr(udata), &a->data);
1569 if (err)
1570 return err;
1571
1572 return sys_ioctl(fd, cmd, (unsigned long)a);
1573}
1574#endif
1575
1576static int ioc_settimeout(unsigned int fd, unsigned int cmd, unsigned long arg) 1385static int ioc_settimeout(unsigned int fd, unsigned int cmd, unsigned long arg)
1577{ 1386{
1578 return rw_long(fd, AUTOFS_IOC_SETTIMEOUT, arg); 1387 return rw_long(fd, AUTOFS_IOC_SETTIMEOUT, arg);
1579} 1388}
1580 1389
1581#ifdef CONFIG_BLOCK
1582/* Fix sizeof(sizeof()) breakage */
1583#define BLKBSZGET_32 _IOR(0x12,112,int)
1584#define BLKBSZSET_32 _IOW(0x12,113,int)
1585#define BLKGETSIZE64_32 _IOR(0x12,114,int)
1586
1587static int do_blkbszget(unsigned int fd, unsigned int cmd, unsigned long arg)
1588{
1589 return sys_ioctl(fd, BLKBSZGET, (unsigned long)compat_ptr(arg));
1590}
1591
1592static int do_blkbszset(unsigned int fd, unsigned int cmd, unsigned long arg)
1593{
1594 return sys_ioctl(fd, BLKBSZSET, (unsigned long)compat_ptr(arg));
1595}
1596
1597static int do_blkgetsize64(unsigned int fd, unsigned int cmd,
1598 unsigned long arg)
1599{
1600 return sys_ioctl(fd, BLKGETSIZE64, (unsigned long)compat_ptr(arg));
1601}
1602#endif
1603
1604/* Bluetooth ioctls */ 1390/* Bluetooth ioctls */
1605#define HCIUARTSETPROTO _IOW('U', 200, int) 1391#define HCIUARTSETPROTO _IOW('U', 200, int)
1606#define HCIUARTGETPROTO _IOR('U', 201, int) 1392#define HCIUARTGETPROTO _IOR('U', 201, int)
@@ -1620,333 +1406,6 @@ static int do_blkgetsize64(unsigned int fd, unsigned int cmd,
1620#define HIDPGETCONNLIST _IOR('H', 210, int) 1406#define HIDPGETCONNLIST _IOR('H', 210, int)
1621#define HIDPGETCONNINFO _IOR('H', 211, int) 1407#define HIDPGETCONNINFO _IOR('H', 211, int)
1622 1408
1623#ifdef CONFIG_BLOCK
1624struct floppy_struct32 {
1625 compat_uint_t size;
1626 compat_uint_t sect;
1627 compat_uint_t head;
1628 compat_uint_t track;
1629 compat_uint_t stretch;
1630 unsigned char gap;
1631 unsigned char rate;
1632 unsigned char spec1;
1633 unsigned char fmt_gap;
1634 const compat_caddr_t name;
1635};
1636
1637struct floppy_drive_params32 {
1638 char cmos;
1639 compat_ulong_t max_dtr;
1640 compat_ulong_t hlt;
1641 compat_ulong_t hut;
1642 compat_ulong_t srt;
1643 compat_ulong_t spinup;
1644 compat_ulong_t spindown;
1645 unsigned char spindown_offset;
1646 unsigned char select_delay;
1647 unsigned char rps;
1648 unsigned char tracks;
1649 compat_ulong_t timeout;
1650 unsigned char interleave_sect;
1651 struct floppy_max_errors max_errors;
1652 char flags;
1653 char read_track;
1654 short autodetect[8];
1655 compat_int_t checkfreq;
1656 compat_int_t native_format;
1657};
1658
1659struct floppy_drive_struct32 {
1660 signed char flags;
1661 compat_ulong_t spinup_date;
1662 compat_ulong_t select_date;
1663 compat_ulong_t first_read_date;
1664 short probed_format;
1665 short track;
1666 short maxblock;
1667 short maxtrack;
1668 compat_int_t generation;
1669 compat_int_t keep_data;
1670 compat_int_t fd_ref;
1671 compat_int_t fd_device;
1672 compat_int_t last_checked;
1673 compat_caddr_t dmabuf;
1674 compat_int_t bufblocks;
1675};
1676
1677struct floppy_fdc_state32 {
1678 compat_int_t spec1;
1679 compat_int_t spec2;
1680 compat_int_t dtr;
1681 unsigned char version;
1682 unsigned char dor;
1683 compat_ulong_t address;
1684 unsigned int rawcmd:2;
1685 unsigned int reset:1;
1686 unsigned int need_configure:1;
1687 unsigned int perp_mode:2;
1688 unsigned int has_fifo:1;
1689 unsigned int driver_version;
1690 unsigned char track[4];
1691};
1692
1693struct floppy_write_errors32 {
1694 unsigned int write_errors;
1695 compat_ulong_t first_error_sector;
1696 compat_int_t first_error_generation;
1697 compat_ulong_t last_error_sector;
1698 compat_int_t last_error_generation;
1699 compat_uint_t badness;
1700};
1701
1702#define FDSETPRM32 _IOW(2, 0x42, struct floppy_struct32)
1703#define FDDEFPRM32 _IOW(2, 0x43, struct floppy_struct32)
1704#define FDGETPRM32 _IOR(2, 0x04, struct floppy_struct32)
1705#define FDSETDRVPRM32 _IOW(2, 0x90, struct floppy_drive_params32)
1706#define FDGETDRVPRM32 _IOR(2, 0x11, struct floppy_drive_params32)
1707#define FDGETDRVSTAT32 _IOR(2, 0x12, struct floppy_drive_struct32)
1708#define FDPOLLDRVSTAT32 _IOR(2, 0x13, struct floppy_drive_struct32)
1709#define FDGETFDCSTAT32 _IOR(2, 0x15, struct floppy_fdc_state32)
1710#define FDWERRORGET32 _IOR(2, 0x17, struct floppy_write_errors32)
1711
1712static struct {
1713 unsigned int cmd32;
1714 unsigned int cmd;
1715} fd_ioctl_trans_table[] = {
1716 { FDSETPRM32, FDSETPRM },
1717 { FDDEFPRM32, FDDEFPRM },
1718 { FDGETPRM32, FDGETPRM },
1719 { FDSETDRVPRM32, FDSETDRVPRM },
1720 { FDGETDRVPRM32, FDGETDRVPRM },
1721 { FDGETDRVSTAT32, FDGETDRVSTAT },
1722 { FDPOLLDRVSTAT32, FDPOLLDRVSTAT },
1723 { FDGETFDCSTAT32, FDGETFDCSTAT },
1724 { FDWERRORGET32, FDWERRORGET }
1725};
1726
1727#define NR_FD_IOCTL_TRANS ARRAY_SIZE(fd_ioctl_trans_table)
1728
1729static int fd_ioctl_trans(unsigned int fd, unsigned int cmd, unsigned long arg)
1730{
1731 mm_segment_t old_fs = get_fs();
1732 void *karg = NULL;
1733 unsigned int kcmd = 0;
1734 int i, err;
1735
1736 for (i = 0; i < NR_FD_IOCTL_TRANS; i++)
1737 if (cmd == fd_ioctl_trans_table[i].cmd32) {
1738 kcmd = fd_ioctl_trans_table[i].cmd;
1739 break;
1740 }
1741 if (!kcmd)
1742 return -EINVAL;
1743
1744 switch (cmd) {
1745 case FDSETPRM32:
1746 case FDDEFPRM32:
1747 case FDGETPRM32:
1748 {
1749 compat_uptr_t name;
1750 struct floppy_struct32 __user *uf;
1751 struct floppy_struct *f;
1752
1753 uf = compat_ptr(arg);
1754 f = karg = kmalloc(sizeof(struct floppy_struct), GFP_KERNEL);
1755 if (!karg)
1756 return -ENOMEM;
1757 if (cmd == FDGETPRM32)
1758 break;
1759 err = __get_user(f->size, &uf->size);
1760 err |= __get_user(f->sect, &uf->sect);
1761 err |= __get_user(f->head, &uf->head);
1762 err |= __get_user(f->track, &uf->track);
1763 err |= __get_user(f->stretch, &uf->stretch);
1764 err |= __get_user(f->gap, &uf->gap);
1765 err |= __get_user(f->rate, &uf->rate);
1766 err |= __get_user(f->spec1, &uf->spec1);
1767 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
1768 err |= __get_user(name, &uf->name);
1769 f->name = compat_ptr(name);
1770 if (err) {
1771 err = -EFAULT;
1772 goto out;
1773 }
1774 break;
1775 }
1776 case FDSETDRVPRM32:
1777 case FDGETDRVPRM32:
1778 {
1779 struct floppy_drive_params32 __user *uf;
1780 struct floppy_drive_params *f;
1781
1782 uf = compat_ptr(arg);
1783 f = karg = kmalloc(sizeof(struct floppy_drive_params), GFP_KERNEL);
1784 if (!karg)
1785 return -ENOMEM;
1786 if (cmd == FDGETDRVPRM32)
1787 break;
1788 err = __get_user(f->cmos, &uf->cmos);
1789 err |= __get_user(f->max_dtr, &uf->max_dtr);
1790 err |= __get_user(f->hlt, &uf->hlt);
1791 err |= __get_user(f->hut, &uf->hut);
1792 err |= __get_user(f->srt, &uf->srt);
1793 err |= __get_user(f->spinup, &uf->spinup);
1794 err |= __get_user(f->spindown, &uf->spindown);
1795 err |= __get_user(f->spindown_offset, &uf->spindown_offset);
1796 err |= __get_user(f->select_delay, &uf->select_delay);
1797 err |= __get_user(f->rps, &uf->rps);
1798 err |= __get_user(f->tracks, &uf->tracks);
1799 err |= __get_user(f->timeout, &uf->timeout);
1800 err |= __get_user(f->interleave_sect, &uf->interleave_sect);
1801 err |= __copy_from_user(&f->max_errors, &uf->max_errors, sizeof(f->max_errors));
1802 err |= __get_user(f->flags, &uf->flags);
1803 err |= __get_user(f->read_track, &uf->read_track);
1804 err |= __copy_from_user(f->autodetect, uf->autodetect, sizeof(f->autodetect));
1805 err |= __get_user(f->checkfreq, &uf->checkfreq);
1806 err |= __get_user(f->native_format, &uf->native_format);
1807 if (err) {
1808 err = -EFAULT;
1809 goto out;
1810 }
1811 break;
1812 }
1813 case FDGETDRVSTAT32:
1814 case FDPOLLDRVSTAT32:
1815 karg = kmalloc(sizeof(struct floppy_drive_struct), GFP_KERNEL);
1816 if (!karg)
1817 return -ENOMEM;
1818 break;
1819 case FDGETFDCSTAT32:
1820 karg = kmalloc(sizeof(struct floppy_fdc_state), GFP_KERNEL);
1821 if (!karg)
1822 return -ENOMEM;
1823 break;
1824 case FDWERRORGET32:
1825 karg = kmalloc(sizeof(struct floppy_write_errors), GFP_KERNEL);
1826 if (!karg)
1827 return -ENOMEM;
1828 break;
1829 default:
1830 return -EINVAL;
1831 }
1832 set_fs (KERNEL_DS);
1833 err = sys_ioctl (fd, kcmd, (unsigned long)karg);
1834 set_fs (old_fs);
1835 if (err)
1836 goto out;
1837 switch (cmd) {
1838 case FDGETPRM32:
1839 {
1840 struct floppy_struct *f = karg;
1841 struct floppy_struct32 __user *uf = compat_ptr(arg);
1842
1843 err = __put_user(f->size, &uf->size);
1844 err |= __put_user(f->sect, &uf->sect);
1845 err |= __put_user(f->head, &uf->head);
1846 err |= __put_user(f->track, &uf->track);
1847 err |= __put_user(f->stretch, &uf->stretch);
1848 err |= __put_user(f->gap, &uf->gap);
1849 err |= __put_user(f->rate, &uf->rate);
1850 err |= __put_user(f->spec1, &uf->spec1);
1851 err |= __put_user(f->fmt_gap, &uf->fmt_gap);
1852 err |= __put_user((u64)f->name, (compat_caddr_t __user *)&uf->name);
1853 break;
1854 }
1855 case FDGETDRVPRM32:
1856 {
1857 struct floppy_drive_params32 __user *uf;
1858 struct floppy_drive_params *f = karg;
1859
1860 uf = compat_ptr(arg);
1861 err = __put_user(f->cmos, &uf->cmos);
1862 err |= __put_user(f->max_dtr, &uf->max_dtr);
1863 err |= __put_user(f->hlt, &uf->hlt);
1864 err |= __put_user(f->hut, &uf->hut);
1865 err |= __put_user(f->srt, &uf->srt);
1866 err |= __put_user(f->spinup, &uf->spinup);
1867 err |= __put_user(f->spindown, &uf->spindown);
1868 err |= __put_user(f->spindown_offset, &uf->spindown_offset);
1869 err |= __put_user(f->select_delay, &uf->select_delay);
1870 err |= __put_user(f->rps, &uf->rps);
1871 err |= __put_user(f->tracks, &uf->tracks);
1872 err |= __put_user(f->timeout, &uf->timeout);
1873 err |= __put_user(f->interleave_sect, &uf->interleave_sect);
1874 err |= __copy_to_user(&uf->max_errors, &f->max_errors, sizeof(f->max_errors));
1875 err |= __put_user(f->flags, &uf->flags);
1876 err |= __put_user(f->read_track, &uf->read_track);
1877 err |= __copy_to_user(uf->autodetect, f->autodetect, sizeof(f->autodetect));
1878 err |= __put_user(f->checkfreq, &uf->checkfreq);
1879 err |= __put_user(f->native_format, &uf->native_format);
1880 break;
1881 }
1882 case FDGETDRVSTAT32:
1883 case FDPOLLDRVSTAT32:
1884 {
1885 struct floppy_drive_struct32 __user *uf;
1886 struct floppy_drive_struct *f = karg;
1887
1888 uf = compat_ptr(arg);
1889 err = __put_user(f->flags, &uf->flags);
1890 err |= __put_user(f->spinup_date, &uf->spinup_date);
1891 err |= __put_user(f->select_date, &uf->select_date);
1892 err |= __put_user(f->first_read_date, &uf->first_read_date);
1893 err |= __put_user(f->probed_format, &uf->probed_format);
1894 err |= __put_user(f->track, &uf->track);
1895 err |= __put_user(f->maxblock, &uf->maxblock);
1896 err |= __put_user(f->maxtrack, &uf->maxtrack);
1897 err |= __put_user(f->generation, &uf->generation);
1898 err |= __put_user(f->keep_data, &uf->keep_data);
1899 err |= __put_user(f->fd_ref, &uf->fd_ref);
1900 err |= __put_user(f->fd_device, &uf->fd_device);
1901 err |= __put_user(f->last_checked, &uf->last_checked);
1902 err |= __put_user((u64)f->dmabuf, &uf->dmabuf);
1903 err |= __put_user((u64)f->bufblocks, &uf->bufblocks);
1904 break;
1905 }
1906 case FDGETFDCSTAT32:
1907 {
1908 struct floppy_fdc_state32 __user *uf;
1909 struct floppy_fdc_state *f = karg;
1910
1911 uf = compat_ptr(arg);
1912 err = __put_user(f->spec1, &uf->spec1);
1913 err |= __put_user(f->spec2, &uf->spec2);
1914 err |= __put_user(f->dtr, &uf->dtr);
1915 err |= __put_user(f->version, &uf->version);
1916 err |= __put_user(f->dor, &uf->dor);
1917 err |= __put_user(f->address, &uf->address);
1918 err |= __copy_to_user((char __user *)&uf->address + sizeof(uf->address),
1919 (char *)&f->address + sizeof(f->address), sizeof(int));
1920 err |= __put_user(f->driver_version, &uf->driver_version);
1921 err |= __copy_to_user(uf->track, f->track, sizeof(f->track));
1922 break;
1923 }
1924 case FDWERRORGET32:
1925 {
1926 struct floppy_write_errors32 __user *uf;
1927 struct floppy_write_errors *f = karg;
1928
1929 uf = compat_ptr(arg);
1930 err = __put_user(f->write_errors, &uf->write_errors);
1931 err |= __put_user(f->first_error_sector, &uf->first_error_sector);
1932 err |= __put_user(f->first_error_generation, &uf->first_error_generation);
1933 err |= __put_user(f->last_error_sector, &uf->last_error_sector);
1934 err |= __put_user(f->last_error_generation, &uf->last_error_generation);
1935 err |= __put_user(f->badness, &uf->badness);
1936 break;
1937 }
1938 default:
1939 break;
1940 }
1941 if (err)
1942 err = -EFAULT;
1943
1944out:
1945 kfree(karg);
1946 return err;
1947}
1948#endif
1949
1950struct mtd_oob_buf32 { 1409struct mtd_oob_buf32 {
1951 u_int32_t start; 1410 u_int32_t start;
1952 u_int32_t length; 1411 u_int32_t length;
@@ -2506,60 +1965,6 @@ COMPATIBLE_IOCTL(FIONREAD) /* This is also TIOCINQ */
2506/* 0x00 */ 1965/* 0x00 */
2507COMPATIBLE_IOCTL(FIBMAP) 1966COMPATIBLE_IOCTL(FIBMAP)
2508COMPATIBLE_IOCTL(FIGETBSZ) 1967COMPATIBLE_IOCTL(FIGETBSZ)
2509/* 0x03 -- HD/IDE ioctl's used by hdparm and friends.
2510 * Some need translations, these do not.
2511 */
2512COMPATIBLE_IOCTL(HDIO_GET_IDENTITY)
2513COMPATIBLE_IOCTL(HDIO_DRIVE_TASK)
2514COMPATIBLE_IOCTL(HDIO_DRIVE_CMD)
2515ULONG_IOCTL(HDIO_SET_MULTCOUNT)
2516ULONG_IOCTL(HDIO_SET_UNMASKINTR)
2517ULONG_IOCTL(HDIO_SET_KEEPSETTINGS)
2518ULONG_IOCTL(HDIO_SET_32BIT)
2519ULONG_IOCTL(HDIO_SET_NOWERR)
2520ULONG_IOCTL(HDIO_SET_DMA)
2521ULONG_IOCTL(HDIO_SET_PIO_MODE)
2522ULONG_IOCTL(HDIO_SET_NICE)
2523ULONG_IOCTL(HDIO_SET_WCACHE)
2524ULONG_IOCTL(HDIO_SET_ACOUSTIC)
2525ULONG_IOCTL(HDIO_SET_BUSSTATE)
2526ULONG_IOCTL(HDIO_SET_ADDRESS)
2527COMPATIBLE_IOCTL(HDIO_SCAN_HWIF)
2528/* 0x330 is reserved -- it used to be HDIO_GETGEO_BIG */
2529COMPATIBLE_IOCTL(0x330)
2530/* 0x02 -- Floppy ioctls */
2531COMPATIBLE_IOCTL(FDMSGON)
2532COMPATIBLE_IOCTL(FDMSGOFF)
2533COMPATIBLE_IOCTL(FDSETEMSGTRESH)
2534COMPATIBLE_IOCTL(FDFLUSH)
2535COMPATIBLE_IOCTL(FDWERRORCLR)
2536COMPATIBLE_IOCTL(FDSETMAXERRS)
2537COMPATIBLE_IOCTL(FDGETMAXERRS)
2538COMPATIBLE_IOCTL(FDGETDRVTYP)
2539COMPATIBLE_IOCTL(FDEJECT)
2540COMPATIBLE_IOCTL(FDCLRPRM)
2541COMPATIBLE_IOCTL(FDFMTBEG)
2542COMPATIBLE_IOCTL(FDFMTEND)
2543COMPATIBLE_IOCTL(FDRESET)
2544COMPATIBLE_IOCTL(FDTWADDLE)
2545COMPATIBLE_IOCTL(FDFMTTRK)
2546COMPATIBLE_IOCTL(FDRAWCMD)
2547/* 0x12 */
2548#ifdef CONFIG_BLOCK
2549COMPATIBLE_IOCTL(BLKRASET)
2550COMPATIBLE_IOCTL(BLKROSET)
2551COMPATIBLE_IOCTL(BLKROGET)
2552COMPATIBLE_IOCTL(BLKRRPART)
2553COMPATIBLE_IOCTL(BLKFLSBUF)
2554COMPATIBLE_IOCTL(BLKSECTSET)
2555COMPATIBLE_IOCTL(BLKSSZGET)
2556COMPATIBLE_IOCTL(BLKTRACESTART)
2557COMPATIBLE_IOCTL(BLKTRACESTOP)
2558COMPATIBLE_IOCTL(BLKTRACESETUP)
2559COMPATIBLE_IOCTL(BLKTRACETEARDOWN)
2560ULONG_IOCTL(BLKRASET)
2561ULONG_IOCTL(BLKFRASET)
2562#endif
2563/* RAID */ 1968/* RAID */
2564COMPATIBLE_IOCTL(RAID_VERSION) 1969COMPATIBLE_IOCTL(RAID_VERSION)
2565COMPATIBLE_IOCTL(GET_ARRAY_INFO) 1970COMPATIBLE_IOCTL(GET_ARRAY_INFO)
@@ -2807,50 +2212,6 @@ COMPATIBLE_IOCTL(PPGETMODE)
2807COMPATIBLE_IOCTL(PPGETPHASE) 2212COMPATIBLE_IOCTL(PPGETPHASE)
2808COMPATIBLE_IOCTL(PPGETFLAGS) 2213COMPATIBLE_IOCTL(PPGETFLAGS)
2809COMPATIBLE_IOCTL(PPSETFLAGS) 2214COMPATIBLE_IOCTL(PPSETFLAGS)
2810/* CDROM stuff */
2811COMPATIBLE_IOCTL(CDROMPAUSE)
2812COMPATIBLE_IOCTL(CDROMRESUME)
2813COMPATIBLE_IOCTL(CDROMPLAYMSF)
2814COMPATIBLE_IOCTL(CDROMPLAYTRKIND)
2815COMPATIBLE_IOCTL(CDROMREADTOCHDR)
2816COMPATIBLE_IOCTL(CDROMREADTOCENTRY)
2817COMPATIBLE_IOCTL(CDROMSTOP)
2818COMPATIBLE_IOCTL(CDROMSTART)
2819COMPATIBLE_IOCTL(CDROMEJECT)
2820COMPATIBLE_IOCTL(CDROMVOLCTRL)
2821COMPATIBLE_IOCTL(CDROMSUBCHNL)
2822ULONG_IOCTL(CDROMEJECT_SW)
2823COMPATIBLE_IOCTL(CDROMMULTISESSION)
2824COMPATIBLE_IOCTL(CDROM_GET_MCN)
2825COMPATIBLE_IOCTL(CDROMRESET)
2826COMPATIBLE_IOCTL(CDROMVOLREAD)
2827COMPATIBLE_IOCTL(CDROMSEEK)
2828COMPATIBLE_IOCTL(CDROMPLAYBLK)
2829COMPATIBLE_IOCTL(CDROMCLOSETRAY)
2830ULONG_IOCTL(CDROM_SET_OPTIONS)
2831ULONG_IOCTL(CDROM_CLEAR_OPTIONS)
2832ULONG_IOCTL(CDROM_SELECT_SPEED)
2833ULONG_IOCTL(CDROM_SELECT_DISC)
2834ULONG_IOCTL(CDROM_MEDIA_CHANGED)
2835ULONG_IOCTL(CDROM_DRIVE_STATUS)
2836COMPATIBLE_IOCTL(CDROM_DISC_STATUS)
2837COMPATIBLE_IOCTL(CDROM_CHANGER_NSLOTS)
2838ULONG_IOCTL(CDROM_LOCKDOOR)
2839ULONG_IOCTL(CDROM_DEBUG)
2840COMPATIBLE_IOCTL(CDROM_GET_CAPABILITY)
2841/* Ignore cdrom.h about these next 5 ioctls, they absolutely do
2842 * not take a struct cdrom_read, instead they take a struct cdrom_msf
2843 * which is compatible.
2844 */
2845COMPATIBLE_IOCTL(CDROMREADMODE2)
2846COMPATIBLE_IOCTL(CDROMREADMODE1)
2847COMPATIBLE_IOCTL(CDROMREADRAW)
2848COMPATIBLE_IOCTL(CDROMREADCOOKED)
2849COMPATIBLE_IOCTL(CDROMREADALL)
2850/* DVD ioctls */
2851COMPATIBLE_IOCTL(DVD_READ_STRUCT)
2852COMPATIBLE_IOCTL(DVD_WRITE_STRUCT)
2853COMPATIBLE_IOCTL(DVD_AUTH)
2854/* pktcdvd */ 2215/* pktcdvd */
2855COMPATIBLE_IOCTL(PACKET_CTRL_CMD) 2216COMPATIBLE_IOCTL(PACKET_CTRL_CMD)
2856/* Big A */ 2217/* Big A */
@@ -3336,33 +2697,6 @@ HANDLE_IOCTL(SIOCGSTAMP, do_siocgstamp)
3336HANDLE_IOCTL(SIOCGSTAMPNS, do_siocgstampns) 2697HANDLE_IOCTL(SIOCGSTAMPNS, do_siocgstampns)
3337#endif 2698#endif
3338#ifdef CONFIG_BLOCK 2699#ifdef CONFIG_BLOCK
3339HANDLE_IOCTL(HDIO_GETGEO, hdio_getgeo)
3340HANDLE_IOCTL(BLKRAGET, w_long)
3341HANDLE_IOCTL(BLKGETSIZE, w_long)
3342HANDLE_IOCTL(0x1260, broken_blkgetsize)
3343HANDLE_IOCTL(BLKFRAGET, w_long)
3344HANDLE_IOCTL(BLKSECTGET, w_long)
3345HANDLE_IOCTL(BLKPG, blkpg_ioctl_trans)
3346HANDLE_IOCTL(HDIO_GET_UNMASKINTR, hdio_ioctl_trans)
3347HANDLE_IOCTL(HDIO_GET_MULTCOUNT, hdio_ioctl_trans)
3348HANDLE_IOCTL(HDIO_GET_KEEPSETTINGS, hdio_ioctl_trans)
3349HANDLE_IOCTL(HDIO_GET_32BIT, hdio_ioctl_trans)
3350HANDLE_IOCTL(HDIO_GET_NOWERR, hdio_ioctl_trans)
3351HANDLE_IOCTL(HDIO_GET_DMA, hdio_ioctl_trans)
3352HANDLE_IOCTL(HDIO_GET_NICE, hdio_ioctl_trans)
3353HANDLE_IOCTL(HDIO_GET_WCACHE, hdio_ioctl_trans)
3354HANDLE_IOCTL(HDIO_GET_ACOUSTIC, hdio_ioctl_trans)
3355HANDLE_IOCTL(HDIO_GET_ADDRESS, hdio_ioctl_trans)
3356HANDLE_IOCTL(HDIO_GET_BUSSTATE, hdio_ioctl_trans)
3357HANDLE_IOCTL(FDSETPRM32, fd_ioctl_trans)
3358HANDLE_IOCTL(FDDEFPRM32, fd_ioctl_trans)
3359HANDLE_IOCTL(FDGETPRM32, fd_ioctl_trans)
3360HANDLE_IOCTL(FDSETDRVPRM32, fd_ioctl_trans)
3361HANDLE_IOCTL(FDGETDRVPRM32, fd_ioctl_trans)
3362HANDLE_IOCTL(FDGETDRVSTAT32, fd_ioctl_trans)
3363HANDLE_IOCTL(FDPOLLDRVSTAT32, fd_ioctl_trans)
3364HANDLE_IOCTL(FDGETFDCSTAT32, fd_ioctl_trans)
3365HANDLE_IOCTL(FDWERRORGET32, fd_ioctl_trans)
3366HANDLE_IOCTL(SG_IO,sg_ioctl_trans) 2700HANDLE_IOCTL(SG_IO,sg_ioctl_trans)
3367HANDLE_IOCTL(SG_GET_REQUEST_TABLE, sg_grt_trans) 2701HANDLE_IOCTL(SG_GET_REQUEST_TABLE, sg_grt_trans)
3368#endif 2702#endif
@@ -3373,8 +2707,6 @@ HANDLE_IOCTL(PPPIOCSACTIVE32, ppp_sock_fprog_ioctl_trans)
3373#ifdef CONFIG_BLOCK 2707#ifdef CONFIG_BLOCK
3374HANDLE_IOCTL(MTIOCGET32, mt_ioctl_trans) 2708HANDLE_IOCTL(MTIOCGET32, mt_ioctl_trans)
3375HANDLE_IOCTL(MTIOCPOS32, mt_ioctl_trans) 2709HANDLE_IOCTL(MTIOCPOS32, mt_ioctl_trans)
3376HANDLE_IOCTL(CDROMREADAUDIO, cdrom_ioctl_trans)
3377HANDLE_IOCTL(CDROM_SEND_PACKET, cdrom_ioctl_trans)
3378#endif 2710#endif
3379#define AUTOFS_IOC_SETTIMEOUT32 _IOWR(0x93,0x64,unsigned int) 2711#define AUTOFS_IOC_SETTIMEOUT32 _IOWR(0x93,0x64,unsigned int)
3380HANDLE_IOCTL(AUTOFS_IOC_SETTIMEOUT32, ioc_settimeout) 2712HANDLE_IOCTL(AUTOFS_IOC_SETTIMEOUT32, ioc_settimeout)
@@ -3415,9 +2747,6 @@ HANDLE_IOCTL(SONET_GETFRAMING, do_atm_ioctl)
3415HANDLE_IOCTL(SONET_GETFRSENSE, do_atm_ioctl) 2747HANDLE_IOCTL(SONET_GETFRSENSE, do_atm_ioctl)
3416/* block stuff */ 2748/* block stuff */
3417#ifdef CONFIG_BLOCK 2749#ifdef CONFIG_BLOCK
3418HANDLE_IOCTL(BLKBSZGET_32, do_blkbszget)
3419HANDLE_IOCTL(BLKBSZSET_32, do_blkbszset)
3420HANDLE_IOCTL(BLKGETSIZE64_32, do_blkgetsize64)
3421/* Raw devices */ 2750/* Raw devices */
3422HANDLE_IOCTL(RAW_SETBIND, raw_ioctl) 2751HANDLE_IOCTL(RAW_SETBIND, raw_ioctl)
3423HANDLE_IOCTL(RAW_GETBIND, raw_ioctl) 2752HANDLE_IOCTL(RAW_GETBIND, raw_ioctl)
diff --git a/fs/direct-io.c b/fs/direct-io.c
index 901dc55e9f54..b5928a7b6a5a 100644
--- a/fs/direct-io.c
+++ b/fs/direct-io.c
@@ -264,15 +264,12 @@ static int dio_bio_complete(struct dio *dio, struct bio *bio);
264/* 264/*
265 * Asynchronous IO callback. 265 * Asynchronous IO callback.
266 */ 266 */
267static int dio_bio_end_aio(struct bio *bio, unsigned int bytes_done, int error) 267static void dio_bio_end_aio(struct bio *bio, int error)
268{ 268{
269 struct dio *dio = bio->bi_private; 269 struct dio *dio = bio->bi_private;
270 unsigned long remaining; 270 unsigned long remaining;
271 unsigned long flags; 271 unsigned long flags;
272 272
273 if (bio->bi_size)
274 return 1;
275
276 /* cleanup the bio */ 273 /* cleanup the bio */
277 dio_bio_complete(dio, bio); 274 dio_bio_complete(dio, bio);
278 275
@@ -287,8 +284,6 @@ static int dio_bio_end_aio(struct bio *bio, unsigned int bytes_done, int error)
287 aio_complete(dio->iocb, ret, 0); 284 aio_complete(dio->iocb, ret, 0);
288 kfree(dio); 285 kfree(dio);
289 } 286 }
290
291 return 0;
292} 287}
293 288
294/* 289/*
@@ -298,21 +293,17 @@ static int dio_bio_end_aio(struct bio *bio, unsigned int bytes_done, int error)
298 * During I/O bi_private points at the dio. After I/O, bi_private is used to 293 * During I/O bi_private points at the dio. After I/O, bi_private is used to
299 * implement a singly-linked list of completed BIOs, at dio->bio_list. 294 * implement a singly-linked list of completed BIOs, at dio->bio_list.
300 */ 295 */
301static int dio_bio_end_io(struct bio *bio, unsigned int bytes_done, int error) 296static void dio_bio_end_io(struct bio *bio, int error)
302{ 297{
303 struct dio *dio = bio->bi_private; 298 struct dio *dio = bio->bi_private;
304 unsigned long flags; 299 unsigned long flags;
305 300
306 if (bio->bi_size)
307 return 1;
308
309 spin_lock_irqsave(&dio->bio_lock, flags); 301 spin_lock_irqsave(&dio->bio_lock, flags);
310 bio->bi_private = dio->bio_list; 302 bio->bi_private = dio->bio_list;
311 dio->bio_list = bio; 303 dio->bio_list = bio;
312 if (--dio->refcount == 1 && dio->waiter) 304 if (--dio->refcount == 1 && dio->waiter)
313 wake_up_process(dio->waiter); 305 wake_up_process(dio->waiter);
314 spin_unlock_irqrestore(&dio->bio_lock, flags); 306 spin_unlock_irqrestore(&dio->bio_lock, flags);
315 return 0;
316} 307}
317 308
318static int 309static int
diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
index a4b142a6a2c7..8d23b0b38717 100644
--- a/fs/fs-writeback.c
+++ b/fs/fs-writeback.c
@@ -14,6 +14,7 @@
14 */ 14 */
15 15
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/module.h>
17#include <linux/spinlock.h> 18#include <linux/spinlock.h>
18#include <linux/sched.h> 19#include <linux/sched.h>
19#include <linux/fs.h> 20#include <linux/fs.h>
diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c
index f916b9740c75..2473e2a86d1b 100644
--- a/fs/gfs2/super.c
+++ b/fs/gfs2/super.c
@@ -160,11 +160,9 @@ int gfs2_check_sb(struct gfs2_sbd *sdp, struct gfs2_sb_host *sb, int silent)
160} 160}
161 161
162 162
163static int end_bio_io_page(struct bio *bio, unsigned int bytes_done, int error) 163static void end_bio_io_page(struct bio *bio, int error)
164{ 164{
165 struct page *page = bio->bi_private; 165 struct page *page = bio->bi_private;
166 if (bio->bi_size)
167 return 1;
168 166
169 if (!error) 167 if (!error)
170 SetPageUptodate(page); 168 SetPageUptodate(page);
diff --git a/fs/jfs/jfs_logmgr.c b/fs/jfs/jfs_logmgr.c
index de3e4a506dbc..57c3b8ac36bf 100644
--- a/fs/jfs/jfs_logmgr.c
+++ b/fs/jfs/jfs_logmgr.c
@@ -2200,16 +2200,13 @@ static int lbmIOWait(struct lbuf * bp, int flag)
2200 * 2200 *
2201 * executed at INTIODONE level 2201 * executed at INTIODONE level
2202 */ 2202 */
2203static int lbmIODone(struct bio *bio, unsigned int bytes_done, int error) 2203static void lbmIODone(struct bio *bio, int error)
2204{ 2204{
2205 struct lbuf *bp = bio->bi_private; 2205 struct lbuf *bp = bio->bi_private;
2206 struct lbuf *nextbp, *tail; 2206 struct lbuf *nextbp, *tail;
2207 struct jfs_log *log; 2207 struct jfs_log *log;
2208 unsigned long flags; 2208 unsigned long flags;
2209 2209
2210 if (bio->bi_size)
2211 return 1;
2212
2213 /* 2210 /*
2214 * get back jfs buffer bound to the i/o buffer 2211 * get back jfs buffer bound to the i/o buffer
2215 */ 2212 */
diff --git a/fs/jfs/jfs_metapage.c b/fs/jfs/jfs_metapage.c
index 62e96be02acf..1332adc0b9fa 100644
--- a/fs/jfs/jfs_metapage.c
+++ b/fs/jfs/jfs_metapage.c
@@ -280,14 +280,10 @@ static void last_read_complete(struct page *page)
280 unlock_page(page); 280 unlock_page(page);
281} 281}
282 282
283static int metapage_read_end_io(struct bio *bio, unsigned int bytes_done, 283static void metapage_read_end_io(struct bio *bio, int err)
284 int err)
285{ 284{
286 struct page *page = bio->bi_private; 285 struct page *page = bio->bi_private;
287 286
288 if (bio->bi_size)
289 return 1;
290
291 if (!test_bit(BIO_UPTODATE, &bio->bi_flags)) { 287 if (!test_bit(BIO_UPTODATE, &bio->bi_flags)) {
292 printk(KERN_ERR "metapage_read_end_io: I/O error\n"); 288 printk(KERN_ERR "metapage_read_end_io: I/O error\n");
293 SetPageError(page); 289 SetPageError(page);
@@ -341,16 +337,12 @@ static void last_write_complete(struct page *page)
341 end_page_writeback(page); 337 end_page_writeback(page);
342} 338}
343 339
344static int metapage_write_end_io(struct bio *bio, unsigned int bytes_done, 340static void metapage_write_end_io(struct bio *bio, int err)
345 int err)
346{ 341{
347 struct page *page = bio->bi_private; 342 struct page *page = bio->bi_private;
348 343
349 BUG_ON(!PagePrivate(page)); 344 BUG_ON(!PagePrivate(page));
350 345
351 if (bio->bi_size)
352 return 1;
353
354 if (! test_bit(BIO_UPTODATE, &bio->bi_flags)) { 346 if (! test_bit(BIO_UPTODATE, &bio->bi_flags)) {
355 printk(KERN_ERR "metapage_write_end_io: I/O error\n"); 347 printk(KERN_ERR "metapage_write_end_io: I/O error\n");
356 SetPageError(page); 348 SetPageError(page);
diff --git a/fs/mpage.c b/fs/mpage.c
index c1698f2291aa..b1c3e5890508 100644
--- a/fs/mpage.c
+++ b/fs/mpage.c
@@ -39,14 +39,11 @@
39 * status of that page is hard. See end_buffer_async_read() for the details. 39 * status of that page is hard. See end_buffer_async_read() for the details.
40 * There is no point in duplicating all that complexity. 40 * There is no point in duplicating all that complexity.
41 */ 41 */
42static int mpage_end_io_read(struct bio *bio, unsigned int bytes_done, int err) 42static void mpage_end_io_read(struct bio *bio, int err)
43{ 43{
44 const int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); 44 const int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags);
45 struct bio_vec *bvec = bio->bi_io_vec + bio->bi_vcnt - 1; 45 struct bio_vec *bvec = bio->bi_io_vec + bio->bi_vcnt - 1;
46 46
47 if (bio->bi_size)
48 return 1;
49
50 do { 47 do {
51 struct page *page = bvec->bv_page; 48 struct page *page = bvec->bv_page;
52 49
@@ -62,17 +59,13 @@ static int mpage_end_io_read(struct bio *bio, unsigned int bytes_done, int err)
62 unlock_page(page); 59 unlock_page(page);
63 } while (bvec >= bio->bi_io_vec); 60 } while (bvec >= bio->bi_io_vec);
64 bio_put(bio); 61 bio_put(bio);
65 return 0;
66} 62}
67 63
68static int mpage_end_io_write(struct bio *bio, unsigned int bytes_done, int err) 64static void mpage_end_io_write(struct bio *bio, int err)
69{ 65{
70 const int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); 66 const int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags);
71 struct bio_vec *bvec = bio->bi_io_vec + bio->bi_vcnt - 1; 67 struct bio_vec *bvec = bio->bi_io_vec + bio->bi_vcnt - 1;
72 68
73 if (bio->bi_size)
74 return 1;
75
76 do { 69 do {
77 struct page *page = bvec->bv_page; 70 struct page *page = bvec->bv_page;
78 71
@@ -87,7 +80,6 @@ static int mpage_end_io_write(struct bio *bio, unsigned int bytes_done, int err)
87 end_page_writeback(page); 80 end_page_writeback(page);
88 } while (bvec >= bio->bi_io_vec); 81 } while (bvec >= bio->bi_io_vec);
89 bio_put(bio); 82 bio_put(bio);
90 return 0;
91} 83}
92 84
93static struct bio *mpage_bio_submit(int rw, struct bio *bio) 85static struct bio *mpage_bio_submit(int rw, struct bio *bio)
diff --git a/fs/ocfs2/cluster/heartbeat.c b/fs/ocfs2/cluster/heartbeat.c
index 2bd7f788cf34..da2c2b442b49 100644
--- a/fs/ocfs2/cluster/heartbeat.c
+++ b/fs/ocfs2/cluster/heartbeat.c
@@ -217,7 +217,6 @@ static void o2hb_wait_on_io(struct o2hb_region *reg,
217} 217}
218 218
219static int o2hb_bio_end_io(struct bio *bio, 219static int o2hb_bio_end_io(struct bio *bio,
220 unsigned int bytes_done,
221 int error) 220 int error)
222{ 221{
223 struct o2hb_bio_wait_ctxt *wc = bio->bi_private; 222 struct o2hb_bio_wait_ctxt *wc = bio->bi_private;
@@ -227,9 +226,6 @@ static int o2hb_bio_end_io(struct bio *bio,
227 wc->wc_error = error; 226 wc->wc_error = error;
228 } 227 }
229 228
230 if (bio->bi_size)
231 return 1;
232
233 o2hb_bio_wait_dec(wc, 1); 229 o2hb_bio_wait_dec(wc, 1);
234 bio_put(bio); 230 bio_put(bio);
235 return 0; 231 return 0;
diff --git a/fs/xfs/linux-2.6/xfs_aops.c b/fs/xfs/linux-2.6/xfs_aops.c
index 5f152f60d74d..3f13519436af 100644
--- a/fs/xfs/linux-2.6/xfs_aops.c
+++ b/fs/xfs/linux-2.6/xfs_aops.c
@@ -326,14 +326,10 @@ xfs_iomap_valid(
326STATIC int 326STATIC int
327xfs_end_bio( 327xfs_end_bio(
328 struct bio *bio, 328 struct bio *bio,
329 unsigned int bytes_done,
330 int error) 329 int error)
331{ 330{
332 xfs_ioend_t *ioend = bio->bi_private; 331 xfs_ioend_t *ioend = bio->bi_private;
333 332
334 if (bio->bi_size)
335 return 1;
336
337 ASSERT(atomic_read(&bio->bi_cnt) >= 1); 333 ASSERT(atomic_read(&bio->bi_cnt) >= 1);
338 ioend->io_error = test_bit(BIO_UPTODATE, &bio->bi_flags) ? 0 : error; 334 ioend->io_error = test_bit(BIO_UPTODATE, &bio->bi_flags) ? 0 : error;
339 335
diff --git a/fs/xfs/linux-2.6/xfs_buf.c b/fs/xfs/linux-2.6/xfs_buf.c
index b0f0e58866de..6a75f4d984a1 100644
--- a/fs/xfs/linux-2.6/xfs_buf.c
+++ b/fs/xfs/linux-2.6/xfs_buf.c
@@ -1106,16 +1106,12 @@ _xfs_buf_ioend(
1106STATIC int 1106STATIC int
1107xfs_buf_bio_end_io( 1107xfs_buf_bio_end_io(
1108 struct bio *bio, 1108 struct bio *bio,
1109 unsigned int bytes_done,
1110 int error) 1109 int error)
1111{ 1110{
1112 xfs_buf_t *bp = (xfs_buf_t *)bio->bi_private; 1111 xfs_buf_t *bp = (xfs_buf_t *)bio->bi_private;
1113 unsigned int blocksize = bp->b_target->bt_bsize; 1112 unsigned int blocksize = bp->b_target->bt_bsize;
1114 struct bio_vec *bvec = bio->bi_io_vec + bio->bi_vcnt - 1; 1113 struct bio_vec *bvec = bio->bi_io_vec + bio->bi_vcnt - 1;
1115 1114
1116 if (bio->bi_size)
1117 return 1;
1118
1119 if (!test_bit(BIO_UPTODATE, &bio->bi_flags)) 1115 if (!test_bit(BIO_UPTODATE, &bio->bi_flags))
1120 bp->b_error = EIO; 1116 bp->b_error = EIO;
1121 1117
diff --git a/include/asm-arm/arch-imx/mmc.h b/include/asm-arm/arch-imx/mmc.h
index 84c726934ace..4712f354dcca 100644
--- a/include/asm-arm/arch-imx/mmc.h
+++ b/include/asm-arm/arch-imx/mmc.h
@@ -3,8 +3,11 @@
3 3
4#include <linux/mmc/host.h> 4#include <linux/mmc/host.h>
5 5
6struct device;
7
6struct imxmmc_platform_data { 8struct imxmmc_platform_data {
7 int (*card_present)(void); 9 int (*card_present)(struct device *);
10 int (*get_ro)(struct device *);
8}; 11};
9 12
10extern void imx_set_mmc_info(struct imxmmc_platform_data *info); 13extern void imx_set_mmc_info(struct imxmmc_platform_data *info);
diff --git a/include/asm-avr32/arch-at32ap/board.h b/include/asm-avr32/arch-at32ap/board.h
index 0215965dc586..7dbd603c38cc 100644
--- a/include/asm-avr32/arch-at32ap/board.h
+++ b/include/asm-avr32/arch-at32ap/board.h
@@ -6,6 +6,8 @@
6 6
7#include <linux/types.h> 7#include <linux/types.h>
8 8
9#define GPIO_PIN_NONE (-1)
10
9/* Add basic devices: system manager, interrupt controller, portmuxes, etc. */ 11/* Add basic devices: system manager, interrupt controller, portmuxes, etc. */
10void at32_add_system_devices(void); 12void at32_add_system_devices(void);
11 13
@@ -36,6 +38,12 @@ struct platform_device *
36at32_add_device_lcdc(unsigned int id, struct atmel_lcdfb_info *data, 38at32_add_device_lcdc(unsigned int id, struct atmel_lcdfb_info *data,
37 unsigned long fbmem_start, unsigned long fbmem_len); 39 unsigned long fbmem_start, unsigned long fbmem_len);
38 40
41struct usba_platform_data {
42 int vbus_pin;
43};
44struct platform_device *
45at32_add_device_usba(unsigned int id, struct usba_platform_data *data);
46
39/* depending on what's hooked up, not all SSC pins will be used */ 47/* depending on what's hooked up, not all SSC pins will be used */
40#define ATMEL_SSC_TK 0x01 48#define ATMEL_SSC_TK 0x01
41#define ATMEL_SSC_TF 0x02 49#define ATMEL_SSC_TF 0x02
diff --git a/include/asm-avr32/arch-at32ap/portmux.h b/include/asm-avr32/arch-at32ap/portmux.h
index 9930871decde..b1abe6b4e4ef 100644
--- a/include/asm-avr32/arch-at32ap/portmux.h
+++ b/include/asm-avr32/arch-at32ap/portmux.h
@@ -19,6 +19,7 @@
19#define AT32_GPIOF_OUTPUT 0x00000002 /* (OUT) Enable output driver */ 19#define AT32_GPIOF_OUTPUT 0x00000002 /* (OUT) Enable output driver */
20#define AT32_GPIOF_HIGH 0x00000004 /* (OUT) Set output high */ 20#define AT32_GPIOF_HIGH 0x00000004 /* (OUT) Set output high */
21#define AT32_GPIOF_DEGLITCH 0x00000008 /* (IN) Filter glitches */ 21#define AT32_GPIOF_DEGLITCH 0x00000008 /* (IN) Filter glitches */
22#define AT32_GPIOF_MULTIDRV 0x00000010 /* Enable multidriver option */
22 23
23void at32_select_periph(unsigned int pin, unsigned int periph, 24void at32_select_periph(unsigned int pin, unsigned int periph,
24 unsigned long flags); 25 unsigned long flags);
diff --git a/include/asm-avr32/arch-at32ap/smc.h b/include/asm-avr32/arch-at32ap/smc.h
index 07152b7fd9c9..c98eea44a70a 100644
--- a/include/asm-avr32/arch-at32ap/smc.h
+++ b/include/asm-avr32/arch-at32ap/smc.h
@@ -15,22 +15,50 @@
15/* 15/*
16 * All timing parameters are in nanoseconds. 16 * All timing parameters are in nanoseconds.
17 */ 17 */
18struct smc_timing {
19 /* Delay from address valid to assertion of given strobe */
20 int ncs_read_setup;
21 int nrd_setup;
22 int ncs_write_setup;
23 int nwe_setup;
24
25 /* Pulse length of given strobe */
26 int ncs_read_pulse;
27 int nrd_pulse;
28 int ncs_write_pulse;
29 int nwe_pulse;
30
31 /* Total cycle length of given operation */
32 int read_cycle;
33 int write_cycle;
34
35 /* Minimal recovery times, will extend cycle if needed */
36 int ncs_read_recover;
37 int nrd_recover;
38 int ncs_write_recover;
39 int nwe_recover;
40};
41
42/*
43 * All timing parameters are in clock cycles.
44 */
18struct smc_config { 45struct smc_config {
46
19 /* Delay from address valid to assertion of given strobe */ 47 /* Delay from address valid to assertion of given strobe */
20 u16 ncs_read_setup; 48 u8 ncs_read_setup;
21 u16 nrd_setup; 49 u8 nrd_setup;
22 u16 ncs_write_setup; 50 u8 ncs_write_setup;
23 u16 nwe_setup; 51 u8 nwe_setup;
24 52
25 /* Pulse length of given strobe */ 53 /* Pulse length of given strobe */
26 u16 ncs_read_pulse; 54 u8 ncs_read_pulse;
27 u16 nrd_pulse; 55 u8 nrd_pulse;
28 u16 ncs_write_pulse; 56 u8 ncs_write_pulse;
29 u16 nwe_pulse; 57 u8 nwe_pulse;
30 58
31 /* Total cycle length of given operation */ 59 /* Total cycle length of given operation */
32 u16 read_cycle; 60 u8 read_cycle;
33 u16 write_cycle; 61 u8 write_cycle;
34 62
35 /* Bus width in bytes */ 63 /* Bus width in bytes */
36 u8 bus_width; 64 u8 bus_width;
@@ -76,6 +104,9 @@ struct smc_config {
76 unsigned int tdf_mode:1; 104 unsigned int tdf_mode:1;
77}; 105};
78 106
107extern void smc_set_timing(struct smc_config *config,
108 const struct smc_timing *timing);
109
79extern int smc_set_configuration(int cs, const struct smc_config *config); 110extern int smc_set_configuration(int cs, const struct smc_config *config);
80extern struct smc_config *smc_get_configuration(int cs); 111extern struct smc_config *smc_get_configuration(int cs);
81 112
diff --git a/include/asm-avr32/dma-mapping.h b/include/asm-avr32/dma-mapping.h
index 21bb60bbb9a1..81e342636ac4 100644
--- a/include/asm-avr32/dma-mapping.h
+++ b/include/asm-avr32/dma-mapping.h
@@ -264,7 +264,11 @@ static inline void
264dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle, 264dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle,
265 size_t size, enum dma_data_direction direction) 265 size_t size, enum dma_data_direction direction)
266{ 266{
267 dma_cache_sync(dev, bus_to_virt(dma_handle), size, direction); 267 /*
268 * No need to do anything since the CPU isn't supposed to
269 * touch this memory after we flushed it at mapping- or
270 * sync-for-device time.
271 */
268} 272}
269 273
270static inline void 274static inline void
@@ -309,12 +313,11 @@ static inline void
309dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, 313dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
310 int nents, enum dma_data_direction direction) 314 int nents, enum dma_data_direction direction)
311{ 315{
312 int i; 316 /*
313 317 * No need to do anything since the CPU isn't supposed to
314 for (i = 0; i < nents; i++) { 318 * touch this memory after we flushed it at mapping- or
315 dma_cache_sync(dev, page_address(sg[i].page) + sg[i].offset, 319 * sync-for-device time.
316 sg[i].length, direction); 320 */
317 }
318} 321}
319 322
320static inline void 323static inline void
diff --git a/include/asm-avr32/system.h b/include/asm-avr32/system.h
index a8236bacc878..dc2d527cef41 100644
--- a/include/asm-avr32/system.h
+++ b/include/asm-avr32/system.h
@@ -73,11 +73,16 @@ extern struct task_struct *__switch_to(struct task_struct *,
73 73
74extern void __xchg_called_with_bad_pointer(void); 74extern void __xchg_called_with_bad_pointer(void);
75 75
76#ifdef __CHECKER__ 76static inline unsigned long xchg_u32(u32 val, volatile u32 *m)
77extern unsigned long __builtin_xchg(void *ptr, unsigned long x); 77{
78#endif 78 u32 ret;
79 79
80#define xchg_u32(val, m) __builtin_xchg((void *)m, val) 80 asm volatile("xchg %[ret], %[m], %[val]"
81 : [ret] "=&r"(ret), "=m"(*m)
82 : "m"(*m), [m] "r"(m), [val] "r"(val)
83 : "memory");
84 return ret;
85}
81 86
82static inline unsigned long __xchg(unsigned long x, 87static inline unsigned long __xchg(unsigned long x,
83 volatile void *ptr, 88 volatile void *ptr,
diff --git a/include/asm-avr32/unistd.h b/include/asm-avr32/unistd.h
index 3b4e35b55c82..de09009593f8 100644
--- a/include/asm-avr32/unistd.h
+++ b/include/asm-avr32/unistd.h
@@ -303,6 +303,19 @@
303#ifdef __KERNEL__ 303#ifdef __KERNEL__
304#define NR_syscalls 282 304#define NR_syscalls 282
305 305
306/* Old stuff */
307#define __IGNORE_uselib
308#define __IGNORE_mmap
309
310/* NUMA stuff */
311#define __IGNORE_mbind
312#define __IGNORE_get_mempolicy
313#define __IGNORE_set_mempolicy
314#define __IGNORE_migrate_pages
315#define __IGNORE_move_pages
316
317/* SMP stuff */
318#define __IGNORE_getcpu
306 319
307#define __ARCH_WANT_IPC_PARSE_VERSION 320#define __ARCH_WANT_IPC_PARSE_VERSION
308#define __ARCH_WANT_STAT64 321#define __ARCH_WANT_STAT64
diff --git a/include/asm-blackfin/bfin5xx_spi.h b/include/asm-blackfin/bfin5xx_spi.h
index 95c1c952e7c1..f617d8765451 100644
--- a/include/asm-blackfin/bfin5xx_spi.h
+++ b/include/asm-blackfin/bfin5xx_spi.h
@@ -21,8 +21,6 @@
21#ifndef _SPI_CHANNEL_H_ 21#ifndef _SPI_CHANNEL_H_
22#define _SPI_CHANNEL_H_ 22#define _SPI_CHANNEL_H_
23 23
24#define SPI0_REGBASE 0xffc00500
25
26#define SPI_READ 0 24#define SPI_READ 0
27#define SPI_WRITE 1 25#define SPI_WRITE 1
28 26
diff --git a/include/asm-blackfin/blackfin.h b/include/asm-blackfin/blackfin.h
index 25b934b7f829..984b74f0a2ec 100644
--- a/include/asm-blackfin/blackfin.h
+++ b/include/asm-blackfin/blackfin.h
@@ -11,78 +11,57 @@
11#define HI(con32) (((con32) >> 16) & 0xFFFF) 11#define HI(con32) (((con32) >> 16) & 0xFFFF)
12#define hi(con32) (((con32) >> 16) & 0xFFFF) 12#define hi(con32) (((con32) >> 16) & 0xFFFF)
13 13
14#include <asm/mach/blackfin.h> 14#include <asm/mach/anomaly.h>
15#include <asm/bfin-global.h>
16 15
17#ifndef __ASSEMBLY__ 16#ifndef __ASSEMBLY__
18 17
19/* SSYNC implementation for C file */ 18/* SSYNC implementation for C file */
20#if defined(ANOMALY_05000312) && defined(ANOMALY_05000244) 19static inline void SSYNC(void)
21static inline void SSYNC (void)
22{
23 int _tmp;
24 __asm__ __volatile__ ("cli %0;\n\t"
25 "nop;nop;\n\t"
26 "ssync;\n\t"
27 "sti %0;\n\t"
28 :"=d"(_tmp):);
29}
30#elif defined(ANOMALY_05000312) && !defined(ANOMALY_05000244)
31static inline void SSYNC (void)
32{ 20{
33 int _tmp; 21 int _tmp;
34 __asm__ __volatile__ ("cli %0;\n\t" 22 if (ANOMALY_05000312)
35 "ssync;\n\t" 23 __asm__ __volatile__(
36 "sti %0;\n\t" 24 "cli %0;"
37 :"=d"(_tmp):); 25 "nop;"
26 "nop;"
27 "ssync;"
28 "sti %0;"
29 : "=d" (_tmp)
30 );
31 else if (ANOMALY_05000244)
32 __asm__ __volatile__(
33 "nop;"
34 "nop;"
35 "nop;"
36 "ssync;"
37 );
38 else
39 __asm__ __volatile__("ssync;");
38} 40}
39#elif !defined(ANOMALY_05000312) && defined(ANOMALY_05000244)
40static inline void SSYNC (void)
41{
42 __asm__ __volatile__ ("nop; nop; nop;\n\t"
43 "ssync;\n\t"
44 ::);
45}
46#elif !defined(ANOMALY_05000312) && !defined(ANOMALY_05000244)
47static inline void SSYNC (void)
48{
49 __asm__ __volatile__ ("ssync;\n\t");
50}
51#endif
52 41
53/* CSYNC implementation for C file */ 42/* CSYNC implementation for C file */
54#if defined(ANOMALY_05000312) && defined(ANOMALY_05000244) 43static inline void CSYNC(void)
55static inline void CSYNC (void)
56{
57 int _tmp;
58 __asm__ __volatile__ ("cli %0;\n\t"
59 "nop;nop;\n\t"
60 "csync;\n\t"
61 "sti %0;\n\t"
62 :"=d"(_tmp):);
63}
64#elif defined(ANOMALY_05000312) && !defined(ANOMALY_05000244)
65static inline void CSYNC (void)
66{ 44{
67 int _tmp; 45 int _tmp;
68 __asm__ __volatile__ ("cli %0;\n\t" 46 if (ANOMALY_05000312)
69 "csync;\n\t" 47 __asm__ __volatile__(
70 "sti %0;\n\t" 48 "cli %0;"
71 :"=d"(_tmp):); 49 "nop;"
72} 50 "nop;"
73#elif !defined(ANOMALY_05000312) && defined(ANOMALY_05000244) 51 "csync;"
74static inline void CSYNC (void) 52 "sti %0;"
75{ 53 : "=d" (_tmp)
76 __asm__ __volatile__ ("nop; nop; nop;\n\t" 54 );
77 "ssync;\n\t" 55 else if (ANOMALY_05000244)
78 ::); 56 __asm__ __volatile__(
57 "nop;"
58 "nop;"
59 "nop;"
60 "csync;"
61 );
62 else
63 __asm__ __volatile__("csync;");
79} 64}
80#elif !defined(ANOMALY_05000312) && !defined(ANOMALY_05000244)
81static inline void CSYNC (void)
82{
83 __asm__ __volatile__ ("csync;\n\t");
84}
85#endif
86 65
87#else /* __ASSEMBLY__ */ 66#else /* __ASSEMBLY__ */
88 67
@@ -91,19 +70,15 @@ static inline void CSYNC (void)
91#define ssync(x) SSYNC(x) 70#define ssync(x) SSYNC(x)
92#define csync(x) CSYNC(x) 71#define csync(x) CSYNC(x)
93 72
94#if defined(ANOMALY_05000312) && defined(ANOMALY_05000244) 73#if ANOMALY_05000312
95#define SSYNC(scratch) cli scratch; nop; nop; SSYNC; sti scratch; 74#define SSYNC(scratch) cli scratch; nop; nop; SSYNC; sti scratch;
96#define CSYNC(scratch) cli scratch; nop; nop; CSYNC; sti scratch; 75#define CSYNC(scratch) cli scratch; nop; nop; CSYNC; sti scratch;
97 76
98#elif defined(ANOMALY_05000312) && !defined(ANOMALY_05000244) 77#elif ANOMALY_05000244
99#define SSYNC(scratch) cli scratch; nop; nop; SSYNC; sti scratch;
100#define CSYNC(scratch) cli scratch; nop; nop; CSYNC; sti scratch;
101
102#elif !defined(ANOMALY_05000312) && defined(ANOMALY_05000244)
103#define SSYNC(scratch) nop; nop; nop; SSYNC; 78#define SSYNC(scratch) nop; nop; nop; SSYNC;
104#define CSYNC(scratch) nop; nop; nop; CSYNC; 79#define CSYNC(scratch) nop; nop; nop; CSYNC;
105 80
106#elif !defined(ANOMALY_05000312) && !defined(ANOMALY_05000244) 81#else
107#define SSYNC(scratch) SSYNC; 82#define SSYNC(scratch) SSYNC;
108#define CSYNC(scratch) CSYNC; 83#define CSYNC(scratch) CSYNC;
109 84
@@ -111,4 +86,7 @@ static inline void CSYNC (void)
111 86
112#endif /* __ASSEMBLY__ */ 87#endif /* __ASSEMBLY__ */
113 88
89#include <asm/mach/blackfin.h>
90#include <asm/bfin-global.h>
91
114#endif /* _BLACKFIN_H_ */ 92#endif /* _BLACKFIN_H_ */
diff --git a/include/asm-blackfin/cacheflush.h b/include/asm-blackfin/cacheflush.h
index e5e000de3c36..d81a77545a04 100644
--- a/include/asm-blackfin/cacheflush.h
+++ b/include/asm-blackfin/cacheflush.h
@@ -48,9 +48,9 @@ extern void blackfin_dflush_page(void *);
48 48
49static inline void flush_icache_range(unsigned start, unsigned end) 49static inline void flush_icache_range(unsigned start, unsigned end)
50{ 50{
51#if defined(CONFIG_BLKFIN_DCACHE) && defined(CONFIG_BLKFIN_CACHE) 51#if defined(CONFIG_BFIN_DCACHE) && defined(CONFIG_BFIN_ICACHE)
52 52
53# if defined(CONFIG_BLKFIN_WT) 53# if defined(CONFIG_BFIN_WT)
54 blackfin_icache_flush_range((start), (end)); 54 blackfin_icache_flush_range((start), (end));
55# else 55# else
56 blackfin_icache_dcache_flush_range((start), (end)); 56 blackfin_icache_dcache_flush_range((start), (end));
@@ -58,10 +58,10 @@ static inline void flush_icache_range(unsigned start, unsigned end)
58 58
59#else 59#else
60 60
61# if defined(CONFIG_BLKFIN_CACHE) 61# if defined(CONFIG_BFIN_ICACHE)
62 blackfin_icache_flush_range((start), (end)); 62 blackfin_icache_flush_range((start), (end));
63# endif 63# endif
64# if defined(CONFIG_BLKFIN_DCACHE) 64# if defined(CONFIG_BFIN_DCACHE)
65 blackfin_dcache_flush_range((start), (end)); 65 blackfin_dcache_flush_range((start), (end));
66# endif 66# endif
67 67
@@ -74,12 +74,12 @@ do { memcpy(dst, src, len); \
74} while (0) 74} while (0)
75#define copy_from_user_page(vma, page, vaddr, dst, src, len) memcpy(dst, src, len) 75#define copy_from_user_page(vma, page, vaddr, dst, src, len) memcpy(dst, src, len)
76 76
77#if defined(CONFIG_BLKFIN_DCACHE) 77#if defined(CONFIG_BFIN_DCACHE)
78# define invalidate_dcache_range(start,end) blackfin_dcache_invalidate_range((start), (end)) 78# define invalidate_dcache_range(start,end) blackfin_dcache_invalidate_range((start), (end))
79#else 79#else
80# define invalidate_dcache_range(start,end) do { } while (0) 80# define invalidate_dcache_range(start,end) do { } while (0)
81#endif 81#endif
82#if defined(CONFIG_BLKFIN_DCACHE) && defined(CONFIG_BLKFIN_WB) 82#if defined(CONFIG_BFIN_DCACHE) && defined(CONFIG_BFIN_WB)
83# define flush_dcache_range(start,end) blackfin_dcache_flush_range((start), (end)) 83# define flush_dcache_range(start,end) blackfin_dcache_flush_range((start), (end))
84# define flush_dcache_page(page) blackfin_dflush_page(page_address(page)) 84# define flush_dcache_page(page) blackfin_dflush_page(page_address(page))
85#else 85#else
@@ -87,4 +87,4 @@ do { memcpy(dst, src, len); \
87# define flush_dcache_page(page) do { } while (0) 87# define flush_dcache_page(page) do { } while (0)
88#endif 88#endif
89 89
90#endif /* _BLACKFIN_CACHEFLUSH_H */ 90#endif /* _BLACKFIN_ICACHEFLUSH_H */
diff --git a/include/asm-blackfin/cplb.h b/include/asm-blackfin/cplb.h
index e0dd56bfa4c7..06828d77a58f 100644
--- a/include/asm-blackfin/cplb.h
+++ b/include/asm-blackfin/cplb.h
@@ -1,17 +1,100 @@
1/************************************************************************ 1/*
2 * File: include/asm-blackfin/cplb.h
3 * Based on: include/asm-blackfin/mach-bf537/bf537.h
4 * Author: Robin Getz <rgetz@blackfin.uclinux.org>
2 * 5 *
3 * cplb.h 6 * Created: 2000
7 * Description: Common CPLB definitions for CPLB init
4 * 8 *
5 * (c) Copyright 2002-2003 Analog Devices, Inc. All rights reserved. 9 * Modified:
10 * Copyright 2004-2007 Analog Devices Inc.
6 * 11 *
7 ************************************************************************/ 12 * Bugs: Enter bugs at http://blackfin.uclinux.org/
8 13 *
9/* Defines necessary for cplb initialisation routines. */ 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 */
10 29
11#ifndef _CPLB_H 30#ifndef _CPLB_H
12#define _CPLB_H 31#define _CPLB_H
13 32
14# include <asm/blackfin.h> 33#include <asm/blackfin.h>
34#include <asm/mach/anomaly.h>
35
36#define SDRAM_IGENERIC (CPLB_L1_CHBL | CPLB_USER_RD | CPLB_VALID | CPLB_PORTPRIO)
37#define SDRAM_IKERNEL (SDRAM_IGENERIC | CPLB_LOCK)
38#define L1_IMEMORY ( CPLB_USER_RD | CPLB_VALID | CPLB_LOCK)
39#define SDRAM_INON_CHBL ( CPLB_USER_RD | CPLB_VALID)
40
41/*Use the menuconfig cache policy here - CONFIG_BFIN_WT/CONFIG_BFIN_WB*/
42
43#if ANOMALY_05000158
44#define ANOMALY_05000158_WORKAROUND 0x200
45#else
46#define ANOMALY_05000158_WORKAROUND 0x0
47#endif
48
49#define CPLB_COMMON (CPLB_DIRTY | CPLB_SUPV_WR | CPLB_USER_WR | CPLB_USER_RD | CPLB_VALID | ANOMALY_05000158_WORKAROUND)
50
51#ifdef CONFIG_BFIN_WB /*Write Back Policy */
52#define SDRAM_DGENERIC (CPLB_L1_CHBL | CPLB_COMMON)
53#else /*Write Through */
54#define SDRAM_DGENERIC (CPLB_L1_CHBL | CPLB_WT | CPLB_L1_AOW | CPLB_COMMON)
55#endif
56
57#define L1_DMEMORY (CPLB_LOCK | CPLB_COMMON)
58#define L2_MEMORY (CPLB_COMMON)
59#define SDRAM_DNON_CHBL (CPLB_COMMON)
60#define SDRAM_EBIU (CPLB_COMMON)
61#define SDRAM_OOPS (CPLB_VALID | ANOMALY_05000158_WORKAROUND | CPLB_LOCK | CPLB_DIRTY)
62
63#define SIZE_1K 0x00000400 /* 1K */
64#define SIZE_4K 0x00001000 /* 4K */
65#define SIZE_1M 0x00100000 /* 1M */
66#define SIZE_4M 0x00400000 /* 4M */
67
68#define MAX_CPLBS (16 * 2)
69
70#define ASYNC_MEMORY_CPLB_COVERAGE ((ASYNC_BANK0_SIZE + ASYNC_BANK1_SIZE + \
71 ASYNC_BANK2_SIZE + ASYNC_BANK3_SIZE) / SIZE_4M)
72
73/*
74* Number of required data CPLB switchtable entries
75* MEMSIZE / 4 (we mostly install 4M page size CPLBs
76* approx 16 for smaller 1MB page size CPLBs for allignment purposes
77* 1 for L1 Data Memory
78* possibly 1 for L2 Data Memory
79* 1 for CONFIG_DEBUG_HUNT_FOR_ZERO
80* 1 for ASYNC Memory
81*/
82
83
84#define MAX_SWITCH_D_CPLBS (((CONFIG_MEM_SIZE / 4) + 16 + 1 + 1 + 1 \
85 + ASYNC_MEMORY_CPLB_COVERAGE) * 2)
86
87/*
88* Number of required instruction CPLB switchtable entries
89* MEMSIZE / 4 (we mostly install 4M page size CPLBs
90* approx 12 for smaller 1MB page size CPLBs for allignment purposes
91* 1 for L1 Instruction Memory
92* possibly 1 for L2 Instruction Memory
93* 1 for CONFIG_DEBUG_HUNT_FOR_ZERO
94*/
95
96#define MAX_SWITCH_I_CPLBS (((CONFIG_MEM_SIZE / 4) + 12 + 1 + 1 + 1) * 2)
97
15 98
16#define CPLB_ENABLE_ICACHE_P 0 99#define CPLB_ENABLE_ICACHE_P 0
17#define CPLB_ENABLE_DCACHE_P 1 100#define CPLB_ENABLE_DCACHE_P 1
@@ -39,8 +122,6 @@
39#define CPLB_DEF_CACHE CPLB_L1_CHBL | CPLB_WT 122#define CPLB_DEF_CACHE CPLB_L1_CHBL | CPLB_WT
40#define CPLB_CACHE_ENABLED CPLB_L1_CHBL | CPLB_DIRTY 123#define CPLB_CACHE_ENABLED CPLB_L1_CHBL | CPLB_DIRTY
41 124
42#define CPLB_ALL_ACCESS CPLB_SUPV_WR | CPLB_USER_RD | CPLB_USER_WR
43
44#define CPLB_I_PAGE_MGMT CPLB_LOCK | CPLB_VALID 125#define CPLB_I_PAGE_MGMT CPLB_LOCK | CPLB_VALID
45#define CPLB_D_PAGE_MGMT CPLB_LOCK | CPLB_ALL_ACCESS | CPLB_VALID 126#define CPLB_D_PAGE_MGMT CPLB_LOCK | CPLB_ALL_ACCESS | CPLB_VALID
46#define CPLB_DNOCACHE CPLB_ALL_ACCESS | CPLB_VALID 127#define CPLB_DNOCACHE CPLB_ALL_ACCESS | CPLB_VALID
diff --git a/include/asm-blackfin/dma.h b/include/asm-blackfin/dma.h
index be0d913e5516..b42a531e7a1b 100644
--- a/include/asm-blackfin/dma.h
+++ b/include/asm-blackfin/dma.h
@@ -152,6 +152,7 @@ struct dma_channel {
152/* functions to set register mode */ 152/* functions to set register mode */
153void set_dma_start_addr(unsigned int channel, unsigned long addr); 153void set_dma_start_addr(unsigned int channel, unsigned long addr);
154void set_dma_next_desc_addr(unsigned int channel, unsigned long addr); 154void set_dma_next_desc_addr(unsigned int channel, unsigned long addr);
155void set_dma_curr_desc_addr(unsigned int channel, unsigned long addr);
155void set_dma_x_count(unsigned int channel, unsigned short x_count); 156void set_dma_x_count(unsigned int channel, unsigned short x_count);
156void set_dma_x_modify(unsigned int channel, short x_modify); 157void set_dma_x_modify(unsigned int channel, short x_modify);
157void set_dma_y_count(unsigned int channel, unsigned short y_count); 158void set_dma_y_count(unsigned int channel, unsigned short y_count);
@@ -159,6 +160,7 @@ void set_dma_y_modify(unsigned int channel, short y_modify);
159void set_dma_config(unsigned int channel, unsigned short config); 160void set_dma_config(unsigned int channel, unsigned short config);
160unsigned short set_bfin_dma_config(char direction, char flow_mode, 161unsigned short set_bfin_dma_config(char direction, char flow_mode,
161 char intr_mode, char dma_mode, char width); 162 char intr_mode, char dma_mode, char width);
163void set_dma_curr_addr(unsigned int channel, unsigned long addr);
162 164
163/* get curr status for polling */ 165/* get curr status for polling */
164unsigned short get_dma_curr_irqstat(unsigned int channel); 166unsigned short get_dma_curr_irqstat(unsigned int channel);
diff --git a/include/asm-blackfin/early_printk.h b/include/asm-blackfin/early_printk.h
new file mode 100644
index 000000000000..110f1c1f845c
--- /dev/null
+++ b/include/asm-blackfin/early_printk.h
@@ -0,0 +1,28 @@
1/*
2 * File: include/asm-blackfin/early_printk.h
3 * Author: Robin Getz <rgetz@blackfin.uclinux.org
4 *
5 * Created: 14Aug2007
6 * Description: function prototpyes for early printk
7 *
8 * Modified:
9 * Copyright 2004-2007 Analog Devices Inc.
10 *
11 * Bugs: Enter bugs at http://blackfin.uclinux.org/
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 */
23
24#ifdef CONFIG_EARLY_PRINTK
25extern int setup_early_printk(char *);
26#else
27#define setup_early_printk(fmt) do { } while (0)
28#endif /* CONFIG_EARLY_PRINTK */
diff --git a/include/asm-blackfin/gpio.h b/include/asm-blackfin/gpio.h
index 7480cfa7e2d6..dd203cd93796 100644
--- a/include/asm-blackfin/gpio.h
+++ b/include/asm-blackfin/gpio.h
@@ -144,6 +144,24 @@
144 144
145#ifdef BF533_FAMILY 145#ifdef BF533_FAMILY
146#define MAX_BLACKFIN_GPIOS 16 146#define MAX_BLACKFIN_GPIOS 16
147
148#define GPIO_PF0 0
149#define GPIO_PF1 1
150#define GPIO_PF2 2
151#define GPIO_PF3 3
152#define GPIO_PF4 4
153#define GPIO_PF5 5
154#define GPIO_PF6 6
155#define GPIO_PF7 7
156#define GPIO_PF8 8
157#define GPIO_PF9 9
158#define GPIO_PF10 10
159#define GPIO_PF11 11
160#define GPIO_PF12 12
161#define GPIO_PF13 13
162#define GPIO_PF14 14
163#define GPIO_PF15 15
164
147#endif 165#endif
148 166
149#ifdef BF537_FAMILY 167#ifdef BF537_FAMILY
@@ -421,6 +439,19 @@ unsigned short gpio_get_value(unsigned short gpio);
421void gpio_direction_input(unsigned short gpio); 439void gpio_direction_input(unsigned short gpio);
422void gpio_direction_output(unsigned short gpio); 440void gpio_direction_output(unsigned short gpio);
423 441
442#include <asm-generic/gpio.h> /* cansleep wrappers */
443#include <asm/irq.h>
444
445static inline int gpio_to_irq(unsigned gpio)
446{
447 return (gpio + GPIO_IRQ_BASE);
448}
449
450static inline int irq_to_gpio(unsigned irq)
451{
452 return (irq - GPIO_IRQ_BASE);
453}
454
424#endif /* __ASSEMBLY__ */ 455#endif /* __ASSEMBLY__ */
425 456
426#endif /* __ARCH_BLACKFIN_GPIO_H__ */ 457#endif /* __ARCH_BLACKFIN_GPIO_H__ */
diff --git a/include/asm-blackfin/io.h b/include/asm-blackfin/io.h
index 142cb333db29..525179bf43d7 100644
--- a/include/asm-blackfin/io.h
+++ b/include/asm-blackfin/io.h
@@ -115,21 +115,21 @@ static inline unsigned int readl(const volatile void __iomem *addr)
115 115
116#ifndef __ASSEMBLY__ 116#ifndef __ASSEMBLY__
117 117
118extern void outsb(void __iomem *port, const void *addr, unsigned short count); 118extern void outsb(unsigned long port, const void *addr, unsigned long count);
119extern void outsw(void __iomem *port, const void *addr, unsigned short count); 119extern void outsw(unsigned long port, const void *addr, unsigned long count);
120extern void outsl(void __iomem *port, const void *addr, unsigned short count); 120extern void outsl(unsigned long port, const void *addr, unsigned long count);
121 121
122extern void insb(const void __iomem *port, void *addr, unsigned short count); 122extern void insb(unsigned long port, void *addr, unsigned long count);
123extern void insw(const void __iomem *port, void *addr, unsigned short count); 123extern void insw(unsigned long port, void *addr, unsigned long count);
124extern void insl(const void __iomem *port, void *addr, unsigned short count); 124extern void insl(unsigned long port, void *addr, unsigned long count);
125 125
126extern void dma_outsb(void __iomem *port, const void *addr, unsigned short count); 126extern void dma_outsb(unsigned long port, const void *addr, unsigned short count);
127extern void dma_outsw(void __iomem *port, const void *addr, unsigned short count); 127extern void dma_outsw(unsigned long port, const void *addr, unsigned short count);
128extern void dma_outsl(void __iomem *port, const void *addr, unsigned short count); 128extern void dma_outsl(unsigned long port, const void *addr, unsigned short count);
129 129
130extern void dma_insb(const void __iomem *port, void *addr, unsigned short count); 130extern void dma_insb(unsigned long port, void *addr, unsigned short count);
131extern void dma_insw(const void __iomem *port, void *addr, unsigned short count); 131extern void dma_insw(unsigned long port, void *addr, unsigned short count);
132extern void dma_insl(const void __iomem *port, void *addr, unsigned short count); 132extern void dma_insl(unsigned long port, void *addr, unsigned short count);
133 133
134/* 134/*
135 * Map some physical address range into the kernel address space. 135 * Map some physical address range into the kernel address space.
diff --git a/include/asm-blackfin/ioctls.h b/include/asm-blackfin/ioctls.h
index 8356204151db..895e3173165d 100644
--- a/include/asm-blackfin/ioctls.h
+++ b/include/asm-blackfin/ioctls.h
@@ -47,8 +47,13 @@
47#define TIOCSBRK 0x5427 /* BSD compatibility */ 47#define TIOCSBRK 0x5427 /* BSD compatibility */
48#define TIOCCBRK 0x5428 /* BSD compatibility */ 48#define TIOCCBRK 0x5428 /* BSD compatibility */
49#define TIOCGSID 0x5429 /* Return the session ID of FD */ 49#define TIOCGSID 0x5429 /* Return the session ID of FD */
50#define TIOCGPTN _IOR('T',0x30, unsigned int) /* Get Pty Number (of pty-mux device) */ 50#define TCGETS2 _IOR('T', 0x2A, struct termios2)
51#define TIOCSPTLCK _IOW('T',0x31, int) /* Lock/unlock Pty */ 51#define TCSETS2 _IOW('T', 0x2B, struct termios2)
52#define TCSETSW2 _IOW('T', 0x2C, struct termios2)
53#define TCSETSF2 _IOW('T', 0x2D, struct termios2)
54/* Get Pty Number (of pty-mux device) */
55#define TIOCGPTN _IOR('T', 0x30, unsigned int)
56#define TIOCSPTLCK _IOW('T', 0x31, int) /* Lock/unlock Pty */
52 57
53#define FIONCLEX 0x5450 /* these numbers need to be adjusted. */ 58#define FIONCLEX 0x5450 /* these numbers need to be adjusted. */
54#define FIOCLEX 0x5451 59#define FIOCLEX 0x5451
diff --git a/include/asm-blackfin/irq_handler.h b/include/asm-blackfin/irq_handler.h
index d830f0a49a1c..139b5208f9d8 100644
--- a/include/asm-blackfin/irq_handler.h
+++ b/include/asm-blackfin/irq_handler.h
@@ -1,13 +1,15 @@
1#ifndef _IRQ_HANDLER_H 1#ifndef _IRQ_HANDLER_H
2#define _IRQ_HANDLER_H 2#define _IRQ_HANDLER_H
3 3
4#include <linux/types.h>
5#include <linux/linkage.h>
6
4/* BASE LEVEL interrupt handler routines */ 7/* BASE LEVEL interrupt handler routines */
5asmlinkage void evt_emulation(void);
6asmlinkage void evt_exception(void); 8asmlinkage void evt_exception(void);
7asmlinkage void trap(void); 9asmlinkage void trap(void);
8asmlinkage void evt_ivhw(void); 10asmlinkage void evt_ivhw(void);
9asmlinkage void evt_timer(void); 11asmlinkage void evt_timer(void);
10asmlinkage void evt_evt2(void); 12asmlinkage void evt_nmi(void);
11asmlinkage void evt_evt7(void); 13asmlinkage void evt_evt7(void);
12asmlinkage void evt_evt8(void); 14asmlinkage void evt_evt8(void);
13asmlinkage void evt_evt9(void); 15asmlinkage void evt_evt9(void);
@@ -18,5 +20,14 @@ asmlinkage void evt_evt13(void);
18asmlinkage void evt_soft_int1(void); 20asmlinkage void evt_soft_int1(void);
19asmlinkage void evt_system_call(void); 21asmlinkage void evt_system_call(void);
20asmlinkage void init_exception_buff(void); 22asmlinkage void init_exception_buff(void);
23asmlinkage void trap_c(struct pt_regs *fp);
24asmlinkage void ex_replaceable(void);
25asmlinkage void early_trap(void);
26
27extern void *ex_table[];
28extern void return_from_exception(void);
29
30extern int bfin_request_exception(unsigned int exception, void (*handler)(void));
31extern int bfin_free_exception(unsigned int exception, void (*handler)(void));
21 32
22#endif 33#endif
diff --git a/include/asm-blackfin/kgdb.h b/include/asm-blackfin/kgdb.h
index 532bd9052004..0f73847fd6bc 100644
--- a/include/asm-blackfin/kgdb.h
+++ b/include/asm-blackfin/kgdb.h
@@ -179,5 +179,6 @@ enum regnames {
179#define STATDA1 0x80 179#define STATDA1 0x80
180 180
181extern void kgdb_print(const char *fmt, ...); 181extern void kgdb_print(const char *fmt, ...);
182extern void init_kgdb_uart(void);
182 183
183#endif 184#endif
diff --git a/include/asm-blackfin/mach-bf527/anomaly.h b/include/asm-blackfin/mach-bf527/anomaly.h
new file mode 100644
index 000000000000..991db986cd4b
--- /dev/null
+++ b/include/asm-blackfin/mach-bf527/anomaly.h
@@ -0,0 +1,41 @@
1/*
2 * File: include/asm-blackfin/mach-bf527/anomaly.h
3 * Bugs: Enter bugs at http://blackfin.uclinux.org/
4 *
5 * Copyright (C) 2004-2007 Analog Devices Inc.
6 * Licensed under the GPL-2 or later.
7 */
8
9/* This file shoule be up to date with:
10 * - Revision A, May 30, 2007; ADSP-BF527 Blackfin Processor Anomaly List
11 */
12
13#ifndef _MACH_ANOMALY_H_
14#define _MACH_ANOMALY_H_
15
16/* Multi-Issue Instruction with dsp32shiftimm in slot1 and P-reg Store in slot2 Not Supported */
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 */
21#define ANOMALY_05000122 (1)
22/* Spurious Hardware Error from an Access in the Shadow of a Conditional Branch */
23#define ANOMALY_05000245 (1)
24/* Sensitivity To Noise with Slow Input Edge Rates on External SPORT TX and RX Clocks */
25#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 */
31#define ANOMALY_05000328 (1)
32/* Disallowed Configuration Prevents Subsequent Allowed Configuration on Host DMA Port */
33#define ANOMALY_05000337 (1)
34/* TWI Does Not Operate Correctly Under Certain Signal Termination Conditions */
35#define ANOMALY_05000342 (1)
36/* Boot ROM Kernel Incorrectly Alters Reset Value of USB Register */
37#define ANOMALY_05000347 (1)
38
39/* Anomalies that don't exist on this proc */
40#define ANOMALY_05000323 (0)
41#endif
diff --git a/include/asm-blackfin/mach-bf527/defBF52x_base.h b/include/asm-blackfin/mach-bf527/defBF52x_base.h
index 0b2fb5036ed0..b1ff67db01f8 100644
--- a/include/asm-blackfin/mach-bf527/defBF52x_base.h
+++ b/include/asm-blackfin/mach-bf527/defBF52x_base.h
@@ -102,6 +102,7 @@
102 102
103 103
104/* SPI Controller (0xFFC00500 - 0xFFC005FF) */ 104/* SPI Controller (0xFFC00500 - 0xFFC005FF) */
105#define SPI0_REGBASE 0xFFC00500
105#define SPI_CTL 0xFFC00500 /* SPI Control Register */ 106#define SPI_CTL 0xFFC00500 /* SPI Control Register */
106#define SPI_FLG 0xFFC00504 /* SPI Flag register */ 107#define SPI_FLG 0xFFC00504 /* SPI Flag register */
107#define SPI_STAT 0xFFC00508 /* SPI Status register */ 108#define SPI_STAT 0xFFC00508 /* SPI Status register */
@@ -480,6 +481,7 @@
480 481
481 482
482/* Two-Wire Interface (0xFFC01400 - 0xFFC014FF) */ 483/* Two-Wire Interface (0xFFC01400 - 0xFFC014FF) */
484#define TWI0_REGBASE 0xFFC01400
483#define TWI_CLKDIV 0xFFC01400 /* Serial Clock Divider Register */ 485#define TWI_CLKDIV 0xFFC01400 /* Serial Clock Divider Register */
484#define TWI_CONTROL 0xFFC01404 /* TWI Control Register */ 486#define TWI_CONTROL 0xFFC01404 /* TWI Control Register */
485#define TWI_SLAVE_CTL 0xFFC01408 /* Slave Mode Control Register */ 487#define TWI_SLAVE_CTL 0xFFC01408 /* Slave Mode Control Register */
diff --git a/include/asm-blackfin/mach-bf533/anomaly.h b/include/asm-blackfin/mach-bf533/anomaly.h
index 7302f290b93d..f36ff5af1b91 100644
--- a/include/asm-blackfin/mach-bf533/anomaly.h
+++ b/include/asm-blackfin/mach-bf533/anomaly.h
@@ -1,247 +1,259 @@
1/* 1/*
2 * File: include/asm-blackfin/mach-bf533/anomaly.h 2 * File: include/asm-blackfin/mach-bf533/anomaly.h
3 * Based on: 3 * Bugs: Enter bugs at http://blackfin.uclinux.org/
4 * Author:
5 * 4 *
6 * Created: 5 * Copyright (C) 2004-2007 Analog Devices Inc.
7 * Description: 6 * Licensed under the GPL-2 or later.
8 *
9 * Rev:
10 *
11 * Modified:
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, or (at your option)
18 * 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; see the file COPYING.
27 * If not, write to the Free Software Foundation,
28 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 */ 7 */
30 8
31/* This file shoule be up to date with: 9/* This file shoule be up to date with:
32 * - Revision U, May 17, 2006; ADSP-BF533 Blackfin Processor Anomaly List 10 * - Revision X, March 23, 2007; ADSP-BF533 Blackfin Processor Anomaly List
33 * - Revision Y, May 17, 2006; ADSP-BF532 Blackfin Processor Anomaly List 11 * - Revision AB, March 23, 2007; ADSP-BF532 Blackfin Processor Anomaly List
34 * - Revision T, May 17, 2006; ADSP-BF531 Blackfin Processor Anomaly List 12 * - Revision W, March 23, 2007; ADSP-BF531 Blackfin Processor Anomaly List
35 */ 13 */
36 14
37#ifndef _MACH_ANOMALY_H_ 15#ifndef _MACH_ANOMALY_H_
38#define _MACH_ANOMALY_H_ 16#define _MACH_ANOMALY_H_
39 17
40/* We do not support 0.1 or 0.2 silicon - sorry */ 18/* We do not support 0.1 or 0.2 silicon - sorry */
41#if (defined(CONFIG_BF_REV_0_1) || defined(CONFIG_BF_REV_0_2)) 19#if __SILICON_REVISION__ < 3
42#error Kernel will not work on BF533 Version 0.1 or 0.2 20# error Kernel will not work on BF533 silicon version 0.0, 0.1, or 0.2
43#endif 21#endif
44 22
45/* Issues that are common to 0.5, 0.4, and 0.3 silicon */ 23#if defined(__ADSPBF531__)
46#if (defined(CONFIG_BF_REV_0_5) || defined(CONFIG_BF_REV_0_4) \ 24# define ANOMALY_BF531 1
47 || defined(CONFIG_BF_REV_0_3)) 25#else
48#define ANOMALY_05000074 /* A multi issue instruction with dsp32shiftimm in 26# define ANOMALY_BF531 0
49 slot1 and store of a P register in slot 2 is not 27#endif
50 supported */ 28#if defined(__ADSPBF532__)
51#define ANOMALY_05000105 /* Watchpoint Status Register (WPSTAT) bits are set on 29# define ANOMALY_BF532 1
52 every corresponding match */ 30#else
53#define ANOMALY_05000119 /* DMA_RUN bit is not valid after a Peripheral Receive 31# define ANOMALY_BF532 0
54 Channel DMA stops */ 32#endif
55#define ANOMALY_05000122 /* Rx.H can not be used to access 16-bit System MMR 33#if defined(__ADSPBF533__)
56 registers. */ 34# define ANOMALY_BF533 1
57#define ANOMALY_05000166 /* PPI Data Lengths Between 8 and 16 do not zero out 35#else
58 upper bits*/ 36# define ANOMALY_BF533 0
59#define ANOMALY_05000167 /* Turning Serial Ports on With External Frame Syncs */ 37#endif
60#define ANOMALY_05000180 /* PPI_DELAY not functional in PPI modes with 0 frame
61 syncs */
62#define ANOMALY_05000208 /* VSTAT status bit in PLL_STAT register is not
63 functional */
64#define ANOMALY_05000219 /* NMI event at boot time results in unpredictable
65 state */
66#define ANOMALY_05000229 /* SPI Slave Boot Mode modifies registers */
67#define ANOMALY_05000272 /* Certain data cache write through modes fail for
68 VDDint <=0.9V */
69#define ANOMALY_05000273 /* Writes to Synchronous SDRAM memory may be lost */
70#define ANOMALY_05000277 /* Writes to a flag data register one SCLK cycle after
71 an edge is detected may clear interrupt */
72#define ANOMALY_05000278 /* Disabling Peripherals with DMA running may cause
73 DMA system instability */
74#define ANOMALY_05000281 /* False Hardware Error Exception when ISR context is
75 not restored */
76#define ANOMALY_05000282 /* Memory DMA corruption with 32-bit data and traffic
77 control */
78#define ANOMALY_05000283 /* A system MMR write is stalled indefinitely when
79 killed in a particular stage*/
80#define ANOMALY_05000311 /* Erroneous flag pin operations under specific
81 sequences */
82#define ANOMALY_05000312 /* Errors when SSYNC, CSYNC, or loads to LT, LB and LC
83 registers are interrupted */
84#define ANOMALY_05000313 /* PPI Is Level-Sensitive on First Transfer */
85#define ANOMALY_05000315 /* Killed System MMR Write Completes Erroneously On
86 * Next System MMR Access */
87#define ANOMALY_05000319 /* Internal Voltage Regulator Values of 1.05V, 1.10V
88 * and 1.15V Not Allowed for LQFP Packages */
89#endif /* Issues that are common to 0.5, 0.4, and 0.3 silicon */
90 38
91/* These issues only occur on 0.3 or 0.4 BF533 */ 39/* Multi-Issue Instruction with dsp32shiftimm in slot1 and P-reg Store in slot 2 Not Supported */
92#if (defined(CONFIG_BF_REV_0_4) || defined(CONFIG_BF_REV_0_3)) 40#define ANOMALY_05000074 (1)
93#define ANOMALY_05000099 /* UART Line Status Register (UART_LSR) bits are not 41/* UART Line Status Register (UART_LSR) Bits Are Not Updated at the Same Time */
94 updated at the same time. */ 42#define ANOMALY_05000099 (__SILICON_REVISION__ < 5)
95#define ANOMALY_05000158 /* Boot fails when data cache enabled: Data from a Data 43/* Watchpoint Status Register (WPSTAT) Bits Are Set on Every Corresponding Match */
96 Cache Fill can be corrupted after or during 44#define ANOMALY_05000105 (1)
97 Instruction DMA if certain core stalls exist */ 45/* DMA_RUN Bit Is Not Valid after a Peripheral Receive Channel DMA Stops */
98#define ANOMALY_05000179 /* PPI_COUNT cannot be programmed to 0 in General 46#define ANOMALY_05000119 (1)
99 Purpose TX or RX modes */ 47/* Rx.H Cannot Be Used to Access 16-bit System MMR Registers */
100#define ANOMALY_05000198 /* Failing SYSTEM MMR accesses when stalled by 48#define ANOMALY_05000122 (1)
101 preceding memory read */ 49/* Instruction DMA Can Cause Data Cache Fills to Fail (Boot Implications) */
102#define ANOMALY_05000200 /* SPORT TFS and DT are incorrectly driven during 50#define ANOMALY_05000158 (__SILICON_REVISION__ < 5)
103 inactive channels in certain conditions */ 51/* PPI Data Lengths Between 8 and 16 Do Not Zero Out Upper Bits */
104#define ANOMALY_05000202 /* Possible infinite stall with specific dual dag 52#define ANOMALY_05000166 (1)
105 situation */ 53/* Turning Serial Ports on with External Frame Syncs */
106#define ANOMALY_05000215 /* UART TX Interrupt masked erroneously */ 54#define ANOMALY_05000167 (1)
107#define ANOMALY_05000225 /* Incorrect pulse-width of UART start-bit */ 55/* PPI_COUNT Cannot Be Programmed to 0 in General Purpose TX or RX Modes */
108#define ANOMALY_05000227 /* Scratchpad memory bank reads may return incorrect 56#define ANOMALY_05000179 (__SILICON_REVISION__ < 5)
109 data*/ 57/* PPI_DELAY Not Functional in PPI Modes with 0 Frame Syncs */
110#define ANOMALY_05000230 /* UART Receiver is less robust against Baudrate 58#define ANOMALY_05000180 (1)
111 Differences in certain Conditions */ 59/* Timer Pin Limitations for PPI TX Modes with External Frame Syncs */
112#define ANOMALY_05000231 /* UART STB bit incorrectly affects receiver setting */ 60#define ANOMALY_05000183 (__SILICON_REVISION__ < 4)
113#define ANOMALY_05000242 /* DF bit in PLL_CTL register does not respond to 61/* False Protection Exceptions */
114 hardware reset */ 62#define ANOMALY_05000189 (__SILICON_REVISION__ < 4)
115#define ANOMALY_05000244 /* With instruction cache enabled, a CSYNC or SSYNC or 63/* False I/O Pin Interrupts on Edge-Sensitive Inputs When Polarity Setting Is Changed */
116 IDLE around a Change of Control causes 64#define ANOMALY_05000193 (__SILICON_REVISION__ < 4)
117 unpredictable results */ 65/* Restarting SPORT in Specific Modes May Cause Data Corruption */
118#define ANOMALY_05000245 /* Spurious Hardware Error from an access in the 66#define ANOMALY_05000194 (__SILICON_REVISION__ < 4)
119 shadow of a conditional branch */ 67/* Failing MMR Accesses When Stalled by Preceding Memory Read */
120#define ANOMALY_05000246 /* Data CPLB's should prevent spurious hardware 68#define ANOMALY_05000198 (__SILICON_REVISION__ < 5)
121 errors */ 69/* Current DMA Address Shows Wrong Value During Carry Fix */
122#define ANOMALY_05000253 /* Maximum external clock speed for Timers */ 70#define ANOMALY_05000199 (__SILICON_REVISION__ < 4)
123#define ANOMALY_05000255 /* Entering Hibernate Mode with RTC Seconds event 71/* SPORT TFS and DT Are Incorrectly Driven During Inactive Channels in Certain Conditions */
124 interrupt not functional */ 72#define ANOMALY_05000200 (__SILICON_REVISION__ < 5)
125#define ANOMALY_05000257 /* An interrupt or exception during short Hardware 73/* Receive Frame Sync Not Ignored During Active Frames in SPORT Multi-Channel Mode */
126 loops may cause the instruction fetch unit to 74#define ANOMALY_05000201 (__SILICON_REVISION__ < 4)
127 malfunction */ 75/* Possible Infinite Stall with Specific Dual-DAG Situation */
128#define ANOMALY_05000258 /* Instruction Cache is corrupted when bit 9 and 12 of 76#define ANOMALY_05000202 (__SILICON_REVISION__ < 5)
129 the ICPLB Data registers differ */ 77/* Specific Sequence That Can Cause DMA Error or DMA Stopping */
130#define ANOMALY_05000260 /* ICPLB_STATUS MMR register may be corrupted */ 78#define ANOMALY_05000203 (__SILICON_REVISION__ < 4)
131#define ANOMALY_05000261 /* DCPLB_FAULT_ADDR MMR register may be corrupted */ 79/* Incorrect data read with write-through cache and allocate cache lines on reads only mode */
132#define ANOMALY_05000262 /* Stores to data cache may be lost */ 80#define ANOMALY_05000204 (__SILICON_REVISION__ < 4 && ANOMALY_BF533)
133#define ANOMALY_05000263 /* Hardware loop corrupted when taking an ICPLB exception */ 81/* Recovery from "Brown-Out" Condition */
134#define ANOMALY_05000264 /* A Sync instruction (CSYNC, SSYNC) or an IDLE 82#define ANOMALY_05000207 (__SILICON_REVISION__ < 4)
135 instruction will cause an infinite stall in the 83/* VSTAT Status Bit in PLL_STAT Register Is Not Functional */
136 second to last instruction in a hardware loop */ 84#define ANOMALY_05000208 (1)
137#define ANOMALY_05000265 /* Sensitivity to noise with slow input edge rates on 85/* Speed Path in Computational Unit Affects Certain Instructions */
138 SPORT external receive and transmit clocks. */ 86#define ANOMALY_05000209 (__SILICON_REVISION__ < 4)
139#define ANOMALY_05000269 /* High I/O activity causes the output voltage of the 87/* UART TX Interrupt Masked Erroneously */
140 internal voltage regulator (VDDint) to increase. */ 88#define ANOMALY_05000215 (__SILICON_REVISION__ < 5)
141#define ANOMALY_05000270 /* High I/O activity causes the output voltage of the 89/* NMI Event at Boot Time Results in Unpredictable State */
142 internal voltage regulator (VDDint) to decrease */ 90#define ANOMALY_05000219 (1)
143#endif /* issues only occur on 0.3 or 0.4 BF533 */ 91/* Incorrect Pulse-Width of UART Start Bit */
92#define ANOMALY_05000225 (__SILICON_REVISION__ < 5)
93/* Scratchpad Memory Bank Reads May Return Incorrect Data */
94#define ANOMALY_05000227 (__SILICON_REVISION__ < 5)
95/* SPI Slave Boot Mode Modifies Registers from Reset Value */
96#define ANOMALY_05000229 (1)
97/* UART Receiver is Less Robust Against Baudrate Differences in Certain Conditions */
98#define ANOMALY_05000230 (__SILICON_REVISION__ < 5)
99/* UART STB Bit Incorrectly Affects Receiver Setting */
100#define ANOMALY_05000231 (__SILICON_REVISION__ < 5)
101/* PPI_FS3 Is Not Driven in 2 or 3 Internal Frame Sync Transmit Modes */
102#define ANOMALY_05000233 (__SILICON_REVISION__ < 4)
103/* Incorrect Revision Number in DSPID Register */
104#define ANOMALY_05000234 (__SILICON_REVISION__ == 4)
105/* DF Bit in PLL_CTL Register Does Not Respond to Hardware Reset */
106#define ANOMALY_05000242 (__SILICON_REVISION__ < 4)
107/* If I-Cache Is On, CSYNC/SSYNC/IDLE Around Change of Control Causes Failures */
108#define ANOMALY_05000244 (__SILICON_REVISION__ < 5)
109/* Spurious Hardware Error from an Access in the Shadow of a Conditional Branch */
110#define ANOMALY_05000245 (1)
111/* Data CPLBs Should Prevent Spurious Hardware Errors */
112#define ANOMALY_05000246 (__SILICON_REVISION__ < 5)
113/* Incorrect Bit Shift of Data Word in Multichannel (TDM) Mode in Certain Conditions */
114#define ANOMALY_05000250 (__SILICON_REVISION__ == 4)
115/* Maximum External Clock Speed for Timers */
116#define ANOMALY_05000253 (__SILICON_REVISION__ < 5)
117/* Incorrect Timer Pulse Width in Single-Shot PWM_OUT Mode with External Clock */
118#define ANOMALY_05000254 (__SILICON_REVISION__ > 4)
119/* Entering Hibernate State with RTC Seconds Interrupt Not Functional */
120#define ANOMALY_05000255 (__SILICON_REVISION__ < 5)
121/* Interrupt/Exception During Short Hardware Loop May Cause Bad Instruction Fetches */
122#define ANOMALY_05000257 (__SILICON_REVISION__ < 5)
123/* Instruction Cache Is Corrupted When Bits 9 and 12 of the ICPLB Data Registers Differ */
124#define ANOMALY_05000258 (__SILICON_REVISION__ < 5)
125/* ICPLB_STATUS MMR Register May Be Corrupted */
126#define ANOMALY_05000260 (__SILICON_REVISION__ < 5)
127/* DCPLB_FAULT_ADDR MMR Register May Be Corrupted */
128#define ANOMALY_05000261 (__SILICON_REVISION__ < 5)
129/* Stores To Data Cache May Be Lost */
130#define ANOMALY_05000262 (__SILICON_REVISION__ < 5)
131/* Hardware Loop Corrupted When Taking an ICPLB Exception */
132#define ANOMALY_05000263 (__SILICON_REVISION__ < 5)
133/* CSYNC/SSYNC/IDLE Causes Infinite Stall in Penultimate Instruction in Hardware Loop */
134#define ANOMALY_05000264 (__SILICON_REVISION__ < 5)
135/* Sensitivity To Noise with Slow Input Edge Rates on External SPORT TX and RX Clocks */
136#define ANOMALY_05000265 (__SILICON_REVISION__ < 5)
137/* High I/O Activity Causes Output Voltage of Internal Voltage Regulator (Vddint) to Increase */
138#define ANOMALY_05000269 (__SILICON_REVISION__ < 5)
139/* High I/O Activity Causes Output Voltage of Internal Voltage Regulator (Vddint) to Decrease */
140#define ANOMALY_05000270 (__SILICON_REVISION__ < 5)
141/* Spontaneous Reset of Internal Voltage Regulator */
142#define ANOMALY_05000271 (__SILICON_REVISION__ < 4)
143/* Certain Data Cache Writethrough Modes Fail for Vddint <= 0.9V */
144#define ANOMALY_05000272 (1)
145/* Writes to Synchronous SDRAM Memory May Be Lost */
146#define ANOMALY_05000273 (1)
147/* Timing Requirements Change for External Frame Sync PPI Modes with Non-Zero PPI_DELAY */
148#define ANOMALY_05000276 (1)
149/* Writes to an I/O Data Register One SCLK Cycle after an Edge Is Detected May Clear Interrupt */
150#define ANOMALY_05000277 (1)
151/* Disabling Peripherals with DMA Running May Cause DMA System Instability */
152#define ANOMALY_05000278 (1)
153/* False Hardware Error Exception When ISR Context Is Not Restored */
154#define ANOMALY_05000281 (1)
155/* Memory DMA Corruption with 32-Bit Data and Traffic Control */
156#define ANOMALY_05000282 (1)
157/* System MMR Write Is Stalled Indefinitely When Killed in a Particular Stage */
158#define ANOMALY_05000283 (1)
159/* SPORTs May Receive Bad Data If FIFOs Fill Up */
160#define ANOMALY_05000288 (1)
161/* Memory-To-Memory DMA Source/Destination Descriptors Must Be in Same Memory Space */
162#define ANOMALY_05000301 (1)
163/* SSYNCs After Writes To DMA MMR Registers May Not Be Handled Correctly */
164#define ANOMALY_05000302 (__SILICON_REVISION__ < 5)
165/* New Feature: Additional Hysteresis on SPORT Input Pins (Not Available On Older Silicon) */
166#define ANOMALY_05000305 (__SILICON_REVISION__ < 5)
167/* New Feature: Additional PPI Frame Sync Sampling Options (Not Available On Older Silicon) */
168#define ANOMALY_05000306 (__SILICON_REVISION__ < 5)
169/* False Hardware Errors Caused by Fetches at the Boundary of Reserved Memory */
170#define ANOMALY_05000310 (1)
171/* Erroneous Flag (GPIO) Pin Operations under Specific Sequences */
172#define ANOMALY_05000311 (1)
173/* Errors When SSYNC, CSYNC, or Loads to LT, LB and LC Registers Are Interrupted */
174#define ANOMALY_05000312 (1)
175/* PPI Is Level-Sensitive on First Transfer */
176#define ANOMALY_05000313 (1)
177/* Killed System MMR Write Completes Erroneously On Next System MMR Access */
178#define ANOMALY_05000315 (1)
179/* Internal Voltage Regulator Values of 1.05V, 1.10V and 1.15V Not Allowed for LQFP Packages */
180#define ANOMALY_05000319 (ANOMALY_BF531 || ANOMALY_BF532)
144 181
145/* These issues are only on 0.4 silicon */ 182/* These anomalies have been "phased" out of analog.com anomaly sheets and are
146#if (defined(CONFIG_BF_REV_0_4)) 183 * here to show running on older silicon just isn't feasible.
147#define ANOMALY_05000234 /* Incorrect Revision Number in DSPID Register */ 184 */
148#define ANOMALY_05000250 /* Incorrect Bit-Shift of Data Word in Multichannel
149 (TDM) */
150#endif /* issues are only on 0.4 silicon */
151 185
152/* These issues are only on 0.3 silicon */ 186/* Watchpoints (Hardware Breakpoints) are not supported */
153#if defined(CONFIG_BF_REV_0_3) 187#define ANOMALY_05000067 (__SILICON_REVISION__ < 3)
154#define ANOMALY_05000183 /* Timer Pin limitations for PPI TX Modes with 188/* Reserved bits in SYSCFG register not set at power on */
155 External Frame Syncs */ 189#define ANOMALY_05000109 (__SILICON_REVISION__ < 3)
156#define ANOMALY_05000189 /* False Protection Exceptions caused by Speculative 190/* Trace Buffers may record discontinuities into emulation mode and/or exception, NMI, reset handlers */
157 Instruction or Data Fetches, or by Fetches at the 191#define ANOMALY_05000116 (__SILICON_REVISION__ < 3)
158 boundary of reserved memory space */ 192/* DTEST_COMMAND initiated memory access may be incorrect if data cache or DMA is active */
159#define ANOMALY_05000193 /* False Flag Pin Interrupts on Edge Sensitive Inputs 193#define ANOMALY_05000123 (__SILICON_REVISION__ < 3)
160 when polarity setting is changed */ 194/* DMA Lock-up at CCLK to SCLK ratios of 4:1, 2:1, or 1:1 */
161#define ANOMALY_05000194 /* Sport Restarting in specific modes may cause data 195#define ANOMALY_05000124 (__SILICON_REVISION__ < 3)
162 corruption */ 196/* Erroneous exception when enabling cache */
163#define ANOMALY_05000199 /* DMA current address shows wrong value during carry 197#define ANOMALY_05000125 (__SILICON_REVISION__ < 3)
164 fix */ 198/* SPI clock polarity and phase bits incorrect during booting */
165#define ANOMALY_05000201 /* Receive frame sync not ignored during active 199#define ANOMALY_05000126 (__SILICON_REVISION__ < 3)
166 frames in sport MCM */ 200/* DMEM_CONTROL is not set on Reset */
167#define ANOMALY_05000203 /* Specific sequence that can cause DMA error or DMA 201#define ANOMALY_05000137 (__SILICON_REVISION__ < 3)
168 stopping */ 202/* SPI boot will not complete if there is a zero fill block in the loader file */
169#if defined(CONFIG_BF533) 203#define ANOMALY_05000138 (__SILICON_REVISION__ < 3)
170#define ANOMALY_05000204 /* Incorrect data read with write-through cache and 204/* Allowing the SPORT RX FIFO to fill will cause an overflow */
171 allocate cache lines on reads only mode */ 205#define ANOMALY_05000140 (__SILICON_REVISION__ < 3)
172#endif /* CONFIG_BF533 */ 206/* An Infinite Stall occurs with a particular sequence of consecutive dual dag events */
173#define ANOMALY_05000207 /* Recovery from "brown-out" condition */ 207#define ANOMALY_05000141 (__SILICON_REVISION__ < 3)
174#define ANOMALY_05000209 /* Speed-Path in computational unit affects certain 208/* Interrupts may be lost when a programmable input flag is configured to be edge sensitive */
175 instructions */ 209#define ANOMALY_05000142 (__SILICON_REVISION__ < 3)
176#define ANOMALY_05000233 /* PPI_FS3 is not driven in 2 or 3 internal Frame 210/* A read from external memory may return a wrong value with data cache enabled */
177 Sync Transmit Mode */ 211#define ANOMALY_05000143 (__SILICON_REVISION__ < 3)
178#define ANOMALY_05000271 /* Spontaneous reset of Internal Voltage Regulator */ 212/* DMA and TESTSET conflict when both are accessing external memory */
179#endif /* only on 0.3 silicon */ 213#define ANOMALY_05000144 (__SILICON_REVISION__ < 3)
214/* In PWM_OUT mode, you must enable the PPI block to generate a waveform from PPI_CLK */
215#define ANOMALY_05000145 (__SILICON_REVISION__ < 3)
216/* MDMA may lose the first few words of a descriptor chain */
217#define ANOMALY_05000146 (__SILICON_REVISION__ < 3)
218/* The source MDMA descriptor may stop with a DMA Error */
219#define ANOMALY_05000147 (__SILICON_REVISION__ < 3)
220/* When booting from a 16-bit asynchronous memory device, the upper 8-bits of each word must be 0x00 */
221#define ANOMALY_05000148 (__SILICON_REVISION__ < 3)
222/* Frame Delay in SPORT Multichannel Mode */
223#define ANOMALY_05000153 (__SILICON_REVISION__ < 3)
224/* SPORT TFS signal is active in Multi-channel mode outside of valid channels */
225#define ANOMALY_05000154 (__SILICON_REVISION__ < 3)
226/* Timer1 can not be used for PWMOUT mode when a certain PPI mode is in use */
227#define ANOMALY_05000155 (__SILICON_REVISION__ < 3)
228/* A killed 32-bit System MMR write will lead to the next system MMR access thinking it should be 32-bit. */
229#define ANOMALY_05000157 (__SILICON_REVISION__ < 3)
230/* SPORT transmit data is not gated by external frame sync in certain conditions */
231#define ANOMALY_05000163 (__SILICON_REVISION__ < 3)
232/* SDRAM auto-refresh and subsequent Power Ups */
233#define ANOMALY_05000168 (__SILICON_REVISION__ < 3)
234/* DATA CPLB page miss can result in lost write-through cache data writes */
235#define ANOMALY_05000169 (__SILICON_REVISION__ < 3)
236/* DMA vs Core accesses to external memory */
237#define ANOMALY_05000173 (__SILICON_REVISION__ < 3)
238/* Cache Fill Buffer Data lost */
239#define ANOMALY_05000174 (__SILICON_REVISION__ < 3)
240/* Overlapping Sequencer and Memory Stalls */
241#define ANOMALY_05000175 (__SILICON_REVISION__ < 3)
242/* Multiplication of (-1) by (-1) followed by an accumulator saturation */
243#define ANOMALY_05000176 (__SILICON_REVISION__ < 3)
244/* Disabling the PPI resets the PPI configuration registers */
245#define ANOMALY_05000181 (__SILICON_REVISION__ < 3)
246/* PPI TX Mode with 2 External Frame Syncs */
247#define ANOMALY_05000185 (__SILICON_REVISION__ < 3)
248/* PPI does not invert the Driving PPICLK edge in Transmit Modes */
249#define ANOMALY_05000191 (__SILICON_REVISION__ < 3)
250/* In PPI Transmit Modes with External Frame Syncs POLC */
251#define ANOMALY_05000192 (__SILICON_REVISION__ < 3)
252/* Internal Voltage Regulator may not start up */
253#define ANOMALY_05000206 (__SILICON_REVISION__ < 3)
180 254
181#if defined(CONFIG_BF_REV_0_2) 255/* Anomalies that don't exist on this proc */
182#define ANOMALY_05000067 /* Watchpoints (Hardware Breakpoints) are not 256#define ANOMALY_05000266 (0)
183 * supported */ 257#define ANOMALY_05000323 (0)
184#define ANOMALY_05000109 /* Reserved bits in SYSCFG register not set at
185 * power on */
186#define ANOMALY_05000116 /* Trace Buffers may record discontinuities into
187 * emulation mode and/or exception, NMI, reset
188 * handlers */
189#define ANOMALY_05000123 /* DTEST_COMMAND initiated memory access may be
190 * incorrect if data cache or DMA is active */
191#define ANOMALY_05000124 /* DMA Lock-up at CCLK to SCLK ratios of 4:1, 2:1,
192 * or 1:1 */
193#define ANOMALY_05000125 /* Erroneous exception when enabling cache */
194#define ANOMALY_05000126 /* SPI clock polarity and phase bits incorrect
195 * during booting */
196#define ANOMALY_05000137 /* DMEM_CONTROL is not set on Reset */
197#define ANOMALY_05000138 /* SPI boot will not complete if there is a zero fill
198 * block in the loader file */
199#define ANOMALY_05000140 /* Allowing the SPORT RX FIFO to fill will cause an
200 * overflow */
201#define ANOMALY_05000141 /* An Infinite Stall occurs with a particular sequence
202 * of consecutive dual dag events */
203#define ANOMALY_05000142 /* Interrupts may be lost when a programmable input
204 * flag is configured to be edge sensitive */
205#define ANOMALY_05000143 /* A read from external memory may return a wrong
206 * value with data cache enabled */
207#define ANOMALY_05000144 /* DMA and TESTSET conflict when both are accessing
208 * external memory */
209#define ANOMALY_05000145 /* In PWM_OUT mode, you must enable the PPI block to
210 * generate a waveform from PPI_CLK */
211#define ANOMALY_05000146 /* MDMA may lose the first few words of a descriptor
212 * chain */
213#define ANOMALY_05000147 /* The source MDMA descriptor may stop with a DMA
214 * Error */
215#define ANOMALY_05000148 /* When booting from a 16-bit asynchronous memory
216 * device, the upper 8-bits of each word must be
217 * 0x00 */
218#define ANOMALY_05000153 /* Frame Delay in SPORT Multichannel Mode */
219#define ANOMALY_05000154 /* SPORT TFS signal is active in Multi-channel mode
220 * outside of valid channels */
221#define ANOMALY_05000155 /* Timer1 can not be used for PWMOUT mode when a
222 * certain PPI mode is in use */
223#define ANOMALY_05000157 /* A killed 32-bit System MMR write will lead to
224 * the next system MMR access thinking it should be
225 * 32-bit. */
226#define ANOMALY_05000163 /* SPORT transmit data is not gated by external frame
227 * sync in certain conditions */
228#define ANOMALY_05000168 /* SDRAM auto-refresh and subsequent Power Ups */
229#define ANOMALY_05000169 /* DATA CPLB page miss can result in lost
230 * write-through cache data writes */
231#define ANOMALY_05000173 /* DMA vs Core accesses to external memory */
232#define ANOMALY_05000174 /* Cache Fill Buffer Data lost */
233#define ANOMALY_05000175 /* Overlapping Sequencer and Memory Stalls */
234#define ANOMALY_05000176 /* Multiplication of (-1) by (-1) followed by an
235 * accumulator saturation */
236#define ANOMALY_05000181 /* Disabling the PPI resets the PPI configuration
237 * registers */
238#define ANOMALY_05000185 /* PPI TX Mode with 2 External Frame Syncs */
239#define ANOMALY_05000191 /* PPI does not invert the Driving PPICLK edge in
240 * Transmit Modes */
241#define ANOMALY_05000192 /* In PPI Transmit Modes with External Frame Syncs
242 * POLC */
243#define ANOMALY_05000206 /* Internal Voltage Regulator may not start up */
244 258
245#endif 259#endif
246
247#endif /* _MACH_ANOMALY_H_ */
diff --git a/include/asm-blackfin/mach-bf533/bf533.h b/include/asm-blackfin/mach-bf533/bf533.h
index 185fc1284858..12a416931991 100644
--- a/include/asm-blackfin/mach-bf533/bf533.h
+++ b/include/asm-blackfin/mach-bf533/bf533.h
@@ -52,12 +52,12 @@
52/***************************/ 52/***************************/
53 53
54 54
55#define BLKFIN_DSUBBANKS 4 55#define BFIN_DSUBBANKS 4
56#define BLKFIN_DWAYS 2 56#define BFIN_DWAYS 2
57#define BLKFIN_DLINES 64 57#define BFIN_DLINES 64
58#define BLKFIN_ISUBBANKS 4 58#define BFIN_ISUBBANKS 4
59#define BLKFIN_IWAYS 4 59#define BFIN_IWAYS 4
60#define BLKFIN_ILINES 32 60#define BFIN_ILINES 32
61 61
62#define WAY0_L 0x1 62#define WAY0_L 0x1
63#define WAY1_L 0x2 63#define WAY1_L 0x2
@@ -141,97 +141,6 @@
141 141
142#define AMGCTLVAL (V_AMBEN | V_AMCKEN | V_CDPRIO) 142#define AMGCTLVAL (V_AMBEN | V_AMCKEN | V_CDPRIO)
143 143
144#define MAX_VC 650000000
145#define MIN_VC 50000000
146
147#ifdef CONFIG_BFIN_KERNEL_CLOCK
148/********************************PLL Settings **************************************/
149#if (CONFIG_VCO_MULT < 0)
150#error "VCO Multiplier is less than 0. Please select a different value"
151#endif
152
153#if (CONFIG_VCO_MULT == 0)
154#error "VCO Multiplier should be greater than 0. Please select a different value"
155#endif
156
157#if (CONFIG_VCO_MULT > 64)
158#error "VCO Multiplier is more than 64. Please select a different value"
159#endif
160
161#ifndef CONFIG_CLKIN_HALF
162#define CONFIG_VCO_HZ (CONFIG_CLKIN_HZ * CONFIG_VCO_MULT)
163#else
164#define CONFIG_VCO_HZ ((CONFIG_CLKIN_HZ * CONFIG_VCO_MULT)/2)
165#endif
166
167#ifndef CONFIG_PLL_BYPASS
168#define CONFIG_CCLK_HZ (CONFIG_VCO_HZ/CONFIG_CCLK_DIV)
169#define CONFIG_SCLK_HZ (CONFIG_VCO_HZ/CONFIG_SCLK_DIV)
170#else
171#define CONFIG_CCLK_HZ CONFIG_CLKIN_HZ
172#define CONFIG_SCLK_HZ CONFIG_CLKIN_HZ
173#endif
174
175#if (CONFIG_SCLK_DIV < 1)
176#error "SCLK DIV cannot be less than 1 or more than 15. Please select a proper value"
177#endif
178
179#if (CONFIG_SCLK_DIV > 15)
180#error "SCLK DIV cannot be less than 1 or more than 15. Please select a proper value"
181#endif
182
183#if (CONFIG_CCLK_DIV != 1)
184#if (CONFIG_CCLK_DIV != 2)
185#if (CONFIG_CCLK_DIV != 4)
186#if (CONFIG_CCLK_DIV != 8)
187#error "CCLK DIV can be 1,2,4 or 8 only. Please select a proper value"
188#endif
189#endif
190#endif
191#endif
192
193#if (CONFIG_VCO_HZ > MAX_VC)
194#error "VCO selected is more than maximum value. Please change the VCO multipler"
195#endif
196
197#if (CONFIG_SCLK_HZ > 133000000)
198#error "Sclk value selected is more than maximum. Please select a proper value for SCLK multiplier"
199#endif
200
201#if (CONFIG_SCLK_HZ < 27000000)
202#error "Sclk value selected is less than minimum. Please select a proper value for SCLK multiplier"
203#endif
204
205#if (CONFIG_SCLK_HZ > CONFIG_CCLK_HZ)
206#if (CONFIG_SCLK_HZ != CONFIG_CLKIN_HZ)
207#if (CONFIG_CCLK_HZ != CONFIG_CLKIN_HZ)
208#error "Please select sclk less than cclk"
209#endif
210#endif
211#endif
212
213#if (CONFIG_CCLK_DIV == 1)
214#define CONFIG_CCLK_ACT_DIV CCLK_DIV1
215#endif
216#if (CONFIG_CCLK_DIV == 2)
217#define CONFIG_CCLK_ACT_DIV CCLK_DIV2
218#endif
219#if (CONFIG_CCLK_DIV == 4)
220#define CONFIG_CCLK_ACT_DIV CCLK_DIV4
221#endif
222#if (CONFIG_CCLK_DIV == 8)
223#define CONFIG_CCLK_ACT_DIV CCLK_DIV8
224#endif
225#ifndef CONFIG_CCLK_ACT_DIV
226#define CONFIG_CCLK_ACT_DIV CONFIG_CCLK_DIV_not_defined_properly
227#endif
228
229#if defined(ANOMALY_05000273) && (CONFIG_CCLK_DIV == 1)
230#error ANOMALY 05000273, please make sure CCLK is at least 2x SCLK
231#endif
232
233#endif /* CONFIG_BFIN_KERNEL_CLOCK */
234
235#ifdef CONFIG_BF533 144#ifdef CONFIG_BF533
236#define CPU "BF533" 145#define CPU "BF533"
237#define CPUID 0x027a5000 146#define CPUID 0x027a5000
@@ -249,58 +158,4 @@
249#define CPUID 0x0 158#define CPUID 0x0
250#endif 159#endif
251 160
252#if (CONFIG_MEM_SIZE % 4)
253#error "SDRAM mem size must be multible of 4MB"
254#endif
255
256#define SDRAM_IGENERIC (CPLB_L1_CHBL | CPLB_USER_RD | CPLB_VALID | CPLB_PORTPRIO)
257#define SDRAM_IKERNEL (SDRAM_IGENERIC | CPLB_LOCK)
258#define L1_IMEMORY ( CPLB_USER_RD | CPLB_VALID | CPLB_LOCK)
259#define SDRAM_INON_CHBL ( CPLB_USER_RD | CPLB_VALID)
260
261/*Use the menuconfig cache policy here - CONFIG_BLKFIN_WT/CONFIG_BLKFIN_WB*/
262
263#define ANOMALY_05000158_WORKAROUND 0x200
264#ifdef CONFIG_BLKFIN_WB /*Write Back Policy */
265#define SDRAM_DGENERIC (CPLB_L1_CHBL | CPLB_DIRTY \
266 | CPLB_SUPV_WR | CPLB_USER_WR | CPLB_USER_RD | CPLB_VALID | ANOMALY_05000158_WORKAROUND)
267#else /*Write Through */
268#define SDRAM_DGENERIC (CPLB_L1_CHBL | CPLB_WT | CPLB_L1_AOW | CPLB_DIRTY \
269 | CPLB_SUPV_WR | CPLB_USER_WR | CPLB_USER_RD | CPLB_VALID | ANOMALY_05000158_WORKAROUND)
270#endif
271
272#define L1_DMEMORY (CPLB_SUPV_WR | CPLB_USER_WR | CPLB_USER_RD | CPLB_VALID | ANOMALY_05000158_WORKAROUND | CPLB_LOCK | CPLB_DIRTY)
273#define SDRAM_DNON_CHBL (CPLB_SUPV_WR | CPLB_USER_WR | CPLB_USER_RD | CPLB_VALID | ANOMALY_05000158_WORKAROUND | CPLB_DIRTY)
274#define SDRAM_EBIU (CPLB_SUPV_WR | CPLB_USER_WR | CPLB_USER_RD | CPLB_VALID | ANOMALY_05000158_WORKAROUND | CPLB_DIRTY)
275#define SDRAM_OOPS (CPLB_VALID | ANOMALY_05000158_WORKAROUND | CPLB_LOCK | CPLB_DIRTY)
276
277#define SIZE_1K 0x00000400 /* 1K */
278#define SIZE_4K 0x00001000 /* 4K */
279#define SIZE_1M 0x00100000 /* 1M */
280#define SIZE_4M 0x00400000 /* 4M */
281
282#define MAX_CPLBS (16 * 2)
283
284/*
285* Number of required data CPLB switchtable entries
286* MEMSIZE / 4 (we mostly install 4M page size CPLBs
287* approx 16 for smaller 1MB page size CPLBs for allignment purposes
288* 1 for L1 Data Memory
289* 1 for CONFIG_DEBUG_HUNT_FOR_ZERO
290* 1 for ASYNC Memory
291*/
292
293
294#define MAX_SWITCH_D_CPLBS (((CONFIG_MEM_SIZE / 4) + 16 + 1 + 1 + 1) * 2)
295
296/*
297* Number of required instruction CPLB switchtable entries
298* MEMSIZE / 4 (we mostly install 4M page size CPLBs
299* approx 12 for smaller 1MB page size CPLBs for allignment purposes
300* 1 for L1 Instruction Memory
301* 1 for CONFIG_DEBUG_HUNT_FOR_ZERO
302*/
303
304#define MAX_SWITCH_I_CPLBS (((CONFIG_MEM_SIZE / 4) + 12 + 1 + 1) * 2)
305
306#endif /* __MACH_BF533_H__ */ 161#endif /* __MACH_BF533_H__ */
diff --git a/include/asm-blackfin/mach-bf533/blackfin.h b/include/asm-blackfin/mach-bf533/blackfin.h
index e4384491e972..f3b240abf170 100644
--- a/include/asm-blackfin/mach-bf533/blackfin.h
+++ b/include/asm-blackfin/mach-bf533/blackfin.h
@@ -38,7 +38,7 @@
38#include "defBF532.h" 38#include "defBF532.h"
39#include "anomaly.h" 39#include "anomaly.h"
40 40
41#if !(defined(__ASSEMBLY__) || defined(ASSEMBLY)) 41#if !defined(__ASSEMBLY__)
42#include "cdefBF532.h" 42#include "cdefBF532.h"
43#endif 43#endif
44 44
diff --git a/include/asm-blackfin/mach-bf533/cdefBF532.h b/include/asm-blackfin/mach-bf533/cdefBF532.h
index 74f967b235e2..c803e14b529c 100644
--- a/include/asm-blackfin/mach-bf533/cdefBF532.h
+++ b/include/asm-blackfin/mach-bf533/cdefBF532.h
@@ -30,11 +30,9 @@
30 30
31#ifndef _CDEF_BF532_H 31#ifndef _CDEF_BF532_H
32#define _CDEF_BF532_H 32#define _CDEF_BF532_H
33/* 33
34#if !defined(__ADSPLPBLACKFIN__) 34#include <asm/blackfin.h>
35#warning cdefBF532.h should only be included for 532 compatible chips. 35
36#endif
37*/
38/*include all Core registers and bit definitions*/ 36/*include all Core registers and bit definitions*/
39#include "defBF532.h" 37#include "defBF532.h"
40 38
@@ -65,7 +63,7 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
65 bfin_write32(SIC_IWR, IWR_ENABLE(0)); 63 bfin_write32(SIC_IWR, IWR_ENABLE(0));
66 64
67 bfin_write16(VR_CTL, val); 65 bfin_write16(VR_CTL, val);
68 __builtin_bfin_ssync(); 66 SSYNC();
69 67
70 local_irq_save(flags); 68 local_irq_save(flags);
71 asm("IDLE;"); 69 asm("IDLE;");
@@ -132,10 +130,6 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
132/* General Purpose IO (0xFFC0 2400-0xFFC0 27FF) */ 130/* General Purpose IO (0xFFC0 2400-0xFFC0 27FF) */
133#define bfin_read_FIO_DIR() bfin_read16(FIO_DIR) 131#define bfin_read_FIO_DIR() bfin_read16(FIO_DIR)
134#define bfin_write_FIO_DIR(val) bfin_write16(FIO_DIR,val) 132#define bfin_write_FIO_DIR(val) bfin_write16(FIO_DIR,val)
135#define bfin_read_FIO_FLAG_C() bfin_read16(FIO_FLAG_C)
136#define bfin_write_FIO_FLAG_C(val) bfin_write16(FIO_FLAG_C,val)
137#define bfin_read_FIO_FLAG_S() bfin_read16(FIO_FLAG_S)
138#define bfin_write_FIO_FLAG_S(val) bfin_write16(FIO_FLAG_S,val)
139#define bfin_read_FIO_MASKA_C() bfin_read16(FIO_MASKA_C) 133#define bfin_read_FIO_MASKA_C() bfin_read16(FIO_MASKA_C)
140#define bfin_write_FIO_MASKA_C(val) bfin_write16(FIO_MASKA_C,val) 134#define bfin_write_FIO_MASKA_C(val) bfin_write16(FIO_MASKA_C,val)
141#define bfin_read_FIO_MASKA_S() bfin_read16(FIO_MASKA_S) 135#define bfin_read_FIO_MASKA_S() bfin_read16(FIO_MASKA_S)
@@ -152,10 +146,6 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
152#define bfin_write_FIO_BOTH(val) bfin_write16(FIO_BOTH,val) 146#define bfin_write_FIO_BOTH(val) bfin_write16(FIO_BOTH,val)
153#define bfin_read_FIO_INEN() bfin_read16(FIO_INEN) 147#define bfin_read_FIO_INEN() bfin_read16(FIO_INEN)
154#define bfin_write_FIO_INEN(val) bfin_write16(FIO_INEN,val) 148#define bfin_write_FIO_INEN(val) bfin_write16(FIO_INEN,val)
155#define bfin_read_FIO_FLAG_D() bfin_read16(FIO_FLAG_D)
156#define bfin_write_FIO_FLAG_D(val) bfin_write16(FIO_FLAG_D,val)
157#define bfin_read_FIO_FLAG_T() bfin_read16(FIO_FLAG_T)
158#define bfin_write_FIO_FLAG_T(val) bfin_write16(FIO_FLAG_T,val)
159#define bfin_read_FIO_MASKA_D() bfin_read16(FIO_MASKA_D) 149#define bfin_read_FIO_MASKA_D() bfin_read16(FIO_MASKA_D)
160#define bfin_write_FIO_MASKA_D(val) bfin_write16(FIO_MASKA_D,val) 150#define bfin_write_FIO_MASKA_D(val) bfin_write16(FIO_MASKA_D,val)
161#define bfin_read_FIO_MASKA_T() bfin_read16(FIO_MASKA_T) 151#define bfin_read_FIO_MASKA_T() bfin_read16(FIO_MASKA_T)
@@ -165,6 +155,50 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
165#define bfin_read_FIO_MASKB_T() bfin_read16(FIO_MASKB_T) 155#define bfin_read_FIO_MASKB_T() bfin_read16(FIO_MASKB_T)
166#define bfin_write_FIO_MASKB_T(val) bfin_write16(FIO_MASKB_T,val) 156#define bfin_write_FIO_MASKB_T(val) bfin_write16(FIO_MASKB_T,val)
167 157
158
159#if ANOMALY_05000311
160#define BFIN_WRITE_FIO_FLAG(name) \
161static __inline__ void bfin_write_FIO_FLAG_ ## name (unsigned short val)\
162{\
163 unsigned long flags;\
164 local_irq_save(flags);\
165 bfin_write16(FIO_FLAG_ ## name,val);\
166 bfin_read_CHIPID();\
167 local_irq_restore(flags);\
168}
169BFIN_WRITE_FIO_FLAG(D)
170BFIN_WRITE_FIO_FLAG(C)
171BFIN_WRITE_FIO_FLAG(S)
172BFIN_WRITE_FIO_FLAG(T)
173
174#define BFIN_READ_FIO_FLAG(name) \
175static __inline__ unsigned short bfin_read_FIO_FLAG_ ## name (void)\
176{\
177 unsigned long flags;\
178 unsigned short ret;\
179 local_irq_save(flags);\
180 ret = bfin_read16(FIO_FLAG_ ## name);\
181 bfin_read_CHIPID();\
182 local_irq_restore(flags);\
183 return ret;\
184}
185BFIN_READ_FIO_FLAG(D)
186BFIN_READ_FIO_FLAG(C)
187BFIN_READ_FIO_FLAG(S)
188BFIN_READ_FIO_FLAG(T)
189
190#else
191#define bfin_write_FIO_FLAG_D(val) bfin_write16(FIO_FLAG_D,val)
192#define bfin_write_FIO_FLAG_C(val) bfin_write16(FIO_FLAG_C,val)
193#define bfin_write_FIO_FLAG_S(val) bfin_write16(FIO_FLAG_S,val)
194#define bfin_write_FIO_FLAG_T(val) bfin_write16(FIO_FLAG_T,val)
195#define bfin_read_FIO_FLAG_T() bfin_read16(FIO_FLAG_T)
196#define bfin_read_FIO_FLAG_C() bfin_read16(FIO_FLAG_C)
197#define bfin_read_FIO_FLAG_S() bfin_read16(FIO_FLAG_S)
198#define bfin_read_FIO_FLAG_D() bfin_read16(FIO_FLAG_D)
199#endif
200
201
168/* DMA Controller */ 202/* DMA Controller */
169#define bfin_read_DMA0_CONFIG() bfin_read16(DMA0_CONFIG) 203#define bfin_read_DMA0_CONFIG() bfin_read16(DMA0_CONFIG)
170#define bfin_write_DMA0_CONFIG(val) bfin_write16(DMA0_CONFIG,val) 204#define bfin_write_DMA0_CONFIG(val) bfin_write16(DMA0_CONFIG,val)
diff --git a/include/asm-blackfin/mach-bf533/defBF532.h b/include/asm-blackfin/mach-bf533/defBF532.h
index 6a3cf93f8b57..37134aaf9954 100644
--- a/include/asm-blackfin/mach-bf533/defBF532.h
+++ b/include/asm-blackfin/mach-bf533/defBF532.h
@@ -104,6 +104,7 @@
104#define UART_GCTL 0xFFC00424 /* Global Control Register */ 104#define UART_GCTL 0xFFC00424 /* Global Control Register */
105 105
106/* SPI Controller (0xFFC00500 - 0xFFC005FF) */ 106/* SPI Controller (0xFFC00500 - 0xFFC005FF) */
107#define SPI0_REGBASE 0xFFC00500
107#define SPI_CTL 0xFFC00500 /* SPI Control Register */ 108#define SPI_CTL 0xFFC00500 /* SPI Control Register */
108#define SPI_FLG 0xFFC00504 /* SPI Flag register */ 109#define SPI_FLG 0xFFC00504 /* SPI Flag register */
109#define SPI_STAT 0xFFC00508 /* SPI Status register */ 110#define SPI_STAT 0xFFC00508 /* SPI Status register */
@@ -928,7 +929,7 @@
928#define GM 0x00000008 /* When RDBR full, get more (=1) data or discard (=0) incoming Data */ 929#define GM 0x00000008 /* When RDBR full, get more (=1) data or discard (=0) incoming Data */
929#define PSSE 0x00000010 /* Enable (=1) Slave-Select input for Master. */ 930#define PSSE 0x00000010 /* Enable (=1) Slave-Select input for Master. */
930#define EMISO 0x00000020 /* Enable (=1) MISO pin as an output. */ 931#define EMISO 0x00000020 /* Enable (=1) MISO pin as an output. */
931#define SPI_LEN 0x00000100 /* Word length (0 => 8 bits, 1 => 16 bits) */ 932#define SIZE 0x00000100 /* Word length (0 => 8 bits, 1 => 16 bits) */
932#define LSBF 0x00000200 /* Data format (0 => MSB sent/received first 1 => LSB sent/received first) */ 933#define LSBF 0x00000200 /* Data format (0 => MSB sent/received first 1 => LSB sent/received first) */
933#define CPHA 0x00000400 /* Clock phase (0 => SPICLK starts toggling in middle of xfer, 1 => SPICLK toggles at the beginning of xfer. */ 934#define CPHA 0x00000400 /* Clock phase (0 => SPICLK starts toggling in middle of xfer, 1 => SPICLK toggles at the beginning of xfer. */
934#define CPOL 0x00000800 /* Clock polarity (0 => active-high, 1 => active-low) */ 935#define CPOL 0x00000800 /* Clock polarity (0 => active-high, 1 => active-low) */
diff --git a/include/asm-blackfin/mach-bf533/irq.h b/include/asm-blackfin/mach-bf533/irq.h
index 9879e68e315c..452fb825d891 100644
--- a/include/asm-blackfin/mach-bf533/irq.h
+++ b/include/asm-blackfin/mach-bf533/irq.h
@@ -128,6 +128,8 @@ Core Emulation **
128#define IRQ_PF14 47 128#define IRQ_PF14 47
129#define IRQ_PF15 48 129#define IRQ_PF15 48
130 130
131#define GPIO_IRQ_BASE IRQ_PF0
132
131#ifdef CONFIG_IRQCHIP_DEMUX_GPIO 133#ifdef CONFIG_IRQCHIP_DEMUX_GPIO
132#define NR_IRQS (IRQ_PF15+1) 134#define NR_IRQS (IRQ_PF15+1)
133#else 135#else
diff --git a/include/asm-blackfin/mach-bf533/mem_map.h b/include/asm-blackfin/mach-bf533/mem_map.h
index e84baa3e939d..94d8c4062eb7 100644
--- a/include/asm-blackfin/mach-bf533/mem_map.h
+++ b/include/asm-blackfin/mach-bf533/mem_map.h
@@ -51,10 +51,10 @@
51 51
52/* Level 1 Memory */ 52/* Level 1 Memory */
53 53
54#ifdef CONFIG_BLKFIN_CACHE 54#ifdef CONFIG_BFIN_ICACHE
55#define BLKFIN_ICACHESIZE (16*1024) 55#define BFIN_ICACHESIZE (16*1024)
56#else 56#else
57#define BLKFIN_ICACHESIZE (0*1024) 57#define BFIN_ICACHESIZE (0*1024)
58#endif 58#endif
59 59
60/* Memory Map for ADSP-BF533 processors */ 60/* Memory Map for ADSP-BF533 processors */
@@ -64,35 +64,35 @@
64#define L1_DATA_A_START 0xFF800000 64#define L1_DATA_A_START 0xFF800000
65#define L1_DATA_B_START 0xFF900000 65#define L1_DATA_B_START 0xFF900000
66 66
67#ifdef CONFIG_BLKFIN_CACHE 67#ifdef CONFIG_BFIN_ICACHE
68#define L1_CODE_LENGTH (0x14000 - 0x4000) 68#define L1_CODE_LENGTH (0x14000 - 0x4000)
69#else 69#else
70#define L1_CODE_LENGTH 0x14000 70#define L1_CODE_LENGTH 0x14000
71#endif 71#endif
72 72
73#ifdef CONFIG_BLKFIN_DCACHE 73#ifdef CONFIG_BFIN_DCACHE
74 74
75#ifdef CONFIG_BLKFIN_DCACHE_BANKA 75#ifdef CONFIG_BFIN_DCACHE_BANKA
76#define DMEM_CNTR (ACACHE_BSRAM | ENDCPLB | PORT_PREF0) 76#define DMEM_CNTR (ACACHE_BSRAM | ENDCPLB | PORT_PREF0)
77#define L1_DATA_A_LENGTH (0x8000 - 0x4000) 77#define L1_DATA_A_LENGTH (0x8000 - 0x4000)
78#define L1_DATA_B_LENGTH 0x8000 78#define L1_DATA_B_LENGTH 0x8000
79#define BLKFIN_DCACHESIZE (16*1024) 79#define BFIN_DCACHESIZE (16*1024)
80#define BLKFIN_DSUPBANKS 1 80#define BFIN_DSUPBANKS 1
81#else 81#else
82#define DMEM_CNTR (ACACHE_BCACHE | ENDCPLB | PORT_PREF0) 82#define DMEM_CNTR (ACACHE_BCACHE | ENDCPLB | PORT_PREF0)
83#define L1_DATA_A_LENGTH (0x8000 - 0x4000) 83#define L1_DATA_A_LENGTH (0x8000 - 0x4000)
84#define L1_DATA_B_LENGTH (0x8000 - 0x4000) 84#define L1_DATA_B_LENGTH (0x8000 - 0x4000)
85#define BLKFIN_DCACHESIZE (32*1024) 85#define BFIN_DCACHESIZE (32*1024)
86#define BLKFIN_DSUPBANKS 2 86#define BFIN_DSUPBANKS 2
87#endif 87#endif
88 88
89#else 89#else
90#define DMEM_CNTR (ASRAM_BSRAM | ENDCPLB | PORT_PREF0) 90#define DMEM_CNTR (ASRAM_BSRAM | ENDCPLB | PORT_PREF0)
91#define L1_DATA_A_LENGTH 0x8000 91#define L1_DATA_A_LENGTH 0x8000
92#define L1_DATA_B_LENGTH 0x8000 92#define L1_DATA_B_LENGTH 0x8000
93#define BLKFIN_DCACHESIZE (0*1024) 93#define BFIN_DCACHESIZE (0*1024)
94#define BLKFIN_DSUPBANKS 0 94#define BFIN_DSUPBANKS 0
95#endif /*CONFIG_BLKFIN_DCACHE*/ 95#endif /*CONFIG_BFIN_DCACHE*/
96#endif 96#endif
97 97
98/* Memory Map for ADSP-BF532 processors */ 98/* Memory Map for ADSP-BF532 processors */
@@ -102,36 +102,36 @@
102#define L1_DATA_A_START 0xFF804000 102#define L1_DATA_A_START 0xFF804000
103#define L1_DATA_B_START 0xFF904000 103#define L1_DATA_B_START 0xFF904000
104 104
105#ifdef CONFIG_BLKFIN_CACHE 105#ifdef CONFIG_BFIN_ICACHE
106#define L1_CODE_LENGTH (0xC000 - 0x4000) 106#define L1_CODE_LENGTH (0xC000 - 0x4000)
107#else 107#else
108#define L1_CODE_LENGTH 0xC000 108#define L1_CODE_LENGTH 0xC000
109#endif 109#endif
110 110
111#ifdef CONFIG_BLKFIN_DCACHE 111#ifdef CONFIG_BFIN_DCACHE
112 112
113#ifdef CONFIG_BLKFIN_DCACHE_BANKA 113#ifdef CONFIG_BFIN_DCACHE_BANKA
114#define DMEM_CNTR (ACACHE_BSRAM | ENDCPLB | PORT_PREF0) 114#define DMEM_CNTR (ACACHE_BSRAM | ENDCPLB | PORT_PREF0)
115#define L1_DATA_A_LENGTH (0x4000 - 0x4000) 115#define L1_DATA_A_LENGTH (0x4000 - 0x4000)
116#define L1_DATA_B_LENGTH 0x4000 116#define L1_DATA_B_LENGTH 0x4000
117#define BLKFIN_DCACHESIZE (16*1024) 117#define BFIN_DCACHESIZE (16*1024)
118#define BLKFIN_DSUPBANKS 1 118#define BFIN_DSUPBANKS 1
119 119
120#else 120#else
121#define DMEM_CNTR (ACACHE_BCACHE | ENDCPLB | PORT_PREF0) 121#define DMEM_CNTR (ACACHE_BCACHE | ENDCPLB | PORT_PREF0)
122#define L1_DATA_A_LENGTH (0x4000 - 0x4000) 122#define L1_DATA_A_LENGTH (0x4000 - 0x4000)
123#define L1_DATA_B_LENGTH (0x4000 - 0x4000) 123#define L1_DATA_B_LENGTH (0x4000 - 0x4000)
124#define BLKFIN_DCACHESIZE (32*1024) 124#define BFIN_DCACHESIZE (32*1024)
125#define BLKFIN_DSUPBANKS 2 125#define BFIN_DSUPBANKS 2
126#endif 126#endif
127 127
128#else 128#else
129#define DMEM_CNTR (ASRAM_BSRAM | ENDCPLB | PORT_PREF0) 129#define DMEM_CNTR (ASRAM_BSRAM | ENDCPLB | PORT_PREF0)
130#define L1_DATA_A_LENGTH 0x4000 130#define L1_DATA_A_LENGTH 0x4000
131#define L1_DATA_B_LENGTH 0x4000 131#define L1_DATA_B_LENGTH 0x4000
132#define BLKFIN_DCACHESIZE (0*1024) 132#define BFIN_DCACHESIZE (0*1024)
133#define BLKFIN_DSUPBANKS 0 133#define BFIN_DSUPBANKS 0
134#endif /*CONFIG_BLKFIN_DCACHE*/ 134#endif /*CONFIG_BFIN_DCACHE*/
135#endif 135#endif
136 136
137/* Memory Map for ADSP-BF531 processors */ 137/* Memory Map for ADSP-BF531 processors */
@@ -144,16 +144,16 @@
144#define L1_DATA_B_LENGTH 0x0000 144#define L1_DATA_B_LENGTH 0x0000
145 145
146 146
147#ifdef CONFIG_BLKFIN_DCACHE 147#ifdef CONFIG_BFIN_DCACHE
148#define DMEM_CNTR (ACACHE_BSRAM | ENDCPLB | PORT_PREF0) 148#define DMEM_CNTR (ACACHE_BSRAM | ENDCPLB | PORT_PREF0)
149#define L1_DATA_A_LENGTH (0x4000 - 0x4000) 149#define L1_DATA_A_LENGTH (0x4000 - 0x4000)
150#define BLKFIN_DCACHESIZE (16*1024) 150#define BFIN_DCACHESIZE (16*1024)
151#define BLKFIN_DSUPBANKS 1 151#define BFIN_DSUPBANKS 1
152#else 152#else
153#define DMEM_CNTR (ASRAM_BSRAM | ENDCPLB | PORT_PREF0) 153#define DMEM_CNTR (ASRAM_BSRAM | ENDCPLB | PORT_PREF0)
154#define L1_DATA_A_LENGTH 0x4000 154#define L1_DATA_A_LENGTH 0x4000
155#define BLKFIN_DCACHESIZE (0*1024) 155#define BFIN_DCACHESIZE (0*1024)
156#define BLKFIN_DSUPBANKS 0 156#define BFIN_DSUPBANKS 0
157#endif 157#endif
158 158
159#endif 159#endif
diff --git a/include/asm-blackfin/mach-bf537/anomaly.h b/include/asm-blackfin/mach-bf537/anomaly.h
index 4453e614c3b1..2b66ecf489f7 100644
--- a/include/asm-blackfin/mach-bf537/anomaly.h
+++ b/include/asm-blackfin/mach-bf537/anomaly.h
@@ -1,139 +1,144 @@
1
2/* 1/*
3 * File: include/asm-blackfin/mach-bf537/anomaly.h 2 * File: include/asm-blackfin/mach-bf537/anomaly.h
4 * Based on: 3 * Bugs: Enter bugs at http://blackfin.uclinux.org/
5 * Author:
6 *
7 * Created:
8 * Description:
9 *
10 * Rev:
11 *
12 * Modified:
13 *
14 *
15 * Bugs: Enter bugs at http://blackfin.uclinux.org/
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2, or (at your option)
20 * any later version.
21 * 4 *
22 * This program is distributed in the hope that it will be useful, 5 * Copyright (C) 2004-2007 Analog Devices Inc.
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of 6 * Licensed under the GPL-2 or later.
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; see the file COPYING.
29 * If not, write to the Free Software Foundation,
30 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 */ 7 */
32 8
33/* This file shoule be up to date with: 9/* This file shoule be up to date with:
34 * - Revision J, June 1, 2006; ADSP-BF537 Blackfin Processor Anomaly List 10 * - Revision M, March 13, 2007; ADSP-BF537 Blackfin Processor Anomaly List
35 * - Revision I, June 1, 2006; ADSP-BF536 Blackfin Processor Anomaly List 11 * - Revision L, March 13, 2007; ADSP-BF536 Blackfin Processor Anomaly List
36 * - Revision J, June 1, 2006; ADSP-BF534 Blackfin Processor Anomaly List 12 * - Revision M, March 13, 2007; ADSP-BF534 Blackfin Processor Anomaly List
37 */ 13 */
38 14
39#ifndef _MACH_ANOMALY_H_ 15#ifndef _MACH_ANOMALY_H_
40#define _MACH_ANOMALY_H_ 16#define _MACH_ANOMALY_H_
41 17
42/* We do not support 0.1 silicon - sorry */ 18/* We do not support 0.1 silicon - sorry */
43#if (defined(CONFIG_BF_REV_0_1)) 19#if __SILICON_REVISION__ < 2
44#error Kernel will not work on BF537/6/4 Version 0.1 20# error Kernel will not work on BF537 silicon version 0.0 or 0.1
45#endif 21#endif
46 22
47#if (defined(CONFIG_BF_REV_0_3) || defined(CONFIG_BF_REV_0_2)) 23#if defined(__ADSPBF534__)
48#define ANOMALY_05000074 /* A multi issue instruction with dsp32shiftimm in 24# define ANOMALY_BF534 1
49 slot1 and store of a P register in slot 2 is not 25#else
50 supported */ 26# define ANOMALY_BF534 0
51#define ANOMALY_05000119 /* DMA_RUN bit is not valid after a Peripheral Receive
52 Channel DMA stops */
53#define ANOMALY_05000122 /* Rx.H can not be used to access 16-bit System MMR
54 registers. */
55#define ANOMALY_05000166 /* PPI Data Lengths Between 8 and 16 do not zero out
56 upper bits*/
57#define ANOMALY_05000180 /* PPI_DELAY not functional in PPI modes with 0 frame
58 syncs */
59#if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
60#define ANOMALY_05000247 /* CLKIN Buffer Output Enable Reset Behavior Is
61 Changed */
62#endif
63#define ANOMALY_05000265 /* Sensitivity to noise with slow input edge rates on
64 SPORT external receive and transmit clocks. */
65#define ANOMALY_05000272 /* Certain data cache write through modes fail for
66 VDDint <=0.9V */
67#define ANOMALY_05000273 /* Writes to Synchronous SDRAM memory may be lost */
68#define ANOMALY_05000277 /* Writes to a flag data register one SCLK cycle after
69 an edge is detected may clear interrupt */
70#define ANOMALY_05000281 /* False Hardware Error Exception when ISR context is
71 not restored */
72#define ANOMALY_05000282 /* Memory DMA corruption with 32-bit data and traffic
73 control */
74#define ANOMALY_05000283 /* A system MMR write is stalled indefinitely when
75 killed in a particular stage*/
76#define ANOMALY_05000310 /* False hardware errors caused by fetches at the
77 * boundary of reserved memory */
78#define ANOMALY_05000312 /* Errors when SSYNC, CSYNC, or loads to LT, LB and LC
79 registers are interrupted */
80#define ANOMALY_05000313 /* PPI is level sensitive on first transfer */
81#define ANOMALY_05000322 /* EMAC RMII mode at 10-Base-T speed: RX frames not
82 * received properly */
83#endif 27#endif
84 28#if defined(__ADSPBF536__)
85#if defined(CONFIG_BF_REV_0_2) 29# define ANOMALY_BF536 1
86#define ANOMALY_05000244 /* With instruction cache enabled, a CSYNC or SSYNC or 30#else
87 IDLE around a Change of Control causes 31# define ANOMALY_BF536 0
88 unpredictable results */
89#define ANOMALY_05000250 /* Incorrect Bit-Shift of Data Word in Multichannel
90 (TDM) */
91#if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
92#define ANOMALY_05000252 /* EMAC Tx DMA error after an early frame abort */
93#endif 32#endif
94#define ANOMALY_05000253 /* Maximum external clock speed for Timers */ 33#if defined(__ADSPBF537__)
95#define ANOMALY_05000255 /* Entering Hibernate Mode with RTC Seconds event 34# define ANOMALY_BF537 1
96 interrupt not functional */ 35#else
97#if (defined(CONFIG_BF537) || defined(CONFIG_BF536)) 36# define ANOMALY_BF537 0
98#define ANOMALY_05000256 /* EMAC MDIO input latched on wrong MDC edge */
99#endif 37#endif
100#define ANOMALY_05000257 /* An interrupt or exception during short Hardware
101 loops may cause the instruction fetch unit to
102 malfunction */
103#define ANOMALY_05000258 /* Instruction Cache is corrupted when bit 9 and 12 of
104 the ICPLB Data registers differ */
105#define ANOMALY_05000260 /* ICPLB_STATUS MMR register may be corrupted */
106#define ANOMALY_05000261 /* DCPLB_FAULT_ADDR MMR register may be corrupted */
107#define ANOMALY_05000262 /* Stores to data cache may be lost */
108#define ANOMALY_05000263 /* Hardware loop corrupted when taking an ICPLB exception */
109#define ANOMALY_05000264 /* A Sync instruction (CSYNC, SSYNC) or an IDLE
110 instruction will cause an infinite stall in the
111 second to last instruction in a hardware loop */
112#define ANOMALY_05000268 /* Memory DMA error when peripheral DMA is running
113 and non-zero DEB_TRAFFIC_PERIOD value */
114#define ANOMALY_05000270 /* High I/O activity causes the output voltage of the
115 internal voltage regulator (VDDint) to decrease */
116#define ANOMALY_05000277 /* Writes to a flag data register one SCLK cycle after
117 an edge is detected may clear interrupt */
118#define ANOMALY_05000278 /* Disabling Peripherals with DMA running may cause
119 DMA system instability */
120#define ANOMALY_05000280 /* SPI Master boot mode does not work well with
121 Atmel Dataflash devices */
122#define ANOMALY_05000281 /* False Hardware Error Exception when ISR context
123 * is not restored */
124#define ANOMALY_05000282 /* Memory DMA corruption with 32-bit data and traffic
125 * control */
126#define ANOMALY_05000283 /* System MMR Write Is Stalled Indefinitely When
127 * Killed in a Particular Stage */
128#define ANOMALY_05000285 /* New Feature: EMAC TX DMA Word Alignment
129 * (Not Available On Older Silicon) */
130#define ANOMALY_05000288 /* SPORTs may receive bad data if FIFOs fill up */
131#define ANOMALY_05000315 /* Killed System MMR Write Completes Erroneously
132 * On Next System MMR Access */
133#define ANOMALY_05000316 /* EMAC RMII mode: collisions occur in Full Duplex
134 * mode */
135#define ANOMALY_05000321 /* EMAC RMII mode: TX frames in half duplex fail with
136 * status No Carrier */
137#endif /* CONFIG_BF_REV_0_2 */
138 38
139#endif /* _MACH_ANOMALY_H_ */ 39/* Multi-issue instruction with dsp32shiftimm in slot1 and P-reg store in slot 2 not supported */
40#define ANOMALY_05000074 (1)
41/* DMA_RUN bit is not valid after a Peripheral Receive Channel DMA stops */
42#define ANOMALY_05000119 (1)
43/* Rx.H cannot be used to access 16-bit System MMR registers */
44#define ANOMALY_05000122 (1)
45/* Killed 32-bit MMR write leads to next system MMR access thinking it should be 32-bit */
46#define ANOMALY_05000157 (__SILICON_REVISION__ < 2)
47/* PPI_DELAY not functional in PPI modes with 0 frame syncs */
48#define ANOMALY_05000180 (1)
49/* Instruction Cache Is Not Functional */
50#define ANOMALY_05000237 (__SILICON_REVISION__ < 2)
51/* If i-cache is on, CSYNC/SSYNC/IDLE around Change of Control causes failures */
52#define ANOMALY_05000244 (__SILICON_REVISION__ < 3)
53/* Spurious Hardware Error from an access in the shadow of a conditional branch */
54#define ANOMALY_05000245 (1)
55/* CLKIN Buffer Output Enable Reset Behavior Is Changed */
56#define ANOMALY_05000247 (1)
57/* Incorrect Bit-Shift of Data Word in Multichannel (TDM) mode in certain conditions */
58#define ANOMALY_05000250 (__SILICON_REVISION__ < 3)
59/* EMAC Tx DMA error after an early frame abort */
60#define ANOMALY_05000252 (__SILICON_REVISION__ < 3)
61/* Maximum external clock speed for Timers */
62#define ANOMALY_05000253 (__SILICON_REVISION__ < 3)
63/* Incorrect Timer Pulse Width in Single-Shot PWM_OUT mode with external clock */
64#define ANOMALY_05000254 (__SILICON_REVISION__ > 2)
65/* Entering Hibernate Mode with RTC Seconds event interrupt not functional */
66#define ANOMALY_05000255 (__SILICON_REVISION__ < 3)
67/* EMAC MDIO input latched on wrong MDC edge */
68#define ANOMALY_05000256 (__SILICON_REVISION__ < 3)
69/* Interrupt/Exception during short hardware loop may cause bad instruction fetches */
70#define ANOMALY_05000257 (__SILICON_REVISION__ < 3)
71/* Instruction Cache is corrupted when bits 9 and 12 of the ICPLB Data registers differ */
72#define ANOMALY_05000258 (((ANOMALY_BF536 || ANOMALY_BF537) && __SILICON_REVISION__ == 1) || __SILICON_REVISION__ == 2)
73/* ICPLB_STATUS MMR register may be corrupted */
74#define ANOMALY_05000260 (__SILICON_REVISION__ == 2)
75/* DCPLB_FAULT_ADDR MMR register may be corrupted */
76#define ANOMALY_05000261 (__SILICON_REVISION__ < 3)
77/* Stores to data cache may be lost */
78#define ANOMALY_05000262 (__SILICON_REVISION__ < 3)
79/* Hardware loop corrupted when taking an ICPLB exception */
80#define ANOMALY_05000263 (__SILICON_REVISION__ == 2)
81/* CSYNC/SSYNC/IDLE causes infinite stall in second to last instruction in hardware loop */
82#define ANOMALY_05000264 (__SILICON_REVISION__ < 3)
83/* Sensitivity to noise with slow input edge rates on external SPORT TX and RX clocks */
84#define ANOMALY_05000265 (1)
85/* Memory DMA error when peripheral DMA is running with non-zero DEB_TRAFFIC_PERIOD */
86#define ANOMALY_05000268 (__SILICON_REVISION__ < 3)
87/* High I/O activity causes output voltage of internal voltage regulator (VDDint) to decrease */
88#define ANOMALY_05000270 (__SILICON_REVISION__ < 3)
89/* Certain data cache write through modes fail for VDDint <=0.9V */
90#define ANOMALY_05000272 (1)
91/* Writes to Synchronous SDRAM memory may be lost */
92#define ANOMALY_05000273 (__SILICON_REVISION__ < 3)
93/* Writes to an I/O data register one SCLK cycle after an edge is detected may clear interrupt */
94#define ANOMALY_05000277 (__SILICON_REVISION__ < 3)
95/* Disabling Peripherals with DMA running may cause DMA system instability */
96#define ANOMALY_05000278 (((ANOMALY_BF536 || ANOMALY_BF537) && __SILICON_REVISION__ < 3) || (ANOMALY_BF534 && __SILICON_REVISION__ < 2))
97/* SPI Master boot mode does not work well with Atmel Data flash devices */
98#define ANOMALY_05000280 (1)
99/* False Hardware Error Exception when ISR context is not restored */
100#define ANOMALY_05000281 (__SILICON_REVISION__ < 3)
101/* Memory DMA corruption with 32-bit data and traffic control */
102#define ANOMALY_05000282 (__SILICON_REVISION__ < 3)
103/* System MMR Write Is Stalled Indefinitely When Killed in a Particular Stage */
104#define ANOMALY_05000283 (__SILICON_REVISION__ < 3)
105/* New Feature: EMAC TX DMA Word Alignment (Not Available On Older Silicon) */
106#define ANOMALY_05000285 (__SILICON_REVISION__ < 3)
107/* SPORTs may receive bad data if FIFOs fill up */
108#define ANOMALY_05000288 (__SILICON_REVISION__ < 3)
109/* Memory to memory DMA source/destination descriptors must be in same memory space */
110#define ANOMALY_05000301 (1)
111/* SSYNCs After Writes To CAN/DMA MMR Registers Are Not Always Handled Correctly */
112#define ANOMALY_05000304 (__SILICON_REVISION__ < 3)
113/* New Feature: Additional Hysteresis on SPORT Input Pins (Not Available On Older Silicon) */
114#define ANOMALY_05000305 (__SILICON_REVISION__ < 3)
115/* SCKELOW Bit Does Not Maintain State Through Hibernate */
116#define ANOMALY_05000307 (__SILICON_REVISION__ < 3)
117/* Writing UART_THR while UART clock is disabled sends erroneous start bit */
118#define ANOMALY_05000309 (__SILICON_REVISION__ < 3)
119/* False hardware errors caused by fetches at the boundary of reserved memory */
120#define ANOMALY_05000310 (1)
121/* Errors when SSYNC, CSYNC, or loads to LT, LB and LC registers are interrupted */
122#define ANOMALY_05000312 (1)
123/* PPI is level sensitive on first transfer */
124#define ANOMALY_05000313 (1)
125/* Killed System MMR Write Completes Erroneously On Next System MMR Access */
126#define ANOMALY_05000315 (__SILICON_REVISION__ < 3)
127/* EMAC RMII mode: collisions occur in Full Duplex mode */
128#define ANOMALY_05000316 (__SILICON_REVISION__ < 3)
129/* EMAC RMII mode: TX frames in half duplex fail with status No Carrier */
130#define ANOMALY_05000321 (__SILICON_REVISION__ < 3)
131/* EMAC RMII mode at 10-Base-T speed: RX frames not received properly */
132#define ANOMALY_05000322 (1)
133
134/* Anomalies that don't exist on this proc */
135#define ANOMALY_05000125 (0)
136#define ANOMALY_05000158 (0)
137#define ANOMALY_05000183 (0)
138#define ANOMALY_05000198 (0)
139#define ANOMALY_05000230 (0)
140#define ANOMALY_05000266 (0)
141#define ANOMALY_05000311 (0)
142#define ANOMALY_05000323 (0)
143
144#endif
diff --git a/include/asm-blackfin/mach-bf537/bf537.h b/include/asm-blackfin/mach-bf537/bf537.h
index b8924cd7730c..cfe2a221112e 100644
--- a/include/asm-blackfin/mach-bf537/bf537.h
+++ b/include/asm-blackfin/mach-bf537/bf537.h
@@ -62,12 +62,12 @@
62/***************************/ 62/***************************/
63 63
64 64
65#define BLKFIN_DSUBBANKS 4 65#define BFIN_DSUBBANKS 4
66#define BLKFIN_DWAYS 2 66#define BFIN_DWAYS 2
67#define BLKFIN_DLINES 64 67#define BFIN_DLINES 64
68#define BLKFIN_ISUBBANKS 4 68#define BFIN_ISUBBANKS 4
69#define BLKFIN_IWAYS 4 69#define BFIN_IWAYS 4
70#define BLKFIN_ILINES 32 70#define BFIN_ILINES 32
71 71
72#define WAY0_L 0x1 72#define WAY0_L 0x1
73#define WAY1_L 0x2 73#define WAY1_L 0x2
@@ -121,97 +121,6 @@
121 121
122#define AMGCTLVAL (V_AMBEN | V_AMCKEN | V_CDPRIO) 122#define AMGCTLVAL (V_AMBEN | V_AMCKEN | V_CDPRIO)
123 123
124#define MAX_VC 650000000
125#define MIN_VC 50000000
126
127/********************************PLL Settings **************************************/
128#ifdef CONFIG_BFIN_KERNEL_CLOCK
129#if (CONFIG_VCO_MULT < 0)
130#error "VCO Multiplier is less than 0. Please select a different value"
131#endif
132
133#if (CONFIG_VCO_MULT == 0)
134#error "VCO Multiplier should be greater than 0. Please select a different value"
135#endif
136
137#if (CONFIG_VCO_MULT > 64)
138#error "VCO Multiplier is more than 64. Please select a different value"
139#endif
140
141#ifndef CONFIG_CLKIN_HALF
142#define CONFIG_VCO_HZ (CONFIG_CLKIN_HZ * CONFIG_VCO_MULT)
143#else
144#define CONFIG_VCO_HZ ((CONFIG_CLKIN_HZ * CONFIG_VCO_MULT)/2)
145#endif
146
147#ifndef CONFIG_PLL_BYPASS
148#define CONFIG_CCLK_HZ (CONFIG_VCO_HZ/CONFIG_CCLK_DIV)
149#define CONFIG_SCLK_HZ (CONFIG_VCO_HZ/CONFIG_SCLK_DIV)
150#else
151#define CONFIG_CCLK_HZ CONFIG_CLKIN_HZ
152#define CONFIG_SCLK_HZ CONFIG_CLKIN_HZ
153#endif
154
155#if (CONFIG_SCLK_DIV < 1)
156#error "SCLK DIV cannot be less than 1 or more than 15. Please select a proper value"
157#endif
158
159#if (CONFIG_SCLK_DIV > 15)
160#error "SCLK DIV cannot be less than 1 or more than 15. Please select a proper value"
161#endif
162
163#if (CONFIG_CCLK_DIV != 1)
164#if (CONFIG_CCLK_DIV != 2)
165#if (CONFIG_CCLK_DIV != 4)
166#if (CONFIG_CCLK_DIV != 8)
167#error "CCLK DIV can be 1,2,4 or 8 only. Please select a proper value"
168#endif
169#endif
170#endif
171#endif
172
173#if (CONFIG_VCO_HZ > MAX_VC)
174#error "VCO selected is more than maximum value. Please change the VCO multipler"
175#endif
176
177#if (CONFIG_SCLK_HZ > 133000000)
178#error "Sclk value selected is more than maximum. Please select a proper value for SCLK multiplier"
179#endif
180
181#if (CONFIG_SCLK_HZ < 27000000)
182#error "Sclk value selected is less than minimum. Please select a proper value for SCLK multiplier"
183#endif
184
185#if (CONFIG_SCLK_HZ >= CONFIG_CCLK_HZ)
186#if (CONFIG_SCLK_HZ != CONFIG_CLKIN_HZ)
187#if (CONFIG_CCLK_HZ != CONFIG_CLKIN_HZ)
188#error "Please select sclk less than cclk"
189#endif
190#endif
191#endif
192
193#if (CONFIG_CCLK_DIV == 1)
194#define CONFIG_CCLK_ACT_DIV CCLK_DIV1
195#endif
196#if (CONFIG_CCLK_DIV == 2)
197#define CONFIG_CCLK_ACT_DIV CCLK_DIV2
198#endif
199#if (CONFIG_CCLK_DIV == 4)
200#define CONFIG_CCLK_ACT_DIV CCLK_DIV4
201#endif
202#if (CONFIG_CCLK_DIV == 8)
203#define CONFIG_CCLK_ACT_DIV CCLK_DIV8
204#endif
205#ifndef CONFIG_CCLK_ACT_DIV
206#define CONFIG_CCLK_ACT_DIV CONFIG_CCLK_DIV_not_defined_properly
207#endif
208
209#if defined(ANOMALY_05000273) && (CONFIG_CCLK_DIV == 1)
210#error ANOMALY 05000273, please make sure CCLK is at least 2x SCLK
211#endif
212
213#endif /* CONFIG_BFIN_KERNEL_CLOCK */
214
215#ifdef CONFIG_BF537 124#ifdef CONFIG_BF537
216#define CPU "BF537" 125#define CPU "BF537"
217#define CPUID 0x027c8000 126#define CPUID 0x027c8000
@@ -229,59 +138,4 @@
229#define CPUID 0x0 138#define CPUID 0x0
230#endif 139#endif
231 140
232#if (CONFIG_MEM_SIZE % 4)
233#error "SDRAM mem size must be multible of 4MB"
234#endif
235
236#define SDRAM_IGENERIC (CPLB_L1_CHBL | CPLB_USER_RD | CPLB_VALID | CPLB_PORTPRIO)
237#define SDRAM_IKERNEL (SDRAM_IGENERIC | CPLB_LOCK)
238#define L1_IMEMORY ( CPLB_USER_RD | CPLB_VALID | CPLB_LOCK)
239#define SDRAM_INON_CHBL ( CPLB_USER_RD | CPLB_VALID)
240
241/*Use the menuconfig cache policy here - CONFIG_BLKFIN_WT/CONFIG_BLKFIN_WB*/
242
243#define ANOMALY_05000158_WORKAROUND 0x200
244#ifdef CONFIG_BLKFIN_WB /*Write Back Policy */
245#define SDRAM_DGENERIC (CPLB_L1_CHBL | CPLB_DIRTY \
246 | CPLB_SUPV_WR | CPLB_USER_WR | CPLB_USER_RD | CPLB_VALID | ANOMALY_05000158_WORKAROUND)
247#else /*Write Through */
248#define SDRAM_DGENERIC (CPLB_L1_CHBL | CPLB_WT | CPLB_L1_AOW \
249 | CPLB_SUPV_WR | CPLB_USER_WR | CPLB_USER_RD | CPLB_VALID | ANOMALY_05000158_WORKAROUND | CPLB_DIRTY )
250#endif
251
252
253#define L1_DMEMORY (CPLB_SUPV_WR | CPLB_USER_WR | CPLB_USER_RD | CPLB_VALID | ANOMALY_05000158_WORKAROUND | CPLB_LOCK | CPLB_DIRTY )
254#define SDRAM_DNON_CHBL (CPLB_SUPV_WR | CPLB_USER_WR | CPLB_USER_RD | CPLB_VALID | ANOMALY_05000158_WORKAROUND | CPLB_DIRTY )
255#define SDRAM_EBIU (CPLB_SUPV_WR | CPLB_USER_WR | CPLB_USER_RD | CPLB_VALID | ANOMALY_05000158_WORKAROUND | CPLB_DIRTY )
256#define SDRAM_OOPS (CPLB_VALID | ANOMALY_05000158_WORKAROUND | CPLB_LOCK | CPLB_DIRTY )
257
258#define SIZE_1K 0x00000400 /* 1K */
259#define SIZE_4K 0x00001000 /* 4K */
260#define SIZE_1M 0x00100000 /* 1M */
261#define SIZE_4M 0x00400000 /* 4M */
262
263#define MAX_CPLBS (16 * 2)
264
265/*
266* Number of required data CPLB switchtable entries
267* MEMSIZE / 4 (we mostly install 4M page size CPLBs
268* approx 16 for smaller 1MB page size CPLBs for allignment purposes
269* 1 for L1 Data Memory
270* 1 for CONFIG_DEBUG_HUNT_FOR_ZERO
271* 1 for ASYNC Memory
272*/
273
274
275#define MAX_SWITCH_D_CPLBS (((CONFIG_MEM_SIZE / 4) + 16 + 1 + 1 + 1) * 2)
276
277/*
278* Number of required instruction CPLB switchtable entries
279* MEMSIZE / 4 (we mostly install 4M page size CPLBs
280* approx 12 for smaller 1MB page size CPLBs for allignment purposes
281* 1 for L1 Instruction Memory
282* 1 for CONFIG_DEBUG_HUNT_FOR_ZERO
283*/
284
285#define MAX_SWITCH_I_CPLBS (((CONFIG_MEM_SIZE / 4) + 12 + 1 + 1) * 2)
286
287#endif /* __MACH_BF537_H__ */ 141#endif /* __MACH_BF537_H__ */
diff --git a/include/asm-blackfin/mach-bf537/blackfin.h b/include/asm-blackfin/mach-bf537/blackfin.h
index bbd97051ec9c..53fcfa3408d0 100644
--- a/include/asm-blackfin/mach-bf537/blackfin.h
+++ b/include/asm-blackfin/mach-bf537/blackfin.h
@@ -43,7 +43,7 @@
43#include "defBF537.h" 43#include "defBF537.h"
44#endif 44#endif
45 45
46#if !(defined(__ASSEMBLY__) || defined(ASSEMBLY)) 46#if !defined(__ASSEMBLY__)
47#include "cdefBF534.h" 47#include "cdefBF534.h"
48 48
49/* UART 0*/ 49/* UART 0*/
@@ -143,284 +143,6 @@
143#define bfin_write_STOPCK_OFF(val) bfin_write_STOPCK(val) 143#define bfin_write_STOPCK_OFF(val) bfin_write_STOPCK(val)
144#define STOPCK_OFF STOPCK 144#define STOPCK_OFF STOPCK
145 145
146/* FIO USE PORT F*/
147#ifdef CONFIG_BF537_PORT_F
148#define bfin_read_PORT_FER() bfin_read_PORTF_FER()
149#define bfin_write_PORT_FER(val) bfin_write_PORTF_FER(val)
150#define bfin_read_FIO_FLAG_D() bfin_read_PORTFIO()
151#define bfin_write_FIO_FLAG_D(val) bfin_write_PORTFIO(val)
152#define bfin_read_FIO_FLAG_C() bfin_read_PORTFIO_CLEAR()
153#define bfin_write_FIO_FLAG_C(val) bfin_write_PORTFIO_CLEAR(val)
154#define bfin_read_FIO_FLAG_S() bfin_read_PORTFIO_SET()
155#define bfin_write_FIO_FLAG_S(val) bfin_write_PORTFIO_SET(val)
156#define bfin_read_FIO_FLAG_T() bfin_read_PORTFIO_TOGGLE()
157#define bfin_write_FIO_FLAG_T(val) bfin_write_PORTFIO_TOGGLE(val)
158#define bfin_read_FIO_MASKA_D() bfin_read_PORTFIO_MASKA()
159#define bfin_write_FIO_MASKA_D(val) bfin_write_PORTFIO_MASKA(val)
160#define bfin_read_FIO_MASKA_C() bfin_read_PORTFIO_MASKA_CLEAR()
161#define bfin_write_FIO_MASKA_C(val) bfin_write_PORTFIO_MASKA_CLEAR(val)
162#define bfin_read_FIO_MASKA_S() bfin_read_PORTFIO_MASKA_SET()
163#define bfin_write_FIO_MASKA_S(val) bfin_write_PORTFIO_MASKA_SET(val)
164#define bfin_read_FIO_MASKA_T() bfin_read_PORTFIO_MASKA_TOGGLE()
165#define bfin_write_FIO_MASKA_T(val) bfin_write_PORTFIO_MASKA_TOGGLE(val)
166#define bfin_read_FIO_MASKB_D() bfin_read_PORTFIO_MASKB()
167#define bfin_write_FIO_MASKB_D(val) bfin_write_PORTFIO_MASKB(val)
168#define bfin_read_FIO_MASKB_C() bfin_read_PORTFIO_MASKB_CLEAR()
169#define bfin_write_FIO_MASKB_C(val) bfin_write_PORTFIO_MASKB_CLEAR(val)
170#define bfin_read_FIO_MASKB_S() bfin_read_PORTFIO_MASKB_SET()
171#define bfin_write_FIO_MASKB_S(val) bfin_write_PORTFIO_MASKB_SET(val)
172#define bfin_read_FIO_MASKB_T() bfin_read_PORTFIO_MASKB_TOGGLE()
173#define bfin_write_FIO_MASKB_T(val) bfin_write_PORTFIO_MASKB_TOGGLE(val)
174#define bfin_read_FIO_DIR() bfin_read_PORTFIO_DIR()
175#define bfin_write_FIO_DIR(val) bfin_write_PORTFIO_DIR(val)
176#define bfin_read_FIO_POLAR() bfin_read_PORTFIO_POLAR()
177#define bfin_write_FIO_POLAR(val) bfin_write_PORTFIO_POLAR(val)
178#define bfin_read_FIO_EDGE() bfin_read_PORTFIO_EDGE()
179#define bfin_write_FIO_EDGE(val) bfin_write_PORTFIO_EDGE(val)
180#define bfin_read_FIO_BOTH() bfin_read_PORTFIO_BOTH()
181#define bfin_write_FIO_BOTH(val) bfin_write_PORTFIO_BOTH(val)
182#define bfin_read_FIO_INEN() bfin_read_PORTFIO_INEN()
183#define bfin_write_FIO_INEN(val) bfin_write_PORTFIO_INEN(val)
184
185#define bfin_read_FIO_FLAG_D() bfin_read_PORTFIO()
186#define bfin_write_FIO_FLAG_D(val) bfin_write_PORTFIO(val)
187#define FIO_FLAG_D PORTFIO
188#define bfin_read_FIO_FLAG_C() bfin_read_PORTFIO_CLEAR()
189#define bfin_write_FIO_FLAG_C(val) bfin_write_PORTFIO_CLEAR(val)
190#define FIO_FLAG_C PORTFIO_CLEAR
191#define bfin_read_FIO_FLAG_S() bfin_read_PORTFIO_SET()
192#define bfin_write_FIO_FLAG_S(val) bfin_write_PORTFIO_SET(val)
193#define FIO_FLAG_S PORTFIO_SET
194#define bfin_read_FIO_FLAG_T() bfin_read_PORTFIO_TOGGLE()
195#define bfin_write_FIO_FLAG_T(val) bfin_write_PORTFIO_TOGGLE(val)
196#define FIO_FLAG_T PORTFIO_TOGGLE
197#define bfin_read_FIO_MASKA_D() bfin_read_PORTFIO_MASKA()
198#define bfin_write_FIO_MASKA_D(val) bfin_write_PORTFIO_MASKA(val)
199#define FIO_MASKA_D PORTFIO_MASKA
200#define bfin_read_FIO_MASKA_C() bfin_read_PORTFIO_MASKA_CLEAR()
201#define bfin_write_FIO_MASKA_C(val) bfin_write_PORTFIO_MASKA_CLEAR(val)
202#define FIO_MASKA_C PORTFIO_MASKA_CLEAR
203#define bfin_read_FIO_MASKA_S() bfin_read_PORTFIO_MASKA_SET()
204#define bfin_write_FIO_MASKA_S(val) bfin_write_PORTFIO_MASKA_SET(val)
205#define FIO_MASKA_S PORTFIO_MASKA_SET
206#define bfin_read_FIO_MASKA_T() bfin_read_PORTFIO_MASKA_TOGGLE()
207#define bfin_write_FIO_MASKA_T(val) bfin_write_PORTFIO_MASKA_TOGGLE(val)
208#define FIO_MASKA_T PORTFIO_MASKA_TOGGLE
209#define bfin_read_FIO_MASKB_D() bfin_read_PORTFIO_MASKB()
210#define bfin_write_FIO_MASKB_D(val) bfin_write_PORTFIO_MASKB(val)
211#define FIO_MASKB_D PORTFIO_MASKB
212#define bfin_read_FIO_MASKB_C() bfin_read_PORTFIO_MASKB_CLEAR()
213#define bfin_write_FIO_MASKB_C(val) bfin_write_PORTFIO_MASKB_CLEAR(val)
214#define FIO_MASKB_C PORTFIO_MASKB_CLEAR
215#define bfin_read_FIO_MASKB_S() bfin_read_PORTFIO_MASKB_SET()
216#define bfin_write_FIO_MASKB_S(val) bfin_write_PORTFIO_MASKB_SET(val)
217#define FIO_MASKB_S PORTFIO_MASKB_SET
218#define bfin_read_FIO_MASKB_T() bfin_read_PORTFIO_MASKB_TOGGLE()
219#define bfin_write_FIO_MASKB_T(val) bfin_write_PORTFIO_MASKB_TOGGLE(val)
220#define FIO_MASKB_T PORTFIO_MASKB_TOGGLE
221#define bfin_read_FIO_DIR() bfin_read_PORTFIO_DIR()
222#define bfin_write_FIO_DIR(val) bfin_write_PORTFIO_DIR(val)
223#define FIO_DIR PORTFIO_DIR
224#define bfin_read_FIO_POLAR() bfin_read_PORTFIO_POLAR()
225#define bfin_write_FIO_POLAR(val) bfin_write_PORTFIO_POLAR(val)
226#define FIO_POLAR PORTFIO_POLAR
227#define bfin_read_FIO_EDGE() bfin_read_PORTFIO_EDGE()
228#define bfin_write_FIO_EDGE(val) bfin_write_PORTFIO_EDGE(val)
229#define FIO_EDGE PORTFIO_EDGE
230#define bfin_read_FIO_BOTH() bfin_read_PORTFIO_BOTH()
231#define bfin_write_FIO_BOTH(val) bfin_write_PORTFIO_BOTH(val)
232#define FIO_BOTH PORTFIO_BOTH
233#define bfin_read_FIO_INEN() bfin_read_PORTFIO_INEN()
234#define bfin_write_FIO_INEN(val) bfin_write_PORTFIO_INEN(val)
235#define FIO_INEN PORTFIO_INEN
236#endif
237
238/* FIO USE PORT G*/
239#ifdef CONFIG_BF537_PORT_G
240#define bfin_read_PORT_FER() bfin_read_PORTG_FER()
241#define bfin_write_PORT_FER(val) bfin_write_PORTG_FER(val)
242#define bfin_read_FIO_FLAG_D() bfin_read_PORTGIO()
243#define bfin_write_FIO_FLAG_D(val) bfin_write_PORTGIO(val)
244#define bfin_read_FIO_FLAG_C() bfin_read_PORTGIO_CLEAR()
245#define bfin_write_FIO_FLAG_C(val) bfin_write_PORTGIO_CLEAR(val)
246#define bfin_read_FIO_FLAG_S() bfin_read_PORTGIO_SET()
247#define bfin_write_FIO_FLAG_S(val) bfin_write_PORTGIO_SET(val)
248#define bfin_read_FIO_FLAG_T() bfin_read_PORTGIO_TOGGLE()
249#define bfin_write_FIO_FLAG_T(val) bfin_write_PORTGIO_TOGGLE(val)
250#define bfin_read_FIO_MASKA_D() bfin_read_PORTGIO_MASKA()
251#define bfin_write_FIO_MASKA_D(val) bfin_write_PORTGIO_MASKA(val)
252#define bfin_read_FIO_MASKA_C() bfin_read_PORTGIO_MASKA_CLEAR()
253#define bfin_write_FIO_MASKA_C(val) bfin_write_PORTGIO_MASKA_CLEAR(val)
254#define bfin_read_FIO_MASKA_S() bfin_read_PORTGIO_MASKA_SET()
255#define bfin_write_FIO_MASKA_S(val) bfin_write_PORTGIO_MASKA_SET(val)
256#define bfin_read_FIO_MASKA_T() bfin_read_PORTGIO_MASKA_TOGGLE()
257#define bfin_write_FIO_MASKA_T(val) bfin_write_PORTGIO_MASKA_TOGGLE(val)
258#define bfin_read_FIO_MASKB_D() bfin_read_PORTGIO_MASKB()
259#define bfin_write_FIO_MASKB_D(val) bfin_write_PORTGIO_MASKB(val)
260#define bfin_read_FIO_MASKB_C() bfin_read_PORTGIO_MASKB_CLEAR()
261#define bfin_write_FIO_MASKB_C(val) bfin_write_PORTGIO_MASKB_CLEAR(val)
262#define bfin_read_FIO_MASKB_S() bfin_read_PORTGIO_MASKB_SET()
263#define bfin_write_FIO_MASKB_S(val) bfin_write_PORTGIO_MASKB_SET(val)
264#define bfin_read_FIO_MASKB_T() bfin_read_PORTGIO_MASKB_TOGGLE()
265#define bfin_write_FIO_MASKB_T(val) bfin_write_PORTGIO_MASKB_TOGGLE(val)
266#define bfin_read_FIO_DIR() bfin_read_PORTGIO_DIR()
267#define bfin_write_FIO_DIR(val) bfin_write_PORTGIO_DIR(val)
268#define bfin_read_FIO_POLAR() bfin_read_PORTGIO_POLAR()
269#define bfin_write_FIO_POLAR(val) bfin_write_PORTGIO_POLAR(val)
270#define bfin_read_FIO_EDGE() bfin_read_PORTGIO_EDGE()
271#define bfin_write_FIO_EDGE(val) bfin_write_PORTGIO_EDGE(val)
272#define bfin_read_FIO_BOTH() bfin_read_PORTGIO_BOTH()
273#define bfin_write_FIO_BOTH(val) bfin_write_PORTGIO_BOTH(val)
274#define bfin_read_FIO_INEN() bfin_read_PORTGIO_INEN()
275#define bfin_write_FIO_INEN(val) bfin_write_PORTGIO_INEN(val)
276
277#define bfin_read_FIO_FLAG_D() bfin_read_PORTGIO()
278#define bfin_write_FIO_FLAG_D(val) bfin_write_PORTGIO(val)
279#define FIO_FLAG_D PORTGIO
280#define bfin_read_FIO_FLAG_C() bfin_read_PORTGIO_CLEAR()
281#define bfin_write_FIO_FLAG_C(val) bfin_write_PORTGIO_CLEAR(val)
282#define FIO_FLAG_C PORTGIO_CLEAR
283#define bfin_read_FIO_FLAG_S() bfin_read_PORTGIO_SET()
284#define bfin_write_FIO_FLAG_S(val) bfin_write_PORTGIO_SET(val)
285#define FIO_FLAG_S PORTGIO_SET
286#define bfin_read_FIO_FLAG_T() bfin_read_PORTGIO_TOGGLE()
287#define bfin_write_FIO_FLAG_T(val) bfin_write_PORTGIO_TOGGLE(val)
288#define FIO_FLAG_T PORTGIO_TOGGLE
289#define bfin_read_FIO_MASKA_D() bfin_read_PORTGIO_MASKA()
290#define bfin_write_FIO_MASKA_D(val) bfin_write_PORTGIO_MASKA(val)
291#define FIO_MASKA_D PORTGIO_MASKA
292#define bfin_read_FIO_MASKA_C() bfin_read_PORTGIO_MASKA_CLEAR()
293#define bfin_write_FIO_MASKA_C(val) bfin_write_PORTGIO_MASKA_CLEAR(val)
294#define FIO_MASKA_C PORTGIO_MASKA_CLEAR
295#define bfin_read_FIO_MASKA_S() bfin_read_PORTGIO_MASKA_SET()
296#define bfin_write_FIO_MASKA_S(val) bfin_write_PORTGIO_MASKA_SET(val)
297#define FIO_MASKA_S PORTGIO_MASKA_SET
298#define bfin_read_FIO_MASKA_T() bfin_read_PORTGIO_MASKA_TOGGLE()
299#define bfin_write_FIO_MASKA_T(val) bfin_write_PORTGIO_MASKA_TOGGLE(val)
300#define FIO_MASKA_T PORTGIO_MASKA_TOGGLE
301#define bfin_read_FIO_MASKB_D() bfin_read_PORTGIO_MASKB()
302#define bfin_write_FIO_MASKB_D(val) bfin_write_PORTGIO_MASKB(val)
303#define FIO_MASKB_D PORTGIO_MASKB
304#define bfin_read_FIO_MASKB_C() bfin_read_PORTGIO_MASKB_CLEAR()
305#define bfin_write_FIO_MASKB_C(val) bfin_write_PORTGIO_MASKB_CLEAR(val)
306#define FIO_MASKB_C PORTGIO_MASKB_CLEAR
307#define bfin_read_FIO_MASKB_S() bfin_read_PORTGIO_MASKB_SET()
308#define bfin_write_FIO_MASKB_S(val) bfin_write_PORTGIO_MASKB_SET(val)
309#define FIO_MASKB_S PORTGIO_MASKB_SET
310#define bfin_read_FIO_MASKB_T() bfin_read_PORTGIO_MASKB_TOGGLE()
311#define bfin_write_FIO_MASKB_T(val) bfin_write_PORTGIO_MASKB_TOGGLE(val)
312#define FIO_MASKB_T PORTGIO_MASKB_TOGGLE
313#define bfin_read_FIO_DIR() bfin_read_PORTGIO_DIR()
314#define bfin_write_FIO_DIR(val) bfin_write_PORTGIO_DIR(val)
315#define FIO_DIR PORTGIO_DIR
316#define bfin_read_FIO_POLAR() bfin_read_PORTGIO_POLAR()
317#define bfin_write_FIO_POLAR(val) bfin_write_PORTGIO_POLAR(val)
318#define FIO_POLAR PORTGIO_POLAR
319#define bfin_read_FIO_EDGE() bfin_read_PORTGIO_EDGE()
320#define bfin_write_FIO_EDGE(val) bfin_write_PORTGIO_EDGE(val)
321#define FIO_EDGE PORTGIO_EDGE
322#define bfin_read_FIO_BOTH() bfin_read_PORTGIO_BOTH()
323#define bfin_write_FIO_BOTH(val) bfin_write_PORTGIO_BOTH(val)
324#define FIO_BOTH PORTGIO_BOTH
325#define bfin_read_FIO_INEN() bfin_read_PORTGIO_INEN()
326#define bfin_write_FIO_INEN(val) bfin_write_PORTGIO_INEN(val)
327#define FIO_INEN PORTGIO_INEN
328
329#endif
330
331/* FIO USE PORT H*/
332#ifdef CONFIG_BF537_PORT_H
333#define bfin_read_PORT_FER() bfin_read_PORTH_FER()
334#define bfin_write_PORT_FER(val) bfin_write_PORTH_FER(val)
335#define bfin_read_FIO_FLAG_D() bfin_read_PORTHIO()
336#define bfin_write_FIO_FLAG_D(val) bfin_write_PORTHIO(val)
337#define bfin_read_FIO_FLAG_C() bfin_read_PORTHIO_CLEAR()
338#define bfin_write_FIO_FLAG_C(val) bfin_write_PORTHIO_CLEAR(val)
339#define bfin_read_FIO_FLAG_S() bfin_read_PORTHIO_SET()
340#define bfin_write_FIO_FLAG_S(val) bfin_write_PORTHIO_SET(val)
341#define bfin_read_FIO_FLAG_T() bfin_read_PORTHIO_TOGGLE()
342#define bfin_write_FIO_FLAG_T(val) bfin_write_PORTHIO_TOGGLE(val)
343#define bfin_read_FIO_MASKA_D() bfin_read_PORTHIO_MASKA()
344#define bfin_write_FIO_MASKA_D(val) bfin_write_PORTHIO_MASKA(val)
345#define bfin_read_FIO_MASKA_C() bfin_read_PORTHIO_MASKA_CLEAR()
346#define bfin_write_FIO_MASKA_C(val) bfin_write_PORTHIO_MASKA_CLEAR(val)
347#define bfin_read_FIO_MASKA_S() bfin_read_PORTHIO_MASKA_SET()
348#define bfin_write_FIO_MASKA_S(val) bfin_write_PORTHIO_MASKA_SET(val)
349#define bfin_read_FIO_MASKA_T() bfin_read_PORTHIO_MASKA_TOGGLE()
350#define bfin_write_FIO_MASKA_T(val) bfin_write_PORTHIO_MASKA_TOGGLE(val)
351#define bfin_read_FIO_MASKB_D() bfin_read_PORTHIO_MASKB()
352#define bfin_write_FIO_MASKB_D(val) bfin_write_PORTHIO_MASKB(val)
353#define bfin_read_FIO_MASKB_C() bfin_read_PORTHIO_MASKB_CLEAR()
354#define bfin_write_FIO_MASKB_C(val) bfin_write_PORTHIO_MASKB_CLEAR(val)
355#define bfin_read_FIO_MASKB_S() bfin_read_PORTHIO_MASKB_SET()
356#define bfin_write_FIO_MASKB_S(val) bfin_write_PORTHIO_MASKB_SET(val)
357#define bfin_read_FIO_MASKB_T() bfin_read_PORTHIO_MASKB_TOGGLE()
358#define bfin_write_FIO_MASKB_T(val) bfin_write_PORTHIO_MASKB_TOGGLE(val)
359#define bfin_read_FIO_DIR() bfin_read_PORTHIO_DIR()
360#define bfin_write_FIO_DIR(val) bfin_write_PORTHIO_DIR(val)
361#define bfin_read_FIO_POLAR() bfin_read_PORTHIO_POLAR()
362#define bfin_write_FIO_POLAR(val) bfin_write_PORTHIO_POLAR(val)
363#define bfin_read_FIO_EDGE() bfin_read_PORTHIO_EDGE()
364#define bfin_write_FIO_EDGE(val) bfin_write_PORTHIO_EDGE(val)
365#define bfin_read_FIO_BOTH() bfin_read_PORTHIO_BOTH()
366#define bfin_write_FIO_BOTH(val) bfin_write_PORTHIO_BOTH(val)
367#define bfin_read_FIO_INEN() bfin_read_PORTHIO_INEN()
368#define bfin_write_FIO_INEN(val) bfin_write_PORTHIO_INEN(val)
369
370#define bfin_read_FIO_FLAG_D() bfin_read_PORTHIO()
371#define bfin_write_FIO_FLAG_D(val) bfin_write_PORTHIO(val)
372#define FIO_FLAG_D PORTHIO
373#define bfin_read_FIO_FLAG_C() bfin_read_PORTHIO_CLEAR()
374#define bfin_write_FIO_FLAG_C(val) bfin_write_PORTHIO_CLEAR(val)
375#define FIO_FLAG_C PORTHIO_CLEAR
376#define bfin_read_FIO_FLAG_S() bfin_read_PORTHIO_SET()
377#define bfin_write_FIO_FLAG_S(val) bfin_write_PORTHIO_SET(val)
378#define FIO_FLAG_S PORTHIO_SET
379#define bfin_read_FIO_FLAG_T() bfin_read_PORTHIO_TOGGLE()
380#define bfin_write_FIO_FLAG_T(val) bfin_write_PORTHIO_TOGGLE(val)
381#define FIO_FLAG_T PORTHIO_TOGGLE
382#define bfin_read_FIO_MASKA_D() bfin_read_PORTHIO_MASKA()
383#define bfin_write_FIO_MASKA_D(val) bfin_write_PORTHIO_MASKA(val)
384#define FIO_MASKA_D PORTHIO_MASKA
385#define bfin_read_FIO_MASKA_C() bfin_read_PORTHIO_MASKA_CLEAR()
386#define bfin_write_FIO_MASKA_C(val) bfin_write_PORTHIO_MASKA_CLEAR(val)
387#define FIO_MASKA_C PORTHIO_MASKA_CLEAR
388#define bfin_read_FIO_MASKA_S() bfin_read_PORTHIO_MASKA_SET()
389#define bfin_write_FIO_MASKA_S(val) bfin_write_PORTHIO_MASKA_SET(val)
390#define FIO_MASKA_S PORTHIO_MASKA_SET
391#define bfin_read_FIO_MASKA_T() bfin_read_PORTHIO_MASKA_TOGGLE()
392#define bfin_write_FIO_MASKA_T(val) bfin_write_PORTHIO_MASKA_TOGGLE(val)
393#define FIO_MASKA_T PORTHIO_MASKA_TOGGLE
394#define bfin_read_FIO_MASKB_D() bfin_read_PORTHIO_MASKB()
395#define bfin_write_FIO_MASKB_D(val) bfin_write_PORTHIO_MASKB(val)
396#define FIO_MASKB_D PORTHIO_MASKB
397#define bfin_read_FIO_MASKB_C() bfin_read_PORTHIO_MASKB_CLEAR()
398#define bfin_write_FIO_MASKB_C(val) bfin_write_PORTHIO_MASKB_CLEAR(val)
399#define FIO_MASKB_C PORTHIO_MASKB_CLEAR
400#define bfin_read_FIO_MASKB_S() bfin_read_PORTHIO_MASKB_SET()
401#define bfin_write_FIO_MASKB_S(val) bfin_write_PORTHIO_MASKB_SET(val)
402#define FIO_MASKB_S PORTHIO_MASKB_SET
403#define bfin_read_FIO_MASKB_T() bfin_read_PORTHIO_MASKB_TOGGLE()
404#define bfin_write_FIO_MASKB_T(val) bfin_write_PORTHIO_MASKB_TOGGLE(val)
405#define FIO_MASKB_T PORTHIO_MASKB_TOGGLE
406#define bfin_read_FIO_DIR() bfin_read_PORTHIO_DIR()
407#define bfin_write_FIO_DIR(val) bfin_write_PORTHIO_DIR(val)
408#define FIO_DIR PORTHIO_DIR
409#define bfin_read_FIO_POLAR() bfin_read_PORTHIO_POLAR()
410#define bfin_write_FIO_POLAR(val) bfin_write_PORTHIO_POLAR(val)
411#define FIO_POLAR PORTHIO_POLAR
412#define bfin_read_FIO_EDGE() bfin_read_PORTHIO_EDGE()
413#define bfin_write_FIO_EDGE(val) bfin_write_PORTHIO_EDGE(val)
414#define FIO_EDGE PORTHIO_EDGE
415#define bfin_read_FIO_BOTH() bfin_read_PORTHIO_BOTH()
416#define bfin_write_FIO_BOTH(val) bfin_write_PORTHIO_BOTH(val)
417#define FIO_BOTH PORTHIO_BOTH
418#define bfin_read_FIO_INEN() bfin_read_PORTHIO_INEN()
419#define bfin_write_FIO_INEN(val) bfin_write_PORTHIO_INEN(val)
420#define FIO_INEN PORTHIO_INEN
421
422#endif
423
424/* PLL_DIV Masks */ 146/* PLL_DIV Masks */
425#define CCLK_DIV1 CSEL_DIV1 /* CCLK = VCO / 1 */ 147#define CCLK_DIV1 CSEL_DIV1 /* CCLK = VCO / 1 */
426#define CCLK_DIV2 CSEL_DIV2 /* CCLK = VCO / 2 */ 148#define CCLK_DIV2 CSEL_DIV2 /* CCLK = VCO / 2 */
diff --git a/include/asm-blackfin/mach-bf537/cdefBF534.h b/include/asm-blackfin/mach-bf537/cdefBF534.h
index 84e58fa73dce..78227bc855df 100644
--- a/include/asm-blackfin/mach-bf537/cdefBF534.h
+++ b/include/asm-blackfin/mach-bf537/cdefBF534.h
@@ -32,6 +32,8 @@
32#ifndef _CDEF_BF534_H 32#ifndef _CDEF_BF534_H
33#define _CDEF_BF534_H 33#define _CDEF_BF534_H
34 34
35#include <asm/blackfin.h>
36
35/* Include all Core registers and bit definitions */ 37/* Include all Core registers and bit definitions */
36#include "defBF534.h" 38#include "defBF534.h"
37 39
@@ -57,7 +59,7 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
57 bfin_write32(SIC_IWR, IWR_ENABLE(0)); 59 bfin_write32(SIC_IWR, IWR_ENABLE(0));
58 60
59 bfin_write16(VR_CTL, val); 61 bfin_write16(VR_CTL, val);
60 __builtin_bfin_ssync(); 62 SSYNC();
61 63
62 local_irq_save(flags); 64 local_irq_save(flags);
63 asm("IDLE;"); 65 asm("IDLE;");
diff --git a/include/asm-blackfin/mach-bf537/defBF534.h b/include/asm-blackfin/mach-bf537/defBF534.h
index 1859f2fee5a7..d0d80d3152ba 100644
--- a/include/asm-blackfin/mach-bf537/defBF534.h
+++ b/include/asm-blackfin/mach-bf537/defBF534.h
@@ -86,6 +86,7 @@
86#define UART0_GCTL 0xFFC00424 /* Global Control Register */ 86#define UART0_GCTL 0xFFC00424 /* Global Control Register */
87 87
88/* SPI Controller (0xFFC00500 - 0xFFC005FF) */ 88/* SPI Controller (0xFFC00500 - 0xFFC005FF) */
89#define SPI0_REGBASE 0xFFC00500
89#define SPI_CTL 0xFFC00500 /* SPI Control Register */ 90#define SPI_CTL 0xFFC00500 /* SPI Control Register */
90#define SPI_FLG 0xFFC00504 /* SPI Flag register */ 91#define SPI_FLG 0xFFC00504 /* SPI Flag register */
91#define SPI_STAT 0xFFC00508 /* SPI Status register */ 92#define SPI_STAT 0xFFC00508 /* SPI Status register */
@@ -456,6 +457,7 @@
456#define PPI_FRAME 0xFFC01010 /* PPI Frame Length Register */ 457#define PPI_FRAME 0xFFC01010 /* PPI Frame Length Register */
457 458
458/* Two-Wire Interface (0xFFC01400 - 0xFFC014FF) */ 459/* Two-Wire Interface (0xFFC01400 - 0xFFC014FF) */
460#define TWI0_REGBASE 0xFFC01400
459#define TWI_CLKDIV 0xFFC01400 /* Serial Clock Divider Register */ 461#define TWI_CLKDIV 0xFFC01400 /* Serial Clock Divider Register */
460#define TWI_CONTROL 0xFFC01404 /* TWI Control Register */ 462#define TWI_CONTROL 0xFFC01404 /* TWI Control Register */
461#define TWI_SLAVE_CTL 0xFFC01408 /* Slave Mode Control Register */ 463#define TWI_SLAVE_CTL 0xFFC01408 /* Slave Mode Control Register */
@@ -1165,7 +1167,7 @@
1165#define GM 0x0008 /* Get More (When RDBR Full, Overwrite/Discard*) */ 1167#define GM 0x0008 /* Get More (When RDBR Full, Overwrite/Discard*) */
1166#define PSSE 0x0010 /* Slave-Select Input Enable */ 1168#define PSSE 0x0010 /* Slave-Select Input Enable */
1167#define EMISO 0x0020 /* Enable MISO As Output */ 1169#define EMISO 0x0020 /* Enable MISO As Output */
1168#define SPI_SIZE 0x0100 /* Size of Words (16/8* Bits) */ 1170#define SIZE 0x0100 /* Size of Words (16/8* Bits) */
1169#define LSBF 0x0200 /* LSB First */ 1171#define LSBF 0x0200 /* LSB First */
1170#define CPHA 0x0400 /* Clock Phase */ 1172#define CPHA 0x0400 /* Clock Phase */
1171#define CPOL 0x0800 /* Clock Polarity */ 1173#define CPOL 0x0800 /* Clock Polarity */
diff --git a/include/asm-blackfin/mach-bf537/irq.h b/include/asm-blackfin/mach-bf537/irq.h
index 8af2a832ef6b..36c44bc1a917 100644
--- a/include/asm-blackfin/mach-bf537/irq.h
+++ b/include/asm-blackfin/mach-bf537/irq.h
@@ -160,6 +160,8 @@ Core Emulation **
160#define IRQ_PH14 96 160#define IRQ_PH14 96
161#define IRQ_PH15 97 161#define IRQ_PH15 97
162 162
163#define GPIO_IRQ_BASE IRQ_PF0
164
163#ifdef CONFIG_IRQCHIP_DEMUX_GPIO 165#ifdef CONFIG_IRQCHIP_DEMUX_GPIO
164#define NR_IRQS (IRQ_PH15+1) 166#define NR_IRQS (IRQ_PH15+1)
165#else 167#else
diff --git a/include/asm-blackfin/mach-bf537/mem_map.h b/include/asm-blackfin/mach-bf537/mem_map.h
index 2a808c1202bf..18759e38eaae 100644
--- a/include/asm-blackfin/mach-bf537/mem_map.h
+++ b/include/asm-blackfin/mach-bf537/mem_map.h
@@ -52,10 +52,10 @@
52 52
53/* Memory Map for ADSP-BF537 processors */ 53/* Memory Map for ADSP-BF537 processors */
54 54
55#ifdef CONFIG_BLKFIN_CACHE 55#ifdef CONFIG_BFIN_ICACHE
56#define BLKFIN_ICACHESIZE (16*1024) 56#define BFIN_ICACHESIZE (16*1024)
57#else 57#else
58#define BLKFIN_ICACHESIZE (0*1024) 58#define BFIN_ICACHESIZE (0*1024)
59#endif 59#endif
60 60
61 61
@@ -66,29 +66,29 @@
66 66
67#define L1_CODE_LENGTH 0xC000 67#define L1_CODE_LENGTH 0xC000
68 68
69#ifdef CONFIG_BLKFIN_DCACHE 69#ifdef CONFIG_BFIN_DCACHE
70 70
71#ifdef CONFIG_BLKFIN_DCACHE_BANKA 71#ifdef CONFIG_BFIN_DCACHE_BANKA
72#define DMEM_CNTR (ACACHE_BSRAM | ENDCPLB | PORT_PREF0) 72#define DMEM_CNTR (ACACHE_BSRAM | ENDCPLB | PORT_PREF0)
73#define L1_DATA_A_LENGTH (0x8000 - 0x4000) 73#define L1_DATA_A_LENGTH (0x8000 - 0x4000)
74#define L1_DATA_B_LENGTH 0x8000 74#define L1_DATA_B_LENGTH 0x8000
75#define BLKFIN_DCACHESIZE (16*1024) 75#define BFIN_DCACHESIZE (16*1024)
76#define BLKFIN_DSUPBANKS 1 76#define BFIN_DSUPBANKS 1
77#else 77#else
78#define DMEM_CNTR (ACACHE_BCACHE | ENDCPLB | PORT_PREF0) 78#define DMEM_CNTR (ACACHE_BCACHE | ENDCPLB | PORT_PREF0)
79#define L1_DATA_A_LENGTH (0x8000 - 0x4000) 79#define L1_DATA_A_LENGTH (0x8000 - 0x4000)
80#define L1_DATA_B_LENGTH (0x8000 - 0x4000) 80#define L1_DATA_B_LENGTH (0x8000 - 0x4000)
81#define BLKFIN_DCACHESIZE (32*1024) 81#define BFIN_DCACHESIZE (32*1024)
82#define BLKFIN_DSUPBANKS 2 82#define BFIN_DSUPBANKS 2
83#endif 83#endif
84 84
85#else 85#else
86#define DMEM_CNTR (ASRAM_BSRAM | ENDCPLB | PORT_PREF0) 86#define DMEM_CNTR (ASRAM_BSRAM | ENDCPLB | PORT_PREF0)
87#define L1_DATA_A_LENGTH 0x8000 87#define L1_DATA_A_LENGTH 0x8000
88#define L1_DATA_B_LENGTH 0x8000 88#define L1_DATA_B_LENGTH 0x8000
89#define BLKFIN_DCACHESIZE (0*1024) 89#define BFIN_DCACHESIZE (0*1024)
90#define BLKFIN_DSUPBANKS 0 90#define BFIN_DSUPBANKS 0
91#endif /*CONFIG_BLKFIN_DCACHE*/ 91#endif /*CONFIG_BFIN_DCACHE*/
92 92
93#endif /*CONFIG_BF537*/ 93#endif /*CONFIG_BF537*/
94 94
@@ -102,30 +102,30 @@
102#define L1_CODE_LENGTH 0xC000 102#define L1_CODE_LENGTH 0xC000
103 103
104 104
105#ifdef CONFIG_BLKFIN_DCACHE 105#ifdef CONFIG_BFIN_DCACHE
106 106
107#ifdef CONFIG_BLKFIN_DCACHE_BANKA 107#ifdef CONFIG_BFIN_DCACHE_BANKA
108#define DMEM_CNTR (ACACHE_BSRAM | ENDCPLB | PORT_PREF0) 108#define DMEM_CNTR (ACACHE_BSRAM | ENDCPLB | PORT_PREF0)
109#define L1_DATA_A_LENGTH (0x4000 - 0x4000) 109#define L1_DATA_A_LENGTH (0x4000 - 0x4000)
110#define L1_DATA_B_LENGTH 0x4000 110#define L1_DATA_B_LENGTH 0x4000
111#define BLKFIN_DCACHESIZE (16*1024) 111#define BFIN_DCACHESIZE (16*1024)
112#define BLKFIN_DSUPBANKS 1 112#define BFIN_DSUPBANKS 1
113 113
114#else 114#else
115#define DMEM_CNTR (ACACHE_BCACHE | ENDCPLB | PORT_PREF0) 115#define DMEM_CNTR (ACACHE_BCACHE | ENDCPLB | PORT_PREF0)
116#define L1_DATA_A_LENGTH (0x4000 - 0x4000) 116#define L1_DATA_A_LENGTH (0x4000 - 0x4000)
117#define L1_DATA_B_LENGTH (0x4000 - 0x4000) 117#define L1_DATA_B_LENGTH (0x4000 - 0x4000)
118#define BLKFIN_DCACHESIZE (32*1024) 118#define BFIN_DCACHESIZE (32*1024)
119#define BLKFIN_DSUPBANKS 2 119#define BFIN_DSUPBANKS 2
120#endif 120#endif
121 121
122#else 122#else
123#define DMEM_CNTR (ASRAM_BSRAM | ENDCPLB | PORT_PREF0) 123#define DMEM_CNTR (ASRAM_BSRAM | ENDCPLB | PORT_PREF0)
124#define L1_DATA_A_LENGTH 0x4000 124#define L1_DATA_A_LENGTH 0x4000
125#define L1_DATA_B_LENGTH 0x4000 125#define L1_DATA_B_LENGTH 0x4000
126#define BLKFIN_DCACHESIZE (0*1024) 126#define BFIN_DCACHESIZE (0*1024)
127#define BLKFIN_DSUPBANKS 0 127#define BFIN_DSUPBANKS 0
128#endif /*CONFIG_BLKFIN_DCACHE*/ 128#endif /*CONFIG_BFIN_DCACHE*/
129 129
130#endif 130#endif
131 131
@@ -138,30 +138,30 @@
138 138
139#define L1_CODE_LENGTH 0xC000 139#define L1_CODE_LENGTH 0xC000
140 140
141#ifdef CONFIG_BLKFIN_DCACHE 141#ifdef CONFIG_BFIN_DCACHE
142 142
143#ifdef CONFIG_BLKFIN_DCACHE_BANKA 143#ifdef CONFIG_BFIN_DCACHE_BANKA
144#define DMEM_CNTR (ACACHE_BSRAM | ENDCPLB | PORT_PREF0) 144#define DMEM_CNTR (ACACHE_BSRAM | ENDCPLB | PORT_PREF0)
145#define L1_DATA_A_LENGTH (0x8000 - 0x4000) 145#define L1_DATA_A_LENGTH (0x8000 - 0x4000)
146#define L1_DATA_B_LENGTH 0x8000 146#define L1_DATA_B_LENGTH 0x8000
147#define BLKFIN_DCACHESIZE (16*1024) 147#define BFIN_DCACHESIZE (16*1024)
148#define BLKFIN_DSUPBANKS 1 148#define BFIN_DSUPBANKS 1
149 149
150#else 150#else
151#define DMEM_CNTR (ACACHE_BCACHE | ENDCPLB | PORT_PREF0) 151#define DMEM_CNTR (ACACHE_BCACHE | ENDCPLB | PORT_PREF0)
152#define L1_DATA_A_LENGTH (0x8000 - 0x4000) 152#define L1_DATA_A_LENGTH (0x8000 - 0x4000)
153#define L1_DATA_B_LENGTH (0x8000 - 0x4000) 153#define L1_DATA_B_LENGTH (0x8000 - 0x4000)
154#define BLKFIN_DCACHESIZE (32*1024) 154#define BFIN_DCACHESIZE (32*1024)
155#define BLKFIN_DSUPBANKS 2 155#define BFIN_DSUPBANKS 2
156#endif 156#endif
157 157
158#else 158#else
159#define DMEM_CNTR (ASRAM_BSRAM | ENDCPLB | PORT_PREF0) 159#define DMEM_CNTR (ASRAM_BSRAM | ENDCPLB | PORT_PREF0)
160#define L1_DATA_A_LENGTH 0x8000 160#define L1_DATA_A_LENGTH 0x8000
161#define L1_DATA_B_LENGTH 0x8000 161#define L1_DATA_B_LENGTH 0x8000
162#define BLKFIN_DCACHESIZE (0*1024) 162#define BFIN_DCACHESIZE (0*1024)
163#define BLKFIN_DSUPBANKS 0 163#define BFIN_DSUPBANKS 0
164#endif /*CONFIG_BLKFIN_DCACHE*/ 164#endif /*CONFIG_BFIN_DCACHE*/
165 165
166#endif 166#endif
167 167
diff --git a/include/asm-blackfin/mach-bf537/portmux.h b/include/asm-blackfin/mach-bf537/portmux.h
index ae6c53b28452..5a3f7d3bf73d 100644
--- a/include/asm-blackfin/mach-bf537/portmux.h
+++ b/include/asm-blackfin/mach-bf537/portmux.h
@@ -99,7 +99,7 @@
99#define P_SPORT0_DRPRI (P_DEFINED | P_IDENT(PORT_PJ8) | P_FUNCT(0)) 99#define P_SPORT0_DRPRI (P_DEFINED | P_IDENT(PORT_PJ8) | P_FUNCT(0))
100#define P_SPORT0_TSCLK (P_DEFINED | P_IDENT(PORT_PJ9) | P_FUNCT(0)) 100#define P_SPORT0_TSCLK (P_DEFINED | P_IDENT(PORT_PJ9) | P_FUNCT(0))
101#define P_SPORT0_TFS (P_DEFINED | P_IDENT(PORT_PJ10) | P_FUNCT(0)) 101#define P_SPORT0_TFS (P_DEFINED | P_IDENT(PORT_PJ10) | P_FUNCT(0))
102#define P_SPORT0_DTPRI (P_DEFINED | P_IDENT(PORT_PJ11) | P_FUNCT(1)) 102#define P_SPORT0_DTPRI (P_DEFINED | P_IDENT(PORT_PJ11) | P_FUNCT(0))
103#define P_CAN0_RX (P_DEFINED | P_IDENT(PORT_PJ4) | P_FUNCT(1)) 103#define P_CAN0_RX (P_DEFINED | P_IDENT(PORT_PJ4) | P_FUNCT(1))
104#define P_CAN0_TX (P_DEFINED | P_IDENT(PORT_PJ5) | P_FUNCT(1)) 104#define P_CAN0_TX (P_DEFINED | P_IDENT(PORT_PJ5) | P_FUNCT(1))
105#define P_SPI0_SSEL3 (P_DEFINED | P_IDENT(PORT_PJ10) | P_FUNCT(1)) 105#define P_SPI0_SSEL3 (P_DEFINED | P_IDENT(PORT_PJ10) | P_FUNCT(1))
diff --git a/include/asm-blackfin/mach-bf548/anomaly.h b/include/asm-blackfin/mach-bf548/anomaly.h
index aca1d4ba145c..c5b63759cdee 100644
--- a/include/asm-blackfin/mach-bf548/anomaly.h
+++ b/include/asm-blackfin/mach-bf548/anomaly.h
@@ -1,74 +1,85 @@
1
2/* 1/*
3 * File: include/asm-blackfin/mach-bf548/anomaly.h 2 * File: include/asm-blackfin/mach-bf548/anomaly.h
4 * Based on: 3 * Bugs: Enter bugs at http://blackfin.uclinux.org/
5 * Author:
6 *
7 * Created:
8 * Description:
9 *
10 * Rev:
11 *
12 * Modified:
13 *
14 *
15 * Bugs: Enter bugs at http://blackfin.uclinux.org/
16 * 4 *
17 * This program is free software; you can redistribute it and/or modify 5 * Copyright (C) 2004-2007 Analog Devices Inc.
18 * it under the terms of the GNU General Public License as published by 6 * Licensed under the GPL-2 or later.
19 * the Free Software Foundation; either version 2, or (at your option) 7 */
20 * any later version. 8
21 * 9/* This file shoule be up to date with:
22 * This program is distributed in the hope that it will be useful, 10 * - Revision C, July 16, 2007; ADSP-BF549 Silicon Anomaly List
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; see the file COPYING.
29 * If not, write to the Free Software Foundation,
30 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 */ 11 */
32 12
33#ifndef _MACH_ANOMALY_H_ 13#ifndef _MACH_ANOMALY_H_
34#define _MACH_ANOMALY_H_ 14#define _MACH_ANOMALY_H_
35#define ANOMALY_05000074 /* A multi issue instruction with dsp32shiftimm in
36 slot1 and store of a P register in slot 2 is not
37 supported */
38#define ANOMALY_05000119 /* DMA_RUN bit is not valid after a Peripheral Receive
39 Channel DMA stops */
40#define ANOMALY_05000122 /* Rx.H can not be used to access 16-bit System MMR
41 registers. */
42#define ANOMALY_05000245 /* Spurious Hardware Error from an Access in the
43 Shadow of a Conditional Branch */
44#define ANOMALY_05000255 /* Entering Hibernate Mode with RTC Seconds event
45 interrupt not functional */
46#define ANOMALY_05000265 /* Sensitivity to noise with slow input edge rates on
47 SPORT external receive and transmit clocks. */
48#define ANOMALY_05000272 /* Certain data cache write through modes fail for
49 VDDint <=0.9V */
50#define ANOMALY_05000281 /* False Hardware Error Exception when ISR context is
51 not restored */
52#define ANOMALY_05000310 /* False Hardware Errors Caused by Fetches at the
53 Boundary of Reserved Memory */
54#define ANOMALY_05000312 /* Errors When SSYNC, CSYNC, or Loads to LT, LB and
55 LC Registers Are Interrupted */
56#define ANOMALY_05000324 /* TWI Slave Boot Mode Is Not Functional */
57#define ANOMALY_05000325 /* External FIFO Boot Mode Is Not Functional */
58#define ANOMALY_05000327 /* Data Lost When Core and DMA Accesses Are Made to
59 the USB FIFO Simultaneously */
60#define ANOMALY_05000328 /* Incorrect Access of OTP_STATUS During otp_write()
61 function */
62#define ANOMALY_05000329 /* Synchronous Burst Flash Boot Mode Is Not Functional
63 */
64#define ANOMALY_05000330 /* Host DMA Boot Mode Is Not Functional */
65#define ANOMALY_05000334 /* Inadequate Timing Margins on DDR DQS to DQ and DQM
66 Skew */
67#define ANOMALY_05000335 /* Inadequate Rotary Debounce Logic Duration */
68#define ANOMALY_05000336 /* Phantom Interrupt Occurs After First Configuration
69 of Host DMA Port */
70#define ANOMALY_05000337 /* Disallowed Configuration Prevents Subsequent
71 Allowed Configuration on Host DMA Port */
72#define ANOMALY_05000338 /* Slave-Mode SPI0 MISO Failure With CPHA = 0 */
73 15
74#endif /* _MACH_ANOMALY_H_ */ 16/* Multi-Issue Instruction with dsp32shiftimm in slot1 and P-reg Store in slot 2 Not Supported */
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 */
21#define ANOMALY_05000122 (1)
22/* Spurious Hardware Error from an Access in the Shadow of a Conditional Branch */
23#define ANOMALY_05000245 (1)
24/* Sensitivity To Noise with Slow Input Edge Rates on External SPORT TX and RX Clocks */
25#define ANOMALY_05000265 (1)
26/* Certain Data Cache Writethrough Modes Fail for Vddint <= 0.9V */
27#define ANOMALY_05000272 (1)
28/* False Hardware Error Exception when ISR context is not restored */
29#define ANOMALY_05000281 (1)
30/* SSYNCs After Writes To CAN/DMA MMR Registers Are Not Always Handled Correctly */
31#define ANOMALY_05000304 (1)
32/* False Hardware Errors Caused by Fetches at the Boundary of Reserved Memory */
33#define ANOMALY_05000310 (1)
34/* Errors When SSYNC, CSYNC, or Loads to LT, LB and LC Registers Are Interrupted */
35#define ANOMALY_05000312 (1)
36/* TWI Slave Boot Mode Is Not Functional */
37#define ANOMALY_05000324 (1)
38/* External FIFO Boot Mode Is Not Functional */
39#define ANOMALY_05000325 (1)
40/* Data Lost When Core and DMA Accesses Are Made to the USB FIFO Simultaneously */
41#define ANOMALY_05000327 (1)
42/* Incorrect Access of OTP_STATUS During otp_write() Function */
43#define ANOMALY_05000328 (1)
44/* Synchronous Burst Flash Boot Mode Is Not Functional */
45#define ANOMALY_05000329 (1)
46/* Host DMA Boot Mode Is Not Functional */
47#define ANOMALY_05000330 (1)
48/* Inadequate Timing Margins on DDR DQS to DQ and DQM Skew */
49#define ANOMALY_05000334 (1)
50/* Inadequate Rotary Debounce Logic Duration */
51#define ANOMALY_05000335 (1)
52/* Phantom Interrupt Occurs After First Configuration of Host DMA Port */
53#define ANOMALY_05000336 (1)
54/* Disallowed Configuration Prevents Subsequent Allowed Configuration on Host DMA Port */
55#define ANOMALY_05000337 (1)
56/* Slave-Mode SPI0 MISO Failure With CPHA = 0 */
57#define ANOMALY_05000338 (1)
58/* If Memory Reads Are Enabled on SDH or HOSTDP, Other DMAC1 Peripherals Cannot Read */
59#define ANOMALY_05000340 (1)
60/* Boot Host Wait (HWAIT) and Boot Host Wait Alternate (HWAITA) Signals Are Swapped */
61#define ANOMALY_05000344 (1)
62/* USB Calibration Value Is Not Intialized */
63#define ANOMALY_05000346 (1)
64/* Boot ROM Kernel Incorrectly Alters Reset Value of USB Register */
65#define ANOMALY_05000347 (1)
66/* Data Lost when Core Reads SDH Data FIFO */
67#define ANOMALY_05000349 (1)
68/* PLL Status Register Is Inaccurate */
69#define ANOMALY_05000351 (1)
70
71/* Anomalies that don't exist on this proc */
72#define ANOMALY_05000125 (0)
73#define ANOMALY_05000158 (0)
74#define ANOMALY_05000183 (0)
75#define ANOMALY_05000198 (0)
76#define ANOMALY_05000230 (0)
77#define ANOMALY_05000244 (0)
78#define ANOMALY_05000261 (0)
79#define ANOMALY_05000263 (0)
80#define ANOMALY_05000266 (0)
81#define ANOMALY_05000273 (0)
82#define ANOMALY_05000311 (0)
83#define ANOMALY_05000323 (0)
84
85#endif
diff --git a/include/asm-blackfin/mach-bf548/bf548.h b/include/asm-blackfin/mach-bf548/bf548.h
index 9498313a2cb7..7e6d349beb08 100644
--- a/include/asm-blackfin/mach-bf548/bf548.h
+++ b/include/asm-blackfin/mach-bf548/bf548.h
@@ -52,12 +52,12 @@
52/***************************/ 52/***************************/
53 53
54 54
55#define BLKFIN_DSUBBANKS 4 55#define BFIN_DSUBBANKS 4
56#define BLKFIN_DWAYS 2 56#define BFIN_DWAYS 2
57#define BLKFIN_DLINES 64 57#define BFIN_DLINES 64
58#define BLKFIN_ISUBBANKS 4 58#define BFIN_ISUBBANKS 4
59#define BLKFIN_IWAYS 4 59#define BFIN_IWAYS 4
60#define BLKFIN_ILINES 32 60#define BFIN_ILINES 32
61 61
62#define WAY0_L 0x1 62#define WAY0_L 0x1
63#define WAY1_L 0x2 63#define WAY1_L 0x2
@@ -106,93 +106,6 @@
106 106
107#define AMGCTLVAL (V_AMBEN | V_AMCKEN) 107#define AMGCTLVAL (V_AMBEN | V_AMCKEN)
108 108
109#define MAX_VC 650000000
110#define MIN_VC 50000000
111
112/********************************PLL Settings **************************************/
113#ifdef CONFIG_BFIN_KERNEL_CLOCK
114#if (CONFIG_VCO_MULT < 0)
115#error "VCO Multiplier is less than 0. Please select a different value"
116#endif
117
118#if (CONFIG_VCO_MULT == 0)
119#error "VCO Multiplier should be greater than 0. Please select a different value"
120#endif
121
122#if (CONFIG_VCO_MULT > 64)
123#error "VCO Multiplier is more than 64. Please select a different value"
124#endif
125
126#ifndef CONFIG_CLKIN_HALF
127#define CONFIG_VCO_HZ (CONFIG_CLKIN_HZ * CONFIG_VCO_MULT)
128#else
129#define CONFIG_VCO_HZ ((CONFIG_CLKIN_HZ * CONFIG_VCO_MULT)/2)
130#endif
131
132#ifndef CONFIG_PLL_BYPASS
133#define CONFIG_CCLK_HZ (CONFIG_VCO_HZ/CONFIG_CCLK_DIV)
134#define CONFIG_SCLK_HZ (CONFIG_VCO_HZ/CONFIG_SCLK_DIV)
135#else
136#define CONFIG_CCLK_HZ CONFIG_CLKIN_HZ
137#define CONFIG_SCLK_HZ CONFIG_CLKIN_HZ
138#endif
139
140#if (CONFIG_SCLK_DIV < 1)
141#error "SCLK DIV cannot be less than 1 or more than 15. Please select a proper value"
142#endif
143
144#if (CONFIG_SCLK_DIV > 15)
145#error "SCLK DIV cannot be less than 1 or more than 15. Please select a proper value"
146#endif
147
148#if (CONFIG_CCLK_DIV != 1)
149#if (CONFIG_CCLK_DIV != 2)
150#if (CONFIG_CCLK_DIV != 4)
151#if (CONFIG_CCLK_DIV != 8)
152#error "CCLK DIV can be 1,2,4 or 8 only. Please select a proper value"
153#endif
154#endif
155#endif
156#endif
157
158#if (CONFIG_VCO_HZ > MAX_VC)
159#error "VCO selected is more than maximum value. Please change the VCO multipler"
160#endif
161
162#if (CONFIG_SCLK_HZ > 133000000)
163#error "Sclk value selected is more than maximum. Please select a proper value for SCLK multiplier"
164#endif
165
166#if (CONFIG_SCLK_HZ < 27000000)
167#error "Sclk value selected is less than minimum. Please select a proper value for SCLK multiplier"
168#endif
169
170#if (CONFIG_SCLK_HZ >= CONFIG_CCLK_HZ)
171#if (CONFIG_SCLK_HZ != CONFIG_CLKIN_HZ)
172#if (CONFIG_CCLK_HZ != CONFIG_CLKIN_HZ)
173#error "Please select sclk less than cclk"
174#endif
175#endif
176#endif
177
178#if (CONFIG_CCLK_DIV == 1)
179#define CONFIG_CCLK_ACT_DIV CCLK_DIV1
180#endif
181#if (CONFIG_CCLK_DIV == 2)
182#define CONFIG_CCLK_ACT_DIV CCLK_DIV2
183#endif
184#if (CONFIG_CCLK_DIV == 4)
185#define CONFIG_CCLK_ACT_DIV CCLK_DIV4
186#endif
187#if (CONFIG_CCLK_DIV == 8)
188#define CONFIG_CCLK_ACT_DIV CCLK_DIV8
189#endif
190#ifndef CONFIG_CCLK_ACT_DIV
191#define CONFIG_CCLK_ACT_DIV CONFIG_CCLK_DIV_not_defined_properly
192#endif
193
194#endif /* CONFIG_BFIN_KERNEL_CLOCK */
195
196#ifdef CONFIG_BF542 109#ifdef CONFIG_BF542
197#define CPU "BF542" 110#define CPU "BF542"
198#define CPUID 0x027c8000 111#define CPUID 0x027c8000
@@ -213,59 +126,4 @@
213#define CPUID 0x0 126#define CPUID 0x0
214#endif 127#endif
215 128
216#if (CONFIG_MEM_SIZE % 4)
217#error "SDRAM mem size must be multible of 4MB"
218#endif
219
220#define SDRAM_IGENERIC (CPLB_L1_CHBL | CPLB_USER_RD | CPLB_VALID | CPLB_PORTPRIO)
221#define SDRAM_IKERNEL (SDRAM_IGENERIC | CPLB_LOCK)
222#define L1_IMEMORY ( CPLB_USER_RD | CPLB_VALID | CPLB_LOCK)
223#define SDRAM_INON_CHBL ( CPLB_USER_RD | CPLB_VALID)
224
225/*Use the menuconfig cache policy here - CONFIG_BLKFIN_WT/CONFIG_BLKFIN_WB*/
226
227#define ANOMALY_05000158_WORKAROUND 0x200
228#ifdef CONFIG_BLKFIN_WB /*Write Back Policy */
229#define SDRAM_DGENERIC (CPLB_L1_CHBL | CPLB_DIRTY \
230 | CPLB_SUPV_WR | CPLB_USER_WR | CPLB_USER_RD | CPLB_VALID | ANOMALY_05000158_WORKAROUND)
231#else /*Write Through */
232#define SDRAM_DGENERIC (CPLB_L1_CHBL | CPLB_WT | CPLB_L1_AOW \
233 | CPLB_SUPV_WR | CPLB_USER_WR | CPLB_USER_RD | CPLB_VALID | ANOMALY_05000158_WORKAROUND | CPLB_DIRTY )
234#endif
235
236
237#define L1_DMEMORY (CPLB_SUPV_WR | CPLB_USER_WR | CPLB_USER_RD | CPLB_VALID | ANOMALY_05000158_WORKAROUND | CPLB_LOCK | CPLB_DIRTY )
238#define SDRAM_DNON_CHBL (CPLB_SUPV_WR | CPLB_USER_WR | CPLB_USER_RD | CPLB_VALID | ANOMALY_05000158_WORKAROUND | CPLB_DIRTY )
239#define SDRAM_EBIU (CPLB_SUPV_WR | CPLB_USER_WR | CPLB_USER_RD | CPLB_VALID | ANOMALY_05000158_WORKAROUND | CPLB_DIRTY )
240#define SDRAM_OOPS (CPLB_VALID | ANOMALY_05000158_WORKAROUND | CPLB_LOCK | CPLB_DIRTY )
241
242#define SIZE_1K 0x00000400 /* 1K */
243#define SIZE_4K 0x00001000 /* 4K */
244#define SIZE_1M 0x00100000 /* 1M */
245#define SIZE_4M 0x00400000 /* 4M */
246
247#define MAX_CPLBS (16 * 2)
248
249/*
250* Number of required data CPLB switchtable entries
251* MEMSIZE / 4 (we mostly install 4M page size CPLBs
252* approx 16 for smaller 1MB page size CPLBs for allignment purposes
253* 1 for L1 Data Memory
254* 1 for CONFIG_DEBUG_HUNT_FOR_ZERO
255* 1 for ASYNC Memory
256*/
257
258
259#define MAX_SWITCH_D_CPLBS (((CONFIG_MEM_SIZE / 4) + 16 + 1 + 1 + 1) * 2)
260
261/*
262* Number of required instruction CPLB switchtable entries
263* MEMSIZE / 4 (we mostly install 4M page size CPLBs
264* approx 12 for smaller 1MB page size CPLBs for allignment purposes
265* 1 for L1 Instruction Memory
266* 1 for CONFIG_DEBUG_HUNT_FOR_ZERO
267*/
268
269#define MAX_SWITCH_I_CPLBS (((CONFIG_MEM_SIZE / 4) + 12 + 1 + 1) * 2)
270
271#endif /* __MACH_BF48_H__ */ 129#endif /* __MACH_BF48_H__ */
diff --git a/include/asm-blackfin/mach-bf548/bfin_serial_5xx.h b/include/asm-blackfin/mach-bf548/bfin_serial_5xx.h
index 2f4afc90db11..f21a1620e6bd 100644
--- a/include/asm-blackfin/mach-bf548/bfin_serial_5xx.h
+++ b/include/asm-blackfin/mach-bf548/bfin_serial_5xx.h
@@ -1,5 +1,6 @@
1#include <linux/serial.h> 1#include <linux/serial.h>
2#include <asm/dma.h> 2#include <asm/dma.h>
3#include <asm/portmux.h>
3 4
4#define NR_PORTS 4 5#define NR_PORTS 4
5 6
@@ -143,50 +144,48 @@ struct bfin_serial_res bfin_serial_resource[] = {
143 144
144int nr_ports = ARRAY_SIZE(bfin_serial_resource); 145int nr_ports = ARRAY_SIZE(bfin_serial_resource);
145 146
147#define DRIVER_NAME "bfin-uart"
148
146static void bfin_serial_hw_init(struct bfin_serial_port *uart) 149static void bfin_serial_hw_init(struct bfin_serial_port *uart)
147{ 150{
148#ifdef CONFIG_SERIAL_BFIN_UART0 151#ifdef CONFIG_SERIAL_BFIN_UART0
149 /* Enable UART0 RX and TX on pin 7 & 8 of PORT E */ 152 peripheral_request(P_UART0_TX, DRIVER_NAME);
150 bfin_write_PORTE_FER(0x180 | bfin_read_PORTE_FER()); 153 peripheral_request(P_UART0_RX, DRIVER_NAME);
151 bfin_write_PORTE_MUX(0x3C000 | bfin_read_PORTE_MUX());
152#endif 154#endif
153 155
154#ifdef CONFIG_SERIAL_BFIN_UART1 156#ifdef CONFIG_SERIAL_BFIN_UART1
155 /* Enable UART1 RX and TX on pin 0 & 1 of PORT H */ 157 peripheral_request(P_UART1_TX, DRIVER_NAME);
156 bfin_write_PORTH_FER(0x3 | bfin_read_PORTH_FER()); 158 peripheral_request(P_UART1_RX, DRIVER_NAME);
157 bfin_write_PORTH_MUX(~0xF & bfin_read_PORTH_MUX()); 159
158#ifdef CONFIG_BFIN_UART1_CTSRTS 160#ifdef CONFIG_BFIN_UART1_CTSRTS
159 /* Enable UART1 RTS and CTS on pin 9 & 10 of PORT E */ 161 peripheral_request(P_UART1_RTS, DRIVER_NAME);
160 bfin_write_PORTE_FER(0x600 | bfin_read_PORTE_FER()); 162 peripheral_request(P_UART1_CTS DRIVER_NAME);
161 bfin_write_PORTE_MUX(~0x3C0000 & bfin_read_PORTE_MUX());
162#endif 163#endif
163#endif 164#endif
164 165
165#ifdef CONFIG_SERIAL_BFIN_UART2 166#ifdef CONFIG_SERIAL_BFIN_UART2
166 /* Enable UART2 RX and TX on pin 4 & 5 of PORT B */ 167 peripheral_request(P_UART2_TX, DRIVER_NAME);
167 bfin_write_PORTB_FER(0x30 | bfin_read_PORTB_FER()); 168 peripheral_request(P_UART2_RX, DRIVER_NAME);
168 bfin_write_PORTB_MUX(~0xF00 & bfin_read_PORTB_MUX());
169#endif 169#endif
170 170
171#ifdef CONFIG_SERIAL_BFIN_UART3 171#ifdef CONFIG_SERIAL_BFIN_UART3
172 /* Enable UART3 RX and TX on pin 6 & 7 of PORT B */ 172 peripheral_request(P_UART3_TX, DRIVER_NAME);
173 bfin_write_PORTB_FER(0xC0 | bfin_read_PORTB_FER()); 173 peripheral_request(P_UART3_RX, DRIVER_NAME);
174 bfin_write_PORTB_MUX(~0xF000 | bfin_read_PORTB_MUX()); 174
175#ifdef CONFIG_BFIN_UART3_CTSRTS 175#ifdef CONFIG_BFIN_UART3_CTSRTS
176 /* Enable UART3 RTS and CTS on pin 2 & 3 of PORT B */ 176 peripheral_request(P_UART3_RTS, DRIVER_NAME);
177 bfin_write_PORTB_FER(0xC | bfin_read_PORTB_FER()); 177 peripheral_request(P_UART3_CTS DRIVER_NAME);
178 bfin_write_PORTB_MUX(~0xF0 | bfin_read_PORTB_MUX());
179#endif 178#endif
180#endif 179#endif
181 SSYNC(); 180 SSYNC();
182#ifdef CONFIG_SERIAL_BFIN_CTSRTS 181#ifdef CONFIG_SERIAL_BFIN_CTSRTS
183 if (uart->cts_pin >= 0) { 182 if (uart->cts_pin >= 0) {
184 gpio_request(uart->cts_pin, NULL); 183 gpio_request(uart->cts_pin, DRIVER_NAME);
185 gpio_direction_input(uart->cts_pin); 184 gpio_direction_input(uart->cts_pin);
186 } 185 }
187 186
188 if (uart->rts_pin >= 0) { 187 if (uart->rts_pin >= 0) {
189 gpio_request(uart->rts_pin, NULL); 188 gpio_request(uart->rts_pin, DRIVER_NAME);
190 gpio_direction_output(uart->rts_pin); 189 gpio_direction_output(uart->rts_pin);
191 } 190 }
192#endif 191#endif
diff --git a/include/asm-blackfin/mach-bf548/blackfin.h b/include/asm-blackfin/mach-bf548/blackfin.h
index 791218fe7d94..19e84dd4c99c 100644
--- a/include/asm-blackfin/mach-bf548/blackfin.h
+++ b/include/asm-blackfin/mach-bf548/blackfin.h
@@ -54,7 +54,7 @@
54#include "defBF549.h" 54#include "defBF549.h"
55#endif 55#endif
56 56
57#if !(defined(__ASSEMBLY__) || defined(ASSEMBLY)) 57#if !defined(__ASSEMBLY__)
58#ifdef CONFIG_BF542 58#ifdef CONFIG_BF542
59#include "cdefBF542.h" 59#include "cdefBF542.h"
60#endif 60#endif
diff --git a/include/asm-blackfin/mach-bf548/cdefBF54x_base.h b/include/asm-blackfin/mach-bf548/cdefBF54x_base.h
index cdf29e75ea59..aefab3f618c1 100644
--- a/include/asm-blackfin/mach-bf548/cdefBF54x_base.h
+++ b/include/asm-blackfin/mach-bf548/cdefBF54x_base.h
@@ -31,6 +31,8 @@
31#ifndef _CDEF_BF54X_H 31#ifndef _CDEF_BF54X_H
32#define _CDEF_BF54X_H 32#define _CDEF_BF54X_H
33 33
34#include <asm/blackfin.h>
35
34#include "defBF54x_base.h" 36#include "defBF54x_base.h"
35#include <asm/system.h> 37#include <asm/system.h>
36 38
@@ -60,7 +62,7 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
60 bfin_write32(SIC_IWR2, 0); 62 bfin_write32(SIC_IWR2, 0);
61 63
62 bfin_write16(VR_CTL, val); 64 bfin_write16(VR_CTL, val);
63 __builtin_bfin_ssync(); 65 SSYNC();
64 66
65 local_irq_save(flags); 67 local_irq_save(flags);
66 asm("IDLE;"); 68 asm("IDLE;");
diff --git a/include/asm-blackfin/mach-bf548/defBF544.h b/include/asm-blackfin/mach-bf548/defBF544.h
index dd955dcd39b8..760307e34b9e 100644
--- a/include/asm-blackfin/mach-bf548/defBF544.h
+++ b/include/asm-blackfin/mach-bf548/defBF544.h
@@ -81,6 +81,7 @@
81 81
82/* Two Wire Interface Registers (TWI1) */ 82/* Two Wire Interface Registers (TWI1) */
83 83
84#define TWI1_REGBASE 0xffc02200
84#define TWI1_CLKDIV 0xffc02200 /* Clock Divider Register */ 85#define TWI1_CLKDIV 0xffc02200 /* Clock Divider Register */
85#define TWI1_CONTROL 0xffc02204 /* TWI Control Register */ 86#define TWI1_CONTROL 0xffc02204 /* TWI Control Register */
86#define TWI1_SLAVE_CTRL 0xffc02208 /* TWI Slave Mode Control Register */ 87#define TWI1_SLAVE_CTRL 0xffc02208 /* TWI Slave Mode Control Register */
diff --git a/include/asm-blackfin/mach-bf548/defBF548.h b/include/asm-blackfin/mach-bf548/defBF548.h
index 8d4214e0807c..70af33c963b0 100644
--- a/include/asm-blackfin/mach-bf548/defBF548.h
+++ b/include/asm-blackfin/mach-bf548/defBF548.h
@@ -120,6 +120,7 @@
120 120
121/* Two Wire Interface Registers (TWI1) */ 121/* Two Wire Interface Registers (TWI1) */
122 122
123#define TWI1_REGBASE 0xffc02200
123#define TWI1_CLKDIV 0xffc02200 /* Clock Divider Register */ 124#define TWI1_CLKDIV 0xffc02200 /* Clock Divider Register */
124#define TWI1_CONTROL 0xffc02204 /* TWI Control Register */ 125#define TWI1_CONTROL 0xffc02204 /* TWI Control Register */
125#define TWI1_SLAVE_CTRL 0xffc02208 /* TWI Slave Mode Control Register */ 126#define TWI1_SLAVE_CTRL 0xffc02208 /* TWI Slave Mode Control Register */
@@ -139,6 +140,7 @@
139 140
140/* SPI2 Registers */ 141/* SPI2 Registers */
141 142
143#define SPI2_REGBASE 0xffc02400
142#define SPI2_CTL 0xffc02400 /* SPI2 Control Register */ 144#define SPI2_CTL 0xffc02400 /* SPI2 Control Register */
143#define SPI2_FLG 0xffc02404 /* SPI2 Flag Register */ 145#define SPI2_FLG 0xffc02404 /* SPI2 Flag Register */
144#define SPI2_STAT 0xffc02408 /* SPI2 Status Register */ 146#define SPI2_STAT 0xffc02408 /* SPI2 Status Register */
diff --git a/include/asm-blackfin/mach-bf548/defBF549.h b/include/asm-blackfin/mach-bf548/defBF549.h
index c2f4734da48d..50b3fe55ef0c 100644
--- a/include/asm-blackfin/mach-bf548/defBF549.h
+++ b/include/asm-blackfin/mach-bf548/defBF549.h
@@ -121,6 +121,7 @@
121 121
122/* Two Wire Interface Registers (TWI1) */ 122/* Two Wire Interface Registers (TWI1) */
123 123
124#define TWI1_REGBASE 0xffc02200
124#define TWI1_CLKDIV 0xffc02200 /* Clock Divider Register */ 125#define TWI1_CLKDIV 0xffc02200 /* Clock Divider Register */
125#define TWI1_CONTROL 0xffc02204 /* TWI Control Register */ 126#define TWI1_CONTROL 0xffc02204 /* TWI Control Register */
126#define TWI1_SLAVE_CTRL 0xffc02208 /* TWI Slave Mode Control Register */ 127#define TWI1_SLAVE_CTRL 0xffc02208 /* TWI Slave Mode Control Register */
@@ -140,6 +141,7 @@
140 141
141/* SPI2 Registers */ 142/* SPI2 Registers */
142 143
144#define SPI2_REGBASE 0xffc02400
143#define SPI2_CTL 0xffc02400 /* SPI2 Control Register */ 145#define SPI2_CTL 0xffc02400 /* SPI2 Control Register */
144#define SPI2_FLG 0xffc02404 /* SPI2 Flag Register */ 146#define SPI2_FLG 0xffc02404 /* SPI2 Flag Register */
145#define SPI2_STAT 0xffc02408 /* SPI2 Status Register */ 147#define SPI2_STAT 0xffc02408 /* SPI2 Status Register */
diff --git a/include/asm-blackfin/mach-bf548/defBF54x_base.h b/include/asm-blackfin/mach-bf548/defBF54x_base.h
index 895ddd40a838..e2632db74baa 100644
--- a/include/asm-blackfin/mach-bf548/defBF54x_base.h
+++ b/include/asm-blackfin/mach-bf548/defBF54x_base.h
@@ -109,6 +109,7 @@
109 109
110/* SPI0 Registers */ 110/* SPI0 Registers */
111 111
112#define SPI0_REGBASE 0xffc00500
112#define SPI0_CTL 0xffc00500 /* SPI0 Control Register */ 113#define SPI0_CTL 0xffc00500 /* SPI0 Control Register */
113#define SPI0_FLG 0xffc00504 /* SPI0 Flag Register */ 114#define SPI0_FLG 0xffc00504 /* SPI0 Flag Register */
114#define SPI0_STAT 0xffc00508 /* SPI0 Status Register */ 115#define SPI0_STAT 0xffc00508 /* SPI0 Status Register */
@@ -121,6 +122,7 @@
121 122
122/* Two Wire Interface Registers (TWI0) */ 123/* Two Wire Interface Registers (TWI0) */
123 124
125#define TWI0_REGBASE 0xffc00700
124#define TWI0_CLKDIV 0xffc00700 /* Clock Divider Register */ 126#define TWI0_CLKDIV 0xffc00700 /* Clock Divider Register */
125#define TWI0_CONTROL 0xffc00704 /* TWI Control Register */ 127#define TWI0_CONTROL 0xffc00704 /* TWI Control Register */
126#define TWI0_SLAVE_CTRL 0xffc00708 /* TWI Slave Mode Control Register */ 128#define TWI0_SLAVE_CTRL 0xffc00708 /* TWI Slave Mode Control Register */
@@ -978,6 +980,7 @@
978 980
979/* SPI1 Registers */ 981/* SPI1 Registers */
980 982
983#define SPI1_REGBASE 0xffc02300
981#define SPI1_CTL 0xffc02300 /* SPI1 Control Register */ 984#define SPI1_CTL 0xffc02300 /* SPI1 Control Register */
982#define SPI1_FLG 0xffc02304 /* SPI1 Flag Register */ 985#define SPI1_FLG 0xffc02304 /* SPI1 Flag Register */
983#define SPI1_STAT 0xffc02308 /* SPI1 Status Register */ 986#define SPI1_STAT 0xffc02308 /* SPI1 Status Register */
diff --git a/include/asm-blackfin/mach-bf548/gpio.h b/include/asm-blackfin/mach-bf548/gpio.h
index dbf66bcabe35..cb8b0f15c9a6 100644
--- a/include/asm-blackfin/mach-bf548/gpio.h
+++ b/include/asm-blackfin/mach-bf548/gpio.h
@@ -209,8 +209,3 @@ struct gpio_port_t {
209 unsigned short dummy7; 209 unsigned short dummy7;
210 unsigned int port_mux; 210 unsigned int port_mux;
211}; 211};
212
213int gpio_request(unsigned short gpio, const char *label);
214void peripheral_free(unsigned short per);
215int peripheral_request_list(unsigned short per[], const char *label);
216void peripheral_free_list(unsigned short per[]);
diff --git a/include/asm-blackfin/mach-bf548/irq.h b/include/asm-blackfin/mach-bf548/irq.h
index e548d3cd81e3..3b08cf9bd6f3 100644
--- a/include/asm-blackfin/mach-bf548/irq.h
+++ b/include/asm-blackfin/mach-bf548/irq.h
@@ -55,287 +55,288 @@ Events (highest priority) EMU 0
55 55
56/* The ABSTRACT IRQ definitions */ 56/* The ABSTRACT IRQ definitions */
57/** the first seven of the following are fixed, the rest you change if you need to **/ 57/** the first seven of the following are fixed, the rest you change if you need to **/
58#define IRQ_EMU 0 /* Emulation */ 58#define IRQ_EMU 0 /* Emulation */
59#define IRQ_RST 1 /* reset */ 59#define IRQ_RST 1 /* reset */
60#define IRQ_NMI 2 /* Non Maskable */ 60#define IRQ_NMI 2 /* Non Maskable */
61#define IRQ_EVX 3 /* Exception */ 61#define IRQ_EVX 3 /* Exception */
62#define IRQ_UNUSED 4 /* - unused interrupt*/ 62#define IRQ_UNUSED 4 /* - unused interrupt*/
63#define IRQ_HWERR 5 /* Hardware Error */ 63#define IRQ_HWERR 5 /* Hardware Error */
64#define IRQ_CORETMR 6 /* Core timer */ 64#define IRQ_CORETMR 6 /* Core timer */
65 65
66#define BFIN_IRQ(x) ((x) + 7) 66#define BFIN_IRQ(x) ((x) + 7)
67 67
68#define IRQ_PLL_WAKEUP BFIN_IRQ(0) /* PLL Wakeup Interrupt */ 68#define IRQ_PLL_WAKEUP BFIN_IRQ(0) /* PLL Wakeup Interrupt */
69#define IRQ_DMAC0_ERR BFIN_IRQ(1) /* DMAC0 Status Interrupt */ 69#define IRQ_DMAC0_ERROR BFIN_IRQ(1) /* DMAC0 Status Interrupt */
70#define IRQ_EPPI0_ERR BFIN_IRQ(2) /* EPPI0 Error Interrupt */ 70#define IRQ_EPPI0_ERROR BFIN_IRQ(2) /* EPPI0 Error Interrupt */
71#define IRQ_SPORT0_ERR BFIN_IRQ(3) /* SPORT0 Error Interrupt */ 71#define IRQ_SPORT0_ERROR BFIN_IRQ(3) /* SPORT0 Error Interrupt */
72#define IRQ_SPORT1_ERR BFIN_IRQ(4) /* SPORT1 Error Interrupt */ 72#define IRQ_SPORT1_ERROR BFIN_IRQ(4) /* SPORT1 Error Interrupt */
73#define IRQ_SPI0_ERR BFIN_IRQ(5) /* SPI0 Status(Error) Interrupt */ 73#define IRQ_SPI0_ERROR BFIN_IRQ(5) /* SPI0 Status(Error) Interrupt */
74#define IRQ_UART0_ERR BFIN_IRQ(6) /* UART0 Status(Error) Interrupt */ 74#define IRQ_UART0_ERROR BFIN_IRQ(6) /* UART0 Status(Error) Interrupt */
75#define IRQ_RTC BFIN_IRQ(7) /* RTC Interrupt */ 75#define IRQ_RTC BFIN_IRQ(7) /* RTC Interrupt */
76#define IRQ_EPPI0 BFIN_IRQ(8) /* EPPI0 Interrupt (DMA12) */ 76#define IRQ_EPPI0 BFIN_IRQ(8) /* EPPI0 Interrupt (DMA12) */
77#define IRQ_SPORT0_RX BFIN_IRQ(9) /* SPORT0 RX Interrupt (DMA0) */ 77#define IRQ_SPORT0_RX BFIN_IRQ(9) /* SPORT0 RX Interrupt (DMA0) */
78#define IRQ_SPORT0_TX BFIN_IRQ(10) /* SPORT0 TX Interrupt (DMA1) */ 78#define IRQ_SPORT0_TX BFIN_IRQ(10) /* SPORT0 TX Interrupt (DMA1) */
79#define IRQ_SPORT1_RX BFIN_IRQ(11) /* SPORT1 RX Interrupt (DMA2) */ 79#define IRQ_SPORT1_RX BFIN_IRQ(11) /* SPORT1 RX Interrupt (DMA2) */
80#define IRQ_SPORT1_TX BFIN_IRQ(12) /* SPORT1 TX Interrupt (DMA3) */ 80#define IRQ_SPORT1_TX BFIN_IRQ(12) /* SPORT1 TX Interrupt (DMA3) */
81#define IRQ_SPI0 BFIN_IRQ(13) /* SPI0 Interrupt (DMA4) */ 81#define IRQ_SPI0 BFIN_IRQ(13) /* SPI0 Interrupt (DMA4) */
82#define IRQ_UART0_RX BFIN_IRQ(14) /* UART0 RX Interrupt (DMA6) */ 82#define IRQ_UART0_RX BFIN_IRQ(14) /* UART0 RX Interrupt (DMA6) */
83#define IRQ_UART0_TX BFIN_IRQ(15) /* UART0 TX Interrupt (DMA7) */ 83#define IRQ_UART0_TX BFIN_IRQ(15) /* UART0 TX Interrupt (DMA7) */
84#define IRQ_TIMER8 BFIN_IRQ(16) /* TIMER 8 Interrupt */ 84#define IRQ_TIMER8 BFIN_IRQ(16) /* TIMER 8 Interrupt */
85#define IRQ_TIMER9 BFIN_IRQ(17) /* TIMER 9 Interrupt */ 85#define IRQ_TIMER9 BFIN_IRQ(17) /* TIMER 9 Interrupt */
86#define IRQ_TIMER10 BFIN_IRQ(18) /* TIMER 10 Interrupt */ 86#define IRQ_TIMER10 BFIN_IRQ(18) /* TIMER 10 Interrupt */
87#define IRQ_PINT0 BFIN_IRQ(19) /* PINT0 Interrupt */ 87#define IRQ_PINT0 BFIN_IRQ(19) /* PINT0 Interrupt */
88#define IRQ_PINT1 BFIN_IRQ(20) /* PINT1 Interrupt */ 88#define IRQ_PINT1 BFIN_IRQ(20) /* PINT1 Interrupt */
89#define IRQ_MDMAS0 BFIN_IRQ(21) /* MDMA Stream 0 Interrupt */ 89#define IRQ_MDMAS0 BFIN_IRQ(21) /* MDMA Stream 0 Interrupt */
90#define IRQ_MDMAS1 BFIN_IRQ(22) /* MDMA Stream 1 Interrupt */ 90#define IRQ_MDMAS1 BFIN_IRQ(22) /* MDMA Stream 1 Interrupt */
91#define IRQ_WATCHDOG BFIN_IRQ(23) /* Watchdog Interrupt */ 91#define IRQ_WATCHDOG BFIN_IRQ(23) /* Watchdog Interrupt */
92#define IRQ_DMAC1_ERR BFIN_IRQ(24) /* DMAC1 Status (Error) Interrupt */ 92#define IRQ_DMAC1_ERROR BFIN_IRQ(24) /* DMAC1 Status (Error) Interrupt */
93#define IRQ_SPORT2_ERR BFIN_IRQ(25) /* SPORT2 Error Interrupt */ 93#define IRQ_SPORT2_ERROR BFIN_IRQ(25) /* SPORT2 Error Interrupt */
94#define IRQ_SPORT3_ERR BFIN_IRQ(26) /* SPORT3 Error Interrupt */ 94#define IRQ_SPORT3_ERROR BFIN_IRQ(26) /* SPORT3 Error Interrupt */
95#define IRQ_MXVR_DATA BFIN_IRQ(27) /* MXVR Data Interrupt */ 95#define IRQ_MXVR_DATA BFIN_IRQ(27) /* MXVR Data Interrupt */
96#define IRQ_SPI1_ERR BFIN_IRQ(28) /* SPI1 Status (Error) Interrupt */ 96#define IRQ_SPI1_ERROR BFIN_IRQ(28) /* SPI1 Status (Error) Interrupt */
97#define IRQ_SPI2_ERR BFIN_IRQ(29) /* SPI2 Status (Error) Interrupt */ 97#define IRQ_SPI2_ERROR BFIN_IRQ(29) /* SPI2 Status (Error) Interrupt */
98#define IRQ_UART1_ERR BFIN_IRQ(30) /* UART1 Status (Error) Interrupt */ 98#define IRQ_UART1_ERROR BFIN_IRQ(30) /* UART1 Status (Error) Interrupt */
99#define IRQ_UART2_ERR BFIN_IRQ(31) /* UART2 Status (Error) Interrupt */ 99#define IRQ_UART2_ERROR BFIN_IRQ(31) /* UART2 Status (Error) Interrupt */
100#define IRQ_CAN0_ERR BFIN_IRQ(32) /* CAN0 Status (Error) Interrupt */ 100#define IRQ_CAN0_ERROR BFIN_IRQ(32) /* CAN0 Status (Error) Interrupt */
101#define IRQ_SPORT2_RX BFIN_IRQ(33) /* SPORT2 RX (DMA18) Interrupt */ 101#define IRQ_SPORT2_RX BFIN_IRQ(33) /* SPORT2 RX (DMA18) Interrupt */
102#define IRQ_SPORT2_TX BFIN_IRQ(34) /* SPORT2 TX (DMA19) Interrupt */ 102#define IRQ_SPORT2_TX BFIN_IRQ(34) /* SPORT2 TX (DMA19) Interrupt */
103#define IRQ_SPORT3_RX BFIN_IRQ(35) /* SPORT3 RX (DMA20) Interrupt */ 103#define IRQ_SPORT3_RX BFIN_IRQ(35) /* SPORT3 RX (DMA20) Interrupt */
104#define IRQ_SPORT3_TX BFIN_IRQ(36) /* SPORT3 TX (DMA21) Interrupt */ 104#define IRQ_SPORT3_TX BFIN_IRQ(36) /* SPORT3 TX (DMA21) Interrupt */
105#define IRQ_EPPI1 BFIN_IRQ(37) /* EPP1 (DMA13) Interrupt */ 105#define IRQ_EPPI1 BFIN_IRQ(37) /* EPP1 (DMA13) Interrupt */
106#define IRQ_EPPI2 BFIN_IRQ(38) /* EPP2 (DMA14) Interrupt */ 106#define IRQ_EPPI2 BFIN_IRQ(38) /* EPP2 (DMA14) Interrupt */
107#define IRQ_SPI1 BFIN_IRQ(39) /* SPI1 (DMA5) Interrupt */ 107#define IRQ_SPI1 BFIN_IRQ(39) /* SPI1 (DMA5) Interrupt */
108#define IRQ_SPI2 BFIN_IRQ(40) /* SPI2 (DMA23) Interrupt */ 108#define IRQ_SPI2 BFIN_IRQ(40) /* SPI2 (DMA23) Interrupt */
109#define IRQ_UART1_RX BFIN_IRQ(41) /* UART1 RX (DMA8) Interrupt */ 109#define IRQ_UART1_RX BFIN_IRQ(41) /* UART1 RX (DMA8) Interrupt */
110#define IRQ_UART1_TX BFIN_IRQ(42) /* UART1 TX (DMA9) Interrupt */ 110#define IRQ_UART1_TX BFIN_IRQ(42) /* UART1 TX (DMA9) Interrupt */
111#define IRQ_ATAPI_RX BFIN_IRQ(43) /* ATAPI RX (DMA10) Interrupt */ 111#define IRQ_ATAPI_RX BFIN_IRQ(43) /* ATAPI RX (DMA10) Interrupt */
112#define IRQ_ATAPI_TX BFIN_IRQ(44) /* ATAPI TX (DMA11) Interrupt */ 112#define IRQ_ATAPI_TX BFIN_IRQ(44) /* ATAPI TX (DMA11) Interrupt */
113#define IRQ_TWI0 BFIN_IRQ(45) /* TWI0 Interrupt */ 113#define IRQ_TWI0 BFIN_IRQ(45) /* TWI0 Interrupt */
114#define IRQ_TWI1 BFIN_IRQ(46) /* TWI1 Interrupt */ 114#define IRQ_TWI1 BFIN_IRQ(46) /* TWI1 Interrupt */
115#define IRQ_TWI IRQ_TWI0 /* TWI Interrupt */ 115#define IRQ_CAN0_RX BFIN_IRQ(47) /* CAN0 Receive Interrupt */
116#define IRQ_CAN0_RX BFIN_IRQ(47) /* CAN0 Receive Interrupt */ 116#define IRQ_CAN0_TX BFIN_IRQ(48) /* CAN0 Transmit Interrupt */
117#define IRQ_CAN0_TX BFIN_IRQ(48) /* CAN0 Transmit Interrupt */ 117#define IRQ_MDMAS2 BFIN_IRQ(49) /* MDMA Stream 2 Interrupt */
118#define IRQ_MDMAS2 BFIN_IRQ(49) /* MDMA Stream 2 Interrupt */ 118#define IRQ_MDMAS3 BFIN_IRQ(50) /* MDMA Stream 3 Interrupt */
119#define IRQ_MDMAS3 BFIN_IRQ(50) /* MDMA Stream 3 Interrupt */ 119#define IRQ_MXVR_ERROR BFIN_IRQ(51) /* MXVR Status (Error) Interrupt */
120#define IRQ_MXVR_ERR BFIN_IRQ(51) /* MXVR Status (Error) Interrupt */ 120#define IRQ_MXVR_MSG BFIN_IRQ(52) /* MXVR Message Interrupt */
121#define IRQ_MXVR_MSG BFIN_IRQ(52) /* MXVR Message Interrupt */ 121#define IRQ_MXVR_PKT BFIN_IRQ(53) /* MXVR Packet Interrupt */
122#define IRQ_MXVR_PKT BFIN_IRQ(53) /* MXVR Packet Interrupt */ 122#define IRQ_EPP1_ERROR BFIN_IRQ(54) /* EPPI1 Error Interrupt */
123#define IRQ_EPP1_ERR BFIN_IRQ(54) /* EPPI1 Error Interrupt */ 123#define IRQ_EPP2_ERROR BFIN_IRQ(55) /* EPPI2 Error Interrupt */
124#define IRQ_EPP2_ERR BFIN_IRQ(55) /* EPPI2 Error Interrupt */ 124#define IRQ_UART3_ERROR BFIN_IRQ(56) /* UART3 Status (Error) Interrupt */
125#define IRQ_UART3_ERR BFIN_IRQ(56) /* UART3 Status (Error) Interrupt */ 125#define IRQ_HOST_ERROR BFIN_IRQ(57) /* HOST Status (Error) Interrupt */
126#define IRQ_HOST_ERR BFIN_IRQ(57) /* HOST Status (Error) Interrupt */ 126#define IRQ_PIXC_ERROR BFIN_IRQ(59) /* PIXC Status (Error) Interrupt */
127#define IRQ_PIXC_ERR BFIN_IRQ(59) /* PIXC Status (Error) Interrupt */ 127#define IRQ_NFC_ERROR BFIN_IRQ(60) /* NFC Error Interrupt */
128#define IRQ_NFC_ERR BFIN_IRQ(60) /* NFC Error Interrupt */ 128#define IRQ_ATAPI_ERROR BFIN_IRQ(61) /* ATAPI Error Interrupt */
129#define IRQ_ATAPI_ERR BFIN_IRQ(61) /* ATAPI Error Interrupt */ 129#define IRQ_CAN1_ERROR BFIN_IRQ(62) /* CAN1 Status (Error) Interrupt */
130#define IRQ_CAN1_ERR BFIN_IRQ(62) /* CAN1 Status (Error) Interrupt */ 130#define IRQ_HS_DMA_ERROR BFIN_IRQ(63) /* Handshake DMA Status Interrupt */
131#define IRQ_HS_DMA_ERR BFIN_IRQ(63) /* Handshake DMA Status Interrupt */ 131#define IRQ_PIXC_IN0 BFIN_IRQ(64) /* PIXC IN0 (DMA15) Interrupt */
132#define IRQ_PIXC_IN0 BFIN_IRQ(64) /* PIXC IN0 (DMA15) Interrupt */ 132#define IRQ_PIXC_IN1 BFIN_IRQ(65) /* PIXC IN1 (DMA16) Interrupt */
133#define IRQ_PIXC_IN1 BFIN_IRQ(65) /* PIXC IN1 (DMA16) Interrupt */ 133#define IRQ_PIXC_OUT BFIN_IRQ(66) /* PIXC OUT (DMA17) Interrupt */
134#define IRQ_PIXC_OUT BFIN_IRQ(66) /* PIXC OUT (DMA17) Interrupt */ 134#define IRQ_SDH BFIN_IRQ(67) /* SDH/NFC (DMA22) Interrupt */
135#define IRQ_SDH BFIN_IRQ(67) /* SDH/NFC (DMA22) Interrupt */ 135#define IRQ_CNT BFIN_IRQ(68) /* CNT Interrupt */
136#define IRQ_CNT BFIN_IRQ(68) /* CNT Interrupt */ 136#define IRQ_KEY BFIN_IRQ(69) /* KEY Interrupt */
137#define IRQ_KEY BFIN_IRQ(69) /* KEY Interrupt */ 137#define IRQ_CAN1_RX BFIN_IRQ(70) /* CAN1 RX Interrupt */
138#define IRQ_CAN1_RX BFIN_IRQ(70) /* CAN1 RX Interrupt */ 138#define IRQ_CAN1_TX BFIN_IRQ(71) /* CAN1 TX Interrupt */
139#define IRQ_CAN1_TX BFIN_IRQ(71) /* CAN1 TX Interrupt */ 139#define IRQ_SDH_MASK0 BFIN_IRQ(72) /* SDH Mask 0 Interrupt */
140#define IRQ_SDH_MASK0 BFIN_IRQ(72) /* SDH Mask 0 Interrupt */ 140#define IRQ_SDH_MASK1 BFIN_IRQ(73) /* SDH Mask 1 Interrupt */
141#define IRQ_SDH_MASK1 BFIN_IRQ(73) /* SDH Mask 1 Interrupt */ 141#define IRQ_USB_INT0 BFIN_IRQ(75) /* USB INT0 Interrupt */
142#define IRQ_USB_INT0 BFIN_IRQ(75) /* USB INT0 Interrupt */ 142#define IRQ_USB_INT1 BFIN_IRQ(76) /* USB INT1 Interrupt */
143#define IRQ_USB_INT1 BFIN_IRQ(76) /* USB INT1 Interrupt */ 143#define IRQ_USB_INT2 BFIN_IRQ(77) /* USB INT2 Interrupt */
144#define IRQ_USB_INT2 BFIN_IRQ(77) /* USB INT2 Interrupt */ 144#define IRQ_USB_DMA BFIN_IRQ(78) /* USB DMA Interrupt */
145#define IRQ_USB_DMA BFIN_IRQ(78) /* USB DMA Interrupt */ 145#define IRQ_OPTSEC BFIN_IRQ(79) /* OTPSEC Interrupt */
146#define IRQ_OPTSEC BFIN_IRQ(79) /* OTPSEC Interrupt */ 146#define IRQ_TIMER0 BFIN_IRQ(86) /* Timer 0 Interrupt */
147#define IRQ_TIMER0 BFIN_IRQ(86) /* Timer 0 Interrupt */ 147#define IRQ_TIMER1 BFIN_IRQ(87) /* Timer 1 Interrupt */
148#define IRQ_TIMER1 BFIN_IRQ(87) /* Timer 1 Interrupt */ 148#define IRQ_TIMER2 BFIN_IRQ(88) /* Timer 2 Interrupt */
149#define IRQ_TIMER2 BFIN_IRQ(88) /* Timer 2 Interrupt */ 149#define IRQ_TIMER3 BFIN_IRQ(89) /* Timer 3 Interrupt */
150#define IRQ_TIMER3 BFIN_IRQ(89) /* Timer 3 Interrupt */ 150#define IRQ_TIMER4 BFIN_IRQ(90) /* Timer 4 Interrupt */
151#define IRQ_TIMER4 BFIN_IRQ(90) /* Timer 4 Interrupt */ 151#define IRQ_TIMER5 BFIN_IRQ(91) /* Timer 5 Interrupt */
152#define IRQ_TIMER5 BFIN_IRQ(91) /* Timer 5 Interrupt */ 152#define IRQ_TIMER6 BFIN_IRQ(92) /* Timer 6 Interrupt */
153#define IRQ_TIMER6 BFIN_IRQ(92) /* Timer 6 Interrupt */ 153#define IRQ_TIMER7 BFIN_IRQ(93) /* Timer 7 Interrupt */
154#define IRQ_TIMER7 BFIN_IRQ(93) /* Timer 7 Interrupt */ 154#define IRQ_PINT2 BFIN_IRQ(94) /* PINT2 Interrupt */
155#define IRQ_PINT2 BFIN_IRQ(94) /* PINT2 Interrupt */ 155#define IRQ_PINT3 BFIN_IRQ(95) /* PINT3 Interrupt */
156#define IRQ_PINT3 BFIN_IRQ(95) /* PINT3 Interrupt */ 156
157 157#define SYS_IRQS IRQ_PINT3
158#define SYS_IRQS IRQ_PINT3 158
159 159#define BFIN_PA_IRQ(x) ((x) + SYS_IRQS + 1)
160#define BFIN_PA_IRQ(x) ((x) + SYS_IRQS + 1) 160#define IRQ_PA0 BFIN_PA_IRQ(0)
161#define IRQ_PA0 BFIN_PA_IRQ(0) 161#define IRQ_PA1 BFIN_PA_IRQ(1)
162#define IRQ_PA1 BFIN_PA_IRQ(1) 162#define IRQ_PA2 BFIN_PA_IRQ(2)
163#define IRQ_PA2 BFIN_PA_IRQ(2) 163#define IRQ_PA3 BFIN_PA_IRQ(3)
164#define IRQ_PA3 BFIN_PA_IRQ(3) 164#define IRQ_PA4 BFIN_PA_IRQ(4)
165#define IRQ_PA4 BFIN_PA_IRQ(4) 165#define IRQ_PA5 BFIN_PA_IRQ(5)
166#define IRQ_PA5 BFIN_PA_IRQ(5) 166#define IRQ_PA6 BFIN_PA_IRQ(6)
167#define IRQ_PA6 BFIN_PA_IRQ(6) 167#define IRQ_PA7 BFIN_PA_IRQ(7)
168#define IRQ_PA7 BFIN_PA_IRQ(7) 168#define IRQ_PA8 BFIN_PA_IRQ(8)
169#define IRQ_PA8 BFIN_PA_IRQ(8) 169#define IRQ_PA9 BFIN_PA_IRQ(9)
170#define IRQ_PA9 BFIN_PA_IRQ(9) 170#define IRQ_PA10 BFIN_PA_IRQ(10)
171#define IRQ_PA10 BFIN_PA_IRQ(10) 171#define IRQ_PA11 BFIN_PA_IRQ(11)
172#define IRQ_PA11 BFIN_PA_IRQ(11) 172#define IRQ_PA12 BFIN_PA_IRQ(12)
173#define IRQ_PA12 BFIN_PA_IRQ(12) 173#define IRQ_PA13 BFIN_PA_IRQ(13)
174#define IRQ_PA13 BFIN_PA_IRQ(13) 174#define IRQ_PA14 BFIN_PA_IRQ(14)
175#define IRQ_PA14 BFIN_PA_IRQ(14) 175#define IRQ_PA15 BFIN_PA_IRQ(15)
176#define IRQ_PA15 BFIN_PA_IRQ(15) 176
177 177#define BFIN_PB_IRQ(x) ((x) + IRQ_PA15 + 1)
178#define BFIN_PB_IRQ(x) ((x) + IRQ_PA15 + 1) 178#define IRQ_PB0 BFIN_PB_IRQ(0)
179#define IRQ_PB0 BFIN_PB_IRQ(0) 179#define IRQ_PB1 BFIN_PB_IRQ(1)
180#define IRQ_PB1 BFIN_PB_IRQ(1) 180#define IRQ_PB2 BFIN_PB_IRQ(2)
181#define IRQ_PB2 BFIN_PB_IRQ(2) 181#define IRQ_PB3 BFIN_PB_IRQ(3)
182#define IRQ_PB3 BFIN_PB_IRQ(3) 182#define IRQ_PB4 BFIN_PB_IRQ(4)
183#define IRQ_PB4 BFIN_PB_IRQ(4) 183#define IRQ_PB5 BFIN_PB_IRQ(5)
184#define IRQ_PB5 BFIN_PB_IRQ(5) 184#define IRQ_PB6 BFIN_PB_IRQ(6)
185#define IRQ_PB6 BFIN_PB_IRQ(6) 185#define IRQ_PB7 BFIN_PB_IRQ(7)
186#define IRQ_PB7 BFIN_PB_IRQ(7) 186#define IRQ_PB8 BFIN_PB_IRQ(8)
187#define IRQ_PB8 BFIN_PB_IRQ(8) 187#define IRQ_PB9 BFIN_PB_IRQ(9)
188#define IRQ_PB9 BFIN_PB_IRQ(9) 188#define IRQ_PB10 BFIN_PB_IRQ(10)
189#define IRQ_PB10 BFIN_PB_IRQ(10) 189#define IRQ_PB11 BFIN_PB_IRQ(11)
190#define IRQ_PB11 BFIN_PB_IRQ(11) 190#define IRQ_PB12 BFIN_PB_IRQ(12)
191#define IRQ_PB12 BFIN_PB_IRQ(12) 191#define IRQ_PB13 BFIN_PB_IRQ(13)
192#define IRQ_PB13 BFIN_PB_IRQ(13) 192#define IRQ_PB14 BFIN_PB_IRQ(14)
193#define IRQ_PB14 BFIN_PB_IRQ(14) 193#define IRQ_PB15 BFIN_PB_IRQ(15) /* N/A */
194#define IRQ_PB15 BFIN_PB_IRQ(15) /* N/A */ 194
195 195#define BFIN_PC_IRQ(x) ((x) + IRQ_PB15 + 1)
196#define BFIN_PC_IRQ(x) ((x) + IRQ_PB15 + 1) 196#define IRQ_PC0 BFIN_PC_IRQ(0)
197#define IRQ_PC0 BFIN_PC_IRQ(0) 197#define IRQ_PC1 BFIN_PC_IRQ(1)
198#define IRQ_PC1 BFIN_PC_IRQ(1) 198#define IRQ_PC2 BFIN_PC_IRQ(2)
199#define IRQ_PC2 BFIN_PC_IRQ(2) 199#define IRQ_PC3 BFIN_PC_IRQ(3)
200#define IRQ_PC3 BFIN_PC_IRQ(3) 200#define IRQ_PC4 BFIN_PC_IRQ(4)
201#define IRQ_PC4 BFIN_PC_IRQ(4) 201#define IRQ_PC5 BFIN_PC_IRQ(5)
202#define IRQ_PC5 BFIN_PC_IRQ(5) 202#define IRQ_PC6 BFIN_PC_IRQ(6)
203#define IRQ_PC6 BFIN_PC_IRQ(6) 203#define IRQ_PC7 BFIN_PC_IRQ(7)
204#define IRQ_PC7 BFIN_PC_IRQ(7) 204#define IRQ_PC8 BFIN_PC_IRQ(8)
205#define IRQ_PC8 BFIN_PC_IRQ(8) 205#define IRQ_PC9 BFIN_PC_IRQ(9)
206#define IRQ_PC9 BFIN_PC_IRQ(9) 206#define IRQ_PC10 BFIN_PC_IRQ(10)
207#define IRQ_PC10 BFIN_PC_IRQ(10) 207#define IRQ_PC11 BFIN_PC_IRQ(11)
208#define IRQ_PC11 BFIN_PC_IRQ(11) 208#define IRQ_PC12 BFIN_PC_IRQ(12)
209#define IRQ_PC12 BFIN_PC_IRQ(12) 209#define IRQ_PC13 BFIN_PC_IRQ(13)
210#define IRQ_PC13 BFIN_PC_IRQ(13) 210#define IRQ_PC14 BFIN_PC_IRQ(14) /* N/A */
211#define IRQ_PC14 BFIN_PC_IRQ(14) /* N/A */ 211#define IRQ_PC15 BFIN_PC_IRQ(15) /* N/A */
212#define IRQ_PC15 BFIN_PC_IRQ(15) /* N/A */ 212
213 213#define BFIN_PD_IRQ(x) ((x) + IRQ_PC15 + 1)
214#define BFIN_PD_IRQ(x) ((x) + IRQ_PC15 + 1) 214#define IRQ_PD0 BFIN_PD_IRQ(0)
215#define IRQ_PD0 BFIN_PD_IRQ(0) 215#define IRQ_PD1 BFIN_PD_IRQ(1)
216#define IRQ_PD1 BFIN_PD_IRQ(1) 216#define IRQ_PD2 BFIN_PD_IRQ(2)
217#define IRQ_PD2 BFIN_PD_IRQ(2) 217#define IRQ_PD3 BFIN_PD_IRQ(3)
218#define IRQ_PD3 BFIN_PD_IRQ(3) 218#define IRQ_PD4 BFIN_PD_IRQ(4)
219#define IRQ_PD4 BFIN_PD_IRQ(4) 219#define IRQ_PD5 BFIN_PD_IRQ(5)
220#define IRQ_PD5 BFIN_PD_IRQ(5) 220#define IRQ_PD6 BFIN_PD_IRQ(6)
221#define IRQ_PD6 BFIN_PD_IRQ(6) 221#define IRQ_PD7 BFIN_PD_IRQ(7)
222#define IRQ_PD7 BFIN_PD_IRQ(7) 222#define IRQ_PD8 BFIN_PD_IRQ(8)
223#define IRQ_PD8 BFIN_PD_IRQ(8) 223#define IRQ_PD9 BFIN_PD_IRQ(9)
224#define IRQ_PD9 BFIN_PD_IRQ(9) 224#define IRQ_PD10 BFIN_PD_IRQ(10)
225#define IRQ_PD10 BFIN_PD_IRQ(10) 225#define IRQ_PD11 BFIN_PD_IRQ(11)
226#define IRQ_PD11 BFIN_PD_IRQ(11) 226#define IRQ_PD12 BFIN_PD_IRQ(12)
227#define IRQ_PD12 BFIN_PD_IRQ(12) 227#define IRQ_PD13 BFIN_PD_IRQ(13)
228#define IRQ_PD13 BFIN_PD_IRQ(13) 228#define IRQ_PD14 BFIN_PD_IRQ(14)
229#define IRQ_PD14 BFIN_PD_IRQ(14) 229#define IRQ_PD15 BFIN_PD_IRQ(15)
230#define IRQ_PD15 BFIN_PD_IRQ(15) 230
231 231#define BFIN_PE_IRQ(x) ((x) + IRQ_PD15 + 1)
232#define BFIN_PE_IRQ(x) ((x) + IRQ_PD15 + 1) 232#define IRQ_PE0 BFIN_PE_IRQ(0)
233#define IRQ_PE0 BFIN_PE_IRQ(0) 233#define IRQ_PE1 BFIN_PE_IRQ(1)
234#define IRQ_PE1 BFIN_PE_IRQ(1) 234#define IRQ_PE2 BFIN_PE_IRQ(2)
235#define IRQ_PE2 BFIN_PE_IRQ(2) 235#define IRQ_PE3 BFIN_PE_IRQ(3)
236#define IRQ_PE3 BFIN_PE_IRQ(3) 236#define IRQ_PE4 BFIN_PE_IRQ(4)
237#define IRQ_PE4 BFIN_PE_IRQ(4) 237#define IRQ_PE5 BFIN_PE_IRQ(5)
238#define IRQ_PE5 BFIN_PE_IRQ(5) 238#define IRQ_PE6 BFIN_PE_IRQ(6)
239#define IRQ_PE6 BFIN_PE_IRQ(6) 239#define IRQ_PE7 BFIN_PE_IRQ(7)
240#define IRQ_PE7 BFIN_PE_IRQ(7) 240#define IRQ_PE8 BFIN_PE_IRQ(8)
241#define IRQ_PE8 BFIN_PE_IRQ(8) 241#define IRQ_PE9 BFIN_PE_IRQ(9)
242#define IRQ_PE9 BFIN_PE_IRQ(9) 242#define IRQ_PE10 BFIN_PE_IRQ(10)
243#define IRQ_PE10 BFIN_PE_IRQ(10) 243#define IRQ_PE11 BFIN_PE_IRQ(11)
244#define IRQ_PE11 BFIN_PE_IRQ(11) 244#define IRQ_PE12 BFIN_PE_IRQ(12)
245#define IRQ_PE12 BFIN_PE_IRQ(12) 245#define IRQ_PE13 BFIN_PE_IRQ(13)
246#define IRQ_PE13 BFIN_PE_IRQ(13) 246#define IRQ_PE14 BFIN_PE_IRQ(14)
247#define IRQ_PE14 BFIN_PE_IRQ(14) 247#define IRQ_PE15 BFIN_PE_IRQ(15)
248#define IRQ_PE15 BFIN_PE_IRQ(15) 248
249 249#define BFIN_PF_IRQ(x) ((x) + IRQ_PE15 + 1)
250#define BFIN_PF_IRQ(x) ((x) + IRQ_PE15 + 1) 250#define IRQ_PF0 BFIN_PF_IRQ(0)
251#define IRQ_PF0 BFIN_PF_IRQ(0) 251#define IRQ_PF1 BFIN_PF_IRQ(1)
252#define IRQ_PF1 BFIN_PF_IRQ(1) 252#define IRQ_PF2 BFIN_PF_IRQ(2)
253#define IRQ_PF2 BFIN_PF_IRQ(2) 253#define IRQ_PF3 BFIN_PF_IRQ(3)
254#define IRQ_PF3 BFIN_PF_IRQ(3) 254#define IRQ_PF4 BFIN_PF_IRQ(4)
255#define IRQ_PF4 BFIN_PF_IRQ(4) 255#define IRQ_PF5 BFIN_PF_IRQ(5)
256#define IRQ_PF5 BFIN_PF_IRQ(5) 256#define IRQ_PF6 BFIN_PF_IRQ(6)
257#define IRQ_PF6 BFIN_PF_IRQ(6) 257#define IRQ_PF7 BFIN_PF_IRQ(7)
258#define IRQ_PF7 BFIN_PF_IRQ(7) 258#define IRQ_PF8 BFIN_PF_IRQ(8)
259#define IRQ_PF8 BFIN_PF_IRQ(8) 259#define IRQ_PF9 BFIN_PF_IRQ(9)
260#define IRQ_PF9 BFIN_PF_IRQ(9) 260#define IRQ_PF10 BFIN_PF_IRQ(10)
261#define IRQ_PF10 BFIN_PF_IRQ(10) 261#define IRQ_PF11 BFIN_PF_IRQ(11)
262#define IRQ_PF11 BFIN_PF_IRQ(11) 262#define IRQ_PF12 BFIN_PF_IRQ(12)
263#define IRQ_PF12 BFIN_PF_IRQ(12) 263#define IRQ_PF13 BFIN_PF_IRQ(13)
264#define IRQ_PF13 BFIN_PF_IRQ(13) 264#define IRQ_PF14 BFIN_PF_IRQ(14)
265#define IRQ_PF14 BFIN_PF_IRQ(14) 265#define IRQ_PF15 BFIN_PF_IRQ(15)
266#define IRQ_PF15 BFIN_PF_IRQ(15) 266
267 267#define BFIN_PG_IRQ(x) ((x) + IRQ_PF15 + 1)
268#define BFIN_PG_IRQ(x) ((x) + IRQ_PF15 + 1) 268#define IRQ_PG0 BFIN_PG_IRQ(0)
269#define IRQ_PG0 BFIN_PG_IRQ(0) 269#define IRQ_PG1 BFIN_PG_IRQ(1)
270#define IRQ_PG1 BFIN_PG_IRQ(1) 270#define IRQ_PG2 BFIN_PG_IRQ(2)
271#define IRQ_PG2 BFIN_PG_IRQ(2) 271#define IRQ_PG3 BFIN_PG_IRQ(3)
272#define IRQ_PG3 BFIN_PG_IRQ(3) 272#define IRQ_PG4 BFIN_PG_IRQ(4)
273#define IRQ_PG4 BFIN_PG_IRQ(4) 273#define IRQ_PG5 BFIN_PG_IRQ(5)
274#define IRQ_PG5 BFIN_PG_IRQ(5) 274#define IRQ_PG6 BFIN_PG_IRQ(6)
275#define IRQ_PG6 BFIN_PG_IRQ(6) 275#define IRQ_PG7 BFIN_PG_IRQ(7)
276#define IRQ_PG7 BFIN_PG_IRQ(7) 276#define IRQ_PG8 BFIN_PG_IRQ(8)
277#define IRQ_PG8 BFIN_PG_IRQ(8) 277#define IRQ_PG9 BFIN_PG_IRQ(9)
278#define IRQ_PG9 BFIN_PG_IRQ(9) 278#define IRQ_PG10 BFIN_PG_IRQ(10)
279#define IRQ_PG10 BFIN_PG_IRQ(10) 279#define IRQ_PG11 BFIN_PG_IRQ(11)
280#define IRQ_PG11 BFIN_PG_IRQ(11) 280#define IRQ_PG12 BFIN_PG_IRQ(12)
281#define IRQ_PG12 BFIN_PG_IRQ(12) 281#define IRQ_PG13 BFIN_PG_IRQ(13)
282#define IRQ_PG13 BFIN_PG_IRQ(13) 282#define IRQ_PG14 BFIN_PG_IRQ(14)
283#define IRQ_PG14 BFIN_PG_IRQ(14) 283#define IRQ_PG15 BFIN_PG_IRQ(15)
284#define IRQ_PG15 BFIN_PG_IRQ(15) 284
285 285#define BFIN_PH_IRQ(x) ((x) + IRQ_PG15 + 1)
286#define BFIN_PH_IRQ(x) ((x) + IRQ_PG15 + 1) 286#define IRQ_PH0 BFIN_PH_IRQ(0)
287#define IRQ_PH0 BFIN_PH_IRQ(0) 287#define IRQ_PH1 BFIN_PH_IRQ(1)
288#define IRQ_PH1 BFIN_PH_IRQ(1) 288#define IRQ_PH2 BFIN_PH_IRQ(2)
289#define IRQ_PH2 BFIN_PH_IRQ(2) 289#define IRQ_PH3 BFIN_PH_IRQ(3)
290#define IRQ_PH3 BFIN_PH_IRQ(3) 290#define IRQ_PH4 BFIN_PH_IRQ(4)
291#define IRQ_PH4 BFIN_PH_IRQ(4) 291#define IRQ_PH5 BFIN_PH_IRQ(5)
292#define IRQ_PH5 BFIN_PH_IRQ(5) 292#define IRQ_PH6 BFIN_PH_IRQ(6)
293#define IRQ_PH6 BFIN_PH_IRQ(6) 293#define IRQ_PH7 BFIN_PH_IRQ(7)
294#define IRQ_PH7 BFIN_PH_IRQ(7) 294#define IRQ_PH8 BFIN_PH_IRQ(8)
295#define IRQ_PH8 BFIN_PH_IRQ(8) 295#define IRQ_PH9 BFIN_PH_IRQ(9)
296#define IRQ_PH9 BFIN_PH_IRQ(9) 296#define IRQ_PH10 BFIN_PH_IRQ(10)
297#define IRQ_PH10 BFIN_PH_IRQ(10) 297#define IRQ_PH11 BFIN_PH_IRQ(11)
298#define IRQ_PH11 BFIN_PH_IRQ(11) 298#define IRQ_PH12 BFIN_PH_IRQ(12)
299#define IRQ_PH12 BFIN_PH_IRQ(12) 299#define IRQ_PH13 BFIN_PH_IRQ(13)
300#define IRQ_PH13 BFIN_PH_IRQ(13) 300#define IRQ_PH14 BFIN_PH_IRQ(14) /* N/A */
301#define IRQ_PH14 BFIN_PH_IRQ(14) /* N/A */ 301#define IRQ_PH15 BFIN_PH_IRQ(15) /* N/A */
302#define IRQ_PH15 BFIN_PH_IRQ(15) /* N/A */ 302
303 303#define BFIN_PI_IRQ(x) ((x) + IRQ_PH15 + 1)
304#define BFIN_PI_IRQ(x) ((x) + IRQ_PH15 + 1) 304#define IRQ_PI0 BFIN_PI_IRQ(0)
305#define IRQ_PI0 BFIN_PI_IRQ(0) 305#define IRQ_PI1 BFIN_PI_IRQ(1)
306#define IRQ_PI1 BFIN_PI_IRQ(1) 306#define IRQ_PI2 BFIN_PI_IRQ(2)
307#define IRQ_PI2 BFIN_PI_IRQ(2) 307#define IRQ_PI3 BFIN_PI_IRQ(3)
308#define IRQ_PI3 BFIN_PI_IRQ(3) 308#define IRQ_PI4 BFIN_PI_IRQ(4)
309#define IRQ_PI4 BFIN_PI_IRQ(4) 309#define IRQ_PI5 BFIN_PI_IRQ(5)
310#define IRQ_PI5 BFIN_PI_IRQ(5) 310#define IRQ_PI6 BFIN_PI_IRQ(6)
311#define IRQ_PI6 BFIN_PI_IRQ(6) 311#define IRQ_PI7 BFIN_PI_IRQ(7)
312#define IRQ_PI7 BFIN_PI_IRQ(7) 312#define IRQ_PI8 BFIN_PI_IRQ(8)
313#define IRQ_PI8 BFIN_PI_IRQ(8) 313#define IRQ_PI9 BFIN_PI_IRQ(9)
314#define IRQ_PI9 BFIN_PI_IRQ(9) 314#define IRQ_PI10 BFIN_PI_IRQ(10)
315#define IRQ_PI10 BFIN_PI_IRQ(10) 315#define IRQ_PI11 BFIN_PI_IRQ(11)
316#define IRQ_PI11 BFIN_PI_IRQ(11) 316#define IRQ_PI12 BFIN_PI_IRQ(12)
317#define IRQ_PI12 BFIN_PI_IRQ(12) 317#define IRQ_PI13 BFIN_PI_IRQ(13)
318#define IRQ_PI13 BFIN_PI_IRQ(13) 318#define IRQ_PI14 BFIN_PI_IRQ(14)
319#define IRQ_PI14 BFIN_PI_IRQ(14) 319#define IRQ_PI15 BFIN_PI_IRQ(15)
320#define IRQ_PI15 BFIN_PI_IRQ(15) 320
321 321#define BFIN_PJ_IRQ(x) ((x) + IRQ_PI15 + 1)
322#define BFIN_PJ_IRQ(x) ((x) + IRQ_PI15 + 1) 322#define IRQ_PJ0 BFIN_PJ_IRQ(0)
323#define IRQ_PJ0 BFIN_PJ_IRQ(0) 323#define IRQ_PJ1 BFIN_PJ_IRQ(1)
324#define IRQ_PJ1 BFIN_PJ_IRQ(1) 324#define IRQ_PJ2 BFIN_PJ_IRQ(2)
325#define IRQ_PJ2 BFIN_PJ_IRQ(2) 325#define IRQ_PJ3 BFIN_PJ_IRQ(3)
326#define IRQ_PJ3 BFIN_PJ_IRQ(3) 326#define IRQ_PJ4 BFIN_PJ_IRQ(4)
327#define IRQ_PJ4 BFIN_PJ_IRQ(4) 327#define IRQ_PJ5 BFIN_PJ_IRQ(5)
328#define IRQ_PJ5 BFIN_PJ_IRQ(5) 328#define IRQ_PJ6 BFIN_PJ_IRQ(6)
329#define IRQ_PJ6 BFIN_PJ_IRQ(6) 329#define IRQ_PJ7 BFIN_PJ_IRQ(7)
330#define IRQ_PJ7 BFIN_PJ_IRQ(7) 330#define IRQ_PJ8 BFIN_PJ_IRQ(8)
331#define IRQ_PJ8 BFIN_PJ_IRQ(8) 331#define IRQ_PJ9 BFIN_PJ_IRQ(9)
332#define IRQ_PJ9 BFIN_PJ_IRQ(9) 332#define IRQ_PJ10 BFIN_PJ_IRQ(10)
333#define IRQ_PJ10 BFIN_PJ_IRQ(10) 333#define IRQ_PJ11 BFIN_PJ_IRQ(11)
334#define IRQ_PJ11 BFIN_PJ_IRQ(11) 334#define IRQ_PJ12 BFIN_PJ_IRQ(12)
335#define IRQ_PJ12 BFIN_PJ_IRQ(12) 335#define IRQ_PJ13 BFIN_PJ_IRQ(13)
336#define IRQ_PJ13 BFIN_PJ_IRQ(13) 336#define IRQ_PJ14 BFIN_PJ_IRQ(14) /* N/A */
337#define IRQ_PJ14 BFIN_PJ_IRQ(14) /* N/A */ 337#define IRQ_PJ15 BFIN_PJ_IRQ(15) /* N/A */
338#define IRQ_PJ15 BFIN_PJ_IRQ(15) /* N/A */ 338
339#define GPIO_IRQ_BASE IRQ_PA0
339 340
340#ifdef CONFIG_IRQCHIP_DEMUX_GPIO 341#ifdef CONFIG_IRQCHIP_DEMUX_GPIO
341#define NR_IRQS (IRQ_PJ15+1) 342#define NR_IRQS (IRQ_PJ15+1)
@@ -343,6 +344,34 @@ Events (highest priority) EMU 0
343#define NR_IRQS (SYS_IRQS+1) 344#define NR_IRQS (SYS_IRQS+1)
344#endif 345#endif
345 346
347/* For compatibility reasons with existing code */
348
349#define IRQ_DMAC0_ERR IRQ_DMAC0_ERROR
350#define IRQ_EPPI0_ERR IRQ_EPPI0_ERROR
351#define IRQ_SPORT0_ERR IRQ_SPORT0_ERROR
352#define IRQ_SPORT1_ERR IRQ_SPORT1_ERROR
353#define IRQ_SPI0_ERR IRQ_SPI0_ERROR
354#define IRQ_UART0_ERR IRQ_UART0_ERROR
355#define IRQ_DMAC1_ERR IRQ_DMAC1_ERROR
356#define IRQ_SPORT2_ERR IRQ_SPORT2_ERROR
357#define IRQ_SPORT3_ERR IRQ_SPORT3_ERROR
358#define IRQ_SPI1_ERR IRQ_SPI1_ERROR
359#define IRQ_SPI2_ERR IRQ_SPI2_ERROR
360#define IRQ_UART1_ERR IRQ_UART1_ERROR
361#define IRQ_UART2_ERR IRQ_UART2_ERROR
362#define IRQ_CAN0_ERR IRQ_CAN0_ERROR
363#define IRQ_MXVR_ERR IRQ_MXVR_ERROR
364#define IRQ_EPP1_ERR IRQ_EPP1_ERROR
365#define IRQ_EPP2_ERR IRQ_EPP2_ERROR
366#define IRQ_UART3_ERR IRQ_UART3_ERROR
367#define IRQ_HOST_ERR IRQ_HOST_ERROR
368#define IRQ_PIXC_ERR IRQ_PIXC_ERROR
369#define IRQ_NFC_ERR IRQ_NFC_ERROR
370#define IRQ_ATAPI_ERR IRQ_ATAPI_ERROR
371#define IRQ_CAN1_ERR IRQ_CAN1_ERROR
372#define IRQ_HS_DMA_ERR IRQ_HS_DMA_ERROR
373
374
346#define IVG7 7 375#define IVG7 7
347#define IVG8 8 376#define IVG8 8
348#define IVG9 9 377#define IVG9 9
diff --git a/include/asm-blackfin/mach-bf548/mem_map.h b/include/asm-blackfin/mach-bf548/mem_map.h
index 72d80e8a6e81..ec1597e31831 100644
--- a/include/asm-blackfin/mach-bf548/mem_map.h
+++ b/include/asm-blackfin/mach-bf548/mem_map.h
@@ -51,10 +51,10 @@
51/* Level 1 Memory */ 51/* Level 1 Memory */
52 52
53/* Memory Map for ADSP-BF548 processors */ 53/* Memory Map for ADSP-BF548 processors */
54#ifdef CONFIG_BLKFIN_ICACHE 54#ifdef CONFIG_BFIN_ICACHE
55#define BLKFIN_ICACHESIZE (16*1024) 55#define BFIN_ICACHESIZE (16*1024)
56#else 56#else
57#define BLKFIN_ICACHESIZE (0*1024) 57#define BFIN_ICACHESIZE (0*1024)
58#endif 58#endif
59 59
60#define L1_CODE_START 0xFFA00000 60#define L1_CODE_START 0xFFA00000
@@ -63,29 +63,29 @@
63 63
64#define L1_CODE_LENGTH 0xC000 64#define L1_CODE_LENGTH 0xC000
65 65
66#ifdef CONFIG_BLKFIN_DCACHE 66#ifdef CONFIG_BFIN_DCACHE
67 67
68#ifdef CONFIG_BLKFIN_DCACHE_BANKA 68#ifdef CONFIG_BFIN_DCACHE_BANKA
69#define DMEM_CNTR (ACACHE_BSRAM | ENDCPLB | PORT_PREF0) 69#define DMEM_CNTR (ACACHE_BSRAM | ENDCPLB | PORT_PREF0)
70#define L1_DATA_A_LENGTH (0x8000 - 0x4000) 70#define L1_DATA_A_LENGTH (0x8000 - 0x4000)
71#define L1_DATA_B_LENGTH 0x8000 71#define L1_DATA_B_LENGTH 0x8000
72#define BLKFIN_DCACHESIZE (16*1024) 72#define BFIN_DCACHESIZE (16*1024)
73#define BLKFIN_DSUPBANKS 1 73#define BFIN_DSUPBANKS 1
74#else 74#else
75#define DMEM_CNTR (ACACHE_BCACHE | ENDCPLB | PORT_PREF0) 75#define DMEM_CNTR (ACACHE_BCACHE | ENDCPLB | PORT_PREF0)
76#define L1_DATA_A_LENGTH (0x8000 - 0x4000) 76#define L1_DATA_A_LENGTH (0x8000 - 0x4000)
77#define L1_DATA_B_LENGTH (0x8000 - 0x4000) 77#define L1_DATA_B_LENGTH (0x8000 - 0x4000)
78#define BLKFIN_DCACHESIZE (32*1024) 78#define BFIN_DCACHESIZE (32*1024)
79#define BLKFIN_DSUPBANKS 2 79#define BFIN_DSUPBANKS 2
80#endif 80#endif
81 81
82#else 82#else
83#define DMEM_CNTR (ASRAM_BSRAM | ENDCPLB | PORT_PREF0) 83#define DMEM_CNTR (ASRAM_BSRAM | ENDCPLB | PORT_PREF0)
84#define L1_DATA_A_LENGTH 0x8000 84#define L1_DATA_A_LENGTH 0x8000
85#define L1_DATA_B_LENGTH 0x8000 85#define L1_DATA_B_LENGTH 0x8000
86#define BLKFIN_DCACHESIZE (0*1024) 86#define BFIN_DCACHESIZE (0*1024)
87#define BLKFIN_DSUPBANKS 0 87#define BFIN_DSUPBANKS 0
88#endif /*CONFIG_BLKFIN_DCACHE*/ 88#endif /*CONFIG_BFIN_DCACHE*/
89 89
90/* Scratch Pad Memory */ 90/* Scratch Pad Memory */
91 91
diff --git a/include/asm-blackfin/mach-bf561/anomaly.h b/include/asm-blackfin/mach-bf561/anomaly.h
index f5b32d66517d..bed956456884 100644
--- a/include/asm-blackfin/mach-bf561/anomaly.h
+++ b/include/asm-blackfin/mach-bf561/anomaly.h
@@ -1,184 +1,256 @@
1
2/* 1/*
3 * File: include/asm-blackfin/mach-bf561/anomaly.h 2 * File: include/asm-blackfin/mach-bf561/anomaly.h
4 * Based on: 3 * Bugs: Enter bugs at http://blackfin.uclinux.org/
5 * Author:
6 *
7 * Created:
8 * Description:
9 *
10 * Rev:
11 *
12 * Modified:
13 *
14 * Bugs: Enter bugs at http://blackfin.uclinux.org/
15 * 4 *
16 * This program is free software; you can redistribute it and/or modify 5 * Copyright (C) 2004-2007 Analog Devices Inc.
17 * it under the terms of the GNU General Public License as published by 6 * Licensed under the GPL-2 or later.
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 */ 7 */
31 8
32/* This file shoule be up to date with: 9/* This file shoule be up to date with:
33 * - Revision L, 10Aug2006; ADSP-BF561 Silicon Anomaly List 10 * - Revision N, March 28, 2007; ADSP-BF561 Silicon Anomaly List
34 */ 11 */
35 12
36#ifndef _MACH_ANOMALY_H_ 13#ifndef _MACH_ANOMALY_H_
37#define _MACH_ANOMALY_H_ 14#define _MACH_ANOMALY_H_
38 15
39/* We do not support 0.1 or 0.4 silicon - sorry */ 16/* We do not support 0.1, 0.2, or 0.4 silicon - sorry */
40#if (defined(CONFIG_BF_REV_0_1) || defined(CONFIG_BF_REV_0_2) || defined(CONFIG_BF_REV_0_4)) 17#if __SILICON_REVISION__ < 3 || __SILICON_REVISION__ == 4
41#error Kernel will not work on BF561 Version 0.1, 0.2, or 0.4 18# error Kernel will not work on BF561 silicon version 0.0, 0.1, 0.2, or 0.4
42#endif 19#endif
43 20
44/* Issues that are common to 0.5 and 0.3 silicon */ 21/* Multi-Issue Instruction with dsp32shiftimm in slot1 and P-reg Store in slot 2 Not Supported */
45#if (defined(CONFIG_BF_REV_0_5) || defined(CONFIG_BF_REV_0_3)) 22#define ANOMALY_05000074 (1)
46#define ANOMALY_05000074 /* A multi issue instruction with dsp32shiftimm in 23/* UART Line Status Register (UART_LSR) Bits Are Not Updated at the Same Time */
47 slot1 and store of a P register in slot 2 is not 24#define ANOMALY_05000099 (__SILICON_REVISION__ < 5)
48 supported */ 25/* Trace Buffers may contain errors in emulation mode and/or exception, NMI, reset handlers */
49#define ANOMALY_05000099 /* UART Line Status Register (UART_LSR) bits are not 26#define ANOMALY_05000116 (__SILICON_REVISION__ < 3)
50 updated at the same time. */ 27/* Testset instructions restricted to 32-bit aligned memory locations */
51#define ANOMALY_05000120 /* Testset instructions restricted to 32-bit aligned 28#define ANOMALY_05000120 (1)
52 memory locations */ 29/* Rx.H Cannot Be Used to Access 16-bit System MMR Registers */
53#define ANOMALY_05000122 /* Rx.H cannot be used to access 16-bit System MMR 30#define ANOMALY_05000122 (1)
54 registers */ 31/* Erroneous exception when enabling cache */
55#define ANOMALY_05000127 /* Signbits instruction not functional under certain 32#define ANOMALY_05000125 (__SILICON_REVISION__ < 3)
56 conditions */ 33/* Signbits instruction not functional under certain conditions */
57#define ANOMALY_05000149 /* IMDMA S1/D1 channel may stall */ 34#define ANOMALY_05000127 (1)
58#define ANOMALY_05000166 /* PPI Data Lengths Between 8 and 16 do not zero out 35/* Two bits in the Watchpoint Status Register (WPSTAT) are swapped */
59 upper bits */ 36#define ANOMALY_05000134 (__SILICON_REVISION__ < 3)
60#define ANOMALY_05000167 /* Turning Serial Ports on With External Frame Syncs */ 37/* Enable wires from the Data Watchpoint Address Control Register (WPDACTL) are swapped */
61#define ANOMALY_05000180 /* PPI_DELAY not functional in PPI modes with 0 frame 38#define ANOMALY_05000135 (__SILICON_REVISION__ < 3)
62 syncs */ 39/* Stall in multi-unit DMA operations */
63#define ANOMALY_05000182 /* IMDMA does not operate to full speed for 600MHz 40#define ANOMALY_05000136 (__SILICON_REVISION__ < 3)
64 and higher devices */ 41/* Allowing the SPORT RX FIFO to fill will cause an overflow */
65#define ANOMALY_05000187 /* IMDMA Corrupted Data after a Halt */ 42#define ANOMALY_05000140 (__SILICON_REVISION__ < 3)
66#define ANOMALY_05000190 /* PPI not functional at core voltage < 1Volt */ 43/* Infinite Stall may occur with a particular sequence of consecutive dual dag events */
67#define ANOMALY_05000208 /* VSTAT status bit in PLL_STAT register is not 44#define ANOMALY_05000141 (__SILICON_REVISION__ < 3)
68 functional */ 45/* Interrupts may be lost when a programmable input flag is configured to be edge sensitive */
69#define ANOMALY_05000245 /* Spurious Hardware Error from an access in the 46#define ANOMALY_05000142 (__SILICON_REVISION__ < 3)
70 shadow of a conditional branch */ 47/* DMA and TESTSET conflict when both are accessing external memory */
71#define ANOMALY_05000257 /* Interrupt/Exception during short hardware loop 48#define ANOMALY_05000144 (__SILICON_REVISION__ < 3)
72 may cause bad instruction fetches */ 49/* In PWM_OUT mode, you must enable the PPI block to generate a waveform from PPI_CLK */
73#define ANOMALY_05000265 /* Sensitivity to noise with slow input edge rates on 50#define ANOMALY_05000145 (__SILICON_REVISION__ < 3)
74 external SPORT TX and RX clocks */ 51/* MDMA may lose the first few words of a descriptor chain */
75#define ANOMALY_05000267 /* IMDMA may corrupt data under certain conditions */ 52#define ANOMALY_05000146 (__SILICON_REVISION__ < 3)
76#define ANOMALY_05000269 /* High I/O activity causes output voltage of internal 53/* Source MDMA descriptor may stop with a DMA Error near beginning of descriptor fetch */
77 voltage regulator (VDDint) to increase */ 54#define ANOMALY_05000147 (__SILICON_REVISION__ < 3)
78#define ANOMALY_05000270 /* High I/O activity causes output voltage of internal 55/* IMDMA S1/D1 channel may stall */
79 voltage regulator (VDDint) to decrease */ 56#define ANOMALY_05000149 (1)
80#define ANOMALY_05000272 /* Certain data cache write through modes fail for 57/* DMA engine may lose data due to incorrect handshaking */
81 VDDint <=0.9V */ 58#define ANOMALY_05000150 (__SILICON_REVISION__ < 3)
82#define ANOMALY_05000274 /* Data cache write back to external synchronous memory 59/* DMA stalls when all three controllers read data from the same source */
83 may be lost */ 60#define ANOMALY_05000151 (__SILICON_REVISION__ < 3)
84#define ANOMALY_05000275 /* PPI Timing and sampling informaton updates */ 61/* Execution stall when executing in L2 and doing external accesses */
85#define ANOMALY_05000312 /* Errors when SSYNC, CSYNC, or loads to LT, LB and LC 62#define ANOMALY_05000152 (__SILICON_REVISION__ < 3)
86 registers are interrupted */ 63/* Frame Delay in SPORT Multichannel Mode */
64#define ANOMALY_05000153 (__SILICON_REVISION__ < 3)
65/* SPORT TFS signal stays active in multichannel mode outside of valid channels */
66#define ANOMALY_05000154 (__SILICON_REVISION__ < 3)
67/* Timers in PWM-Out Mode with PPI GP Receive (Input) Mode with 0 Frame Syncs */
68#define ANOMALY_05000156 (__SILICON_REVISION__ < 4)
69/* Killed 32-bit MMR write leads to next system MMR access thinking it should be 32-bit */
70#define ANOMALY_05000157 (__SILICON_REVISION__ < 3)
71/* DMA Lock-up at CCLK to SCLK ratios of 4:1, 2:1, or 1:1 */
72#define ANOMALY_05000159 (__SILICON_REVISION__ < 3)
73/* A read from external memory may return a wrong value with data cache enabled */
74#define ANOMALY_05000160 (__SILICON_REVISION__ < 3)
75/* Data Cache Fill data can be corrupted after/during Instruction DMA if certain core stalls exist */
76#define ANOMALY_05000161 (__SILICON_REVISION__ < 3)
77/* DMEM_CONTROL<12> is not set on Reset */
78#define ANOMALY_05000162 (__SILICON_REVISION__ < 3)
79/* SPORT transmit data is not gated by external frame sync in certain conditions */
80#define ANOMALY_05000163 (__SILICON_REVISION__ < 3)
81/* PPI Data Lengths Between 8 and 16 Do Not Zero Out Upper Bits */
82#define ANOMALY_05000166 (1)
83/* Turning Serial Ports on with External Frame Syncs */
84#define ANOMALY_05000167 (1)
85/* SDRAM auto-refresh and subsequent Power Ups */
86#define ANOMALY_05000168 (__SILICON_REVISION__ < 5)
87/* DATA CPLB page miss can result in lost write-through cache data writes */
88#define ANOMALY_05000169 (__SILICON_REVISION__ < 5)
89/* Boot-ROM code modifies SICA_IWRx wakeup registers */
90#define ANOMALY_05000171 (__SILICON_REVISION__ < 5)
91/* DSPID register values incorrect */
92#define ANOMALY_05000172 (__SILICON_REVISION__ < 3)
93/* DMA vs Core accesses to external memory */
94#define ANOMALY_05000173 (__SILICON_REVISION__ < 3)
95/* Cache Fill Buffer Data lost */
96#define ANOMALY_05000174 (__SILICON_REVISION__ < 5)
97/* Overlapping Sequencer and Memory Stalls */
98#define ANOMALY_05000175 (__SILICON_REVISION__ < 5)
99/* Multiplication of (-1) by (-1) followed by an accumulator saturation */
100#define ANOMALY_05000176 (__SILICON_REVISION__ < 5)
101/* PPI_COUNT Cannot Be Programmed to 0 in General Purpose TX or RX Modes */
102#define ANOMALY_05000179 (__SILICON_REVISION__ < 5)
103/* PPI_DELAY Not Functional in PPI Modes with 0 Frame Syncs */
104#define ANOMALY_05000180 (1)
105/* Disabling the PPI resets the PPI configuration registers */
106#define ANOMALY_05000181 (__SILICON_REVISION__ < 5)
107/* IMDMA does not operate to full speed for 600MHz and higher devices */
108#define ANOMALY_05000182 (1)
109/* Timer Pin limitations for PPI TX Modes with External Frame Syncs */
110#define ANOMALY_05000184 (__SILICON_REVISION__ < 5)
111/* PPI TX Mode with 2 External Frame Syncs */
112#define ANOMALY_05000185 (__SILICON_REVISION__ < 5)
113/* PPI packing with Data Length greater than 8 bits (not a meaningful mode) */
114#define ANOMALY_05000186 (__SILICON_REVISION__ < 5)
115/* IMDMA Corrupted Data after a Halt */
116#define ANOMALY_05000187 (1)
117/* IMDMA Restrictions on Descriptor and Buffer Placement in Memory */
118#define ANOMALY_05000188 (__SILICON_REVISION__ < 5)
119/* False Protection Exceptions */
120#define ANOMALY_05000189 (__SILICON_REVISION__ < 5)
121/* PPI not functional at core voltage < 1Volt */
122#define ANOMALY_05000190 (1)
123/* PPI does not invert the Driving PPICLK edge in Transmit Modes */
124#define ANOMALY_05000191 (__SILICON_REVISION__ < 3)
125/* False I/O Pin Interrupts on Edge-Sensitive Inputs When Polarity Setting Is Changed */
126#define ANOMALY_05000193 (__SILICON_REVISION__ < 5)
127/* Restarting SPORT in Specific Modes May Cause Data Corruption */
128#define ANOMALY_05000194 (__SILICON_REVISION__ < 5)
129/* Failing MMR Accesses When Stalled by Preceding Memory Read */
130#define ANOMALY_05000198 (__SILICON_REVISION__ < 5)
131/* Current DMA Address Shows Wrong Value During Carry Fix */
132#define ANOMALY_05000199 (__SILICON_REVISION__ < 5)
133/* SPORT TFS and DT Are Incorrectly Driven During Inactive Channels in Certain Conditions */
134#define ANOMALY_05000200 (__SILICON_REVISION__ < 5)
135/* Possible Infinite Stall with Specific Dual-DAG Situation */
136#define ANOMALY_05000202 (__SILICON_REVISION__ < 5)
137/* Incorrect data read with write-through cache and allocate cache lines on reads only mode */
138#define ANOMALY_05000204 (__SILICON_REVISION__ < 5)
139/* Specific sequence that can cause DMA error or DMA stopping */
140#define ANOMALY_05000205 (__SILICON_REVISION__ < 5)
141/* Recovery from "Brown-Out" Condition */
142#define ANOMALY_05000207 (__SILICON_REVISION__ < 5)
143/* VSTAT Status Bit in PLL_STAT Register Is Not Functional */
144#define ANOMALY_05000208 (1)
145/* Speed Path in Computational Unit Affects Certain Instructions */
146#define ANOMALY_05000209 (__SILICON_REVISION__ < 5)
147/* UART TX Interrupt Masked Erroneously */
148#define ANOMALY_05000215 (__SILICON_REVISION__ < 5)
149/* NMI Event at Boot Time Results in Unpredictable State */
150#define ANOMALY_05000219 (__SILICON_REVISION__ < 5)
151/* Data Corruption with Cached External Memory and Non-Cached On-Chip L2 Memory */
152#define ANOMALY_05000220 (__SILICON_REVISION__ < 5)
153/* Incorrect Pulse-Width of UART Start Bit */
154#define ANOMALY_05000225 (__SILICON_REVISION__ < 5)
155/* Scratchpad Memory Bank Reads May Return Incorrect Data */
156#define ANOMALY_05000227 (__SILICON_REVISION__ < 5)
157/* UART Receiver is Less Robust Against Baudrate Differences in Certain Conditions */
158#define ANOMALY_05000230 (__SILICON_REVISION__ < 5)
159/* UART STB Bit Incorrectly Affects Receiver Setting */
160#define ANOMALY_05000231 (__SILICON_REVISION__ < 5)
161/* SPORT data transmit lines are incorrectly driven in multichannel mode */
162#define ANOMALY_05000232 (__SILICON_REVISION__ < 5)
163/* DF Bit in PLL_CTL Register Does Not Respond to Hardware Reset */
164#define ANOMALY_05000242 (__SILICON_REVISION__ < 5)
165/* If I-Cache Is On, CSYNC/SSYNC/IDLE Around Change of Control Causes Failures */
166#define ANOMALY_05000244 (__SILICON_REVISION__ < 5)
167/* Spurious Hardware Error from an Access in the Shadow of a Conditional Branch */
168#define ANOMALY_05000245 (__SILICON_REVISION__ < 5)
169/* TESTSET operation forces stall on the other core */
170#define ANOMALY_05000248 (__SILICON_REVISION__ < 5)
171/* Incorrect Bit Shift of Data Word in Multichannel (TDM) Mode in Certain Conditions */
172#define ANOMALY_05000250 (__SILICON_REVISION__ > 2 && __SILICON_REVISION__ < 5)
173/* Exception Not Generated for MMR Accesses in Reserved Region */
174#define ANOMALY_05000251 (__SILICON_REVISION__ < 5)
175/* Maximum External Clock Speed for Timers */
176#define ANOMALY_05000253 (__SILICON_REVISION__ < 5)
177/* Incorrect Timer Pulse Width in Single-Shot PWM_OUT Mode with External Clock */
178#define ANOMALY_05000254 (__SILICON_REVISION__ > 3)
179/* Interrupt/Exception During Short Hardware Loop May Cause Bad Instruction Fetches */
180#define ANOMALY_05000257 (__SILICON_REVISION__ < 5)
181/* Instruction Cache Is Corrupted When Bits 9 and 12 of the ICPLB Data Registers Differ */
182#define ANOMALY_05000258 (__SILICON_REVISION__ < 5)
183/* ICPLB_STATUS MMR Register May Be Corrupted */
184#define ANOMALY_05000260 (__SILICON_REVISION__ < 5)
185/* DCPLB_FAULT_ADDR MMR Register May Be Corrupted */
186#define ANOMALY_05000261 (__SILICON_REVISION__ < 5)
187/* Stores To Data Cache May Be Lost */
188#define ANOMALY_05000262 (__SILICON_REVISION__ < 5)
189/* Hardware Loop Corrupted When Taking an ICPLB Exception */
190#define ANOMALY_05000263 (__SILICON_REVISION__ < 5)
191/* CSYNC/SSYNC/IDLE Causes Infinite Stall in Penultimate Instruction in Hardware Loop */
192#define ANOMALY_05000264 (__SILICON_REVISION__ < 5)
193/* Sensitivity To Noise with Slow Input Edge Rates on External SPORT TX and RX Clocks */
194#define ANOMALY_05000265 (__SILICON_REVISION__ < 5)
195/* IMDMA destination IRQ status must be read prior to using IMDMA */
196#define ANOMALY_05000266 (__SILICON_REVISION__ > 3)
197/* IMDMA may corrupt data under certain conditions */
198#define ANOMALY_05000267 (1)
199/* High I/O Activity Causes Output Voltage of Internal Voltage Regulator (Vddint) to Increase */
200#define ANOMALY_05000269 (1)
201/* High I/O Activity Causes Output Voltage of Internal Voltage Regulator (Vddint) to Decrease */
202#define ANOMALY_05000270 (1)
203/* Certain Data Cache Writethrough Modes Fail for Vddint <= 0.9V */
204#define ANOMALY_05000272 (1)
205/* Data cache write back to external synchronous memory may be lost */
206#define ANOMALY_05000274 (1)
207/* PPI Timing and Sampling Information Updates */
208#define ANOMALY_05000275 (__SILICON_REVISION__ > 2)
209/* Timing Requirements Change for External Frame Sync PPI Modes with Non-Zero PPI_DELAY */
210#define ANOMALY_05000276 (__SILICON_REVISION__ < 5)
211/* Disabling Peripherals with DMA Running May Cause DMA System Instability */
212#define ANOMALY_05000278 (__SILICON_REVISION__ < 5)
213/* False Hardware Error Exception When ISR Context Is Not Restored */
214#define ANOMALY_05000281 (__SILICON_REVISION__ < 5)
215/* System MMR Write Is Stalled Indefinitely When Killed in a Particular Stage */
216#define ANOMALY_05000283 (1)
217/* A read will receive incorrect data under certain conditions */
218#define ANOMALY_05000287 (__SILICON_REVISION__ < 5)
219/* SPORTs May Receive Bad Data If FIFOs Fill Up */
220#define ANOMALY_05000288 (__SILICON_REVISION__ < 5)
221/* Memory-To-Memory DMA Source/Destination Descriptors Must Be in Same Memory Space */
222#define ANOMALY_05000301 (1)
223/* SSYNCs After Writes To DMA MMR Registers May Not Be Handled Correctly */
224#define ANOMALY_05000302 (1)
225/* New Feature: Additional Hysteresis on SPORT Input Pins (Not Available On Older Silicon) */
226#define ANOMALY_05000305 (__SILICON_REVISION__ < 5)
227/* SCKELOW Bit Does Not Maintain State Through Hibernate */
228#define ANOMALY_05000307 (__SILICON_REVISION__ < 5)
229/* False Hardware Errors Caused by Fetches at the Boundary of Reserved Memory */
230#define ANOMALY_05000310 (1)
231/* Errors When SSYNC, CSYNC, or Loads to LT, LB and LC Registers Are Interrupted */
232#define ANOMALY_05000312 (1)
233/* PPI Is Level-Sensitive on First Transfer */
234#define ANOMALY_05000313 (1)
235/* Killed System MMR Write Completes Erroneously On Next System MMR Access */
236#define ANOMALY_05000315 (1)
237/* PF2 Output Remains Asserted After SPI Master Boot */
238#define ANOMALY_05000320 (__SILICON_REVISION__ > 3)
239/* Erroneous GPIO Flag Pin Operations Under Specific Sequences */
240#define ANOMALY_05000323 (1)
241/* SPORT Secondary Receive Channel Not Functional When Word Length Exceeds 16 Bits */
242#define ANOMALY_05000326 (__SILICON_REVISION__ > 3)
243/* New Feature: 24-Bit SPI Boot Mode Support (Not Available On Older Silicon) */
244#define ANOMALY_05000331 (__SILICON_REVISION__ < 5)
245/* New Feature: Slave SPI Boot Mode Supported (Not Available On Older Silicon) */
246#define ANOMALY_05000332 (__SILICON_REVISION__ < 5)
247/* Flag Data Register Writes One SCLK Cycle After Edge Is Detected May Clear Interrupt Status */
248#define ANOMALY_05000333 (__SILICON_REVISION__ < 5)
87 249
88#endif /* (defined(CONFIG_BF_REV_0_5) || defined(CONFIG_BF_REV_0_3)) */ 250/* Anomalies that don't exist on this proc */
251#define ANOMALY_05000158 (0)
252#define ANOMALY_05000183 (0)
253#define ANOMALY_05000273 (0)
254#define ANOMALY_05000311 (0)
89 255
90#if (defined(CONFIG_BF_REV_0_5))
91#define ANOMALY_05000254 /* Incorrect Timer Pulse Width in Single-Shot PWM_OUT
92 mode with external clock */
93#define ANOMALY_05000266 /* IMDMA destination IRQ status must be read prior to
94 using IMDMA */
95#endif 256#endif
96
97#if (defined(CONFIG_BF_REV_0_3))
98#define ANOMALY_05000156 /* Timers in PWM-Out Mode with PPI GP Receive (Input)
99 Mode with 0 Frame Syncs */
100#define ANOMALY_05000168 /* SDRAM auto-refresh and subsequent Power Ups */
101#define ANOMALY_05000169 /* DATA CPLB page miss can result in lost write-through
102 cache data writes */
103#define ANOMALY_05000171 /* Boot-ROM code modifies SICA_IWRx wakeup registers */
104#define ANOMALY_05000174 /* Cache Fill Buffer Data lost */
105#define ANOMALY_05000175 /* Overlapping Sequencer and Memory Stalls */
106#define ANOMALY_05000176 /* Multiplication of (-1) by (-1) followed by an
107 accumulator saturation */
108#define ANOMALY_05000179 /* PPI_COUNT cannot be programmed to 0 in General
109 Purpose TX or RX modes */
110#define ANOMALY_05000181 /* Disabling the PPI resets the PPI configuration
111 registers */
112#define ANOMALY_05000184 /* Timer Pin limitations for PPI TX Modes with
113 External Frame Syncs */
114#define ANOMALY_05000185 /* PPI TX Mode with 2 External Frame Syncs */
115#define ANOMALY_05000186 /* PPI packing with Data Length greater than 8 bits
116 (not a meaningful mode) */
117#define ANOMALY_05000188 /* IMDMA Restrictions on Descriptor and Buffer
118 Placement in Memory */
119#define ANOMALY_05000189 /* False Protection Exception */
120#define ANOMALY_05000193 /* False Flag Pin Interrupts on Edge Sensitive Inputs
121 when polarity setting is changed */
122#define ANOMALY_05000194 /* Restarting SPORT in specific modes may cause data
123 corruption */
124#define ANOMALY_05000198 /* Failing MMR accesses when stalled by preceding
125 memory read */
126#define ANOMALY_05000199 /* DMA current address shows wrong value during carry
127 fix */
128#define ANOMALY_05000200 /* SPORT TFS and DT are incorrectly driven during
129 inactive channels in certain conditions */
130#define ANOMALY_05000202 /* Possible infinite stall with specific dual-DAG
131 situation */
132#define ANOMALY_05000204 /* Incorrect data read with write-through cache and
133 allocate cache lines on reads only mode */
134#define ANOMALY_05000205 /* Specific sequence that can cause DMA error or DMA
135 stopping */
136#define ANOMALY_05000207 /* Recovery from "brown-out" condition */
137#define ANOMALY_05000209 /* Speed-Path in computational unit affects certain
138 instructions */
139#define ANOMALY_05000215 /* UART TX Interrupt masked erroneously */
140#define ANOMALY_05000219 /* NMI event at boot time results in unpredictable
141 state */
142#define ANOMALY_05000220 /* Data Corruption with Cached External Memory and
143 Non-Cached On-Chip L2 Memory */
144#define ANOMALY_05000225 /* Incorrect pulse-width of UART start-bit */
145#define ANOMALY_05000227 /* Scratchpad memory bank reads may return incorrect
146 data */
147#define ANOMALY_05000230 /* UART Receiver is less robust against Baudrate
148 Differences in certain Conditions */
149#define ANOMALY_05000231 /* UART STB bit incorrectly affects receiver setting */
150#define ANOMALY_05000232 /* SPORT data transmit lines are incorrectly driven in
151 multichannel mode */
152#define ANOMALY_05000242 /* DF bit in PLL_CTL register does not respond to
153 hardware reset */
154#define ANOMALY_05000244 /* If i-cache is on, CSYNC/SSYNC/IDLE around Change of
155 Control causes failures */
156#define ANOMALY_05000248 /* TESTSET operation forces stall on the other core */
157#define ANOMALY_05000250 /* Incorrect Bit-Shift of Data Word in Multichannel
158 (TDM) mode in certain conditions */
159#define ANOMALY_05000251 /* Exception not generated for MMR accesses in
160 reserved region */
161#define ANOMALY_05000253 /* Maximum external clock speed for Timers */
162#define ANOMALY_05000258 /* Instruction Cache is corrupted when bits 9 and 12
163 of the ICPLB Data registers differ */
164#define ANOMALY_05000260 /* ICPLB_STATUS MMR register may be corrupted */
165#define ANOMALY_05000261 /* DCPLB_FAULT_ADDR MMR register may be corrupted */
166#define ANOMALY_05000262 /* Stores to data cache may be lost */
167#define ANOMALY_05000263 /* Hardware loop corrupted when taking an ICPLB
168 exception */
169#define ANOMALY_05000264 /* CSYNC/SSYNC/IDLE causes infinite stall in second
170 to last instruction in hardware loop */
171#define ANOMALY_05000276 /* Timing requirements change for External Frame
172 Sync PPI Modes with non-zero PPI_DELAY */
173#define ANOMALY_05000278 /* Disabling Peripherals with DMA running may cause
174 DMA system instability */
175#define ANOMALY_05000281 /* False Hardware Error Exception when ISR context is
176 not restored */
177#define ANOMALY_05000283 /* An MMR write is stalled indefinitely when killed
178 in a particular stage */
179#define ANOMALY_05000287 /* A read will receive incorrect data under certain
180 conditions */
181#define ANOMALY_05000288 /* SPORTs may receive bad data if FIFOs fill up */
182#endif
183
184#endif /* _MACH_ANOMALY_H_ */
diff --git a/include/asm-blackfin/mach-bf561/bf561.h b/include/asm-blackfin/mach-bf561/bf561.h
index 96a5d3a47e45..17e1d5dcef02 100644
--- a/include/asm-blackfin/mach-bf561/bf561.h
+++ b/include/asm-blackfin/mach-bf561/bf561.h
@@ -73,13 +73,13 @@
73 */ 73 */
74 74
75 75
76#define BLKFIN_ISUBBANKS 4 76#define BFIN_ISUBBANKS 4
77#define BLKFIN_IWAYS 4 77#define BFIN_IWAYS 4
78#define BLKFIN_ILINES 32 78#define BFIN_ILINES 32
79 79
80#define BLKFIN_DSUBBANKS 4 80#define BFIN_DSUBBANKS 4
81#define BLKFIN_DWAYS 2 81#define BFIN_DWAYS 2
82#define BLKFIN_DLINES 64 82#define BFIN_DLINES 64
83 83
84#define WAY0_L 0x1 84#define WAY0_L 0x1
85#define WAY1_L 0x2 85#define WAY1_L 0x2
@@ -230,93 +230,6 @@
230 230
231#define AMGCTLVAL (V_AMBEN | V_AMCKEN | V_CDPRIO | V_B0PEN | V_B1PEN | V_B2PEN | V_B3PEN | 0x0002) 231#define AMGCTLVAL (V_AMBEN | V_AMCKEN | V_CDPRIO | V_B0PEN | V_B1PEN | V_B2PEN | V_B3PEN | 0x0002)
232 232
233#define MAX_VC 600000000
234#define MIN_VC 50000000
235
236/******************************* PLL Settings ********************************/
237#ifdef CONFIG_BFIN_KERNEL_CLOCK
238#if (CONFIG_VCO_MULT < 0)
239#error "VCO Multiplier is less than 0. Please select a different value"
240#endif
241
242#if (CONFIG_VCO_MULT == 0)
243#error "VCO Multiplier should be greater than 0. Please select a different value"
244#endif
245
246#ifndef CONFIG_CLKIN_HALF
247#define CONFIG_VCO_HZ (CONFIG_CLKIN_HZ * CONFIG_VCO_MULT)
248#else
249#define CONFIG_VCO_HZ ((CONFIG_CLKIN_HZ * CONFIG_VCO_MULT)/2)
250#endif
251
252#ifndef CONFIG_PLL_BYPASS
253#define CONFIG_CCLK_HZ (CONFIG_VCO_HZ/CONFIG_CCLK_DIV)
254#define CONFIG_SCLK_HZ (CONFIG_VCO_HZ/CONFIG_SCLK_DIV)
255#else
256#define CONFIG_CCLK_HZ CONFIG_CLKIN_HZ
257#define CONFIG_SCLK_HZ CONFIG_CLKIN_HZ
258#endif
259
260#if (CONFIG_SCLK_DIV < 1)
261#error "SCLK DIV cannot be less than 1 or more than 15. Please select a proper value"
262#endif
263
264#if (CONFIG_SCLK_DIV > 15)
265#error "SCLK DIV cannot be less than 1 or more than 15. Please select a proper value"
266#endif
267
268#if (CONFIG_CCLK_DIV != 1)
269#if (CONFIG_CCLK_DIV != 2)
270#if (CONFIG_CCLK_DIV != 4)
271#if (CONFIG_CCLK_DIV != 8)
272#error "CCLK DIV can be 1,2,4 or 8 only. Please select a proper value"
273#endif
274#endif
275#endif
276#endif
277
278#if (CONFIG_VCO_HZ > MAX_VC)
279#error "VCO selected is more than maximum value. Please change the VCO multipler"
280#endif
281
282#if (CONFIG_SCLK_HZ > 133000000)
283#error "Sclk value selected is more than maximum. Please select a proper value for SCLK multiplier"
284#endif
285
286#if (CONFIG_SCLK_HZ < 27000000)
287#error "Sclk value selected is less than minimum. Please select a proper value for SCLK multiplier"
288#endif
289
290#if (CONFIG_SCLK_HZ >= CONFIG_CCLK_HZ)
291#if (CONFIG_SCLK_HZ != CONFIG_CLKIN_HZ)
292#if (CONFIG_CCLK_HZ != CONFIG_CLKIN_HZ)
293#error "Please select sclk less than cclk"
294#endif
295#endif
296#endif
297
298#if (CONFIG_CCLK_DIV == 1)
299#define CONFIG_CCLK_ACT_DIV CCLK_DIV1
300#endif
301#if (CONFIG_CCLK_DIV == 2)
302#define CONFIG_CCLK_ACT_DIV CCLK_DIV2
303#endif
304#if (CONFIG_CCLK_DIV == 4)
305#define CONFIG_CCLK_ACT_DIV CCLK_DIV4
306#endif
307#if (CONFIG_CCLK_DIV == 8)
308#define CONFIG_CCLK_ACT_DIV CCLK_DIV8
309#endif
310#ifndef CONFIG_CCLK_ACT_DIV
311#define CONFIG_CCLK_ACT_DIV CONFIG_CCLK_DIV_not_defined_properly
312#endif
313
314#if defined(ANOMALY_05000273) && (CONFIG_CCLK_DIV == 1)
315#error ANOMALY 05000273, please make sure CCLK is at least 2x SCLK
316#endif
317
318#endif /* CONFIG_BFIN_KERNEL_CLOCK */
319
320#ifdef CONFIG_BF561 233#ifdef CONFIG_BF561
321#define CPU "BF561" 234#define CPU "BF561"
322#define CPUID 0x027bb000 235#define CPUID 0x027bb000
@@ -326,83 +239,4 @@
326#define CPUID 0x0 239#define CPUID 0x0
327#endif 240#endif
328 241
329#if (CONFIG_MEM_SIZE % 4)
330#error "SDRAM memory size must be a multiple of 4MB!"
331#endif
332#define SDRAM_IGENERIC (CPLB_L1_CHBL | CPLB_USER_RD | CPLB_VALID | CPLB_PORTPRIO)
333#define SDRAM_IKERNEL (SDRAM_IGENERIC | CPLB_LOCK)
334#define L1_IMEMORY ( CPLB_USER_RD | CPLB_VALID | CPLB_LOCK)
335#define SDRAM_INON_CHBL ( CPLB_USER_RD | CPLB_VALID)
336
337/*Use the menuconfig cache policy here - CONFIG_BLKFIN_WT/CONFIG_BLKFIN_WB*/
338
339#define ANOMALY_05000158_WORKAROUND 0x200
340#ifdef CONFIG_BLKFIN_WB /*Write Back Policy */
341#define SDRAM_DGENERIC (CPLB_L1_CHBL | CPLB_DIRTY \
342 | CPLB_SUPV_WR | CPLB_USER_WR | CPLB_USER_RD | CPLB_VALID | ANOMALY_05000158_WORKAROUND)
343#else /*Write Through */
344#define SDRAM_DGENERIC (CPLB_L1_CHBL | CPLB_WT | CPLB_L1_AOW | CPLB_DIRTY \
345 | CPLB_SUPV_WR | CPLB_USER_WR | CPLB_USER_RD | CPLB_VALID | ANOMALY_05000158_WORKAROUND)
346#endif
347
348
349#define L1_DMEMORY (CPLB_SUPV_WR | CPLB_USER_WR | CPLB_USER_RD | CPLB_VALID | ANOMALY_05000158_WORKAROUND | CPLB_LOCK | CPLB_DIRTY)
350#define SDRAM_DNON_CHBL (CPLB_SUPV_WR | CPLB_USER_WR | CPLB_USER_RD | CPLB_VALID | ANOMALY_05000158_WORKAROUND | CPLB_DIRTY)
351#define SDRAM_EBIU (CPLB_SUPV_WR | CPLB_USER_WR | CPLB_USER_RD | CPLB_VALID | ANOMALY_05000158_WORKAROUND | CPLB_DIRTY)
352#define SDRAM_OOPS (CPLB_VALID | ANOMALY_05000158_WORKAROUND | CPLB_LOCK | CPLB_DIRTY)
353
354#define L2_MEMORY (CPLB_SUPV_WR | CPLB_USER_WR | CPLB_USER_RD | CPLB_VALID | ANOMALY_05000158_WORKAROUND | CPLB_DIRTY)
355
356#define SIZE_1K 0x00000400 /* 1K */
357#define SIZE_4K 0x00001000 /* 4K */
358#define SIZE_1M 0x00100000 /* 1M */
359#define SIZE_4M 0x00400000 /* 4M */
360
361#define MAX_CPLBS (16 * 2)
362
363/*
364* Number of required data CPLB switchtable entries
365* MEMSIZE / 4 (we mostly install 4M page size CPLBs
366* approx 16 for smaller 1MB page size CPLBs for allignment purposes
367* 1 for L1 Data Memory
368* 1 for L2 Data Memory
369* 1 for CONFIG_DEBUG_HUNT_FOR_ZERO
370* 64 for ASYNC Memory
371*/
372
373
374#define MAX_SWITCH_D_CPLBS (((CONFIG_MEM_SIZE / 4) + 16 + 1 + 1 + 1 + 64) * 2)
375
376/*
377* Number of required instruction CPLB switchtable entries
378* MEMSIZE / 4 (we mostly install 4M page size CPLBs
379* approx 12 for smaller 1MB page size CPLBs for allignment purposes
380* 1 for L1 Instruction Memory
381* 1 for L2 Instruction Memory
382* 1 for CONFIG_DEBUG_HUNT_FOR_ZERO
383*/
384
385#define MAX_SWITCH_I_CPLBS (((CONFIG_MEM_SIZE / 4) + 12 + 1 + 1 + 1) * 2)
386
387#if 0 /* comment by mhfan */
388/* Event Vector Table Address */
389#define EVT_EMULATION_ADDR 0xffe02000
390#define EVT_RESET_ADDR 0xffe02004
391#define EVT_NMI_ADDR 0xffe02008
392#define EVT_EXCEPTION_ADDR 0xffe0200c
393#define EVT_GLOBAL_INT_ENB_ADDR 0xffe02010
394#define EVT_HARDWARE_ERROR_ADDR 0xffe02014
395#define EVT_TIMER_ADDR 0xffe02018
396#define EVT_IVG7_ADDR 0xffe0201c
397#define EVT_IVG8_ADDR 0xffe02020
398#define EVT_IVG9_ADDR 0xffe02024
399#define EVT_IVG10_ADDR 0xffe02028
400#define EVT_IVG11_ADDR 0xffe0202c
401#define EVT_IVG12_ADDR 0xffe02030
402#define EVT_IVG13_ADDR 0xffe02034
403#define EVT_IVG14_ADDR 0xffe02038
404#define EVT_IVG15_ADDR 0xffe0203c
405#define EVT_OVERRIDE_ADDR 0xffe02100
406#endif /* comment by mhfan */
407
408#endif /* __MACH_BF561_H__ */ 242#endif /* __MACH_BF561_H__ */
diff --git a/include/asm-blackfin/mach-bf561/blackfin.h b/include/asm-blackfin/mach-bf561/blackfin.h
index 2537c845e8b0..562aee39895c 100644
--- a/include/asm-blackfin/mach-bf561/blackfin.h
+++ b/include/asm-blackfin/mach-bf561/blackfin.h
@@ -38,7 +38,7 @@
38#include "defBF561.h" 38#include "defBF561.h"
39#include "anomaly.h" 39#include "anomaly.h"
40 40
41#if !(defined(__ASSEMBLY__) || defined(ASSEMBLY)) 41#if !defined(__ASSEMBLY__)
42#include "cdefBF561.h" 42#include "cdefBF561.h"
43#endif 43#endif
44 44
diff --git a/include/asm-blackfin/mach-bf561/cdefBF561.h b/include/asm-blackfin/mach-bf561/cdefBF561.h
index 73d4d65249cd..d667816486c0 100644
--- a/include/asm-blackfin/mach-bf561/cdefBF561.h
+++ b/include/asm-blackfin/mach-bf561/cdefBF561.h
@@ -31,11 +31,8 @@
31#ifndef _CDEF_BF561_H 31#ifndef _CDEF_BF561_H
32#define _CDEF_BF561_H 32#define _CDEF_BF561_H
33 33
34/* 34#include <asm/blackfin.h>
35#if !defined(__ADSPBF561__) 35
36#warning cdefBF561.h should only be included for BF561 chip.
37#endif
38*/
39/* include all Core registers and bit definitions */ 36/* include all Core registers and bit definitions */
40#include "defBF561.h" 37#include "defBF561.h"
41 38
@@ -67,7 +64,7 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
67 bfin_write32(SICA_IWR1, 0); 64 bfin_write32(SICA_IWR1, 0);
68 65
69 bfin_write16(VR_CTL, val); 66 bfin_write16(VR_CTL, val);
70 __builtin_bfin_ssync(); 67 SSYNC();
71 68
72 local_irq_save(flags); 69 local_irq_save(flags);
73 asm("IDLE;"); 70 asm("IDLE;");
diff --git a/include/asm-blackfin/mach-bf561/defBF561.h b/include/asm-blackfin/mach-bf561/defBF561.h
index 0f2dc6e6335b..bf7dc4e00065 100644
--- a/include/asm-blackfin/mach-bf561/defBF561.h
+++ b/include/asm-blackfin/mach-bf561/defBF561.h
@@ -120,6 +120,7 @@
120#define UART_GCTL 0xFFC00424 /* Global Control Register */ 120#define UART_GCTL 0xFFC00424 /* Global Control Register */
121 121
122/* SPI Controller (0xFFC00500 - 0xFFC005FF) */ 122/* SPI Controller (0xFFC00500 - 0xFFC005FF) */
123#define SPI0_REGBASE 0xFFC00500
123#define SPI_CTL 0xFFC00500 /* SPI Control Register */ 124#define SPI_CTL 0xFFC00500 /* SPI Control Register */
124#define SPI_FLG 0xFFC00504 /* SPI Flag register */ 125#define SPI_FLG 0xFFC00504 /* SPI Flag register */
125#define SPI_STAT 0xFFC00508 /* SPI Status register */ 126#define SPI_STAT 0xFFC00508 /* SPI Status register */
diff --git a/include/asm-blackfin/mach-bf561/irq.h b/include/asm-blackfin/mach-bf561/irq.h
index a753ce720d74..12789927db3d 100644
--- a/include/asm-blackfin/mach-bf561/irq.h
+++ b/include/asm-blackfin/mach-bf561/irq.h
@@ -289,6 +289,8 @@
289#define IRQ_PF46 119 289#define IRQ_PF46 119
290#define IRQ_PF47 120 290#define IRQ_PF47 120
291 291
292#define GPIO_IRQ_BASE IRQ_PF0
293
292#ifdef CONFIG_IRQCHIP_DEMUX_GPIO 294#ifdef CONFIG_IRQCHIP_DEMUX_GPIO
293#define NR_IRQS (IRQ_PF47 + 1) 295#define NR_IRQS (IRQ_PF47 + 1)
294#else 296#else
diff --git a/include/asm-blackfin/mach-bf561/mem_map.h b/include/asm-blackfin/mach-bf561/mem_map.h
index ebac9a8d838d..f7ac09cf2c3d 100644
--- a/include/asm-blackfin/mach-bf561/mem_map.h
+++ b/include/asm-blackfin/mach-bf561/mem_map.h
@@ -21,10 +21,10 @@
21 21
22/* Level 1 Memory */ 22/* Level 1 Memory */
23 23
24#ifdef CONFIG_BLKFIN_CACHE 24#ifdef CONFIG_BFIN_ICACHE
25#define BLKFIN_ICACHESIZE (16*1024) 25#define BFIN_ICACHESIZE (16*1024)
26#else 26#else
27#define BLKFIN_ICACHESIZE (0*1024) 27#define BFIN_ICACHESIZE (0*1024)
28#endif 28#endif
29 29
30/* Memory Map for ADSP-BF561 processors */ 30/* Memory Map for ADSP-BF561 processors */
@@ -36,29 +36,29 @@
36 36
37#define L1_CODE_LENGTH 0x4000 37#define L1_CODE_LENGTH 0x4000
38 38
39#ifdef CONFIG_BLKFIN_DCACHE 39#ifdef CONFIG_BFIN_DCACHE
40 40
41#ifdef CONFIG_BLKFIN_DCACHE_BANKA 41#ifdef CONFIG_BFIN_DCACHE_BANKA
42#define DMEM_CNTR (ACACHE_BSRAM | ENDCPLB | PORT_PREF0) 42#define DMEM_CNTR (ACACHE_BSRAM | ENDCPLB | PORT_PREF0)
43#define L1_DATA_A_LENGTH (0x8000 - 0x4000) 43#define L1_DATA_A_LENGTH (0x8000 - 0x4000)
44#define L1_DATA_B_LENGTH 0x8000 44#define L1_DATA_B_LENGTH 0x8000
45#define BLKFIN_DCACHESIZE (16*1024) 45#define BFIN_DCACHESIZE (16*1024)
46#define BLKFIN_DSUPBANKS 1 46#define BFIN_DSUPBANKS 1
47#else 47#else
48#define DMEM_CNTR (ACACHE_BCACHE | ENDCPLB | PORT_PREF0) 48#define DMEM_CNTR (ACACHE_BCACHE | ENDCPLB | PORT_PREF0)
49#define L1_DATA_A_LENGTH (0x8000 - 0x4000) 49#define L1_DATA_A_LENGTH (0x8000 - 0x4000)
50#define L1_DATA_B_LENGTH (0x8000 - 0x4000) 50#define L1_DATA_B_LENGTH (0x8000 - 0x4000)
51#define BLKFIN_DCACHESIZE (32*1024) 51#define BFIN_DCACHESIZE (32*1024)
52#define BLKFIN_DSUPBANKS 2 52#define BFIN_DSUPBANKS 2
53#endif 53#endif
54 54
55#else 55#else
56#define DMEM_CNTR (ASRAM_BSRAM | ENDCPLB | PORT_PREF0) 56#define DMEM_CNTR (ASRAM_BSRAM | ENDCPLB | PORT_PREF0)
57#define L1_DATA_A_LENGTH 0x8000 57#define L1_DATA_A_LENGTH 0x8000
58#define L1_DATA_B_LENGTH 0x8000 58#define L1_DATA_B_LENGTH 0x8000
59#define BLKFIN_DCACHESIZE (0*1024) 59#define BFIN_DCACHESIZE (0*1024)
60#define BLKFIN_DSUPBANKS 0 60#define BFIN_DSUPBANKS 0
61#endif /*CONFIG_BLKFIN_DCACHE*/ 61#endif /*CONFIG_BFIN_DCACHE*/
62#endif 62#endif
63 63
64/* Level 2 Memory */ 64/* Level 2 Memory */
diff --git a/include/asm-blackfin/mach-bf561/portmux.h b/include/asm-blackfin/mach-bf561/portmux.h
index 10d11d5ffe23..132ad31665e3 100644
--- a/include/asm-blackfin/mach-bf561/portmux.h
+++ b/include/asm-blackfin/mach-bf561/portmux.h
@@ -81,7 +81,7 @@
81#define P_TMR1 (P_DEFINED | P_IDENT(GPIO_PF1)) 81#define P_TMR1 (P_DEFINED | P_IDENT(GPIO_PF1))
82#define P_TMR0 (P_DEFINED | P_IDENT(GPIO_PF0)) 82#define P_TMR0 (P_DEFINED | P_IDENT(GPIO_PF0))
83#define P_SPI0_MOSI (P_DONTCARE) 83#define P_SPI0_MOSI (P_DONTCARE)
84#define P_SPI0_MIS0 (P_DONTCARE) 84#define P_SPI0_MISO (P_DONTCARE)
85#define P_SPI0_SCK (P_DONTCARE) 85#define P_SPI0_SCK (P_DONTCARE)
86 86
87#endif /* _MACH_PORTMUX_H_ */ 87#endif /* _MACH_PORTMUX_H_ */
diff --git a/include/asm-blackfin/mach-common/cdef_LPBlackfin.h b/include/asm-blackfin/mach-common/cdef_LPBlackfin.h
index 94ed381e5606..ede210eca4ec 100644
--- a/include/asm-blackfin/mach-common/cdef_LPBlackfin.h
+++ b/include/asm-blackfin/mach-common/cdef_LPBlackfin.h
@@ -39,7 +39,7 @@
39#define bfin_read_SRAM_BASE_ADDRESS() bfin_read32(SRAM_BASE_ADDRESS) 39#define bfin_read_SRAM_BASE_ADDRESS() bfin_read32(SRAM_BASE_ADDRESS)
40#define bfin_write_SRAM_BASE_ADDRESS(val) bfin_write32(SRAM_BASE_ADDRESS,val) 40#define bfin_write_SRAM_BASE_ADDRESS(val) bfin_write32(SRAM_BASE_ADDRESS,val)
41#define bfin_read_DMEM_CONTROL() bfin_read32(DMEM_CONTROL) 41#define bfin_read_DMEM_CONTROL() bfin_read32(DMEM_CONTROL)
42#ifdef ANOMALY_05000125 42#if ANOMALY_05000125
43extern void bfin_write_DMEM_CONTROL(unsigned int val); 43extern void bfin_write_DMEM_CONTROL(unsigned int val);
44#else 44#else
45#define bfin_write_DMEM_CONTROL(val) bfin_write32(DMEM_CONTROL,val) 45#define bfin_write_DMEM_CONTROL(val) bfin_write32(DMEM_CONTROL,val)
@@ -129,7 +129,7 @@ extern void bfin_write_DMEM_CONTROL(unsigned int val);
129#define DTEST_DATA3 0xFFE0040C 129#define DTEST_DATA3 0xFFE0040C
130*/ 130*/
131#define bfin_read_IMEM_CONTROL() bfin_read32(IMEM_CONTROL) 131#define bfin_read_IMEM_CONTROL() bfin_read32(IMEM_CONTROL)
132#ifdef ANOMALY_05000125 132#if ANOMALY_05000125
133extern void bfin_write_IMEM_CONTROL(unsigned int val); 133extern void bfin_write_IMEM_CONTROL(unsigned int val);
134#else 134#else
135#define bfin_write_IMEM_CONTROL(val) bfin_write32(IMEM_CONTROL,val) 135#define bfin_write_IMEM_CONTROL(val) bfin_write32(IMEM_CONTROL,val)
diff --git a/include/asm-blackfin/mach-common/clocks.h b/include/asm-blackfin/mach-common/clocks.h
new file mode 100644
index 000000000000..033bba92d61c
--- /dev/null
+++ b/include/asm-blackfin/mach-common/clocks.h
@@ -0,0 +1,70 @@
1/*
2 * File: include/asm-blackfin/mach-common/clocks.h
3 * Based on: include/asm-blackfin/mach-bf537/bf537.h
4 * Author: Robin Getz <rgetz@blackfin.uclinux.org>
5 *
6 * Created: 25Jul07
7 * Description: Common Clock definitions for various kernel files
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#ifndef _BFIN_CLOCKS_H
31#define _BFIN_CLOCKS_H
32
33#ifdef CONFIG_CCLK_DIV_1
34# define CONFIG_CCLK_ACT_DIV CCLK_DIV1
35# define CONFIG_CCLK_DIV 1
36#endif
37
38#ifdef CONFIG_CCLK_DIV_2
39# define CONFIG_CCLK_ACT_DIV CCLK_DIV2
40# define CONFIG_CCLK_DIV 2
41#endif
42
43#ifdef CONFIG_CCLK_DIV_4
44# define CONFIG_CCLK_ACT_DIV CCLK_DIV4
45# define CONFIG_CCLK_DIV 4
46#endif
47
48#ifdef CONFIG_CCLK_DIV_8
49# define CONFIG_CCLK_ACT_DIV CCLK_DIV8
50# define CONFIG_CCLK_DIV 8
51#endif
52
53#ifndef CONFIG_PLL_BYPASS
54# ifndef CONFIG_CLKIN_HALF
55# define CONFIG_VCO_HZ (CONFIG_CLKIN_HZ * CONFIG_VCO_MULT)
56# else
57# define CONFIG_VCO_HZ ((CONFIG_CLKIN_HZ * CONFIG_VCO_MULT)/2)
58# endif
59
60# define CONFIG_CCLK_HZ (CONFIG_VCO_HZ/CONFIG_CCLK_DIV)
61# define CONFIG_SCLK_HZ (CONFIG_VCO_HZ/CONFIG_SCLK_DIV)
62
63#else
64# define CONFIG_VCO_HZ (CONFIG_CLKIN_HZ)
65# define CONFIG_CCLK_HZ (CONFIG_CLKIN_HZ)
66# define CONFIG_SCLK_HZ (CONFIG_CLKIN_HZ)
67# define CONFIG_VCO_MULT 0
68#endif
69
70#endif
diff --git a/include/asm-blackfin/mach-common/def_LPBlackfin.h b/include/asm-blackfin/mach-common/def_LPBlackfin.h
index be1ece8c0c27..c1d8c4a78fcf 100644
--- a/include/asm-blackfin/mach-common/def_LPBlackfin.h
+++ b/include/asm-blackfin/mach-common/def_LPBlackfin.h
@@ -33,81 +33,77 @@
33 33
34#include <asm/mach/anomaly.h> 34#include <asm/mach/anomaly.h>
35 35
36/*#if !defined(__ADSPLPBLACKFIN__)
37#warning def_LPBlackfin.h should only be included for 532 compatible chips.
38#endif
39*/
40
41#define MK_BMSK_(x) (1<<x) 36#define MK_BMSK_(x) (1<<x)
42 37
43#if defined(ANOMALY_05000198) 38#ifndef __ASSEMBLY__
44
45#define bfin_read8(addr) ({ unsigned char __v; \
46 __asm__ __volatile__ ("NOP;\n\t" \
47 "%0 = b[%1] (z);\n\t" \
48 : "=d"(__v) : "a"(addr)); \
49 __v; })
50
51#define bfin_read16(addr) ({ unsigned __v; \
52 __asm__ __volatile__ ("NOP;\n\t"\
53 "%0 = w[%1] (z);\n\t"\
54 : "=d"(__v) : "a"(addr)); (unsigned short)__v; })
55
56#define bfin_read32(addr) ({ unsigned __v; \
57 __asm__ __volatile__ ("NOP;\n\t"\
58 "%0 = [%1];\n\t"\
59 : "=d"(__v) : "a"(addr)); __v; })
60
61#define bfin_write8(addr, val) ({ \
62 __asm__ __volatile__ ("NOP;\n\t" \
63 "b[%0] = %1;\n\t" \
64 : : "a"(addr), "d"(val) : "memory");})
65 39
66#define bfin_write16(addr,val) ({\ 40#include <linux/types.h>
67 __asm__ __volatile__ ("NOP;\n\t"\
68 "w[%0] = %1;\n\t"\
69 : : "a"(addr) , "d"(val) : "memory");})
70
71#define bfin_write32(addr,val) ({\
72 __asm__ __volatile__ ("NOP;\n\t"\
73 "[%0] = %1;\n\t"\
74 : : "a"(addr) , "d"(val) : "memory");})
75 41
42#if ANOMALY_05000198
43# define NOP_PAD_ANOMALY_05000198 "nop;"
76#else 44#else
77 45# define NOP_PAD_ANOMALY_05000198
78#define bfin_read8(addr) ({ unsigned char __v; \
79 __asm__ __volatile__ ( \
80 "%0 = b[%1] (z);\n\t" \
81 :"=d"(__v) : "a"(addr)); \
82 __v; })
83
84#define bfin_read16(addr) ({ unsigned __v; \
85 __asm__ __volatile__ (\
86 "%0 = w[%1] (z);\n\t"\
87 : "=d"(__v) : "a"(addr)); (unsigned short)__v; })
88
89#define bfin_read32(addr) ({ unsigned __v; \
90 __asm__ __volatile__ (\
91 "%0 = [%1];\n\t"\
92 : "=d"(__v) : "a"(addr)); __v; })
93
94#define bfin_write8(addr, val) ({ \
95 __asm__ __volatile__ ( \
96 "b[%0] = %1; \n\t" \
97 ::"a"(addr), "d"(val) : "memory");})
98
99#define bfin_write16(addr,val) ({\
100 __asm__ __volatile__ (\
101 "w[%0] = %1;\n\t"\
102 : : "a"(addr) , "d"(val) : "memory");})
103
104#define bfin_write32(addr,val) ({\
105 __asm__ __volatile__ (\
106 "[%0] = %1;\n\t"\
107 : : "a"(addr) , "d"(val) : "memory");})
108
109#endif 46#endif
110 47
48#define bfin_read8(addr) ({ \
49 uint8_t __v; \
50 __asm__ __volatile__( \
51 NOP_PAD_ANOMALY_05000198 \
52 "%0 = b[%1] (z);" \
53 : "=d" (__v) \
54 : "a" (addr) \
55 ); \
56 __v; })
57
58#define bfin_read16(addr) ({ \
59 uint16_t __v; \
60 __asm__ __volatile__( \
61 NOP_PAD_ANOMALY_05000198 \
62 "%0 = w[%1] (z);" \
63 : "=d" (__v) \
64 : "a" (addr) \
65 ); \
66 __v; })
67
68#define bfin_read32(addr) ({ \
69 uint32_t __v; \
70 __asm__ __volatile__( \
71 NOP_PAD_ANOMALY_05000198 \
72 "%0 = [%1];" \
73 : "=d" (__v) \
74 : "a" (addr) \
75 ); \
76 __v; })
77
78#define bfin_write8(addr, val) \
79 __asm__ __volatile__( \
80 NOP_PAD_ANOMALY_05000198 \
81 "b[%0] = %1;" \
82 : \
83 : "a" (addr), "d" (val) \
84 : "memory" \
85 )
86
87#define bfin_write16(addr, val) \
88 __asm__ __volatile__( \
89 NOP_PAD_ANOMALY_05000198 \
90 "w[%0] = %1;" \
91 : \
92 : "a" (addr), "d" (val) \
93 : "memory" \
94 )
95
96#define bfin_write32(addr, val) \
97 __asm__ __volatile__( \
98 NOP_PAD_ANOMALY_05000198 \
99 "[%0] = %1;" \
100 : \
101 : "a" (addr), "d" (val) \
102 : "memory" \
103 )
104
105#endif /* __ASSEMBLY__ */
106
111/************************************************** 107/**************************************************
112 * System Register Bits 108 * System Register Bits
113 **************************************************/ 109 **************************************************/
@@ -643,6 +639,7 @@
643#define CPLB_USER_RD 0x00000004 /* 0=no read access, 1=read access 639#define CPLB_USER_RD 0x00000004 /* 0=no read access, 1=read access
644 * allowed (user mode) 640 * allowed (user mode)
645 */ 641 */
642
646#define PAGE_SIZE_1KB 0x00000000 /* 1 KB page size */ 643#define PAGE_SIZE_1KB 0x00000000 /* 1 KB page size */
647#define PAGE_SIZE_4KB 0x00010000 /* 4 KB page size */ 644#define PAGE_SIZE_4KB 0x00010000 /* 4 KB page size */
648#define PAGE_SIZE_1MB 0x00020000 /* 1 MB page size */ 645#define PAGE_SIZE_1MB 0x00020000 /* 1 MB page size */
@@ -675,6 +672,8 @@
675 */ 672 */
676#define CPLB_WT 0x00004000 /* 0=write-back, 1=write-through */ 673#define CPLB_WT 0x00004000 /* 0=write-back, 1=write-through */
677 674
675#define CPLB_ALL_ACCESS CPLB_SUPV_WR | CPLB_USER_RD | CPLB_USER_WR
676
678/* TBUFCTL Masks */ 677/* TBUFCTL Masks */
679#define TBUFPWR 0x0001 678#define TBUFPWR 0x0001
680#define TBUFEN 0x0002 679#define TBUFEN 0x0002
diff --git a/include/asm-blackfin/pgtable.h b/include/asm-blackfin/pgtable.h
index 5a8f9e431c40..b11b114689c0 100644
--- a/include/asm-blackfin/pgtable.h
+++ b/include/asm-blackfin/pgtable.h
@@ -4,7 +4,7 @@
4#include <asm-generic/4level-fixup.h> 4#include <asm-generic/4level-fixup.h>
5 5
6#include <asm/page.h> 6#include <asm/page.h>
7#include <asm/cplb.h> 7#include <asm/mach-common/def_LPBlackfin.h>
8 8
9typedef pte_t *pte_addr_t; 9typedef pte_t *pte_addr_t;
10/* 10/*
diff --git a/include/asm-blackfin/reboot.h b/include/asm-blackfin/reboot.h
new file mode 100644
index 000000000000..6d448b5f5985
--- /dev/null
+++ b/include/asm-blackfin/reboot.h
@@ -0,0 +1,20 @@
1/*
2 * include/asm-blackfin/reboot.h - shutdown/reboot header
3 *
4 * Copyright 2004-2007 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#ifndef __ASM_REBOOT_H__
10#define __ASM_REBOOT_H__
11
12/* optional board specific hooks */
13extern void native_machine_restart(char *cmd);
14extern void native_machine_halt(void);
15extern void native_machine_power_off(void);
16
17/* common reboot workarounds */
18extern void bfin_gpio_reset_spi0_ssel1(void);
19
20#endif
diff --git a/include/asm-blackfin/system.h b/include/asm-blackfin/system.h
index 5e5f1a0566c0..2b3d47d0bbb6 100644
--- a/include/asm-blackfin/system.h
+++ b/include/asm-blackfin/system.h
@@ -36,6 +36,7 @@
36 36
37#include <linux/linkage.h> 37#include <linux/linkage.h>
38#include <linux/compiler.h> 38#include <linux/compiler.h>
39#include <asm/mach/anomaly.h>
39 40
40/* 41/*
41 * Interrupt configuring macros. 42 * Interrupt configuring macros.
@@ -43,53 +44,60 @@
43 44
44extern unsigned long irq_flags; 45extern unsigned long irq_flags;
45 46
46#define local_irq_enable() do { \ 47#define local_irq_enable() \
47 __asm__ __volatile__ ( \ 48 __asm__ __volatile__( \
48 "sti %0;" \ 49 "sti %0;" \
49 ::"d"(irq_flags)); \ 50 : \
50} while (0) 51 : "d" (irq_flags) \
52 )
51 53
52#define local_irq_disable() do { \ 54#define local_irq_disable() \
53 int _tmp_dummy; \ 55 do { \
54 __asm__ __volatile__ ( \ 56 int __tmp_dummy; \
55 "cli %0;" \ 57 __asm__ __volatile__( \
56 :"=d" (_tmp_dummy):); \ 58 "cli %0;" \
57} while (0) 59 : "=d" (__tmp_dummy) \
60 ); \
61 } while (0)
58 62
59#if defined(ANOMALY_05000244) && defined (CONFIG_BLKFIN_CACHE) 63#if ANOMALY_05000244 && defined(CONFIG_BFIN_ICACHE)
60#define idle_with_irq_disabled() do { \ 64# define NOP_PAD_ANOMALY_05000244 "nop; nop;"
61 __asm__ __volatile__ ( \
62 "nop; nop;\n" \
63 ".align 8;\n" \
64 "sti %0; idle;\n" \
65 ::"d" (irq_flags)); \
66} while (0)
67#else 65#else
68#define idle_with_irq_disabled() do { \ 66# define NOP_PAD_ANOMALY_05000244
69 __asm__ __volatile__ ( \
70 ".align 8;\n" \
71 "sti %0; idle;\n" \
72 ::"d" (irq_flags)); \
73} while (0)
74#endif 67#endif
75 68
69#define idle_with_irq_disabled() \
70 __asm__ __volatile__( \
71 NOP_PAD_ANOMALY_05000244 \
72 ".align 8;" \
73 "sti %0;" \
74 "idle;" \
75 : \
76 : "d" (irq_flags) \
77 )
78
76#ifdef CONFIG_DEBUG_HWERR 79#ifdef CONFIG_DEBUG_HWERR
77#define __save_and_cli(x) do { \ 80# define __save_and_cli(x) \
78 __asm__ __volatile__ ( \ 81 __asm__ __volatile__( \
79 "cli %0;\n\tsti %1;" \ 82 "cli %0;" \
80 :"=&d"(x): "d" (0x3F)); \ 83 "sti %1;" \
81} while (0) 84 : "=&d" (x) \
85 : "d" (0x3F) \
86 )
82#else 87#else
83#define __save_and_cli(x) do { \ 88# define __save_and_cli(x) \
84 __asm__ __volatile__ ( \ 89 __asm__ __volatile__( \
85 "cli %0;" \ 90 "cli %0;" \
86 :"=&d"(x):); \ 91 : "=&d" (x) \
87} while (0) 92 )
88#endif 93#endif
89 94
90#define local_save_flags(x) asm volatile ("cli %0;" \ 95#define local_save_flags(x) \
91 "sti %0;" \ 96 __asm__ __volatile__( \
92 :"=d"(x):); 97 "cli %0;" \
98 "sti %0;" \
99 : "=d" (x) \
100 )
93 101
94#ifdef CONFIG_DEBUG_HWERR 102#ifdef CONFIG_DEBUG_HWERR
95#define irqs_enabled_from_flags(x) (((x) & ~0x3f) != 0) 103#define irqs_enabled_from_flags(x) (((x) & ~0x3f) != 0)
@@ -97,10 +105,11 @@ extern unsigned long irq_flags;
97#define irqs_enabled_from_flags(x) ((x) != 0x1f) 105#define irqs_enabled_from_flags(x) ((x) != 0x1f)
98#endif 106#endif
99 107
100#define local_irq_restore(x) do { \ 108#define local_irq_restore(x) \
101 if (irqs_enabled_from_flags(x)) \ 109 do { \
102 local_irq_enable (); \ 110 if (irqs_enabled_from_flags(x)) \
103} while (0) 111 local_irq_enable(); \
112 } while (0)
104 113
105/* For spinlocks etc */ 114/* For spinlocks etc */
106#define local_irq_save(x) __save_and_cli(x) 115#define local_irq_save(x) __save_and_cli(x)
diff --git a/include/asm-blackfin/termbits.h b/include/asm-blackfin/termbits.h
index 4eac38de8ce1..f37feb7cf895 100644
--- a/include/asm-blackfin/termbits.h
+++ b/include/asm-blackfin/termbits.h
@@ -140,6 +140,7 @@ struct ktermios {
140#define HUPCL 0002000 140#define HUPCL 0002000
141#define CLOCAL 0004000 141#define CLOCAL 0004000
142#define CBAUDEX 0010000 142#define CBAUDEX 0010000
143#define BOTHER 0010000
143#define B57600 0010001 144#define B57600 0010001
144#define B115200 0010002 145#define B115200 0010002
145#define B230400 0010003 146#define B230400 0010003
@@ -155,10 +156,12 @@ struct ktermios {
155#define B3000000 0010015 156#define B3000000 0010015
156#define B3500000 0010016 157#define B3500000 0010016
157#define B4000000 0010017 158#define B4000000 0010017
158#define CIBAUD 002003600000 /* input baud rate (not used) */ 159#define CIBAUD 002003600000 /* input baud rate */
159#define CMSPAR 010000000000 /* mark or space (stick) parity */ 160#define CMSPAR 010000000000 /* mark or space (stick) parity */
160#define CRTSCTS 020000000000 /* flow control */ 161#define CRTSCTS 020000000000 /* flow control */
161 162
163#define IBSHIFT 16 /* Shift from CBAUD to CIBAUD */
164
162/* c_lflag bits */ 165/* c_lflag bits */
163#define ISIG 0000001 166#define ISIG 0000001
164#define ICANON 0000002 167#define ICANON 0000002
diff --git a/include/asm-blackfin/termios.h b/include/asm-blackfin/termios.h
index 5c41478a51c6..e31fe859650b 100644
--- a/include/asm-blackfin/termios.h
+++ b/include/asm-blackfin/termios.h
@@ -98,8 +98,14 @@ struct termio {
98 copy_to_user((termio)->c_cc, (termios)->c_cc, NCC); \ 98 copy_to_user((termio)->c_cc, (termios)->c_cc, NCC); \
99}) 99})
100 100
101#define user_termios_to_kernel_termios(k, u) copy_from_user(k, u, sizeof(struct termios)) 101#define user_termios_to_kernel_termios(k, u) \
102#define kernel_termios_to_user_termios(u, k) copy_to_user(u, k, sizeof(struct termios)) 102 copy_from_user(k, u, sizeof(struct termios2))
103#define kernel_termios_to_user_termios(u, k) \
104 copy_to_user(u, k, sizeof(struct termios2))
105#define user_termios_to_kernel_termios_1(k, u) \
106 copy_from_user(k, u, sizeof(struct termios))
107#define kernel_termios_to_user_termios_1(u, k) \
108 copy_to_user(u, k, sizeof(struct termios))
103 109
104#endif /* __KERNEL__ */ 110#endif /* __KERNEL__ */
105 111
diff --git a/include/asm-blackfin/trace.h b/include/asm-blackfin/trace.h
index 9c2474c9a589..6313aace9d59 100644
--- a/include/asm-blackfin/trace.h
+++ b/include/asm-blackfin/trace.h
@@ -6,23 +6,46 @@
6#ifndef _BLACKFIN_TRACE_ 6#ifndef _BLACKFIN_TRACE_
7#define _BLACKFIN_TRACE_ 7#define _BLACKFIN_TRACE_
8 8
9/* Normally, we use ON, but you can't turn on software expansion until
10 * interrupts subsystem is ready
11 */
12
13#define BFIN_TRACE_INIT ((CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION << 4) | 0x03)
14#ifdef CONFIG_DEBUG_BFIN_HWTRACE_EXPAND
15#define BFIN_TRACE_ON (BFIN_TRACE_INIT | (CONFIG_DEBUG_BFIN_HWTRACE_EXPAND << 2))
16#else
17#define BFIN_TRACE_ON (BFIN_TRACE_INIT)
18#endif
19
9#ifndef __ASSEMBLY__ 20#ifndef __ASSEMBLY__
21extern unsigned long trace_buff_offset;
22extern unsigned long software_trace_buff[];
23
10/* Trace Macros for C files */ 24/* Trace Macros for C files */
11 25
26#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
27
12#define trace_buffer_save(x) \ 28#define trace_buffer_save(x) \
13 do { \ 29 do { \
14 (x) = bfin_read_TBUFCTL(); \ 30 (x) = bfin_read_TBUFCTL(); \
15 bfin_write_TBUFCTL((x) & ~TBUFEN); \ 31 bfin_write_TBUFCTL((x) & ~TBUFEN); \
16 } while (0) 32 } while (0)
17 33
18#define trace_buffer_restore(x) \ 34#define trace_buffer_restore(x) \
19 do { \ 35 do { \
20 bfin_write_TBUFCTL((x)); \ 36 bfin_write_TBUFCTL((x)); \
21 } while (0) 37 } while (0)
38#else /* DEBUG_BFIN_HWTRACE_ON */
39
40#define trace_buffer_save(x)
41#define trace_buffer_restore(x)
42#endif /* CONFIG_DEBUG_BFIN_HWTRACE_ON */
22 43
23#else 44#else
24/* Trace Macros for Assembly files */ 45/* Trace Macros for Assembly files */
25 46
47#ifdef CONFIG_DEBUG_BFIN_HWTRACE_ON
48
26#define TRACE_BUFFER_START(preg, dreg) trace_buffer_start(preg, dreg) 49#define TRACE_BUFFER_START(preg, dreg) trace_buffer_start(preg, dreg)
27#define TRACE_BUFFER_STOP(preg, dreg) trace_buffer_stop(preg, dreg) 50#define TRACE_BUFFER_STOP(preg, dreg) trace_buffer_stop(preg, dreg)
28 51
@@ -32,12 +55,26 @@
32 dreg = 0x1; \ 55 dreg = 0x1; \
33 [preg] = dreg; 56 [preg] = dreg;
34 57
35#define trace_buffer_start(preg, dreg) \ 58#define trace_buffer_start(preg, dreg) \
36 preg.L = LO(TBUFCTL); \ 59 preg.L = LO(TBUFCTL); \
37 preg.H = HI(TBUFCTL); \ 60 preg.H = HI(TBUFCTL); \
38 dreg = 0x13; \ 61 dreg = BFIN_TRACE_ON; \
62 [preg] = dreg;
63
64#define trace_buffer_init(preg, dreg) \
65 preg.L = LO(TBUFCTL); \
66 preg.H = HI(TBUFCTL); \
67 dreg = BFIN_TRACE_INIT; \
39 [preg] = dreg; 68 [preg] = dreg;
40 69
70#else /* CONFIG_DEBUG_BFIN_HWTRACE_ON */
71
72#define trace_buffer_stop(preg, dreg)
73#define trace_buffer_start(preg, dreg)
74#define trace_buffer_init(preg, dreg)
75
76#endif /* CONFIG_DEBUG_BFIN_HWTRACE_ON */
77
41#ifdef CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE 78#ifdef CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE
42# define DEBUG_START_HWTRACE(preg, dreg) trace_buffer_start(preg, dreg) 79# define DEBUG_START_HWTRACE(preg, dreg) trace_buffer_start(preg, dreg)
43# define DEBUG_STOP_HWTRACE(preg, dreg) trace_buffer_stop(preg, dreg) 80# define DEBUG_STOP_HWTRACE(preg, dreg) trace_buffer_stop(preg, dreg)
diff --git a/include/asm-i386/Kbuild b/include/asm-i386/Kbuild
deleted file mode 100644
index cbf6e8f1087b..000000000000
--- a/include/asm-i386/Kbuild
+++ /dev/null
@@ -1,12 +0,0 @@
1include include/asm-generic/Kbuild.asm
2
3header-y += boot.h
4header-y += debugreg.h
5header-y += ldt.h
6header-y += msr-index.h
7header-y += ptrace-abi.h
8header-y += ucontext.h
9
10unifdef-y += msr.h
11unifdef-y += mtrr.h
12unifdef-y += vm86.h
diff --git a/include/asm-i386/k8.h b/include/asm-i386/k8.h
deleted file mode 100644
index dfd88a6e6040..000000000000
--- a/include/asm-i386/k8.h
+++ /dev/null
@@ -1 +0,0 @@
1#include <asm-x86_64/k8.h>
diff --git a/include/asm-i386/pci-direct.h b/include/asm-i386/pci-direct.h
deleted file mode 100644
index 4f6738b08206..000000000000
--- a/include/asm-i386/pci-direct.h
+++ /dev/null
@@ -1 +0,0 @@
1#include "asm-x86_64/pci-direct.h"
diff --git a/include/asm-i386/stacktrace.h b/include/asm-i386/stacktrace.h
deleted file mode 100644
index 7d1f6a5cbfca..000000000000
--- a/include/asm-i386/stacktrace.h
+++ /dev/null
@@ -1 +0,0 @@
1#include <asm-x86_64/stacktrace.h>
diff --git a/include/asm-i386/termios.h b/include/asm-i386/termios.h
deleted file mode 100644
index f520b7c16fa2..000000000000
--- a/include/asm-i386/termios.h
+++ /dev/null
@@ -1,91 +0,0 @@
1#ifndef _I386_TERMIOS_H
2#define _I386_TERMIOS_H
3
4#include <asm/termbits.h>
5#include <asm/ioctls.h>
6
7struct winsize {
8 unsigned short ws_row;
9 unsigned short ws_col;
10 unsigned short ws_xpixel;
11 unsigned short ws_ypixel;
12};
13
14#define NCC 8
15struct termio {
16 unsigned short c_iflag; /* input mode flags */
17 unsigned short c_oflag; /* output mode flags */
18 unsigned short c_cflag; /* control mode flags */
19 unsigned short c_lflag; /* local mode flags */
20 unsigned char c_line; /* line discipline */
21 unsigned char c_cc[NCC]; /* control characters */
22};
23
24/* modem lines */
25#define TIOCM_LE 0x001
26#define TIOCM_DTR 0x002
27#define TIOCM_RTS 0x004
28#define TIOCM_ST 0x008
29#define TIOCM_SR 0x010
30#define TIOCM_CTS 0x020
31#define TIOCM_CAR 0x040
32#define TIOCM_RNG 0x080
33#define TIOCM_DSR 0x100
34#define TIOCM_CD TIOCM_CAR
35#define TIOCM_RI TIOCM_RNG
36#define TIOCM_OUT1 0x2000
37#define TIOCM_OUT2 0x4000
38#define TIOCM_LOOP 0x8000
39
40/* ioctl (fd, TIOCSERGETLSR, &result) where result may be as below */
41
42#ifdef __KERNEL__
43#include <linux/module.h>
44
45/* intr=^C quit=^\ erase=del kill=^U
46 eof=^D vtime=\0 vmin=\1 sxtc=\0
47 start=^Q stop=^S susp=^Z eol=\0
48 reprint=^R discard=^U werase=^W lnext=^V
49 eol2=\0
50*/
51#define INIT_C_CC "\003\034\177\025\004\0\1\0\021\023\032\0\022\017\027\026\0"
52
53/*
54 * Translate a "termio" structure into a "termios". Ugh.
55 */
56#define SET_LOW_TERMIOS_BITS(termios, termio, x) { \
57 unsigned short __tmp; \
58 get_user(__tmp,&(termio)->x); \
59 *(unsigned short *) &(termios)->x = __tmp; \
60}
61
62#define user_termio_to_kernel_termios(termios, termio) \
63({ \
64 SET_LOW_TERMIOS_BITS(termios, termio, c_iflag); \
65 SET_LOW_TERMIOS_BITS(termios, termio, c_oflag); \
66 SET_LOW_TERMIOS_BITS(termios, termio, c_cflag); \
67 SET_LOW_TERMIOS_BITS(termios, termio, c_lflag); \
68 copy_from_user((termios)->c_cc, (termio)->c_cc, NCC); \
69})
70
71/*
72 * Translate a "termios" structure into a "termio". Ugh.
73 */
74#define kernel_termios_to_user_termio(termio, termios) \
75({ \
76 put_user((termios)->c_iflag, &(termio)->c_iflag); \
77 put_user((termios)->c_oflag, &(termio)->c_oflag); \
78 put_user((termios)->c_cflag, &(termio)->c_cflag); \
79 put_user((termios)->c_lflag, &(termio)->c_lflag); \
80 put_user((termios)->c_line, &(termio)->c_line); \
81 copy_to_user((termio)->c_cc, (termios)->c_cc, NCC); \
82})
83
84#define user_termios_to_kernel_termios(k, u) copy_from_user(k, u, sizeof(struct termios2))
85#define kernel_termios_to_user_termios(u, k) copy_to_user(u, k, sizeof(struct termios2))
86#define user_termios_to_kernel_termios_1(k, u) copy_from_user(k, u, sizeof(struct termios))
87#define kernel_termios_to_user_termios_1(u, k) copy_to_user(u, k, sizeof(struct termios))
88
89#endif /* __KERNEL__ */
90
91#endif /* _I386_TERMIOS_H */
diff --git a/include/asm-sh/mpc1211/mc146818rtc.h b/include/asm-sh/mpc1211/mc146818rtc.h
index 0ec78f66cea4..e245f2a3cd78 100644
--- a/include/asm-sh/mpc1211/mc146818rtc.h
+++ b/include/asm-sh/mpc1211/mc146818rtc.h
@@ -1,6 +1,6 @@
1/* 1/*
2 * MPC1211 uses PC/AT style RTC definitions. 2 * MPC1211 uses PC/AT style RTC definitions.
3 */ 3 */
4#include <asm-i386/mc146818rtc.h> 4#include <asm-x86/mc146818rtc_32.h>
5 5
6 6
diff --git a/include/asm-x86/8253pit.h b/include/asm-x86/8253pit.h
new file mode 100644
index 000000000000..d3c2b38a6618
--- /dev/null
+++ b/include/asm-x86/8253pit.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "8253pit_32.h"
3#else
4# include "8253pit_64.h"
5#endif
diff --git a/include/asm-i386/8253pit.h b/include/asm-x86/8253pit_32.h
index 96c7c3592daf..96c7c3592daf 100644
--- a/include/asm-i386/8253pit.h
+++ b/include/asm-x86/8253pit_32.h
diff --git a/include/asm-x86_64/8253pit.h b/include/asm-x86/8253pit_64.h
index 285f78488ccb..285f78488ccb 100644
--- a/include/asm-x86_64/8253pit.h
+++ b/include/asm-x86/8253pit_64.h
diff --git a/include/asm-x86/Kbuild b/include/asm-x86/Kbuild
new file mode 100644
index 000000000000..c5e43cb39874
--- /dev/null
+++ b/include/asm-x86/Kbuild
@@ -0,0 +1,88 @@
1include include/asm-generic/Kbuild.asm
2
3header-y += boot.h
4header-y += bootsetup.h
5header-y += debugreg_32.h
6header-y += debugreg_64.h
7header-y += debugreg.h
8header-y += ldt_32.h
9header-y += ldt_64.h
10header-y += ldt.h
11header-y += msr-index.h
12header-y += prctl.h
13header-y += ptrace-abi_32.h
14header-y += ptrace-abi_64.h
15header-y += ptrace-abi.h
16header-y += sigcontext32.h
17header-y += ucontext_32.h
18header-y += ucontext_64.h
19header-y += ucontext.h
20header-y += vsyscall32.h
21
22unifdef-y += a.out_32.h
23unifdef-y += a.out_64.h
24unifdef-y += auxvec_32.h
25unifdef-y += auxvec_64.h
26unifdef-y += byteorder_32.h
27unifdef-y += byteorder_64.h
28unifdef-y += elf_32.h
29unifdef-y += elf_64.h
30unifdef-y += errno_32.h
31unifdef-y += errno_64.h
32unifdef-y += ioctls_32.h
33unifdef-y += ioctls_64.h
34unifdef-y += ipcbuf_32.h
35unifdef-y += ipcbuf_64.h
36unifdef-y += mce.h
37unifdef-y += mman_32.h
38unifdef-y += mman_64.h
39unifdef-y += msgbuf_32.h
40unifdef-y += msgbuf_64.h
41unifdef-y += msr_32.h
42unifdef-y += msr_64.h
43unifdef-y += msr.h
44unifdef-y += mtrr_32.h
45unifdef-y += mtrr_64.h
46unifdef-y += mtrr.h
47unifdef-y += page_32.h
48unifdef-y += page_64.h
49unifdef-y += param_32.h
50unifdef-y += param_64.h
51unifdef-y += posix_types_32.h
52unifdef-y += posix_types_64.h
53unifdef-y += ptrace_32.h
54unifdef-y += ptrace_64.h
55unifdef-y += resource_32.h
56unifdef-y += resource_64.h
57unifdef-y += sembuf_32.h
58unifdef-y += sembuf_64.h
59unifdef-y += setup_32.h
60unifdef-y += setup_64.h
61unifdef-y += shmbuf_32.h
62unifdef-y += shmbuf_64.h
63unifdef-y += shmparam_32.h
64unifdef-y += shmparam_64.h
65unifdef-y += sigcontext_32.h
66unifdef-y += sigcontext_64.h
67unifdef-y += siginfo_32.h
68unifdef-y += siginfo_64.h
69unifdef-y += signal_32.h
70unifdef-y += signal_64.h
71unifdef-y += sockios_32.h
72unifdef-y += sockios_64.h
73unifdef-y += stat_32.h
74unifdef-y += stat_64.h
75unifdef-y += statfs_32.h
76unifdef-y += statfs_64.h
77unifdef-y += termbits_32.h
78unifdef-y += termbits_64.h
79unifdef-y += termios_32.h
80unifdef-y += termios_64.h
81unifdef-y += types_32.h
82unifdef-y += types_64.h
83unifdef-y += unistd_32.h
84unifdef-y += unistd_64.h
85unifdef-y += user_32.h
86unifdef-y += user_64.h
87unifdef-y += vm86.h
88unifdef-y += vsyscall.h
diff --git a/include/asm-x86/a.out.h b/include/asm-x86/a.out.h
new file mode 100644
index 000000000000..5bc9b1d3b227
--- /dev/null
+++ b/include/asm-x86/a.out.h
@@ -0,0 +1,13 @@
1#ifdef __KERNEL__
2# ifdef CONFIG_X86_32
3# include "a.out_32.h"
4# else
5# include "a.out_64.h"
6# endif
7#else
8# ifdef __i386__
9# include "a.out_32.h"
10# else
11# include "a.out_64.h"
12# endif
13#endif
diff --git a/include/asm-i386/a.out.h b/include/asm-x86/a.out_32.h
index 851a60f8258c..851a60f8258c 100644
--- a/include/asm-i386/a.out.h
+++ b/include/asm-x86/a.out_32.h
diff --git a/include/asm-x86_64/a.out.h b/include/asm-x86/a.out_64.h
index e789300e41a5..e789300e41a5 100644
--- a/include/asm-x86_64/a.out.h
+++ b/include/asm-x86/a.out_64.h
diff --git a/include/asm-x86/acpi.h b/include/asm-x86/acpi.h
new file mode 100644
index 000000000000..0693689d4146
--- /dev/null
+++ b/include/asm-x86/acpi.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "acpi_32.h"
3#else
4# include "acpi_64.h"
5#endif
diff --git a/include/asm-i386/acpi.h b/include/asm-x86/acpi_32.h
index 125179adf044..125179adf044 100644
--- a/include/asm-i386/acpi.h
+++ b/include/asm-x86/acpi_32.h
diff --git a/include/asm-x86_64/acpi.h b/include/asm-x86/acpi_64.h
index 98173357dd89..98173357dd89 100644
--- a/include/asm-x86_64/acpi.h
+++ b/include/asm-x86/acpi_64.h
diff --git a/include/asm-x86/agp.h b/include/asm-x86/agp.h
new file mode 100644
index 000000000000..9348f1e4f6f1
--- /dev/null
+++ b/include/asm-x86/agp.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "agp_32.h"
3#else
4# include "agp_64.h"
5#endif
diff --git a/include/asm-i386/agp.h b/include/asm-x86/agp_32.h
index 6af173dbf123..6af173dbf123 100644
--- a/include/asm-i386/agp.h
+++ b/include/asm-x86/agp_32.h
diff --git a/include/asm-x86_64/agp.h b/include/asm-x86/agp_64.h
index de338666f3f9..de338666f3f9 100644
--- a/include/asm-x86_64/agp.h
+++ b/include/asm-x86/agp_64.h
diff --git a/include/asm-x86/alternative-asm.i b/include/asm-x86/alternative-asm.i
new file mode 100644
index 000000000000..4f360cd3c888
--- /dev/null
+++ b/include/asm-x86/alternative-asm.i
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "alternative-asm_32.i"
3#else
4# include "alternative-asm_64.i"
5#endif
diff --git a/include/asm-i386/alternative-asm.i b/include/asm-x86/alternative-asm_32.i
index f0510209ccbe..f0510209ccbe 100644
--- a/include/asm-i386/alternative-asm.i
+++ b/include/asm-x86/alternative-asm_32.i
diff --git a/include/asm-x86_64/alternative-asm.i b/include/asm-x86/alternative-asm_64.i
index 0b3f1a2bb2cb..0b3f1a2bb2cb 100644
--- a/include/asm-x86_64/alternative-asm.i
+++ b/include/asm-x86/alternative-asm_64.i
diff --git a/include/asm-x86/alternative.h b/include/asm-x86/alternative.h
new file mode 100644
index 000000000000..9eef6a32a130
--- /dev/null
+++ b/include/asm-x86/alternative.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "alternative_32.h"
3#else
4# include "alternative_64.h"
5#endif
diff --git a/include/asm-i386/alternative.h b/include/asm-x86/alternative_32.h
index bda6c810c0f4..bda6c810c0f4 100644
--- a/include/asm-i386/alternative.h
+++ b/include/asm-x86/alternative_32.h
diff --git a/include/asm-x86_64/alternative.h b/include/asm-x86/alternative_64.h
index ab161e810151..ab161e810151 100644
--- a/include/asm-x86_64/alternative.h
+++ b/include/asm-x86/alternative_64.h
diff --git a/include/asm-x86/apic.h b/include/asm-x86/apic.h
new file mode 100644
index 000000000000..9fbcc0bd2ac4
--- /dev/null
+++ b/include/asm-x86/apic.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "apic_32.h"
3#else
4# include "apic_64.h"
5#endif
diff --git a/include/asm-i386/apic.h b/include/asm-x86/apic_32.h
index 4091b33dcb10..4091b33dcb10 100644
--- a/include/asm-i386/apic.h
+++ b/include/asm-x86/apic_32.h
diff --git a/include/asm-x86_64/apic.h b/include/asm-x86/apic_64.h
index 85125ef3c414..85125ef3c414 100644
--- a/include/asm-x86_64/apic.h
+++ b/include/asm-x86/apic_64.h
diff --git a/include/asm-x86/apicdef.h b/include/asm-x86/apicdef.h
new file mode 100644
index 000000000000..4542c220bf4d
--- /dev/null
+++ b/include/asm-x86/apicdef.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "apicdef_32.h"
3#else
4# include "apicdef_64.h"
5#endif
diff --git a/include/asm-i386/apicdef.h b/include/asm-x86/apicdef_32.h
index 9f6995341fdc..9f6995341fdc 100644
--- a/include/asm-i386/apicdef.h
+++ b/include/asm-x86/apicdef_32.h
diff --git a/include/asm-x86_64/apicdef.h b/include/asm-x86/apicdef_64.h
index 1dd40067c67c..1dd40067c67c 100644
--- a/include/asm-x86_64/apicdef.h
+++ b/include/asm-x86/apicdef_64.h
diff --git a/include/asm-i386/arch_hooks.h b/include/asm-x86/arch_hooks.h
index a8c1fca9726d..a8c1fca9726d 100644
--- a/include/asm-i386/arch_hooks.h
+++ b/include/asm-x86/arch_hooks.h
diff --git a/include/asm-x86/atomic.h b/include/asm-x86/atomic.h
new file mode 100644
index 000000000000..4e1b8873c474
--- /dev/null
+++ b/include/asm-x86/atomic.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "atomic_32.h"
3#else
4# include "atomic_64.h"
5#endif
diff --git a/include/asm-i386/atomic.h b/include/asm-x86/atomic_32.h
index 437aac801711..437aac801711 100644
--- a/include/asm-i386/atomic.h
+++ b/include/asm-x86/atomic_32.h
diff --git a/include/asm-x86_64/atomic.h b/include/asm-x86/atomic_64.h
index f2e64634fa48..f2e64634fa48 100644
--- a/include/asm-x86_64/atomic.h
+++ b/include/asm-x86/atomic_64.h
diff --git a/include/asm-x86/auxvec.h b/include/asm-x86/auxvec.h
new file mode 100644
index 000000000000..7ff866f829ca
--- /dev/null
+++ b/include/asm-x86/auxvec.h
@@ -0,0 +1,13 @@
1#ifdef __KERNEL__
2# ifdef CONFIG_X86_32
3# include "auxvec_32.h"
4# else
5# include "auxvec_64.h"
6# endif
7#else
8# ifdef __i386__
9# include "auxvec_32.h"
10# else
11# include "auxvec_64.h"
12# endif
13#endif
diff --git a/include/asm-i386/auxvec.h b/include/asm-x86/auxvec_32.h
index 395e13016bfb..395e13016bfb 100644
--- a/include/asm-i386/auxvec.h
+++ b/include/asm-x86/auxvec_32.h
diff --git a/include/asm-x86_64/auxvec.h b/include/asm-x86/auxvec_64.h
index 1d5ab0d03950..1d5ab0d03950 100644
--- a/include/asm-x86_64/auxvec.h
+++ b/include/asm-x86/auxvec_64.h
diff --git a/include/asm-x86/bitops.h b/include/asm-x86/bitops.h
new file mode 100644
index 000000000000..07e3f6d4fe47
--- /dev/null
+++ b/include/asm-x86/bitops.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "bitops_32.h"
3#else
4# include "bitops_64.h"
5#endif
diff --git a/include/asm-i386/bitops.h b/include/asm-x86/bitops_32.h
index a20fe9822f60..a20fe9822f60 100644
--- a/include/asm-i386/bitops.h
+++ b/include/asm-x86/bitops_32.h
diff --git a/include/asm-x86_64/bitops.h b/include/asm-x86/bitops_64.h
index d4dbbe5f7bd9..d4dbbe5f7bd9 100644
--- a/include/asm-x86_64/bitops.h
+++ b/include/asm-x86/bitops_64.h
diff --git a/include/asm-i386/boot.h b/include/asm-x86/boot.h
index ed8affbf96cb..ed8affbf96cb 100644
--- a/include/asm-i386/boot.h
+++ b/include/asm-x86/boot.h
diff --git a/include/asm-i386/bootparam.h b/include/asm-x86/bootparam.h
index b91b01783e4b..b91b01783e4b 100644
--- a/include/asm-i386/bootparam.h
+++ b/include/asm-x86/bootparam.h
diff --git a/include/asm-x86_64/bootsetup.h b/include/asm-x86/bootsetup.h
index 7b1c3ad155fd..7b1c3ad155fd 100644
--- a/include/asm-x86_64/bootsetup.h
+++ b/include/asm-x86/bootsetup.h
diff --git a/include/asm-x86/bug.h b/include/asm-x86/bug.h
new file mode 100644
index 000000000000..c655d7f3a5e0
--- /dev/null
+++ b/include/asm-x86/bug.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "bug_32.h"
3#else
4# include "bug_64.h"
5#endif
diff --git a/include/asm-i386/bug.h b/include/asm-x86/bug_32.h
index b0fd78ca2619..b0fd78ca2619 100644
--- a/include/asm-i386/bug.h
+++ b/include/asm-x86/bug_32.h
diff --git a/include/asm-x86_64/bug.h b/include/asm-x86/bug_64.h
index 682606414913..682606414913 100644
--- a/include/asm-x86_64/bug.h
+++ b/include/asm-x86/bug_64.h
diff --git a/include/asm-x86/bugs.h b/include/asm-x86/bugs.h
new file mode 100644
index 000000000000..ddf42d36dd50
--- /dev/null
+++ b/include/asm-x86/bugs.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "bugs_32.h"
3#else
4# include "bugs_64.h"
5#endif
diff --git a/include/asm-i386/bugs.h b/include/asm-x86/bugs_32.h
index d28979ff73be..d28979ff73be 100644
--- a/include/asm-i386/bugs.h
+++ b/include/asm-x86/bugs_32.h
diff --git a/include/asm-x86_64/bugs.h b/include/asm-x86/bugs_64.h
index b33dc04d8f42..b33dc04d8f42 100644
--- a/include/asm-x86_64/bugs.h
+++ b/include/asm-x86/bugs_64.h
diff --git a/include/asm-x86/byteorder.h b/include/asm-x86/byteorder.h
new file mode 100644
index 000000000000..eb14b1870ed7
--- /dev/null
+++ b/include/asm-x86/byteorder.h
@@ -0,0 +1,13 @@
1#ifdef __KERNEL__
2# ifdef CONFIG_X86_32
3# include "byteorder_32.h"
4# else
5# include "byteorder_64.h"
6# endif
7#else
8# ifdef __i386__
9# include "byteorder_32.h"
10# else
11# include "byteorder_64.h"
12# endif
13#endif
diff --git a/include/asm-i386/byteorder.h b/include/asm-x86/byteorder_32.h
index a45470a8b74a..a45470a8b74a 100644
--- a/include/asm-i386/byteorder.h
+++ b/include/asm-x86/byteorder_32.h
diff --git a/include/asm-x86_64/byteorder.h b/include/asm-x86/byteorder_64.h
index 5e86c868c75e..5e86c868c75e 100644
--- a/include/asm-x86_64/byteorder.h
+++ b/include/asm-x86/byteorder_64.h
diff --git a/include/asm-x86/cache.h b/include/asm-x86/cache.h
new file mode 100644
index 000000000000..c36d190ac9d8
--- /dev/null
+++ b/include/asm-x86/cache.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "cache_32.h"
3#else
4# include "cache_64.h"
5#endif
diff --git a/include/asm-i386/cache.h b/include/asm-x86/cache_32.h
index 57c62f414158..57c62f414158 100644
--- a/include/asm-i386/cache.h
+++ b/include/asm-x86/cache_32.h
diff --git a/include/asm-x86_64/cache.h b/include/asm-x86/cache_64.h
index 052df758ae61..052df758ae61 100644
--- a/include/asm-x86_64/cache.h
+++ b/include/asm-x86/cache_64.h
diff --git a/include/asm-x86/cacheflush.h b/include/asm-x86/cacheflush.h
new file mode 100644
index 000000000000..e2df3b55034a
--- /dev/null
+++ b/include/asm-x86/cacheflush.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "cacheflush_32.h"
3#else
4# include "cacheflush_64.h"
5#endif
diff --git a/include/asm-i386/cacheflush.h b/include/asm-x86/cacheflush_32.h
index 74e03c8f2e51..74e03c8f2e51 100644
--- a/include/asm-i386/cacheflush.h
+++ b/include/asm-x86/cacheflush_32.h
diff --git a/include/asm-x86_64/cacheflush.h b/include/asm-x86/cacheflush_64.h
index ab1cb5c7dc92..ab1cb5c7dc92 100644
--- a/include/asm-x86_64/cacheflush.h
+++ b/include/asm-x86/cacheflush_64.h
diff --git a/include/asm-x86_64/calgary.h b/include/asm-x86/calgary.h
index 67f60406e2d8..67f60406e2d8 100644
--- a/include/asm-x86_64/calgary.h
+++ b/include/asm-x86/calgary.h
diff --git a/include/asm-x86_64/calling.h b/include/asm-x86/calling.h
index 6f4f63af96e1..6f4f63af96e1 100644
--- a/include/asm-x86_64/calling.h
+++ b/include/asm-x86/calling.h
diff --git a/include/asm-x86/checksum.h b/include/asm-x86/checksum.h
new file mode 100644
index 000000000000..848850fd7d62
--- /dev/null
+++ b/include/asm-x86/checksum.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "checksum_32.h"
3#else
4# include "checksum_64.h"
5#endif
diff --git a/include/asm-i386/checksum.h b/include/asm-x86/checksum_32.h
index 75194abbe8ee..75194abbe8ee 100644
--- a/include/asm-i386/checksum.h
+++ b/include/asm-x86/checksum_32.h
diff --git a/include/asm-x86_64/checksum.h b/include/asm-x86/checksum_64.h
index 419fe88a0342..419fe88a0342 100644
--- a/include/asm-x86_64/checksum.h
+++ b/include/asm-x86/checksum_64.h
diff --git a/include/asm-x86/cmpxchg.h b/include/asm-x86/cmpxchg.h
new file mode 100644
index 000000000000..a460fa088d4c
--- /dev/null
+++ b/include/asm-x86/cmpxchg.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "cmpxchg_32.h"
3#else
4# include "cmpxchg_64.h"
5#endif
diff --git a/include/asm-i386/cmpxchg.h b/include/asm-x86/cmpxchg_32.h
index f86ede28f6dc..f86ede28f6dc 100644
--- a/include/asm-i386/cmpxchg.h
+++ b/include/asm-x86/cmpxchg_32.h
diff --git a/include/asm-x86_64/cmpxchg.h b/include/asm-x86/cmpxchg_64.h
index 5e182062e6ec..5e182062e6ec 100644
--- a/include/asm-x86_64/cmpxchg.h
+++ b/include/asm-x86/cmpxchg_64.h
diff --git a/include/asm-x86_64/compat.h b/include/asm-x86/compat.h
index 53cb96b68a62..53cb96b68a62 100644
--- a/include/asm-x86_64/compat.h
+++ b/include/asm-x86/compat.h
diff --git a/include/asm-i386/cpu.h b/include/asm-x86/cpu.h
index 9d914e1e4aad..9d914e1e4aad 100644
--- a/include/asm-i386/cpu.h
+++ b/include/asm-x86/cpu.h
diff --git a/include/asm-x86/cpufeature.h b/include/asm-x86/cpufeature.h
new file mode 100644
index 000000000000..b7160a4598d7
--- /dev/null
+++ b/include/asm-x86/cpufeature.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "cpufeature_32.h"
3#else
4# include "cpufeature_64.h"
5#endif
diff --git a/include/asm-i386/cpufeature.h b/include/asm-x86/cpufeature_32.h
index 7b3aa28ebc6e..7b3aa28ebc6e 100644
--- a/include/asm-i386/cpufeature.h
+++ b/include/asm-x86/cpufeature_32.h
diff --git a/include/asm-x86/cpufeature_64.h b/include/asm-x86/cpufeature_64.h
new file mode 100644
index 000000000000..2983501e8b3e
--- /dev/null
+++ b/include/asm-x86/cpufeature_64.h
@@ -0,0 +1,30 @@
1/*
2 * cpufeature_32.h
3 *
4 * Defines x86 CPU feature bits
5 */
6
7#ifndef __ASM_X8664_CPUFEATURE_H
8#define __ASM_X8664_CPUFEATURE_H
9
10#include <asm/cpufeature_32.h>
11
12#undef cpu_has_vme
13#define cpu_has_vme 0
14
15#undef cpu_has_pae
16#define cpu_has_pae ___BUG___
17
18#undef cpu_has_mp
19#define cpu_has_mp 1 /* XXX */
20
21#undef cpu_has_k6_mtrr
22#define cpu_has_k6_mtrr 0
23
24#undef cpu_has_cyrix_arr
25#define cpu_has_cyrix_arr 0
26
27#undef cpu_has_centaur_mcr
28#define cpu_has_centaur_mcr 0
29
30#endif /* __ASM_X8664_CPUFEATURE_H */
diff --git a/include/asm-x86/cputime.h b/include/asm-x86/cputime.h
new file mode 100644
index 000000000000..87c37cf6b707
--- /dev/null
+++ b/include/asm-x86/cputime.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "cputime_32.h"
3#else
4# include "cputime_64.h"
5#endif
diff --git a/include/asm-i386/cputime.h b/include/asm-x86/cputime_32.h
index 398ed7cd171d..398ed7cd171d 100644
--- a/include/asm-i386/cputime.h
+++ b/include/asm-x86/cputime_32.h
diff --git a/include/asm-x86_64/cputime.h b/include/asm-x86/cputime_64.h
index a07012dc5a3c..a07012dc5a3c 100644
--- a/include/asm-x86_64/cputime.h
+++ b/include/asm-x86/cputime_64.h
diff --git a/include/asm-x86/current.h b/include/asm-x86/current.h
new file mode 100644
index 000000000000..d2526d3f7346
--- /dev/null
+++ b/include/asm-x86/current.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "current_32.h"
3#else
4# include "current_64.h"
5#endif
diff --git a/include/asm-i386/current.h b/include/asm-x86/current_32.h
index d35248539912..d35248539912 100644
--- a/include/asm-i386/current.h
+++ b/include/asm-x86/current_32.h
diff --git a/include/asm-x86_64/current.h b/include/asm-x86/current_64.h
index bc8adecee66d..bc8adecee66d 100644
--- a/include/asm-x86_64/current.h
+++ b/include/asm-x86/current_64.h
diff --git a/include/asm-x86/debugreg.h b/include/asm-x86/debugreg.h
new file mode 100644
index 000000000000..b6ce7e4fa002
--- /dev/null
+++ b/include/asm-x86/debugreg.h
@@ -0,0 +1,13 @@
1#ifdef __KERNEL__
2# ifdef CONFIG_X86_32
3# include "debugreg_32.h"
4# else
5# include "debugreg_64.h"
6# endif
7#else
8# ifdef __i386__
9# include "debugreg_32.h"
10# else
11# include "debugreg_64.h"
12# endif
13#endif
diff --git a/include/asm-i386/debugreg.h b/include/asm-x86/debugreg_32.h
index f0b2b06ae0f7..f0b2b06ae0f7 100644
--- a/include/asm-i386/debugreg.h
+++ b/include/asm-x86/debugreg_32.h
diff --git a/include/asm-x86_64/debugreg.h b/include/asm-x86/debugreg_64.h
index bd1aab1d8c4a..bd1aab1d8c4a 100644
--- a/include/asm-x86_64/debugreg.h
+++ b/include/asm-x86/debugreg_64.h
diff --git a/include/asm-x86/delay.h b/include/asm-x86/delay.h
new file mode 100644
index 000000000000..10f2c71d622b
--- /dev/null
+++ b/include/asm-x86/delay.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "delay_32.h"
3#else
4# include "delay_64.h"
5#endif
diff --git a/include/asm-i386/delay.h b/include/asm-x86/delay_32.h
index 9ae5e3782ed8..9ae5e3782ed8 100644
--- a/include/asm-i386/delay.h
+++ b/include/asm-x86/delay_32.h
diff --git a/include/asm-x86_64/delay.h b/include/asm-x86/delay_64.h
index c2669f1f5529..c2669f1f5529 100644
--- a/include/asm-x86_64/delay.h
+++ b/include/asm-x86/delay_64.h
diff --git a/include/asm-x86/desc.h b/include/asm-x86/desc.h
new file mode 100644
index 000000000000..6065c5092265
--- /dev/null
+++ b/include/asm-x86/desc.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "desc_32.h"
3#else
4# include "desc_64.h"
5#endif
diff --git a/include/asm-i386/desc.h b/include/asm-x86/desc_32.h
index c547403f341d..c547403f341d 100644
--- a/include/asm-i386/desc.h
+++ b/include/asm-x86/desc_32.h
diff --git a/include/asm-x86_64/desc.h b/include/asm-x86/desc_64.h
index ac991b5ca0fd..ac991b5ca0fd 100644
--- a/include/asm-x86_64/desc.h
+++ b/include/asm-x86/desc_64.h
diff --git a/include/asm-x86_64/desc_defs.h b/include/asm-x86/desc_defs.h
index 089004070099..089004070099 100644
--- a/include/asm-x86_64/desc_defs.h
+++ b/include/asm-x86/desc_defs.h
diff --git a/include/asm-x86/device.h b/include/asm-x86/device.h
new file mode 100644
index 000000000000..e2bcf7c7dcee
--- /dev/null
+++ b/include/asm-x86/device.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "device_32.h"
3#else
4# include "device_64.h"
5#endif
diff --git a/include/asm-i386/device.h b/include/asm-x86/device_32.h
index 849604c70e6b..849604c70e6b 100644
--- a/include/asm-i386/device.h
+++ b/include/asm-x86/device_32.h
diff --git a/include/asm-x86_64/device.h b/include/asm-x86/device_64.h
index 3afa03f33a36..3afa03f33a36 100644
--- a/include/asm-x86_64/device.h
+++ b/include/asm-x86/device_64.h
diff --git a/include/asm-x86/div64.h b/include/asm-x86/div64.h
new file mode 100644
index 000000000000..8ac7da6ca284
--- /dev/null
+++ b/include/asm-x86/div64.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "div64_32.h"
3#else
4# include "div64_64.h"
5#endif
diff --git a/include/asm-i386/div64.h b/include/asm-x86/div64_32.h
index 438e980068bd..438e980068bd 100644
--- a/include/asm-i386/div64.h
+++ b/include/asm-x86/div64_32.h
diff --git a/include/asm-x86_64/div64.h b/include/asm-x86/div64_64.h
index 6cd978cefb28..6cd978cefb28 100644
--- a/include/asm-x86_64/div64.h
+++ b/include/asm-x86/div64_64.h
diff --git a/include/asm-x86/dma-mapping.h b/include/asm-x86/dma-mapping.h
new file mode 100644
index 000000000000..58f790f4df52
--- /dev/null
+++ b/include/asm-x86/dma-mapping.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "dma-mapping_32.h"
3#else
4# include "dma-mapping_64.h"
5#endif
diff --git a/include/asm-i386/dma-mapping.h b/include/asm-x86/dma-mapping_32.h
index f1d72d177f68..f1d72d177f68 100644
--- a/include/asm-i386/dma-mapping.h
+++ b/include/asm-x86/dma-mapping_32.h
diff --git a/include/asm-x86_64/dma-mapping.h b/include/asm-x86/dma-mapping_64.h
index 6897e2a436e5..6897e2a436e5 100644
--- a/include/asm-x86_64/dma-mapping.h
+++ b/include/asm-x86/dma-mapping_64.h
diff --git a/include/asm-x86/dma.h b/include/asm-x86/dma.h
new file mode 100644
index 000000000000..9f936c61a4e5
--- /dev/null
+++ b/include/asm-x86/dma.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "dma_32.h"
3#else
4# include "dma_64.h"
5#endif
diff --git a/include/asm-i386/dma.h b/include/asm-x86/dma_32.h
index d23aac8e1a50..d23aac8e1a50 100644
--- a/include/asm-i386/dma.h
+++ b/include/asm-x86/dma_32.h
diff --git a/include/asm-x86_64/dma.h b/include/asm-x86/dma_64.h
index a37c16f06289..a37c16f06289 100644
--- a/include/asm-x86_64/dma.h
+++ b/include/asm-x86/dma_64.h
diff --git a/include/asm-x86/dmi.h b/include/asm-x86/dmi.h
new file mode 100644
index 000000000000..c9e4e8ebc270
--- /dev/null
+++ b/include/asm-x86/dmi.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "dmi_32.h"
3#else
4# include "dmi_64.h"
5#endif
diff --git a/include/asm-i386/dmi.h b/include/asm-x86/dmi_32.h
index 38d4eeb7fc7e..38d4eeb7fc7e 100644
--- a/include/asm-i386/dmi.h
+++ b/include/asm-x86/dmi_32.h
diff --git a/include/asm-x86_64/dmi.h b/include/asm-x86/dmi_64.h
index d02e32e3c3f0..d02e32e3c3f0 100644
--- a/include/asm-x86_64/dmi.h
+++ b/include/asm-x86/dmi_64.h
diff --git a/include/asm-x86/dwarf2.h b/include/asm-x86/dwarf2.h
new file mode 100644
index 000000000000..b3cbb0ccae18
--- /dev/null
+++ b/include/asm-x86/dwarf2.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "dwarf2_32.h"
3#else
4# include "dwarf2_64.h"
5#endif
diff --git a/include/asm-i386/dwarf2.h b/include/asm-x86/dwarf2_32.h
index 6d66398a307d..6d66398a307d 100644
--- a/include/asm-i386/dwarf2.h
+++ b/include/asm-x86/dwarf2_32.h
diff --git a/include/asm-x86_64/dwarf2.h b/include/asm-x86/dwarf2_64.h
index eedc08526b0b..eedc08526b0b 100644
--- a/include/asm-x86_64/dwarf2.h
+++ b/include/asm-x86/dwarf2_64.h
diff --git a/include/asm-x86/e820.h b/include/asm-x86/e820.h
new file mode 100644
index 000000000000..5d4d2183e5db
--- /dev/null
+++ b/include/asm-x86/e820.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "e820_32.h"
3#else
4# include "e820_64.h"
5#endif
diff --git a/include/asm-i386/e820.h b/include/asm-x86/e820_32.h
index cf67dbb1db79..cf67dbb1db79 100644
--- a/include/asm-i386/e820.h
+++ b/include/asm-x86/e820_32.h
diff --git a/include/asm-x86_64/e820.h b/include/asm-x86/e820_64.h
index 3486e701bd86..3486e701bd86 100644
--- a/include/asm-x86_64/e820.h
+++ b/include/asm-x86/e820_64.h
diff --git a/include/asm-x86/edac.h b/include/asm-x86/edac.h
new file mode 100644
index 000000000000..f8b888e140b0
--- /dev/null
+++ b/include/asm-x86/edac.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "edac_32.h"
3#else
4# include "edac_64.h"
5#endif
diff --git a/include/asm-i386/edac.h b/include/asm-x86/edac_32.h
index 3e7dd0ab68ce..3e7dd0ab68ce 100644
--- a/include/asm-i386/edac.h
+++ b/include/asm-x86/edac_32.h
diff --git a/include/asm-x86_64/edac.h b/include/asm-x86/edac_64.h
index cad1cd42b4ee..cad1cd42b4ee 100644
--- a/include/asm-x86_64/edac.h
+++ b/include/asm-x86/edac_64.h
diff --git a/include/asm-x86/elf.h b/include/asm-x86/elf.h
new file mode 100644
index 000000000000..ed6bb6e546b9
--- /dev/null
+++ b/include/asm-x86/elf.h
@@ -0,0 +1,13 @@
1#ifdef __KERNEL__
2# ifdef CONFIG_X86_32
3# include "elf_32.h"
4# else
5# include "elf_64.h"
6# endif
7#else
8# ifdef __i386__
9# include "elf_32.h"
10# else
11# include "elf_64.h"
12# endif
13#endif
diff --git a/include/asm-i386/elf.h b/include/asm-x86/elf_32.h
index b32df3a332da..b32df3a332da 100644
--- a/include/asm-i386/elf.h
+++ b/include/asm-x86/elf_32.h
diff --git a/include/asm-x86_64/elf.h b/include/asm-x86/elf_64.h
index b4fbe47f6ccd..b4fbe47f6ccd 100644
--- a/include/asm-x86_64/elf.h
+++ b/include/asm-x86/elf_64.h
diff --git a/include/asm-i386/emergency-restart.h b/include/asm-x86/emergency-restart.h
index 680c39563345..680c39563345 100644
--- a/include/asm-i386/emergency-restart.h
+++ b/include/asm-x86/emergency-restart.h
diff --git a/include/asm-x86/errno.h b/include/asm-x86/errno.h
new file mode 100644
index 000000000000..9d511be8e573
--- /dev/null
+++ b/include/asm-x86/errno.h
@@ -0,0 +1,13 @@
1#ifdef __KERNEL__
2# ifdef CONFIG_X86_32
3# include "errno_32.h"
4# else
5# include "errno_64.h"
6# endif
7#else
8# ifdef __i386__
9# include "errno_32.h"
10# else
11# include "errno_64.h"
12# endif
13#endif
diff --git a/include/asm-i386/errno.h b/include/asm-x86/errno_32.h
index 969b34374728..969b34374728 100644
--- a/include/asm-i386/errno.h
+++ b/include/asm-x86/errno_32.h
diff --git a/include/asm-x86_64/errno.h b/include/asm-x86/errno_64.h
index 311182129e32..311182129e32 100644
--- a/include/asm-x86_64/errno.h
+++ b/include/asm-x86/errno_64.h
diff --git a/include/asm-x86/fb.h b/include/asm-x86/fb.h
new file mode 100644
index 000000000000..238c7ca45877
--- /dev/null
+++ b/include/asm-x86/fb.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "fb_32.h"
3#else
4# include "fb_64.h"
5#endif
diff --git a/include/asm-i386/fb.h b/include/asm-x86/fb_32.h
index d1c6297d4a61..d1c6297d4a61 100644
--- a/include/asm-i386/fb.h
+++ b/include/asm-x86/fb_32.h
diff --git a/include/asm-x86_64/fb.h b/include/asm-x86/fb_64.h
index 60548e651d12..60548e651d12 100644
--- a/include/asm-x86_64/fb.h
+++ b/include/asm-x86/fb_64.h
diff --git a/include/asm-i386/fcntl.h b/include/asm-x86/fcntl.h
index 46ab12db5739..46ab12db5739 100644
--- a/include/asm-i386/fcntl.h
+++ b/include/asm-x86/fcntl.h
diff --git a/include/asm-x86/fixmap.h b/include/asm-x86/fixmap.h
new file mode 100644
index 000000000000..382eb271a892
--- /dev/null
+++ b/include/asm-x86/fixmap.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "fixmap_32.h"
3#else
4# include "fixmap_64.h"
5#endif
diff --git a/include/asm-i386/fixmap.h b/include/asm-x86/fixmap_32.h
index 249e753ac805..249e753ac805 100644
--- a/include/asm-i386/fixmap.h
+++ b/include/asm-x86/fixmap_32.h
diff --git a/include/asm-x86_64/fixmap.h b/include/asm-x86/fixmap_64.h
index cdfbe4a6ae6f..cdfbe4a6ae6f 100644
--- a/include/asm-x86_64/fixmap.h
+++ b/include/asm-x86/fixmap_64.h
diff --git a/include/asm-x86/floppy.h b/include/asm-x86/floppy.h
new file mode 100644
index 000000000000..aecbb6dca21d
--- /dev/null
+++ b/include/asm-x86/floppy.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "floppy_32.h"
3#else
4# include "floppy_64.h"
5#endif
diff --git a/include/asm-i386/floppy.h b/include/asm-x86/floppy_32.h
index 44ef2f55a8e9..44ef2f55a8e9 100644
--- a/include/asm-i386/floppy.h
+++ b/include/asm-x86/floppy_32.h
diff --git a/include/asm-x86_64/floppy.h b/include/asm-x86/floppy_64.h
index 6ea13c3806f3..6ea13c3806f3 100644
--- a/include/asm-x86_64/floppy.h
+++ b/include/asm-x86/floppy_64.h
diff --git a/include/asm-x86_64/fpu32.h b/include/asm-x86/fpu32.h
index 4153db5c0c31..4153db5c0c31 100644
--- a/include/asm-x86_64/fpu32.h
+++ b/include/asm-x86/fpu32.h
diff --git a/include/asm-i386/frame.i b/include/asm-x86/frame.i
index 03620251ae17..03620251ae17 100644
--- a/include/asm-i386/frame.i
+++ b/include/asm-x86/frame.i
diff --git a/include/asm-x86/futex.h b/include/asm-x86/futex.h
new file mode 100644
index 000000000000..1f4610e0c613
--- /dev/null
+++ b/include/asm-x86/futex.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "futex_32.h"
3#else
4# include "futex_64.h"
5#endif
diff --git a/include/asm-i386/futex.h b/include/asm-x86/futex_32.h
index 438ef0ec7101..438ef0ec7101 100644
--- a/include/asm-i386/futex.h
+++ b/include/asm-x86/futex_32.h
diff --git a/include/asm-x86_64/futex.h b/include/asm-x86/futex_64.h
index 5cdfb08013c3..5cdfb08013c3 100644
--- a/include/asm-x86_64/futex.h
+++ b/include/asm-x86/futex_64.h
diff --git a/include/asm-x86/genapic.h b/include/asm-x86/genapic.h
new file mode 100644
index 000000000000..d48bee663a6f
--- /dev/null
+++ b/include/asm-x86/genapic.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "genapic_32.h"
3#else
4# include "genapic_64.h"
5#endif
diff --git a/include/asm-i386/genapic.h b/include/asm-x86/genapic_32.h
index 33e3ffe1766c..33e3ffe1766c 100644
--- a/include/asm-i386/genapic.h
+++ b/include/asm-x86/genapic_32.h
diff --git a/include/asm-x86_64/genapic.h b/include/asm-x86/genapic_64.h
index d7e516ccbaa4..d7e516ccbaa4 100644
--- a/include/asm-x86_64/genapic.h
+++ b/include/asm-x86/genapic_64.h
diff --git a/include/asm-i386/geode.h b/include/asm-x86/geode.h
index 6da4bbbea3dc..6da4bbbea3dc 100644
--- a/include/asm-i386/geode.h
+++ b/include/asm-x86/geode.h
diff --git a/include/asm-x86/hardirq.h b/include/asm-x86/hardirq.h
new file mode 100644
index 000000000000..314434d664e7
--- /dev/null
+++ b/include/asm-x86/hardirq.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "hardirq_32.h"
3#else
4# include "hardirq_64.h"
5#endif
diff --git a/include/asm-i386/hardirq.h b/include/asm-x86/hardirq_32.h
index 0e358dc405f8..0e358dc405f8 100644
--- a/include/asm-i386/hardirq.h
+++ b/include/asm-x86/hardirq_32.h
diff --git a/include/asm-x86_64/hardirq.h b/include/asm-x86/hardirq_64.h
index 95d5e090ed89..95d5e090ed89 100644
--- a/include/asm-x86_64/hardirq.h
+++ b/include/asm-x86/hardirq_64.h
diff --git a/include/asm-i386/highmem.h b/include/asm-x86/highmem.h
index 13cdcd66fff2..13cdcd66fff2 100644
--- a/include/asm-i386/highmem.h
+++ b/include/asm-x86/highmem.h
diff --git a/include/asm-x86/hpet.h b/include/asm-x86/hpet.h
new file mode 100644
index 000000000000..9eff48601254
--- /dev/null
+++ b/include/asm-x86/hpet.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "hpet_32.h"
3#else
4# include "hpet_64.h"
5#endif
diff --git a/include/asm-i386/hpet.h b/include/asm-x86/hpet_32.h
index c82dc7ed96b3..c82dc7ed96b3 100644
--- a/include/asm-i386/hpet.h
+++ b/include/asm-x86/hpet_32.h
diff --git a/include/asm-x86/hpet_64.h b/include/asm-x86/hpet_64.h
new file mode 100644
index 000000000000..fd4decac93a8
--- /dev/null
+++ b/include/asm-x86/hpet_64.h
@@ -0,0 +1,18 @@
1#ifndef _ASM_X8664_HPET_H
2#define _ASM_X8664_HPET_H 1
3
4#include <asm/hpet_32.h>
5
6#define HPET_TICK_RATE (HZ * 100000UL)
7
8extern int hpet_rtc_timer_init(void);
9extern int hpet_arch_init(void);
10extern int hpet_timer_stop_set_go(unsigned long tick);
11extern int hpet_reenable(void);
12extern unsigned int hpet_calibrate_tsc(void);
13
14extern int hpet_use_timer;
15extern unsigned long hpet_period;
16extern unsigned long hpet_tick;
17
18#endif
diff --git a/include/asm-x86/hw_irq.h b/include/asm-x86/hw_irq.h
new file mode 100644
index 000000000000..bf025399d939
--- /dev/null
+++ b/include/asm-x86/hw_irq.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "hw_irq_32.h"
3#else
4# include "hw_irq_64.h"
5#endif
diff --git a/include/asm-i386/hw_irq.h b/include/asm-x86/hw_irq_32.h
index 0bedbdf5e907..0bedbdf5e907 100644
--- a/include/asm-i386/hw_irq.h
+++ b/include/asm-x86/hw_irq_32.h
diff --git a/include/asm-x86_64/hw_irq.h b/include/asm-x86/hw_irq_64.h
index 09dfc18a6dd0..09dfc18a6dd0 100644
--- a/include/asm-x86_64/hw_irq.h
+++ b/include/asm-x86/hw_irq_64.h
diff --git a/include/asm-i386/hypertransport.h b/include/asm-x86/hypertransport.h
index c16c6ff4bdd7..c16c6ff4bdd7 100644
--- a/include/asm-i386/hypertransport.h
+++ b/include/asm-x86/hypertransport.h
diff --git a/include/asm-x86/i387.h b/include/asm-x86/i387.h
new file mode 100644
index 000000000000..a8bbed349664
--- /dev/null
+++ b/include/asm-x86/i387.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "i387_32.h"
3#else
4# include "i387_64.h"
5#endif
diff --git a/include/asm-i386/i387.h b/include/asm-x86/i387_32.h
index cdd1e248e3b4..cdd1e248e3b4 100644
--- a/include/asm-i386/i387.h
+++ b/include/asm-x86/i387_32.h
diff --git a/include/asm-x86_64/i387.h b/include/asm-x86/i387_64.h
index 0217b74cc9fc..0217b74cc9fc 100644
--- a/include/asm-x86_64/i387.h
+++ b/include/asm-x86/i387_64.h
diff --git a/include/asm-x86/i8253.h b/include/asm-x86/i8253.h
new file mode 100644
index 000000000000..b2a4f995a33f
--- /dev/null
+++ b/include/asm-x86/i8253.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "i8253_32.h"
3#else
4# include "i8253_64.h"
5#endif
diff --git a/include/asm-i386/i8253.h b/include/asm-x86/i8253_32.h
index 7577d058d86e..7577d058d86e 100644
--- a/include/asm-i386/i8253.h
+++ b/include/asm-x86/i8253_32.h
diff --git a/include/asm-x86_64/i8253.h b/include/asm-x86/i8253_64.h
index 015d8df07690..015d8df07690 100644
--- a/include/asm-x86_64/i8253.h
+++ b/include/asm-x86/i8253_64.h
diff --git a/include/asm-i386/i8259.h b/include/asm-x86/i8259.h
index 29d8f9a6b3fc..29d8f9a6b3fc 100644
--- a/include/asm-i386/i8259.h
+++ b/include/asm-x86/i8259.h
diff --git a/include/asm-x86_64/ia32.h b/include/asm-x86/ia32.h
index 0190b7c4e319..0190b7c4e319 100644
--- a/include/asm-x86_64/ia32.h
+++ b/include/asm-x86/ia32.h
diff --git a/include/asm-x86_64/ia32_unistd.h b/include/asm-x86/ia32_unistd.h
index 5b52ce507338..5b52ce507338 100644
--- a/include/asm-x86_64/ia32_unistd.h
+++ b/include/asm-x86/ia32_unistd.h
diff --git a/include/asm-i386/ide.h b/include/asm-x86/ide.h
index e7817a3d6578..e7817a3d6578 100644
--- a/include/asm-i386/ide.h
+++ b/include/asm-x86/ide.h
diff --git a/include/asm-x86_64/idle.h b/include/asm-x86/idle.h
index 6bd47dcf2067..6bd47dcf2067 100644
--- a/include/asm-x86_64/idle.h
+++ b/include/asm-x86/idle.h
diff --git a/include/asm-x86/intel_arch_perfmon.h b/include/asm-x86/intel_arch_perfmon.h
new file mode 100644
index 000000000000..4f6d4e6bf57e
--- /dev/null
+++ b/include/asm-x86/intel_arch_perfmon.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "intel_arch_perfmon_32.h"
3#else
4# include "intel_arch_perfmon_64.h"
5#endif
diff --git a/include/asm-i386/intel_arch_perfmon.h b/include/asm-x86/intel_arch_perfmon_32.h
index b52cd60a075b..b52cd60a075b 100644
--- a/include/asm-i386/intel_arch_perfmon.h
+++ b/include/asm-x86/intel_arch_perfmon_32.h
diff --git a/include/asm-x86_64/intel_arch_perfmon.h b/include/asm-x86/intel_arch_perfmon_64.h
index 8633331420ec..8633331420ec 100644
--- a/include/asm-x86_64/intel_arch_perfmon.h
+++ b/include/asm-x86/intel_arch_perfmon_64.h
diff --git a/include/asm-x86/io.h b/include/asm-x86/io.h
new file mode 100644
index 000000000000..5a58b176dd61
--- /dev/null
+++ b/include/asm-x86/io.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "io_32.h"
3#else
4# include "io_64.h"
5#endif
diff --git a/include/asm-i386/io.h b/include/asm-x86/io_32.h
index e8e0bd641120..e8e0bd641120 100644
--- a/include/asm-i386/io.h
+++ b/include/asm-x86/io_32.h
diff --git a/include/asm-x86_64/io.h b/include/asm-x86/io_64.h
index 7475095c5061..7475095c5061 100644
--- a/include/asm-x86_64/io.h
+++ b/include/asm-x86/io_64.h
diff --git a/include/asm-x86/io_apic.h b/include/asm-x86/io_apic.h
new file mode 100644
index 000000000000..88494966beeb
--- /dev/null
+++ b/include/asm-x86/io_apic.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "io_apic_32.h"
3#else
4# include "io_apic_64.h"
5#endif
diff --git a/include/asm-i386/io_apic.h b/include/asm-x86/io_apic_32.h
index dbe734ddf2af..dbe734ddf2af 100644
--- a/include/asm-i386/io_apic.h
+++ b/include/asm-x86/io_apic_32.h
diff --git a/include/asm-x86_64/io_apic.h b/include/asm-x86/io_apic_64.h
index d9f2e54324d5..d9f2e54324d5 100644
--- a/include/asm-x86_64/io_apic.h
+++ b/include/asm-x86/io_apic_64.h
diff --git a/include/asm-i386/ioctl.h b/include/asm-x86/ioctl.h
index b279fe06dfe5..b279fe06dfe5 100644
--- a/include/asm-i386/ioctl.h
+++ b/include/asm-x86/ioctl.h
diff --git a/include/asm-x86/ioctls.h b/include/asm-x86/ioctls.h
new file mode 100644
index 000000000000..1e0fd48f18bc
--- /dev/null
+++ b/include/asm-x86/ioctls.h
@@ -0,0 +1,13 @@
1#ifdef __KERNEL__
2# ifdef CONFIG_X86_32
3# include "ioctls_32.h"
4# else
5# include "ioctls_64.h"
6# endif
7#else
8# ifdef __i386__
9# include "ioctls_32.h"
10# else
11# include "ioctls_64.h"
12# endif
13#endif
diff --git a/include/asm-i386/ioctls.h b/include/asm-x86/ioctls_32.h
index ef5878762dc9..ef5878762dc9 100644
--- a/include/asm-i386/ioctls.h
+++ b/include/asm-x86/ioctls_32.h
diff --git a/include/asm-x86_64/ioctls.h b/include/asm-x86/ioctls_64.h
index 3fc0b15a0d7e..3fc0b15a0d7e 100644
--- a/include/asm-x86_64/ioctls.h
+++ b/include/asm-x86/ioctls_64.h
diff --git a/include/asm-x86_64/iommu.h b/include/asm-x86/iommu.h
index 5af471f228ee..5af471f228ee 100644
--- a/include/asm-x86_64/iommu.h
+++ b/include/asm-x86/iommu.h
diff --git a/include/asm-i386/ipc.h b/include/asm-x86/ipc.h
index a46e3d9c2a3f..a46e3d9c2a3f 100644
--- a/include/asm-i386/ipc.h
+++ b/include/asm-x86/ipc.h
diff --git a/include/asm-x86/ipcbuf.h b/include/asm-x86/ipcbuf.h
new file mode 100644
index 000000000000..eb2e448c6e28
--- /dev/null
+++ b/include/asm-x86/ipcbuf.h
@@ -0,0 +1,13 @@
1#ifdef __KERNEL__
2# ifdef CONFIG_X86_32
3# include "ipcbuf_32.h"
4# else
5# include "ipcbuf_64.h"
6# endif
7#else
8# ifdef __i386__
9# include "ipcbuf_32.h"
10# else
11# include "ipcbuf_64.h"
12# endif
13#endif
diff --git a/include/asm-i386/ipcbuf.h b/include/asm-x86/ipcbuf_32.h
index 0dcad4f84c2a..0dcad4f84c2a 100644
--- a/include/asm-i386/ipcbuf.h
+++ b/include/asm-x86/ipcbuf_32.h
diff --git a/include/asm-x86_64/ipcbuf.h b/include/asm-x86/ipcbuf_64.h
index 470cf85e3ba8..470cf85e3ba8 100644
--- a/include/asm-x86_64/ipcbuf.h
+++ b/include/asm-x86/ipcbuf_64.h
diff --git a/include/asm-x86_64/ipi.h b/include/asm-x86/ipi.h
index a7c75ea408a8..a7c75ea408a8 100644
--- a/include/asm-x86_64/ipi.h
+++ b/include/asm-x86/ipi.h
diff --git a/include/asm-x86/irq.h b/include/asm-x86/irq.h
new file mode 100644
index 000000000000..7ba905465a53
--- /dev/null
+++ b/include/asm-x86/irq.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "irq_32.h"
3#else
4# include "irq_64.h"
5#endif
diff --git a/include/asm-i386/irq.h b/include/asm-x86/irq_32.h
index 36f310632c49..36f310632c49 100644
--- a/include/asm-i386/irq.h
+++ b/include/asm-x86/irq_32.h
diff --git a/include/asm-x86_64/irq.h b/include/asm-x86/irq_64.h
index 5006c6e75656..5006c6e75656 100644
--- a/include/asm-x86_64/irq.h
+++ b/include/asm-x86/irq_64.h
diff --git a/include/asm-x86/irq_regs.h b/include/asm-x86/irq_regs.h
new file mode 100644
index 000000000000..89c898ab298b
--- /dev/null
+++ b/include/asm-x86/irq_regs.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "irq_regs_32.h"
3#else
4# include "irq_regs_64.h"
5#endif
diff --git a/include/asm-i386/irq_regs.h b/include/asm-x86/irq_regs_32.h
index 3368b20c0b48..3368b20c0b48 100644
--- a/include/asm-i386/irq_regs.h
+++ b/include/asm-x86/irq_regs_32.h
diff --git a/include/asm-x86_64/irq_regs.h b/include/asm-x86/irq_regs_64.h
index 3dd9c0b70270..3dd9c0b70270 100644
--- a/include/asm-x86_64/irq_regs.h
+++ b/include/asm-x86/irq_regs_64.h
diff --git a/include/asm-x86/irqflags.h b/include/asm-x86/irqflags.h
new file mode 100644
index 000000000000..1b695ff52687
--- /dev/null
+++ b/include/asm-x86/irqflags.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "irqflags_32.h"
3#else
4# include "irqflags_64.h"
5#endif
diff --git a/include/asm-i386/irqflags.h b/include/asm-x86/irqflags_32.h
index eff8585cb741..eff8585cb741 100644
--- a/include/asm-i386/irqflags.h
+++ b/include/asm-x86/irqflags_32.h
diff --git a/include/asm-x86_64/irqflags.h b/include/asm-x86/irqflags_64.h
index 86e70fe23659..86e70fe23659 100644
--- a/include/asm-x86_64/irqflags.h
+++ b/include/asm-x86/irqflags_64.h
diff --git a/include/asm-i386/ist.h b/include/asm-x86/ist.h
index ef2003ebc6f9..ef2003ebc6f9 100644
--- a/include/asm-i386/ist.h
+++ b/include/asm-x86/ist.h
diff --git a/include/asm-x86_64/k8.h b/include/asm-x86/k8.h
index 699dd6961eda..699dd6961eda 100644
--- a/include/asm-x86_64/k8.h
+++ b/include/asm-x86/k8.h
diff --git a/include/asm-x86/kdebug.h b/include/asm-x86/kdebug.h
new file mode 100644
index 000000000000..38479106c259
--- /dev/null
+++ b/include/asm-x86/kdebug.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "kdebug_32.h"
3#else
4# include "kdebug_64.h"
5#endif
diff --git a/include/asm-i386/kdebug.h b/include/asm-x86/kdebug_32.h
index a185b5f73e7f..a185b5f73e7f 100644
--- a/include/asm-i386/kdebug.h
+++ b/include/asm-x86/kdebug_32.h
diff --git a/include/asm-x86_64/kdebug.h b/include/asm-x86/kdebug_64.h
index d7e2bcf49e4f..d7e2bcf49e4f 100644
--- a/include/asm-x86_64/kdebug.h
+++ b/include/asm-x86/kdebug_64.h
diff --git a/include/asm-x86/kexec.h b/include/asm-x86/kexec.h
new file mode 100644
index 000000000000..718ddbfb9516
--- /dev/null
+++ b/include/asm-x86/kexec.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "kexec_32.h"
3#else
4# include "kexec_64.h"
5#endif
diff --git a/include/asm-i386/kexec.h b/include/asm-x86/kexec_32.h
index 4b9dc9e6b701..4b9dc9e6b701 100644
--- a/include/asm-i386/kexec.h
+++ b/include/asm-x86/kexec_32.h
diff --git a/include/asm-x86_64/kexec.h b/include/asm-x86/kexec_64.h
index 738e581b67f8..738e581b67f8 100644
--- a/include/asm-x86_64/kexec.h
+++ b/include/asm-x86/kexec_64.h
diff --git a/include/asm-x86/kmap_types.h b/include/asm-x86/kmap_types.h
new file mode 100644
index 000000000000..e4ec724b298e
--- /dev/null
+++ b/include/asm-x86/kmap_types.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "kmap_types_32.h"
3#else
4# include "kmap_types_64.h"
5#endif
diff --git a/include/asm-i386/kmap_types.h b/include/asm-x86/kmap_types_32.h
index 806aae3c5338..806aae3c5338 100644
--- a/include/asm-i386/kmap_types.h
+++ b/include/asm-x86/kmap_types_32.h
diff --git a/include/asm-x86_64/kmap_types.h b/include/asm-x86/kmap_types_64.h
index 7486338c6cea..7486338c6cea 100644
--- a/include/asm-x86_64/kmap_types.h
+++ b/include/asm-x86/kmap_types_64.h
diff --git a/include/asm-x86/kprobes.h b/include/asm-x86/kprobes.h
new file mode 100644
index 000000000000..b7bbd25ba2a6
--- /dev/null
+++ b/include/asm-x86/kprobes.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "kprobes_32.h"
3#else
4# include "kprobes_64.h"
5#endif
diff --git a/include/asm-i386/kprobes.h b/include/asm-x86/kprobes_32.h
index 06f7303c30ca..06f7303c30ca 100644
--- a/include/asm-i386/kprobes.h
+++ b/include/asm-x86/kprobes_32.h
diff --git a/include/asm-x86_64/kprobes.h b/include/asm-x86/kprobes_64.h
index 7db825403e01..7db825403e01 100644
--- a/include/asm-x86_64/kprobes.h
+++ b/include/asm-x86/kprobes_64.h
diff --git a/include/asm-x86/ldt.h b/include/asm-x86/ldt.h
new file mode 100644
index 000000000000..3d9cc20d2ba4
--- /dev/null
+++ b/include/asm-x86/ldt.h
@@ -0,0 +1,13 @@
1#ifdef __KERNEL__
2# ifdef CONFIG_X86_32
3# include "ldt_32.h"
4# else
5# include "ldt_64.h"
6# endif
7#else
8# ifdef __i386__
9# include "ldt_32.h"
10# else
11# include "ldt_64.h"
12# endif
13#endif
diff --git a/include/asm-i386/ldt.h b/include/asm-x86/ldt_32.h
index e9d3de1dee6c..e9d3de1dee6c 100644
--- a/include/asm-i386/ldt.h
+++ b/include/asm-x86/ldt_32.h
diff --git a/include/asm-x86_64/ldt.h b/include/asm-x86/ldt_64.h
index 9ef647b890d2..9ef647b890d2 100644
--- a/include/asm-x86_64/ldt.h
+++ b/include/asm-x86/ldt_64.h
diff --git a/include/asm-x86/linkage.h b/include/asm-x86/linkage.h
new file mode 100644
index 000000000000..94b257fa8701
--- /dev/null
+++ b/include/asm-x86/linkage.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "linkage_32.h"
3#else
4# include "linkage_64.h"
5#endif
diff --git a/include/asm-i386/linkage.h b/include/asm-x86/linkage_32.h
index f4a6ebac0247..f4a6ebac0247 100644
--- a/include/asm-i386/linkage.h
+++ b/include/asm-x86/linkage_32.h
diff --git a/include/asm-x86_64/linkage.h b/include/asm-x86/linkage_64.h
index b5f39d0189ce..b5f39d0189ce 100644
--- a/include/asm-x86_64/linkage.h
+++ b/include/asm-x86/linkage_64.h
diff --git a/include/asm-x86/local.h b/include/asm-x86/local.h
new file mode 100644
index 000000000000..c7a1b1c66c96
--- /dev/null
+++ b/include/asm-x86/local.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "local_32.h"
3#else
4# include "local_64.h"
5#endif
diff --git a/include/asm-i386/local.h b/include/asm-x86/local_32.h
index 6e85975b9ed2..6e85975b9ed2 100644
--- a/include/asm-i386/local.h
+++ b/include/asm-x86/local_32.h
diff --git a/include/asm-x86_64/local.h b/include/asm-x86/local_64.h
index e87492bb0693..e87492bb0693 100644
--- a/include/asm-x86_64/local.h
+++ b/include/asm-x86/local_64.h
diff --git a/include/asm-i386/mach-bigsmp/mach_apic.h b/include/asm-x86/mach-bigsmp/mach_apic.h
index ebd319f838ab..ebd319f838ab 100644
--- a/include/asm-i386/mach-bigsmp/mach_apic.h
+++ b/include/asm-x86/mach-bigsmp/mach_apic.h
diff --git a/include/asm-i386/mach-bigsmp/mach_apicdef.h b/include/asm-x86/mach-bigsmp/mach_apicdef.h
index a58ab5a75c8c..a58ab5a75c8c 100644
--- a/include/asm-i386/mach-bigsmp/mach_apicdef.h
+++ b/include/asm-x86/mach-bigsmp/mach_apicdef.h
diff --git a/include/asm-i386/mach-bigsmp/mach_ipi.h b/include/asm-x86/mach-bigsmp/mach_ipi.h
index 9404c535b7ec..9404c535b7ec 100644
--- a/include/asm-i386/mach-bigsmp/mach_ipi.h
+++ b/include/asm-x86/mach-bigsmp/mach_ipi.h
diff --git a/include/asm-i386/mach-bigsmp/mach_mpspec.h b/include/asm-x86/mach-bigsmp/mach_mpspec.h
index 6b5dadcf1d0e..6b5dadcf1d0e 100644
--- a/include/asm-i386/mach-bigsmp/mach_mpspec.h
+++ b/include/asm-x86/mach-bigsmp/mach_mpspec.h
diff --git a/include/asm-i386/mach-default/apm.h b/include/asm-x86/mach-default/apm.h
index 1f730b8bd1fd..1f730b8bd1fd 100644
--- a/include/asm-i386/mach-default/apm.h
+++ b/include/asm-x86/mach-default/apm.h
diff --git a/include/asm-i386/mach-default/bios_ebda.h b/include/asm-x86/mach-default/bios_ebda.h
index 9cbd9a668af8..9cbd9a668af8 100644
--- a/include/asm-i386/mach-default/bios_ebda.h
+++ b/include/asm-x86/mach-default/bios_ebda.h
diff --git a/include/asm-i386/mach-default/do_timer.h b/include/asm-x86/mach-default/do_timer.h
index 23ecda0b28a0..23ecda0b28a0 100644
--- a/include/asm-i386/mach-default/do_timer.h
+++ b/include/asm-x86/mach-default/do_timer.h
diff --git a/include/asm-i386/mach-default/entry_arch.h b/include/asm-x86/mach-default/entry_arch.h
index bc861469bdba..bc861469bdba 100644
--- a/include/asm-i386/mach-default/entry_arch.h
+++ b/include/asm-x86/mach-default/entry_arch.h
diff --git a/include/asm-i386/mach-default/io_ports.h b/include/asm-x86/mach-default/io_ports.h
index 48540ba97166..48540ba97166 100644
--- a/include/asm-i386/mach-default/io_ports.h
+++ b/include/asm-x86/mach-default/io_ports.h
diff --git a/include/asm-i386/mach-default/irq_vectors.h b/include/asm-x86/mach-default/irq_vectors.h
index 881c63ca61ad..881c63ca61ad 100644
--- a/include/asm-i386/mach-default/irq_vectors.h
+++ b/include/asm-x86/mach-default/irq_vectors.h
diff --git a/include/asm-i386/mach-default/irq_vectors_limits.h b/include/asm-x86/mach-default/irq_vectors_limits.h
index a90c7a60109f..a90c7a60109f 100644
--- a/include/asm-i386/mach-default/irq_vectors_limits.h
+++ b/include/asm-x86/mach-default/irq_vectors_limits.h
diff --git a/include/asm-i386/mach-default/mach_apic.h b/include/asm-x86/mach-default/mach_apic.h
index 6db1c3babe9a..6db1c3babe9a 100644
--- a/include/asm-i386/mach-default/mach_apic.h
+++ b/include/asm-x86/mach-default/mach_apic.h
diff --git a/include/asm-i386/mach-default/mach_apicdef.h b/include/asm-x86/mach-default/mach_apicdef.h
index 7bcb350c3ee8..7bcb350c3ee8 100644
--- a/include/asm-i386/mach-default/mach_apicdef.h
+++ b/include/asm-x86/mach-default/mach_apicdef.h
diff --git a/include/asm-i386/mach-default/mach_ipi.h b/include/asm-x86/mach-default/mach_ipi.h
index 0dba244c86db..0dba244c86db 100644
--- a/include/asm-i386/mach-default/mach_ipi.h
+++ b/include/asm-x86/mach-default/mach_ipi.h
diff --git a/include/asm-i386/mach-default/mach_mpparse.h b/include/asm-x86/mach-default/mach_mpparse.h
index 1d3832482580..1d3832482580 100644
--- a/include/asm-i386/mach-default/mach_mpparse.h
+++ b/include/asm-x86/mach-default/mach_mpparse.h
diff --git a/include/asm-i386/mach-default/mach_mpspec.h b/include/asm-x86/mach-default/mach_mpspec.h
index 51c9a9775932..51c9a9775932 100644
--- a/include/asm-i386/mach-default/mach_mpspec.h
+++ b/include/asm-x86/mach-default/mach_mpspec.h
diff --git a/include/asm-i386/mach-default/mach_reboot.h b/include/asm-x86/mach-default/mach_reboot.h
index e23fd9fbebb3..e23fd9fbebb3 100644
--- a/include/asm-i386/mach-default/mach_reboot.h
+++ b/include/asm-x86/mach-default/mach_reboot.h
diff --git a/include/asm-i386/mach-default/mach_time.h b/include/asm-x86/mach-default/mach_time.h
index 31eb5de6f3dc..31eb5de6f3dc 100644
--- a/include/asm-i386/mach-default/mach_time.h
+++ b/include/asm-x86/mach-default/mach_time.h
diff --git a/include/asm-i386/mach-default/mach_timer.h b/include/asm-x86/mach-default/mach_timer.h
index 807992fd4171..807992fd4171 100644
--- a/include/asm-i386/mach-default/mach_timer.h
+++ b/include/asm-x86/mach-default/mach_timer.h
diff --git a/include/asm-i386/mach-default/mach_traps.h b/include/asm-x86/mach-default/mach_traps.h
index 625438b8a6eb..625438b8a6eb 100644
--- a/include/asm-i386/mach-default/mach_traps.h
+++ b/include/asm-x86/mach-default/mach_traps.h
diff --git a/include/asm-i386/mach-default/mach_wakecpu.h b/include/asm-x86/mach-default/mach_wakecpu.h
index 3ebb17893aa5..3ebb17893aa5 100644
--- a/include/asm-i386/mach-default/mach_wakecpu.h
+++ b/include/asm-x86/mach-default/mach_wakecpu.h
diff --git a/include/asm-i386/mach-default/pci-functions.h b/include/asm-x86/mach-default/pci-functions.h
index ed0bab427354..ed0bab427354 100644
--- a/include/asm-i386/mach-default/pci-functions.h
+++ b/include/asm-x86/mach-default/pci-functions.h
diff --git a/include/asm-i386/mach-default/setup_arch.h b/include/asm-x86/mach-default/setup_arch.h
index 605e3ccb991b..605e3ccb991b 100644
--- a/include/asm-i386/mach-default/setup_arch.h
+++ b/include/asm-x86/mach-default/setup_arch.h
diff --git a/include/asm-i386/mach-default/smpboot_hooks.h b/include/asm-x86/mach-default/smpboot_hooks.h
index 7f45f6311059..7f45f6311059 100644
--- a/include/asm-i386/mach-default/smpboot_hooks.h
+++ b/include/asm-x86/mach-default/smpboot_hooks.h
diff --git a/include/asm-i386/mach-es7000/mach_apic.h b/include/asm-x86/mach-es7000/mach_apic.h
index caec64be516d..caec64be516d 100644
--- a/include/asm-i386/mach-es7000/mach_apic.h
+++ b/include/asm-x86/mach-es7000/mach_apic.h
diff --git a/include/asm-i386/mach-es7000/mach_apicdef.h b/include/asm-x86/mach-es7000/mach_apicdef.h
index a58ab5a75c8c..a58ab5a75c8c 100644
--- a/include/asm-i386/mach-es7000/mach_apicdef.h
+++ b/include/asm-x86/mach-es7000/mach_apicdef.h
diff --git a/include/asm-i386/mach-es7000/mach_ipi.h b/include/asm-x86/mach-es7000/mach_ipi.h
index 5e61bd220b06..5e61bd220b06 100644
--- a/include/asm-i386/mach-es7000/mach_ipi.h
+++ b/include/asm-x86/mach-es7000/mach_ipi.h
diff --git a/include/asm-i386/mach-es7000/mach_mpparse.h b/include/asm-x86/mach-es7000/mach_mpparse.h
index 8aa10547b4b1..8aa10547b4b1 100644
--- a/include/asm-i386/mach-es7000/mach_mpparse.h
+++ b/include/asm-x86/mach-es7000/mach_mpparse.h
diff --git a/include/asm-i386/mach-es7000/mach_mpspec.h b/include/asm-x86/mach-es7000/mach_mpspec.h
index b1f5039d4506..b1f5039d4506 100644
--- a/include/asm-i386/mach-es7000/mach_mpspec.h
+++ b/include/asm-x86/mach-es7000/mach_mpspec.h
diff --git a/include/asm-i386/mach-es7000/mach_wakecpu.h b/include/asm-x86/mach-es7000/mach_wakecpu.h
index 84ff58314501..84ff58314501 100644
--- a/include/asm-i386/mach-es7000/mach_wakecpu.h
+++ b/include/asm-x86/mach-es7000/mach_wakecpu.h
diff --git a/include/asm-i386/mach-generic/irq_vectors_limits.h b/include/asm-x86/mach-generic/irq_vectors_limits.h
index 890ce3f5e09a..890ce3f5e09a 100644
--- a/include/asm-i386/mach-generic/irq_vectors_limits.h
+++ b/include/asm-x86/mach-generic/irq_vectors_limits.h
diff --git a/include/asm-i386/mach-generic/mach_apic.h b/include/asm-x86/mach-generic/mach_apic.h
index a236e7021528..a236e7021528 100644
--- a/include/asm-i386/mach-generic/mach_apic.h
+++ b/include/asm-x86/mach-generic/mach_apic.h
diff --git a/include/asm-i386/mach-generic/mach_apicdef.h b/include/asm-x86/mach-generic/mach_apicdef.h
index 28ed98972ca8..28ed98972ca8 100644
--- a/include/asm-i386/mach-generic/mach_apicdef.h
+++ b/include/asm-x86/mach-generic/mach_apicdef.h
diff --git a/include/asm-i386/mach-generic/mach_ipi.h b/include/asm-x86/mach-generic/mach_ipi.h
index 441b0fe3ed1d..441b0fe3ed1d 100644
--- a/include/asm-i386/mach-generic/mach_ipi.h
+++ b/include/asm-x86/mach-generic/mach_ipi.h
diff --git a/include/asm-i386/mach-generic/mach_mpparse.h b/include/asm-x86/mach-generic/mach_mpparse.h
index dbd9fce54f4d..dbd9fce54f4d 100644
--- a/include/asm-i386/mach-generic/mach_mpparse.h
+++ b/include/asm-x86/mach-generic/mach_mpparse.h
diff --git a/include/asm-i386/mach-generic/mach_mpspec.h b/include/asm-x86/mach-generic/mach_mpspec.h
index 9ef0b941bb22..9ef0b941bb22 100644
--- a/include/asm-i386/mach-generic/mach_mpspec.h
+++ b/include/asm-x86/mach-generic/mach_mpspec.h
diff --git a/include/asm-i386/mach-numaq/mach_apic.h b/include/asm-x86/mach-numaq/mach_apic.h
index 5e5e7dd2692e..5e5e7dd2692e 100644
--- a/include/asm-i386/mach-numaq/mach_apic.h
+++ b/include/asm-x86/mach-numaq/mach_apic.h
diff --git a/include/asm-i386/mach-numaq/mach_apicdef.h b/include/asm-x86/mach-numaq/mach_apicdef.h
index bf439d0690f5..bf439d0690f5 100644
--- a/include/asm-i386/mach-numaq/mach_apicdef.h
+++ b/include/asm-x86/mach-numaq/mach_apicdef.h
diff --git a/include/asm-i386/mach-numaq/mach_ipi.h b/include/asm-x86/mach-numaq/mach_ipi.h
index c6044488e9e6..c6044488e9e6 100644
--- a/include/asm-i386/mach-numaq/mach_ipi.h
+++ b/include/asm-x86/mach-numaq/mach_ipi.h
diff --git a/include/asm-i386/mach-numaq/mach_mpparse.h b/include/asm-x86/mach-numaq/mach_mpparse.h
index 51bbac8fc0c2..51bbac8fc0c2 100644
--- a/include/asm-i386/mach-numaq/mach_mpparse.h
+++ b/include/asm-x86/mach-numaq/mach_mpparse.h
diff --git a/include/asm-i386/mach-numaq/mach_mpspec.h b/include/asm-x86/mach-numaq/mach_mpspec.h
index dffb09856f8f..dffb09856f8f 100644
--- a/include/asm-i386/mach-numaq/mach_mpspec.h
+++ b/include/asm-x86/mach-numaq/mach_mpspec.h
diff --git a/include/asm-i386/mach-numaq/mach_wakecpu.h b/include/asm-x86/mach-numaq/mach_wakecpu.h
index 00530041a991..00530041a991 100644
--- a/include/asm-i386/mach-numaq/mach_wakecpu.h
+++ b/include/asm-x86/mach-numaq/mach_wakecpu.h
diff --git a/include/asm-i386/mach-summit/irq_vectors_limits.h b/include/asm-x86/mach-summit/irq_vectors_limits.h
index 890ce3f5e09a..890ce3f5e09a 100644
--- a/include/asm-i386/mach-summit/irq_vectors_limits.h
+++ b/include/asm-x86/mach-summit/irq_vectors_limits.h
diff --git a/include/asm-i386/mach-summit/mach_apic.h b/include/asm-x86/mach-summit/mach_apic.h
index 732f776aab8e..732f776aab8e 100644
--- a/include/asm-i386/mach-summit/mach_apic.h
+++ b/include/asm-x86/mach-summit/mach_apic.h
diff --git a/include/asm-i386/mach-summit/mach_apicdef.h b/include/asm-x86/mach-summit/mach_apicdef.h
index a58ab5a75c8c..a58ab5a75c8c 100644
--- a/include/asm-i386/mach-summit/mach_apicdef.h
+++ b/include/asm-x86/mach-summit/mach_apicdef.h
diff --git a/include/asm-i386/mach-summit/mach_ipi.h b/include/asm-x86/mach-summit/mach_ipi.h
index 9404c535b7ec..9404c535b7ec 100644
--- a/include/asm-i386/mach-summit/mach_ipi.h
+++ b/include/asm-x86/mach-summit/mach_ipi.h
diff --git a/include/asm-i386/mach-summit/mach_mpparse.h b/include/asm-x86/mach-summit/mach_mpparse.h
index c2520539d934..c2520539d934 100644
--- a/include/asm-i386/mach-summit/mach_mpparse.h
+++ b/include/asm-x86/mach-summit/mach_mpparse.h
diff --git a/include/asm-i386/mach-summit/mach_mpspec.h b/include/asm-x86/mach-summit/mach_mpspec.h
index bd765523511a..bd765523511a 100644
--- a/include/asm-i386/mach-summit/mach_mpspec.h
+++ b/include/asm-x86/mach-summit/mach_mpspec.h
diff --git a/include/asm-i386/mach-visws/cobalt.h b/include/asm-x86/mach-visws/cobalt.h
index 33c36225a042..33c36225a042 100644
--- a/include/asm-i386/mach-visws/cobalt.h
+++ b/include/asm-x86/mach-visws/cobalt.h
diff --git a/include/asm-i386/mach-visws/entry_arch.h b/include/asm-x86/mach-visws/entry_arch.h
index b183fa6d83d9..b183fa6d83d9 100644
--- a/include/asm-i386/mach-visws/entry_arch.h
+++ b/include/asm-x86/mach-visws/entry_arch.h
diff --git a/include/asm-i386/mach-visws/irq_vectors.h b/include/asm-x86/mach-visws/irq_vectors.h
index cb572d8db505..cb572d8db505 100644
--- a/include/asm-i386/mach-visws/irq_vectors.h
+++ b/include/asm-x86/mach-visws/irq_vectors.h
diff --git a/include/asm-i386/mach-visws/lithium.h b/include/asm-x86/mach-visws/lithium.h
index d443e68d0066..d443e68d0066 100644
--- a/include/asm-i386/mach-visws/lithium.h
+++ b/include/asm-x86/mach-visws/lithium.h
diff --git a/include/asm-i386/mach-visws/mach_apic.h b/include/asm-x86/mach-visws/mach_apic.h
index efac6f0d139f..efac6f0d139f 100644
--- a/include/asm-i386/mach-visws/mach_apic.h
+++ b/include/asm-x86/mach-visws/mach_apic.h
diff --git a/include/asm-i386/mach-visws/mach_apicdef.h b/include/asm-x86/mach-visws/mach_apicdef.h
index 826cfa97d778..826cfa97d778 100644
--- a/include/asm-i386/mach-visws/mach_apicdef.h
+++ b/include/asm-x86/mach-visws/mach_apicdef.h
diff --git a/include/asm-i386/mach-visws/piix4.h b/include/asm-x86/mach-visws/piix4.h
index 83ea4f46e419..83ea4f46e419 100644
--- a/include/asm-i386/mach-visws/piix4.h
+++ b/include/asm-x86/mach-visws/piix4.h
diff --git a/include/asm-i386/mach-visws/setup_arch.h b/include/asm-x86/mach-visws/setup_arch.h
index 33f700ef6831..33f700ef6831 100644
--- a/include/asm-i386/mach-visws/setup_arch.h
+++ b/include/asm-x86/mach-visws/setup_arch.h
diff --git a/include/asm-i386/mach-visws/smpboot_hooks.h b/include/asm-x86/mach-visws/smpboot_hooks.h
index d926471fa359..d926471fa359 100644
--- a/include/asm-i386/mach-visws/smpboot_hooks.h
+++ b/include/asm-x86/mach-visws/smpboot_hooks.h
diff --git a/include/asm-i386/mach-voyager/do_timer.h b/include/asm-x86/mach-voyager/do_timer.h
index bc2b58926308..bc2b58926308 100644
--- a/include/asm-i386/mach-voyager/do_timer.h
+++ b/include/asm-x86/mach-voyager/do_timer.h
diff --git a/include/asm-i386/mach-voyager/entry_arch.h b/include/asm-x86/mach-voyager/entry_arch.h
index 4a1e1e8c10b6..4a1e1e8c10b6 100644
--- a/include/asm-i386/mach-voyager/entry_arch.h
+++ b/include/asm-x86/mach-voyager/entry_arch.h
diff --git a/include/asm-i386/mach-voyager/irq_vectors.h b/include/asm-x86/mach-voyager/irq_vectors.h
index 165421f5821c..165421f5821c 100644
--- a/include/asm-i386/mach-voyager/irq_vectors.h
+++ b/include/asm-x86/mach-voyager/irq_vectors.h
diff --git a/include/asm-i386/mach-voyager/setup_arch.h b/include/asm-x86/mach-voyager/setup_arch.h
index 84d01ad33459..84d01ad33459 100644
--- a/include/asm-i386/mach-voyager/setup_arch.h
+++ b/include/asm-x86/mach-voyager/setup_arch.h
diff --git a/include/asm-x86_64/mach_apic.h b/include/asm-x86/mach_apic.h
index 7b7115a0c1c9..7b7115a0c1c9 100644
--- a/include/asm-x86_64/mach_apic.h
+++ b/include/asm-x86/mach_apic.h
diff --git a/include/asm-i386/math_emu.h b/include/asm-x86/math_emu.h
index a4b0aa3320e6..a4b0aa3320e6 100644
--- a/include/asm-i386/math_emu.h
+++ b/include/asm-x86/math_emu.h
diff --git a/include/asm-x86/mc146818rtc.h b/include/asm-x86/mc146818rtc.h
new file mode 100644
index 000000000000..5c2bb66caf17
--- /dev/null
+++ b/include/asm-x86/mc146818rtc.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "mc146818rtc_32.h"
3#else
4# include "mc146818rtc_64.h"
5#endif
diff --git a/include/asm-i386/mc146818rtc.h b/include/asm-x86/mc146818rtc_32.h
index 1613b42eaf58..1613b42eaf58 100644
--- a/include/asm-i386/mc146818rtc.h
+++ b/include/asm-x86/mc146818rtc_32.h
diff --git a/include/asm-x86_64/mc146818rtc.h b/include/asm-x86/mc146818rtc_64.h
index d6e3009430c1..d6e3009430c1 100644
--- a/include/asm-x86_64/mc146818rtc.h
+++ b/include/asm-x86/mc146818rtc_64.h
diff --git a/include/asm-i386/mca.h b/include/asm-x86/mca.h
index 09adf2eac4dc..09adf2eac4dc 100644
--- a/include/asm-i386/mca.h
+++ b/include/asm-x86/mca.h
diff --git a/include/asm-i386/mca_dma.h b/include/asm-x86/mca_dma.h
index fbb1f3b71279..fbb1f3b71279 100644
--- a/include/asm-i386/mca_dma.h
+++ b/include/asm-x86/mca_dma.h
diff --git a/include/asm-x86/mce.h b/include/asm-x86/mce.h
new file mode 100644
index 000000000000..cc8ca389912e
--- /dev/null
+++ b/include/asm-x86/mce.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "mce_32.h"
3#else
4# include "mce_64.h"
5#endif
diff --git a/include/asm-i386/mce.h b/include/asm-x86/mce_32.h
index d56d89742e8f..d56d89742e8f 100644
--- a/include/asm-i386/mce.h
+++ b/include/asm-x86/mce_32.h
diff --git a/include/asm-x86_64/mce.h b/include/asm-x86/mce_64.h
index 7bc030a1996d..7bc030a1996d 100644
--- a/include/asm-x86_64/mce.h
+++ b/include/asm-x86/mce_64.h
diff --git a/include/asm-x86/mman.h b/include/asm-x86/mman.h
new file mode 100644
index 000000000000..322db07e82c3
--- /dev/null
+++ b/include/asm-x86/mman.h
@@ -0,0 +1,13 @@
1#ifdef __KERNEL__
2# ifdef CONFIG_X86_32
3# include "mman_32.h"
4# else
5# include "mman_64.h"
6# endif
7#else
8# ifdef __i386__
9# include "mman_32.h"
10# else
11# include "mman_64.h"
12# endif
13#endif
diff --git a/include/asm-i386/mman.h b/include/asm-x86/mman_32.h
index 8fd9d7ab7faf..8fd9d7ab7faf 100644
--- a/include/asm-i386/mman.h
+++ b/include/asm-x86/mman_32.h
diff --git a/include/asm-x86_64/mman.h b/include/asm-x86/mman_64.h
index dd5cb0534d37..dd5cb0534d37 100644
--- a/include/asm-x86_64/mman.h
+++ b/include/asm-x86/mman_64.h
diff --git a/include/asm-x86_64/mmsegment.h b/include/asm-x86/mmsegment.h
index d3f80c996330..d3f80c996330 100644
--- a/include/asm-x86_64/mmsegment.h
+++ b/include/asm-x86/mmsegment.h
diff --git a/include/asm-x86/mmu.h b/include/asm-x86/mmu.h
new file mode 100644
index 000000000000..9c628cd70e23
--- /dev/null
+++ b/include/asm-x86/mmu.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "mmu_32.h"
3#else
4# include "mmu_64.h"
5#endif
diff --git a/include/asm-i386/mmu.h b/include/asm-x86/mmu_32.h
index 8358dd3df7aa..8358dd3df7aa 100644
--- a/include/asm-i386/mmu.h
+++ b/include/asm-x86/mmu_32.h
diff --git a/include/asm-x86_64/mmu.h b/include/asm-x86/mmu_64.h
index d2cd4a9d984d..d2cd4a9d984d 100644
--- a/include/asm-x86_64/mmu.h
+++ b/include/asm-x86/mmu_64.h
diff --git a/include/asm-x86/mmu_context.h b/include/asm-x86/mmu_context.h
new file mode 100644
index 000000000000..6598450da6c6
--- /dev/null
+++ b/include/asm-x86/mmu_context.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "mmu_context_32.h"
3#else
4# include "mmu_context_64.h"
5#endif
diff --git a/include/asm-i386/mmu_context.h b/include/asm-x86/mmu_context_32.h
index 7eb0b0b1fb3c..7eb0b0b1fb3c 100644
--- a/include/asm-i386/mmu_context.h
+++ b/include/asm-x86/mmu_context_32.h
diff --git a/include/asm-x86_64/mmu_context.h b/include/asm-x86/mmu_context_64.h
index 0cce83a78378..0cce83a78378 100644
--- a/include/asm-x86_64/mmu_context.h
+++ b/include/asm-x86/mmu_context_64.h
diff --git a/include/asm-i386/mmx.h b/include/asm-x86/mmx.h
index 46b71da99869..46b71da99869 100644
--- a/include/asm-i386/mmx.h
+++ b/include/asm-x86/mmx.h
diff --git a/include/asm-x86/mmzone.h b/include/asm-x86/mmzone.h
new file mode 100644
index 000000000000..64217ea16a36
--- /dev/null
+++ b/include/asm-x86/mmzone.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "mmzone_32.h"
3#else
4# include "mmzone_64.h"
5#endif
diff --git a/include/asm-i386/mmzone.h b/include/asm-x86/mmzone_32.h
index 118e9812778f..118e9812778f 100644
--- a/include/asm-i386/mmzone.h
+++ b/include/asm-x86/mmzone_32.h
diff --git a/include/asm-x86_64/mmzone.h b/include/asm-x86/mmzone_64.h
index 19a89377b123..19a89377b123 100644
--- a/include/asm-x86_64/mmzone.h
+++ b/include/asm-x86/mmzone_64.h
diff --git a/include/asm-x86/module.h b/include/asm-x86/module.h
new file mode 100644
index 000000000000..2b2f18d8a531
--- /dev/null
+++ b/include/asm-x86/module.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "module_32.h"
3#else
4# include "module_64.h"
5#endif
diff --git a/include/asm-i386/module.h b/include/asm-x86/module_32.h
index 7e5fda6c3976..7e5fda6c3976 100644
--- a/include/asm-i386/module.h
+++ b/include/asm-x86/module_32.h
diff --git a/include/asm-x86_64/module.h b/include/asm-x86/module_64.h
index 67f8f69fa7b1..67f8f69fa7b1 100644
--- a/include/asm-x86_64/module.h
+++ b/include/asm-x86/module_64.h
diff --git a/include/asm-x86/mpspec.h b/include/asm-x86/mpspec.h
new file mode 100644
index 000000000000..8f268e8fd2e9
--- /dev/null
+++ b/include/asm-x86/mpspec.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "mpspec_32.h"
3#else
4# include "mpspec_64.h"
5#endif
diff --git a/include/asm-i386/mpspec.h b/include/asm-x86/mpspec_32.h
index f21349399d14..f21349399d14 100644
--- a/include/asm-i386/mpspec.h
+++ b/include/asm-x86/mpspec_32.h
diff --git a/include/asm-x86_64/mpspec.h b/include/asm-x86/mpspec_64.h
index 017fddb61dc5..017fddb61dc5 100644
--- a/include/asm-x86_64/mpspec.h
+++ b/include/asm-x86/mpspec_64.h
diff --git a/include/asm-i386/mpspec_def.h b/include/asm-x86/mpspec_def.h
index 13bafb16e7af..13bafb16e7af 100644
--- a/include/asm-i386/mpspec_def.h
+++ b/include/asm-x86/mpspec_def.h
diff --git a/include/asm-x86/msgbuf.h b/include/asm-x86/msgbuf.h
new file mode 100644
index 000000000000..154f7d64e862
--- /dev/null
+++ b/include/asm-x86/msgbuf.h
@@ -0,0 +1,13 @@
1#ifdef __KERNEL__
2# ifdef CONFIG_X86_32
3# include "msgbuf_32.h"
4# else
5# include "msgbuf_64.h"
6# endif
7#else
8# ifdef __i386__
9# include "msgbuf_32.h"
10# else
11# include "msgbuf_64.h"
12# endif
13#endif
diff --git a/include/asm-i386/msgbuf.h b/include/asm-x86/msgbuf_32.h
index b8d659c157ae..b8d659c157ae 100644
--- a/include/asm-i386/msgbuf.h
+++ b/include/asm-x86/msgbuf_32.h
diff --git a/include/asm-x86_64/msgbuf.h b/include/asm-x86/msgbuf_64.h
index cd6f95dd54da..cd6f95dd54da 100644
--- a/include/asm-x86_64/msgbuf.h
+++ b/include/asm-x86/msgbuf_64.h
diff --git a/include/asm-i386/msidef.h b/include/asm-x86/msidef.h
index 5b8acddb70fb..5b8acddb70fb 100644
--- a/include/asm-i386/msidef.h
+++ b/include/asm-x86/msidef.h
diff --git a/include/asm-i386/msr-index.h b/include/asm-x86/msr-index.h
index a02eb2991349..a02eb2991349 100644
--- a/include/asm-i386/msr-index.h
+++ b/include/asm-x86/msr-index.h
diff --git a/include/asm-x86/msr.h b/include/asm-x86/msr.h
new file mode 100644
index 000000000000..2f87ce007002
--- /dev/null
+++ b/include/asm-x86/msr.h
@@ -0,0 +1,13 @@
1#ifdef __KERNEL__
2# ifdef CONFIG_X86_32
3# include "msr_32.h"
4# else
5# include "msr_64.h"
6# endif
7#else
8# ifdef __i386__
9# include "msr_32.h"
10# else
11# include "msr_64.h"
12# endif
13#endif
diff --git a/include/asm-i386/msr.h b/include/asm-x86/msr_32.h
index df21ea049369..df21ea049369 100644
--- a/include/asm-i386/msr.h
+++ b/include/asm-x86/msr_32.h
diff --git a/include/asm-x86_64/msr.h b/include/asm-x86/msr_64.h
index d5c55b80da54..d5c55b80da54 100644
--- a/include/asm-x86_64/msr.h
+++ b/include/asm-x86/msr_64.h
diff --git a/include/asm-x86/mtrr.h b/include/asm-x86/mtrr.h
new file mode 100644
index 000000000000..34f633b3e00c
--- /dev/null
+++ b/include/asm-x86/mtrr.h
@@ -0,0 +1,13 @@
1#ifdef __KERNEL__
2# ifdef CONFIG_X86_32
3# include "mtrr_32.h"
4# else
5# include "mtrr_64.h"
6# endif
7#else
8# ifdef __i386__
9# include "mtrr_32.h"
10# else
11# include "mtrr_64.h"
12# endif
13#endif
diff --git a/include/asm-i386/mtrr.h b/include/asm-x86/mtrr_32.h
index 7e9c7ccbdcfe..7e9c7ccbdcfe 100644
--- a/include/asm-i386/mtrr.h
+++ b/include/asm-x86/mtrr_32.h
diff --git a/include/asm-x86_64/mtrr.h b/include/asm-x86/mtrr_64.h
index b557c486bef8..b557c486bef8 100644
--- a/include/asm-x86_64/mtrr.h
+++ b/include/asm-x86/mtrr_64.h
diff --git a/include/asm-x86/mutex.h b/include/asm-x86/mutex.h
new file mode 100644
index 000000000000..a731b9c573a6
--- /dev/null
+++ b/include/asm-x86/mutex.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "mutex_32.h"
3#else
4# include "mutex_64.h"
5#endif
diff --git a/include/asm-i386/mutex.h b/include/asm-x86/mutex_32.h
index 7a17d9e58ad6..7a17d9e58ad6 100644
--- a/include/asm-i386/mutex.h
+++ b/include/asm-x86/mutex_32.h
diff --git a/include/asm-x86_64/mutex.h b/include/asm-x86/mutex_64.h
index 6c2949a3c677..6c2949a3c677 100644
--- a/include/asm-x86_64/mutex.h
+++ b/include/asm-x86/mutex_64.h
diff --git a/include/asm-x86/namei.h b/include/asm-x86/namei.h
new file mode 100644
index 000000000000..732f8f0b3dcd
--- /dev/null
+++ b/include/asm-x86/namei.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "namei_32.h"
3#else
4# include "namei_64.h"
5#endif
diff --git a/include/asm-i386/namei.h b/include/asm-x86/namei_32.h
index 814865088617..814865088617 100644
--- a/include/asm-i386/namei.h
+++ b/include/asm-x86/namei_32.h
diff --git a/include/asm-x86_64/namei.h b/include/asm-x86/namei_64.h
index bef239f5318f..bef239f5318f 100644
--- a/include/asm-x86_64/namei.h
+++ b/include/asm-x86/namei_64.h
diff --git a/include/asm-x86/nmi.h b/include/asm-x86/nmi.h
new file mode 100644
index 000000000000..53ccac14cead
--- /dev/null
+++ b/include/asm-x86/nmi.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "nmi_32.h"
3#else
4# include "nmi_64.h"
5#endif
diff --git a/include/asm-i386/nmi.h b/include/asm-x86/nmi_32.h
index 70a958a8e381..70a958a8e381 100644
--- a/include/asm-i386/nmi.h
+++ b/include/asm-x86/nmi_32.h
diff --git a/include/asm-x86_64/nmi.h b/include/asm-x86/nmi_64.h
index 65b6acf3bb59..65b6acf3bb59 100644
--- a/include/asm-x86_64/nmi.h
+++ b/include/asm-x86/nmi_64.h
diff --git a/include/asm-x86/numa.h b/include/asm-x86/numa.h
new file mode 100644
index 000000000000..27da400d3138
--- /dev/null
+++ b/include/asm-x86/numa.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "numa_32.h"
3#else
4# include "numa_64.h"
5#endif
diff --git a/include/asm-i386/numa.h b/include/asm-x86/numa_32.h
index 96fcb157db1d..96fcb157db1d 100644
--- a/include/asm-i386/numa.h
+++ b/include/asm-x86/numa_32.h
diff --git a/include/asm-x86_64/numa.h b/include/asm-x86/numa_64.h
index 933ff11ece15..933ff11ece15 100644
--- a/include/asm-x86_64/numa.h
+++ b/include/asm-x86/numa_64.h
diff --git a/include/asm-i386/numaq.h b/include/asm-x86/numaq.h
index 38f710dc37f2..38f710dc37f2 100644
--- a/include/asm-i386/numaq.h
+++ b/include/asm-x86/numaq.h
diff --git a/include/asm-x86/page.h b/include/asm-x86/page.h
new file mode 100644
index 000000000000..a757eb26141d
--- /dev/null
+++ b/include/asm-x86/page.h
@@ -0,0 +1,13 @@
1#ifdef __KERNEL__
2# ifdef CONFIG_X86_32
3# include "page_32.h"
4# else
5# include "page_64.h"
6# endif
7#else
8# ifdef __i386__
9# include "page_32.h"
10# else
11# include "page_64.h"
12# endif
13#endif
diff --git a/include/asm-i386/page.h b/include/asm-x86/page_32.h
index 80ecc66b6d86..80ecc66b6d86 100644
--- a/include/asm-i386/page.h
+++ b/include/asm-x86/page_32.h
diff --git a/include/asm-x86_64/page.h b/include/asm-x86/page_64.h
index 88adf1afb0a2..88adf1afb0a2 100644
--- a/include/asm-x86_64/page.h
+++ b/include/asm-x86/page_64.h
diff --git a/include/asm-x86/param.h b/include/asm-x86/param.h
new file mode 100644
index 000000000000..640851bab124
--- /dev/null
+++ b/include/asm-x86/param.h
@@ -0,0 +1,13 @@
1#ifdef __KERNEL__
2# ifdef CONFIG_X86_32
3# include "param_32.h"
4# else
5# include "param_64.h"
6# endif
7#else
8# ifdef __i386__
9# include "param_32.h"
10# else
11# include "param_64.h"
12# endif
13#endif
diff --git a/include/asm-i386/param.h b/include/asm-x86/param_32.h
index 21b32466fcdc..21b32466fcdc 100644
--- a/include/asm-i386/param.h
+++ b/include/asm-x86/param_32.h
diff --git a/include/asm-x86_64/param.h b/include/asm-x86/param_64.h
index a728786c3c7c..a728786c3c7c 100644
--- a/include/asm-x86_64/param.h
+++ b/include/asm-x86/param_64.h
diff --git a/include/asm-i386/paravirt.h b/include/asm-x86/paravirt.h
index 9fa3fa9e62d1..9fa3fa9e62d1 100644
--- a/include/asm-i386/paravirt.h
+++ b/include/asm-x86/paravirt.h
diff --git a/include/asm-x86/parport.h b/include/asm-x86/parport.h
new file mode 100644
index 000000000000..2a31157349c9
--- /dev/null
+++ b/include/asm-x86/parport.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "parport_32.h"
3#else
4# include "parport_64.h"
5#endif
diff --git a/include/asm-i386/parport.h b/include/asm-x86/parport_32.h
index fa0e321e498e..fa0e321e498e 100644
--- a/include/asm-i386/parport.h
+++ b/include/asm-x86/parport_32.h
diff --git a/include/asm-x86_64/parport.h b/include/asm-x86/parport_64.h
index 7135ef977c96..7135ef977c96 100644
--- a/include/asm-x86_64/parport.h
+++ b/include/asm-x86/parport_64.h
diff --git a/include/asm-x86_64/pci-direct.h b/include/asm-x86/pci-direct.h
index 6823fa4f1afa..6823fa4f1afa 100644
--- a/include/asm-x86_64/pci-direct.h
+++ b/include/asm-x86/pci-direct.h
diff --git a/include/asm-x86/pci.h b/include/asm-x86/pci.h
new file mode 100644
index 000000000000..a8cac8c2cde7
--- /dev/null
+++ b/include/asm-x86/pci.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "pci_32.h"
3#else
4# include "pci_64.h"
5#endif
diff --git a/include/asm-i386/pci.h b/include/asm-x86/pci_32.h
index 4fcacc711385..4fcacc711385 100644
--- a/include/asm-i386/pci.h
+++ b/include/asm-x86/pci_32.h
diff --git a/include/asm-x86_64/pci.h b/include/asm-x86/pci_64.h
index 5da8cb0c0599..5da8cb0c0599 100644
--- a/include/asm-x86_64/pci.h
+++ b/include/asm-x86/pci_64.h
diff --git a/include/asm-x86_64/pda.h b/include/asm-x86/pda.h
index 5642634843c4..5642634843c4 100644
--- a/include/asm-x86_64/pda.h
+++ b/include/asm-x86/pda.h
diff --git a/include/asm-x86/percpu.h b/include/asm-x86/percpu.h
new file mode 100644
index 000000000000..a1aaad274cca
--- /dev/null
+++ b/include/asm-x86/percpu.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "percpu_32.h"
3#else
4# include "percpu_64.h"
5#endif
diff --git a/include/asm-i386/percpu.h b/include/asm-x86/percpu_32.h
index a7ebd436f3cc..a7ebd436f3cc 100644
--- a/include/asm-i386/percpu.h
+++ b/include/asm-x86/percpu_32.h
diff --git a/include/asm-x86_64/percpu.h b/include/asm-x86/percpu_64.h
index 5abd48270101..5abd48270101 100644
--- a/include/asm-x86_64/percpu.h
+++ b/include/asm-x86/percpu_64.h
diff --git a/include/asm-x86/pgalloc.h b/include/asm-x86/pgalloc.h
new file mode 100644
index 000000000000..5886eed05886
--- /dev/null
+++ b/include/asm-x86/pgalloc.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "pgalloc_32.h"
3#else
4# include "pgalloc_64.h"
5#endif
diff --git a/include/asm-i386/pgalloc.h b/include/asm-x86/pgalloc_32.h
index f2fc33ceb9f2..f2fc33ceb9f2 100644
--- a/include/asm-i386/pgalloc.h
+++ b/include/asm-x86/pgalloc_32.h
diff --git a/include/asm-x86_64/pgalloc.h b/include/asm-x86/pgalloc_64.h
index 8bb564687860..8bb564687860 100644
--- a/include/asm-x86_64/pgalloc.h
+++ b/include/asm-x86/pgalloc_64.h
diff --git a/include/asm-i386/pgtable-2level-defs.h b/include/asm-x86/pgtable-2level-defs.h
index 0f71c9f13da4..0f71c9f13da4 100644
--- a/include/asm-i386/pgtable-2level-defs.h
+++ b/include/asm-x86/pgtable-2level-defs.h
diff --git a/include/asm-i386/pgtable-2level.h b/include/asm-x86/pgtable-2level.h
index 84b03cf56a79..84b03cf56a79 100644
--- a/include/asm-i386/pgtable-2level.h
+++ b/include/asm-x86/pgtable-2level.h
diff --git a/include/asm-i386/pgtable-3level-defs.h b/include/asm-x86/pgtable-3level-defs.h
index c0df89f66e8b..c0df89f66e8b 100644
--- a/include/asm-i386/pgtable-3level-defs.h
+++ b/include/asm-x86/pgtable-3level-defs.h
diff --git a/include/asm-i386/pgtable-3level.h b/include/asm-x86/pgtable-3level.h
index 948a33414118..948a33414118 100644
--- a/include/asm-i386/pgtable-3level.h
+++ b/include/asm-x86/pgtable-3level.h
diff --git a/include/asm-x86/pgtable.h b/include/asm-x86/pgtable.h
new file mode 100644
index 000000000000..1039140652af
--- /dev/null
+++ b/include/asm-x86/pgtable.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "pgtable_32.h"
3#else
4# include "pgtable_64.h"
5#endif
diff --git a/include/asm-i386/pgtable.h b/include/asm-x86/pgtable_32.h
index c7fefa6b12fd..c7fefa6b12fd 100644
--- a/include/asm-i386/pgtable.h
+++ b/include/asm-x86/pgtable_32.h
diff --git a/include/asm-x86_64/pgtable.h b/include/asm-x86/pgtable_64.h
index 57dd6b3107ea..57dd6b3107ea 100644
--- a/include/asm-x86_64/pgtable.h
+++ b/include/asm-x86/pgtable_64.h
diff --git a/include/asm-i386/poll.h b/include/asm-x86/poll.h
index c98509d3149e..c98509d3149e 100644
--- a/include/asm-i386/poll.h
+++ b/include/asm-x86/poll.h
diff --git a/include/asm-x86/posix_types.h b/include/asm-x86/posix_types.h
new file mode 100644
index 000000000000..bb7133dc155d
--- /dev/null
+++ b/include/asm-x86/posix_types.h
@@ -0,0 +1,13 @@
1#ifdef __KERNEL__
2# ifdef CONFIG_X86_32
3# include "posix_types_32.h"
4# else
5# include "posix_types_64.h"
6# endif
7#else
8# ifdef __i386__
9# include "posix_types_32.h"
10# else
11# include "posix_types_64.h"
12# endif
13#endif
diff --git a/include/asm-i386/posix_types.h b/include/asm-x86/posix_types_32.h
index 133e31e7dfde..133e31e7dfde 100644
--- a/include/asm-i386/posix_types.h
+++ b/include/asm-x86/posix_types_32.h
diff --git a/include/asm-x86_64/posix_types.h b/include/asm-x86/posix_types_64.h
index 9926aa43775b..9926aa43775b 100644
--- a/include/asm-x86_64/posix_types.h
+++ b/include/asm-x86/posix_types_64.h
diff --git a/include/asm-x86_64/prctl.h b/include/asm-x86/prctl.h
index 52952adef1ca..52952adef1ca 100644
--- a/include/asm-x86_64/prctl.h
+++ b/include/asm-x86/prctl.h
diff --git a/include/asm-i386/processor-cyrix.h b/include/asm-x86/processor-cyrix.h
index 97568ada1f97..97568ada1f97 100644
--- a/include/asm-i386/processor-cyrix.h
+++ b/include/asm-x86/processor-cyrix.h
diff --git a/include/asm-i386/processor-flags.h b/include/asm-x86/processor-flags.h
index 5404e90edd57..5404e90edd57 100644
--- a/include/asm-i386/processor-flags.h
+++ b/include/asm-x86/processor-flags.h
diff --git a/include/asm-x86/processor.h b/include/asm-x86/processor.h
new file mode 100644
index 000000000000..46e1c04e309c
--- /dev/null
+++ b/include/asm-x86/processor.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "processor_32.h"
3#else
4# include "processor_64.h"
5#endif
diff --git a/include/asm-i386/processor.h b/include/asm-x86/processor_32.h
index 3845fe72383e..3845fe72383e 100644
--- a/include/asm-i386/processor.h
+++ b/include/asm-x86/processor_32.h
diff --git a/include/asm-x86_64/processor.h b/include/asm-x86/processor_64.h
index 31f579b828f2..31f579b828f2 100644
--- a/include/asm-x86_64/processor.h
+++ b/include/asm-x86/processor_64.h
diff --git a/include/asm-x86_64/proto.h b/include/asm-x86/proto.h
index 31f20ad65876..31f20ad65876 100644
--- a/include/asm-x86_64/proto.h
+++ b/include/asm-x86/proto.h
diff --git a/include/asm-x86/ptrace-abi.h b/include/asm-x86/ptrace-abi.h
new file mode 100644
index 000000000000..6824c49def1c
--- /dev/null
+++ b/include/asm-x86/ptrace-abi.h
@@ -0,0 +1,13 @@
1#ifdef __KERNEL__
2# ifdef CONFIG_X86_32
3# include "ptrace-abi_32.h"
4# else
5# include "ptrace-abi_64.h"
6# endif
7#else
8# ifdef __i386__
9# include "ptrace-abi_32.h"
10# else
11# include "ptrace-abi_64.h"
12# endif
13#endif
diff --git a/include/asm-i386/ptrace-abi.h b/include/asm-x86/ptrace-abi_32.h
index a44901817a26..a44901817a26 100644
--- a/include/asm-i386/ptrace-abi.h
+++ b/include/asm-x86/ptrace-abi_32.h
diff --git a/include/asm-x86_64/ptrace-abi.h b/include/asm-x86/ptrace-abi_64.h
index 19184b0806b1..19184b0806b1 100644
--- a/include/asm-x86_64/ptrace-abi.h
+++ b/include/asm-x86/ptrace-abi_64.h
diff --git a/include/asm-x86/ptrace.h b/include/asm-x86/ptrace.h
new file mode 100644
index 000000000000..bc4d64a87689
--- /dev/null
+++ b/include/asm-x86/ptrace.h
@@ -0,0 +1,13 @@
1#ifdef __KERNEL__
2# ifdef CONFIG_X86_32
3# include "ptrace_32.h"
4# else
5# include "ptrace_64.h"
6# endif
7#else
8# ifdef __i386__
9# include "ptrace_32.h"
10# else
11# include "ptrace_64.h"
12# endif
13#endif
diff --git a/include/asm-i386/ptrace.h b/include/asm-x86/ptrace_32.h
index 6002597b9e12..6002597b9e12 100644
--- a/include/asm-i386/ptrace.h
+++ b/include/asm-x86/ptrace_32.h
diff --git a/include/asm-x86_64/ptrace.h b/include/asm-x86/ptrace_64.h
index 7f166ccb0606..7f166ccb0606 100644
--- a/include/asm-x86_64/ptrace.h
+++ b/include/asm-x86/ptrace_64.h
diff --git a/include/asm-i386/reboot.h b/include/asm-x86/reboot.h
index e9e3ffc22c07..e9e3ffc22c07 100644
--- a/include/asm-i386/reboot.h
+++ b/include/asm-x86/reboot.h
diff --git a/include/asm-i386/reboot_fixups.h b/include/asm-x86/reboot_fixups.h
index 0cb7d87c2b68..0cb7d87c2b68 100644
--- a/include/asm-i386/reboot_fixups.h
+++ b/include/asm-x86/reboot_fixups.h
diff --git a/include/asm-x86/required-features.h b/include/asm-x86/required-features.h
new file mode 100644
index 000000000000..8b64f3ea2b78
--- /dev/null
+++ b/include/asm-x86/required-features.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "required-features_32.h"
3#else
4# include "required-features_64.h"
5#endif
diff --git a/include/asm-i386/required-features.h b/include/asm-x86/required-features_32.h
index 618feb98f9f5..618feb98f9f5 100644
--- a/include/asm-i386/required-features.h
+++ b/include/asm-x86/required-features_32.h
diff --git a/include/asm-x86_64/required-features.h b/include/asm-x86/required-features_64.h
index e80d5761b00a..e80d5761b00a 100644
--- a/include/asm-x86_64/required-features.h
+++ b/include/asm-x86/required-features_64.h
diff --git a/include/asm-x86/resource.h b/include/asm-x86/resource.h
new file mode 100644
index 000000000000..732410a8c02a
--- /dev/null
+++ b/include/asm-x86/resource.h
@@ -0,0 +1,13 @@
1#ifdef __KERNEL__
2# ifdef CONFIG_X86_32
3# include "resource_32.h"
4# else
5# include "resource_64.h"
6# endif
7#else
8# ifdef __i386__
9# include "resource_32.h"
10# else
11# include "resource_64.h"
12# endif
13#endif
diff --git a/include/asm-i386/resource.h b/include/asm-x86/resource_32.h
index 6c1ea37c7718..6c1ea37c7718 100644
--- a/include/asm-i386/resource.h
+++ b/include/asm-x86/resource_32.h
diff --git a/include/asm-x86_64/resource.h b/include/asm-x86/resource_64.h
index f40b40623234..f40b40623234 100644
--- a/include/asm-x86_64/resource.h
+++ b/include/asm-x86/resource_64.h
diff --git a/include/asm-x86/resume-trace.h b/include/asm-x86/resume-trace.h
new file mode 100644
index 000000000000..9b6dd093a9f7
--- /dev/null
+++ b/include/asm-x86/resume-trace.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "resume-trace_32.h"
3#else
4# include "resume-trace_64.h"
5#endif
diff --git a/include/asm-i386/resume-trace.h b/include/asm-x86/resume-trace_32.h
index ec9cfd656230..ec9cfd656230 100644
--- a/include/asm-i386/resume-trace.h
+++ b/include/asm-x86/resume-trace_32.h
diff --git a/include/asm-x86_64/resume-trace.h b/include/asm-x86/resume-trace_64.h
index 34bf998fdf62..34bf998fdf62 100644
--- a/include/asm-x86_64/resume-trace.h
+++ b/include/asm-x86/resume-trace_64.h
diff --git a/include/asm-x86_64/rio.h b/include/asm-x86/rio.h
index c7350f6d2015..c7350f6d2015 100644
--- a/include/asm-x86_64/rio.h
+++ b/include/asm-x86/rio.h
diff --git a/include/asm-x86/rtc.h b/include/asm-x86/rtc.h
new file mode 100644
index 000000000000..1f0c98eb2e38
--- /dev/null
+++ b/include/asm-x86/rtc.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "rtc_32.h"
3#else
4# include "rtc_64.h"
5#endif
diff --git a/include/asm-i386/rtc.h b/include/asm-x86/rtc_32.h
index ffd02109a0e5..ffd02109a0e5 100644
--- a/include/asm-i386/rtc.h
+++ b/include/asm-x86/rtc_32.h
diff --git a/include/asm-x86_64/rtc.h b/include/asm-x86/rtc_64.h
index 18ed713ac7de..18ed713ac7de 100644
--- a/include/asm-x86_64/rtc.h
+++ b/include/asm-x86/rtc_64.h
diff --git a/include/asm-x86/rwlock.h b/include/asm-x86/rwlock.h
new file mode 100644
index 000000000000..a3be7d8364af
--- /dev/null
+++ b/include/asm-x86/rwlock.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "rwlock_32.h"
3#else
4# include "rwlock_64.h"
5#endif
diff --git a/include/asm-i386/rwlock.h b/include/asm-x86/rwlock_32.h
index c3e5db32fa48..c3e5db32fa48 100644
--- a/include/asm-i386/rwlock.h
+++ b/include/asm-x86/rwlock_32.h
diff --git a/include/asm-x86_64/rwlock.h b/include/asm-x86/rwlock_64.h
index 72aeebed920b..72aeebed920b 100644
--- a/include/asm-x86_64/rwlock.h
+++ b/include/asm-x86/rwlock_64.h
diff --git a/include/asm-i386/rwsem.h b/include/asm-x86/rwsem.h
index 041906f3c6df..041906f3c6df 100644
--- a/include/asm-i386/rwsem.h
+++ b/include/asm-x86/rwsem.h
diff --git a/include/asm-x86/scatterlist.h b/include/asm-x86/scatterlist.h
new file mode 100644
index 000000000000..3a1e76257a27
--- /dev/null
+++ b/include/asm-x86/scatterlist.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "scatterlist_32.h"
3#else
4# include "scatterlist_64.h"
5#endif
diff --git a/include/asm-i386/scatterlist.h b/include/asm-x86/scatterlist_32.h
index d7e45a8f1aae..d7e45a8f1aae 100644
--- a/include/asm-i386/scatterlist.h
+++ b/include/asm-x86/scatterlist_32.h
diff --git a/include/asm-x86_64/scatterlist.h b/include/asm-x86/scatterlist_64.h
index eaf7ada27e14..eaf7ada27e14 100644
--- a/include/asm-x86_64/scatterlist.h
+++ b/include/asm-x86/scatterlist_64.h
diff --git a/include/asm-x86/seccomp.h b/include/asm-x86/seccomp.h
new file mode 100644
index 000000000000..c62e58a5a90d
--- /dev/null
+++ b/include/asm-x86/seccomp.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "seccomp_32.h"
3#else
4# include "seccomp_64.h"
5#endif
diff --git a/include/asm-i386/seccomp.h b/include/asm-x86/seccomp_32.h
index 18da19e89bff..18da19e89bff 100644
--- a/include/asm-i386/seccomp.h
+++ b/include/asm-x86/seccomp_32.h
diff --git a/include/asm-x86_64/seccomp.h b/include/asm-x86/seccomp_64.h
index 553af65a2287..553af65a2287 100644
--- a/include/asm-x86_64/seccomp.h
+++ b/include/asm-x86/seccomp_64.h
diff --git a/include/asm-x86/sections.h b/include/asm-x86/sections.h
new file mode 100644
index 000000000000..ae6c69d9be3f
--- /dev/null
+++ b/include/asm-x86/sections.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "sections_32.h"
3#else
4# include "sections_64.h"
5#endif
diff --git a/include/asm-i386/sections.h b/include/asm-x86/sections_32.h
index 2dcbb92918b2..2dcbb92918b2 100644
--- a/include/asm-i386/sections.h
+++ b/include/asm-x86/sections_32.h
diff --git a/include/asm-x86_64/sections.h b/include/asm-x86/sections_64.h
index c746d9f1e70c..c746d9f1e70c 100644
--- a/include/asm-x86_64/sections.h
+++ b/include/asm-x86/sections_64.h
diff --git a/include/asm-x86/segment.h b/include/asm-x86/segment.h
new file mode 100644
index 000000000000..605068280e28
--- /dev/null
+++ b/include/asm-x86/segment.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "segment_32.h"
3#else
4# include "segment_64.h"
5#endif
diff --git a/include/asm-i386/segment.h b/include/asm-x86/segment_32.h
index 597a47c2515f..597a47c2515f 100644
--- a/include/asm-i386/segment.h
+++ b/include/asm-x86/segment_32.h
diff --git a/include/asm-x86_64/segment.h b/include/asm-x86/segment_64.h
index 04b8ab21328f..04b8ab21328f 100644
--- a/include/asm-x86_64/segment.h
+++ b/include/asm-x86/segment_64.h
diff --git a/include/asm-x86/semaphore.h b/include/asm-x86/semaphore.h
new file mode 100644
index 000000000000..572c0b67a6b0
--- /dev/null
+++ b/include/asm-x86/semaphore.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "semaphore_32.h"
3#else
4# include "semaphore_64.h"
5#endif
diff --git a/include/asm-i386/semaphore.h b/include/asm-x86/semaphore_32.h
index 4e34a468c383..4e34a468c383 100644
--- a/include/asm-i386/semaphore.h
+++ b/include/asm-x86/semaphore_32.h
diff --git a/include/asm-x86_64/semaphore.h b/include/asm-x86/semaphore_64.h
index 1194888536b9..1194888536b9 100644
--- a/include/asm-x86_64/semaphore.h
+++ b/include/asm-x86/semaphore_64.h
diff --git a/include/asm-x86/sembuf.h b/include/asm-x86/sembuf.h
new file mode 100644
index 000000000000..e42c971e383f
--- /dev/null
+++ b/include/asm-x86/sembuf.h
@@ -0,0 +1,13 @@
1#ifdef __KERNEL__
2# ifdef CONFIG_X86_32
3# include "sembuf_32.h"
4# else
5# include "sembuf_64.h"
6# endif
7#else
8# ifdef __i386__
9# include "sembuf_32.h"
10# else
11# include "sembuf_64.h"
12# endif
13#endif
diff --git a/include/asm-i386/sembuf.h b/include/asm-x86/sembuf_32.h
index 323835166c14..323835166c14 100644
--- a/include/asm-i386/sembuf.h
+++ b/include/asm-x86/sembuf_32.h
diff --git a/include/asm-x86_64/sembuf.h b/include/asm-x86/sembuf_64.h
index 63b52925ae2a..63b52925ae2a 100644
--- a/include/asm-x86_64/sembuf.h
+++ b/include/asm-x86/sembuf_64.h
diff --git a/include/asm-x86/serial.h b/include/asm-x86/serial.h
new file mode 100644
index 000000000000..cf1b05227b29
--- /dev/null
+++ b/include/asm-x86/serial.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "serial_32.h"
3#else
4# include "serial_64.h"
5#endif
diff --git a/include/asm-i386/serial.h b/include/asm-x86/serial_32.h
index bd67480ca109..bd67480ca109 100644
--- a/include/asm-i386/serial.h
+++ b/include/asm-x86/serial_32.h
diff --git a/include/asm-x86_64/serial.h b/include/asm-x86/serial_64.h
index b0496e0d72a6..b0496e0d72a6 100644
--- a/include/asm-x86_64/serial.h
+++ b/include/asm-x86/serial_64.h
diff --git a/include/asm-x86/setup.h b/include/asm-x86/setup.h
new file mode 100644
index 000000000000..81c0d98bb1c8
--- /dev/null
+++ b/include/asm-x86/setup.h
@@ -0,0 +1,13 @@
1#ifdef __KERNEL__
2# ifdef CONFIG_X86_32
3# include "setup_32.h"
4# else
5# include "setup_64.h"
6# endif
7#else
8# ifdef __i386__
9# include "setup_32.h"
10# else
11# include "setup_64.h"
12# endif
13#endif
diff --git a/include/asm-i386/setup.h b/include/asm-x86/setup_32.h
index 7862fe858a9e..7862fe858a9e 100644
--- a/include/asm-i386/setup.h
+++ b/include/asm-x86/setup_32.h
diff --git a/include/asm-x86_64/setup.h b/include/asm-x86/setup_64.h
index eaeff73d6c10..eaeff73d6c10 100644
--- a/include/asm-x86_64/setup.h
+++ b/include/asm-x86/setup_64.h
diff --git a/include/asm-x86/shmbuf.h b/include/asm-x86/shmbuf.h
new file mode 100644
index 000000000000..e85f1cb11217
--- /dev/null
+++ b/include/asm-x86/shmbuf.h
@@ -0,0 +1,13 @@
1#ifdef __KERNEL__
2# ifdef CONFIG_X86_32
3# include "shmbuf_32.h"
4# else
5# include "shmbuf_64.h"
6# endif
7#else
8# ifdef __i386__
9# include "shmbuf_32.h"
10# else
11# include "shmbuf_64.h"
12# endif
13#endif
diff --git a/include/asm-i386/shmbuf.h b/include/asm-x86/shmbuf_32.h
index d1cdc3cb079b..d1cdc3cb079b 100644
--- a/include/asm-i386/shmbuf.h
+++ b/include/asm-x86/shmbuf_32.h
diff --git a/include/asm-x86_64/shmbuf.h b/include/asm-x86/shmbuf_64.h
index 5a6d6dda7c48..5a6d6dda7c48 100644
--- a/include/asm-x86_64/shmbuf.h
+++ b/include/asm-x86/shmbuf_64.h
diff --git a/include/asm-x86/shmparam.h b/include/asm-x86/shmparam.h
new file mode 100644
index 000000000000..165627cc5345
--- /dev/null
+++ b/include/asm-x86/shmparam.h
@@ -0,0 +1,13 @@
1#ifdef __KERNEL__
2# ifdef CONFIG_X86_32
3# include "shmparam_32.h"
4# else
5# include "shmparam_64.h"
6# endif
7#else
8# ifdef __i386__
9# include "shmparam_32.h"
10# else
11# include "shmparam_64.h"
12# endif
13#endif
diff --git a/include/asm-i386/shmparam.h b/include/asm-x86/shmparam_32.h
index 786243a5b319..786243a5b319 100644
--- a/include/asm-i386/shmparam.h
+++ b/include/asm-x86/shmparam_32.h
diff --git a/include/asm-x86_64/shmparam.h b/include/asm-x86/shmparam_64.h
index d7021620dcb7..d7021620dcb7 100644
--- a/include/asm-x86_64/shmparam.h
+++ b/include/asm-x86/shmparam_64.h
diff --git a/include/asm-x86/sigcontext.h b/include/asm-x86/sigcontext.h
new file mode 100644
index 000000000000..0d16ceff1599
--- /dev/null
+++ b/include/asm-x86/sigcontext.h
@@ -0,0 +1,13 @@
1#ifdef __KERNEL__
2# ifdef CONFIG_X86_32
3# include "sigcontext_32.h"
4# else
5# include "sigcontext_64.h"
6# endif
7#else
8# ifdef __i386__
9# include "sigcontext_32.h"
10# else
11# include "sigcontext_64.h"
12# endif
13#endif
diff --git a/include/asm-x86_64/sigcontext32.h b/include/asm-x86/sigcontext32.h
index 3d657038ab7c..3d657038ab7c 100644
--- a/include/asm-x86_64/sigcontext32.h
+++ b/include/asm-x86/sigcontext32.h
diff --git a/include/asm-i386/sigcontext.h b/include/asm-x86/sigcontext_32.h
index aaef089a7787..aaef089a7787 100644
--- a/include/asm-i386/sigcontext.h
+++ b/include/asm-x86/sigcontext_32.h
diff --git a/include/asm-x86_64/sigcontext.h b/include/asm-x86/sigcontext_64.h
index b4e40236666c..b4e40236666c 100644
--- a/include/asm-x86_64/sigcontext.h
+++ b/include/asm-x86/sigcontext_64.h
diff --git a/include/asm-x86/siginfo.h b/include/asm-x86/siginfo.h
new file mode 100644
index 000000000000..0b8e4bb47d25
--- /dev/null
+++ b/include/asm-x86/siginfo.h
@@ -0,0 +1,13 @@
1#ifdef __KERNEL__
2# ifdef CONFIG_X86_32
3# include "siginfo_32.h"
4# else
5# include "siginfo_64.h"
6# endif
7#else
8# ifdef __i386__
9# include "siginfo_32.h"
10# else
11# include "siginfo_64.h"
12# endif
13#endif
diff --git a/include/asm-i386/siginfo.h b/include/asm-x86/siginfo_32.h
index fe18f98fccfa..fe18f98fccfa 100644
--- a/include/asm-i386/siginfo.h
+++ b/include/asm-x86/siginfo_32.h
diff --git a/include/asm-x86_64/siginfo.h b/include/asm-x86/siginfo_64.h
index d09a1e6e7246..d09a1e6e7246 100644
--- a/include/asm-x86_64/siginfo.h
+++ b/include/asm-x86/siginfo_64.h
diff --git a/include/asm-x86/signal.h b/include/asm-x86/signal.h
new file mode 100644
index 000000000000..bf5a63f457da
--- /dev/null
+++ b/include/asm-x86/signal.h
@@ -0,0 +1,13 @@
1#ifdef __KERNEL__
2# ifdef CONFIG_X86_32
3# include "signal_32.h"
4# else
5# include "signal_64.h"
6# endif
7#else
8# ifdef __i386__
9# include "signal_32.h"
10# else
11# include "signal_64.h"
12# endif
13#endif
diff --git a/include/asm-i386/signal.h b/include/asm-x86/signal_32.h
index c3e8adec5918..c3e8adec5918 100644
--- a/include/asm-i386/signal.h
+++ b/include/asm-x86/signal_32.h
diff --git a/include/asm-x86_64/signal.h b/include/asm-x86/signal_64.h
index 4581f978b299..4581f978b299 100644
--- a/include/asm-x86_64/signal.h
+++ b/include/asm-x86/signal_64.h
diff --git a/include/asm-x86/smp.h b/include/asm-x86/smp.h
new file mode 100644
index 000000000000..f2e8319a6b0b
--- /dev/null
+++ b/include/asm-x86/smp.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "smp_32.h"
3#else
4# include "smp_64.h"
5#endif
diff --git a/include/asm-i386/smp.h b/include/asm-x86/smp_32.h
index 1f73bde165b1..1f73bde165b1 100644
--- a/include/asm-i386/smp.h
+++ b/include/asm-x86/smp_32.h
diff --git a/include/asm-x86_64/smp.h b/include/asm-x86/smp_64.h
index 3f303d2365ed..3f303d2365ed 100644
--- a/include/asm-x86_64/smp.h
+++ b/include/asm-x86/smp_64.h
diff --git a/include/asm-i386/socket.h b/include/asm-x86/socket.h
index 99ca648b94c5..99ca648b94c5 100644
--- a/include/asm-i386/socket.h
+++ b/include/asm-x86/socket.h
diff --git a/include/asm-x86/sockios.h b/include/asm-x86/sockios.h
new file mode 100644
index 000000000000..5a134fc70b9c
--- /dev/null
+++ b/include/asm-x86/sockios.h
@@ -0,0 +1,13 @@
1#ifdef __KERNEL__
2# ifdef CONFIG_X86_32
3# include "sockios_32.h"
4# else
5# include "sockios_64.h"
6# endif
7#else
8# ifdef __i386__
9# include "sockios_32.h"
10# else
11# include "sockios_64.h"
12# endif
13#endif
diff --git a/include/asm-i386/sockios.h b/include/asm-x86/sockios_32.h
index ff528c7d255c..ff528c7d255c 100644
--- a/include/asm-i386/sockios.h
+++ b/include/asm-x86/sockios_32.h
diff --git a/include/asm-x86_64/sockios.h b/include/asm-x86/sockios_64.h
index d726ba2513e3..d726ba2513e3 100644
--- a/include/asm-x86_64/sockios.h
+++ b/include/asm-x86/sockios_64.h
diff --git a/include/asm-x86/sparsemem.h b/include/asm-x86/sparsemem.h
new file mode 100644
index 000000000000..3f203b1d9ee8
--- /dev/null
+++ b/include/asm-x86/sparsemem.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "sparsemem_32.h"
3#else
4# include "sparsemem_64.h"
5#endif
diff --git a/include/asm-i386/sparsemem.h b/include/asm-x86/sparsemem_32.h
index cfeed990585f..cfeed990585f 100644
--- a/include/asm-i386/sparsemem.h
+++ b/include/asm-x86/sparsemem_32.h
diff --git a/include/asm-x86_64/sparsemem.h b/include/asm-x86/sparsemem_64.h
index dabb16714a71..dabb16714a71 100644
--- a/include/asm-x86_64/sparsemem.h
+++ b/include/asm-x86/sparsemem_64.h
diff --git a/include/asm-x86/spinlock.h b/include/asm-x86/spinlock.h
new file mode 100644
index 000000000000..d74d85e71dcb
--- /dev/null
+++ b/include/asm-x86/spinlock.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "spinlock_32.h"
3#else
4# include "spinlock_64.h"
5#endif
diff --git a/include/asm-i386/spinlock.h b/include/asm-x86/spinlock_32.h
index d3bcebed60ca..d3bcebed60ca 100644
--- a/include/asm-i386/spinlock.h
+++ b/include/asm-x86/spinlock_32.h
diff --git a/include/asm-x86_64/spinlock.h b/include/asm-x86/spinlock_64.h
index 88bf981e73cf..88bf981e73cf 100644
--- a/include/asm-x86_64/spinlock.h
+++ b/include/asm-x86/spinlock_64.h
diff --git a/include/asm-i386/spinlock_types.h b/include/asm-x86/spinlock_types.h
index 4da9345c1500..4da9345c1500 100644
--- a/include/asm-i386/spinlock_types.h
+++ b/include/asm-x86/spinlock_types.h
diff --git a/include/asm-i386/srat.h b/include/asm-x86/srat.h
index 165ab4bdc02b..165ab4bdc02b 100644
--- a/include/asm-i386/srat.h
+++ b/include/asm-x86/srat.h
diff --git a/include/asm-x86_64/stacktrace.h b/include/asm-x86/stacktrace.h
index 6f0b54594307..6f0b54594307 100644
--- a/include/asm-x86_64/stacktrace.h
+++ b/include/asm-x86/stacktrace.h
diff --git a/include/asm-x86/stat.h b/include/asm-x86/stat.h
new file mode 100644
index 000000000000..3ff6b50ef833
--- /dev/null
+++ b/include/asm-x86/stat.h
@@ -0,0 +1,13 @@
1#ifdef __KERNEL__
2# ifdef CONFIG_X86_32
3# include "stat_32.h"
4# else
5# include "stat_64.h"
6# endif
7#else
8# ifdef __i386__
9# include "stat_32.h"
10# else
11# include "stat_64.h"
12# endif
13#endif
diff --git a/include/asm-i386/stat.h b/include/asm-x86/stat_32.h
index 67eae78323ba..67eae78323ba 100644
--- a/include/asm-i386/stat.h
+++ b/include/asm-x86/stat_32.h
diff --git a/include/asm-x86_64/stat.h b/include/asm-x86/stat_64.h
index fd9f00d560f8..fd9f00d560f8 100644
--- a/include/asm-x86_64/stat.h
+++ b/include/asm-x86/stat_64.h
diff --git a/include/asm-x86/statfs.h b/include/asm-x86/statfs.h
new file mode 100644
index 000000000000..327fb5d7a148
--- /dev/null
+++ b/include/asm-x86/statfs.h
@@ -0,0 +1,13 @@
1#ifdef __KERNEL__
2# ifdef CONFIG_X86_32
3# include "statfs_32.h"
4# else
5# include "statfs_64.h"
6# endif
7#else
8# ifdef __i386__
9# include "statfs_32.h"
10# else
11# include "statfs_64.h"
12# endif
13#endif
diff --git a/include/asm-i386/statfs.h b/include/asm-x86/statfs_32.h
index 24972c175132..24972c175132 100644
--- a/include/asm-i386/statfs.h
+++ b/include/asm-x86/statfs_32.h
diff --git a/include/asm-x86_64/statfs.h b/include/asm-x86/statfs_64.h
index b3f4718af30b..b3f4718af30b 100644
--- a/include/asm-x86_64/statfs.h
+++ b/include/asm-x86/statfs_64.h
diff --git a/include/asm-x86/string.h b/include/asm-x86/string.h
new file mode 100644
index 000000000000..6dfd6d9373a0
--- /dev/null
+++ b/include/asm-x86/string.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "string_32.h"
3#else
4# include "string_64.h"
5#endif
diff --git a/include/asm-i386/string.h b/include/asm-x86/string_32.h
index a9b64453bdf5..a9b64453bdf5 100644
--- a/include/asm-i386/string.h
+++ b/include/asm-x86/string_32.h
diff --git a/include/asm-x86_64/string.h b/include/asm-x86/string_64.h
index e583da7918fb..e583da7918fb 100644
--- a/include/asm-x86_64/string.h
+++ b/include/asm-x86/string_64.h
diff --git a/include/asm-x86/suspend.h b/include/asm-x86/suspend.h
new file mode 100644
index 000000000000..9bd521fe4570
--- /dev/null
+++ b/include/asm-x86/suspend.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "suspend_32.h"
3#else
4# include "suspend_64.h"
5#endif
diff --git a/include/asm-i386/suspend.h b/include/asm-x86/suspend_32.h
index a2520732ffd6..a2520732ffd6 100644
--- a/include/asm-i386/suspend.h
+++ b/include/asm-x86/suspend_32.h
diff --git a/include/asm-x86_64/suspend.h b/include/asm-x86/suspend_64.h
index b897e8cb55fb..b897e8cb55fb 100644
--- a/include/asm-x86_64/suspend.h
+++ b/include/asm-x86/suspend_64.h
diff --git a/include/asm-x86_64/swiotlb.h b/include/asm-x86/swiotlb.h
index f9c589539a82..f9c589539a82 100644
--- a/include/asm-x86_64/swiotlb.h
+++ b/include/asm-x86/swiotlb.h
diff --git a/include/asm-i386/sync_bitops.h b/include/asm-x86/sync_bitops.h
index cbce08a2d135..cbce08a2d135 100644
--- a/include/asm-i386/sync_bitops.h
+++ b/include/asm-x86/sync_bitops.h
diff --git a/include/asm-x86/system.h b/include/asm-x86/system.h
new file mode 100644
index 000000000000..692562b48f2a
--- /dev/null
+++ b/include/asm-x86/system.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "system_32.h"
3#else
4# include "system_64.h"
5#endif
diff --git a/include/asm-i386/system.h b/include/asm-x86/system_32.h
index d69ba937e092..d69ba937e092 100644
--- a/include/asm-i386/system.h
+++ b/include/asm-x86/system_32.h
diff --git a/include/asm-x86_64/system.h b/include/asm-x86/system_64.h
index 02175aa1d16a..02175aa1d16a 100644
--- a/include/asm-x86_64/system.h
+++ b/include/asm-x86/system_64.h
diff --git a/include/asm-x86_64/tce.h b/include/asm-x86/tce.h
index cd955d3d112f..cd955d3d112f 100644
--- a/include/asm-x86_64/tce.h
+++ b/include/asm-x86/tce.h
diff --git a/include/asm-x86/termbits.h b/include/asm-x86/termbits.h
new file mode 100644
index 000000000000..69f3080e2a1d
--- /dev/null
+++ b/include/asm-x86/termbits.h
@@ -0,0 +1,13 @@
1#ifdef __KERNEL__
2# ifdef CONFIG_X86_32
3# include "termbits_32.h"
4# else
5# include "termbits_64.h"
6# endif
7#else
8# ifdef __i386__
9# include "termbits_32.h"
10# else
11# include "termbits_64.h"
12# endif
13#endif
diff --git a/include/asm-i386/termbits.h b/include/asm-x86/termbits_32.h
index a21700352e7b..a21700352e7b 100644
--- a/include/asm-i386/termbits.h
+++ b/include/asm-x86/termbits_32.h
diff --git a/include/asm-x86_64/termbits.h b/include/asm-x86/termbits_64.h
index 7405756dd41b..7405756dd41b 100644
--- a/include/asm-x86_64/termbits.h
+++ b/include/asm-x86/termbits_64.h
diff --git a/include/asm-x86/termios.h b/include/asm-x86/termios.h
new file mode 100644
index 000000000000..a4f4ae20a591
--- /dev/null
+++ b/include/asm-x86/termios.h
@@ -0,0 +1,13 @@
1#ifdef __KERNEL__
2# ifdef CONFIG_X86_32
3# include "termios_32.h"
4# else
5# include "termios_64.h"
6# endif
7#else
8# ifdef __i386__
9# include "termios_32.h"
10# else
11# include "termios_64.h"
12# endif
13#endif
diff --git a/include/asm-x86/termios_32.h b/include/asm-x86/termios_32.h
new file mode 100644
index 000000000000..6fdb2c841b73
--- /dev/null
+++ b/include/asm-x86/termios_32.h
@@ -0,0 +1,90 @@
1#ifndef _I386_TERMIOS_H
2#define _I386_TERMIOS_H
3
4#include <asm/termbits.h>
5#include <asm/ioctls.h>
6
7struct winsize {
8 unsigned short ws_row;
9 unsigned short ws_col;
10 unsigned short ws_xpixel;
11 unsigned short ws_ypixel;
12};
13
14#define NCC 8
15struct termio {
16 unsigned short c_iflag; /* input mode flags */
17 unsigned short c_oflag; /* output mode flags */
18 unsigned short c_cflag; /* control mode flags */
19 unsigned short c_lflag; /* local mode flags */
20 unsigned char c_line; /* line discipline */
21 unsigned char c_cc[NCC]; /* control characters */
22};
23
24/* modem lines */
25#define TIOCM_LE 0x001
26#define TIOCM_DTR 0x002
27#define TIOCM_RTS 0x004
28#define TIOCM_ST 0x008
29#define TIOCM_SR 0x010
30#define TIOCM_CTS 0x020
31#define TIOCM_CAR 0x040
32#define TIOCM_RNG 0x080
33#define TIOCM_DSR 0x100
34#define TIOCM_CD TIOCM_CAR
35#define TIOCM_RI TIOCM_RNG
36#define TIOCM_OUT1 0x2000
37#define TIOCM_OUT2 0x4000
38#define TIOCM_LOOP 0x8000
39
40/* ioctl (fd, TIOCSERGETLSR, &result) where result may be as below */
41
42#ifdef __KERNEL__
43
44/* intr=^C quit=^\ erase=del kill=^U
45 eof=^D vtime=\0 vmin=\1 sxtc=\0
46 start=^Q stop=^S susp=^Z eol=\0
47 reprint=^R discard=^U werase=^W lnext=^V
48 eol2=\0
49*/
50#define INIT_C_CC "\003\034\177\025\004\0\1\0\021\023\032\0\022\017\027\026\0"
51
52/*
53 * Translate a "termio" structure into a "termios". Ugh.
54 */
55#define SET_LOW_TERMIOS_BITS(termios, termio, x) { \
56 unsigned short __tmp; \
57 get_user(__tmp,&(termio)->x); \
58 *(unsigned short *) &(termios)->x = __tmp; \
59}
60
61#define user_termio_to_kernel_termios(termios, termio) \
62({ \
63 SET_LOW_TERMIOS_BITS(termios, termio, c_iflag); \
64 SET_LOW_TERMIOS_BITS(termios, termio, c_oflag); \
65 SET_LOW_TERMIOS_BITS(termios, termio, c_cflag); \
66 SET_LOW_TERMIOS_BITS(termios, termio, c_lflag); \
67 copy_from_user((termios)->c_cc, (termio)->c_cc, NCC); \
68})
69
70/*
71 * Translate a "termios" structure into a "termio". Ugh.
72 */
73#define kernel_termios_to_user_termio(termio, termios) \
74({ \
75 put_user((termios)->c_iflag, &(termio)->c_iflag); \
76 put_user((termios)->c_oflag, &(termio)->c_oflag); \
77 put_user((termios)->c_cflag, &(termio)->c_cflag); \
78 put_user((termios)->c_lflag, &(termio)->c_lflag); \
79 put_user((termios)->c_line, &(termio)->c_line); \
80 copy_to_user((termio)->c_cc, (termios)->c_cc, NCC); \
81})
82
83#define user_termios_to_kernel_termios(k, u) copy_from_user(k, u, sizeof(struct termios2))
84#define kernel_termios_to_user_termios(u, k) copy_to_user(u, k, sizeof(struct termios2))
85#define user_termios_to_kernel_termios_1(k, u) copy_from_user(k, u, sizeof(struct termios))
86#define kernel_termios_to_user_termios_1(u, k) copy_to_user(u, k, sizeof(struct termios))
87
88#endif /* __KERNEL__ */
89
90#endif /* _I386_TERMIOS_H */
diff --git a/include/asm-x86_64/termios.h b/include/asm-x86/termios_64.h
index 35ee59b78329..35ee59b78329 100644
--- a/include/asm-x86_64/termios.h
+++ b/include/asm-x86/termios_64.h
diff --git a/include/asm-i386/therm_throt.h b/include/asm-x86/therm_throt.h
index 399bf6026b16..399bf6026b16 100644
--- a/include/asm-i386/therm_throt.h
+++ b/include/asm-x86/therm_throt.h
diff --git a/include/asm-x86/thread_info.h b/include/asm-x86/thread_info.h
new file mode 100644
index 000000000000..d5fd12f2abdb
--- /dev/null
+++ b/include/asm-x86/thread_info.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "thread_info_32.h"
3#else
4# include "thread_info_64.h"
5#endif
diff --git a/include/asm-i386/thread_info.h b/include/asm-x86/thread_info_32.h
index 22a8cbcd35e2..22a8cbcd35e2 100644
--- a/include/asm-i386/thread_info.h
+++ b/include/asm-x86/thread_info_32.h
diff --git a/include/asm-x86_64/thread_info.h b/include/asm-x86/thread_info_64.h
index beae2bfb62ca..beae2bfb62ca 100644
--- a/include/asm-x86_64/thread_info.h
+++ b/include/asm-x86/thread_info_64.h
diff --git a/include/asm-i386/time.h b/include/asm-x86/time.h
index eac011366dc2..eac011366dc2 100644
--- a/include/asm-i386/time.h
+++ b/include/asm-x86/time.h
diff --git a/include/asm-i386/timer.h b/include/asm-x86/timer.h
index 0db7e994fb8b..0db7e994fb8b 100644
--- a/include/asm-i386/timer.h
+++ b/include/asm-x86/timer.h
diff --git a/include/asm-x86/timex.h b/include/asm-x86/timex.h
new file mode 100644
index 000000000000..d01c18cfccef
--- /dev/null
+++ b/include/asm-x86/timex.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "timex_32.h"
3#else
4# include "timex_64.h"
5#endif
diff --git a/include/asm-i386/timex.h b/include/asm-x86/timex_32.h
index 3666044409f0..3666044409f0 100644
--- a/include/asm-i386/timex.h
+++ b/include/asm-x86/timex_32.h
diff --git a/include/asm-x86_64/timex.h b/include/asm-x86/timex_64.h
index 6ed21f44d308..6ed21f44d308 100644
--- a/include/asm-x86_64/timex.h
+++ b/include/asm-x86/timex_64.h
diff --git a/include/asm-x86/tlb.h b/include/asm-x86/tlb.h
new file mode 100644
index 000000000000..7d55c3762b43
--- /dev/null
+++ b/include/asm-x86/tlb.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "tlb_32.h"
3#else
4# include "tlb_64.h"
5#endif
diff --git a/include/asm-i386/tlb.h b/include/asm-x86/tlb_32.h
index c006c5c92bea..c006c5c92bea 100644
--- a/include/asm-i386/tlb.h
+++ b/include/asm-x86/tlb_32.h
diff --git a/include/asm-x86_64/tlb.h b/include/asm-x86/tlb_64.h
index cd4c3c590a0e..cd4c3c590a0e 100644
--- a/include/asm-x86_64/tlb.h
+++ b/include/asm-x86/tlb_64.h
diff --git a/include/asm-x86/tlbflush.h b/include/asm-x86/tlbflush.h
new file mode 100644
index 000000000000..9af4cc83a1af
--- /dev/null
+++ b/include/asm-x86/tlbflush.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "tlbflush_32.h"
3#else
4# include "tlbflush_64.h"
5#endif
diff --git a/include/asm-i386/tlbflush.h b/include/asm-x86/tlbflush_32.h
index a50fa6741486..a50fa6741486 100644
--- a/include/asm-i386/tlbflush.h
+++ b/include/asm-x86/tlbflush_32.h
diff --git a/include/asm-x86_64/tlbflush.h b/include/asm-x86/tlbflush_64.h
index 888eb4abdd07..888eb4abdd07 100644
--- a/include/asm-x86_64/tlbflush.h
+++ b/include/asm-x86/tlbflush_64.h
diff --git a/include/asm-x86/topology.h b/include/asm-x86/topology.h
new file mode 100644
index 000000000000..b10fde9798ea
--- /dev/null
+++ b/include/asm-x86/topology.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "topology_32.h"
3#else
4# include "topology_64.h"
5#endif
diff --git a/include/asm-i386/topology.h b/include/asm-x86/topology_32.h
index 19b2dafd0c81..19b2dafd0c81 100644
--- a/include/asm-i386/topology.h
+++ b/include/asm-x86/topology_32.h
diff --git a/include/asm-x86_64/topology.h b/include/asm-x86/topology_64.h
index 36e52fba7960..36e52fba7960 100644
--- a/include/asm-x86_64/topology.h
+++ b/include/asm-x86/topology_64.h
diff --git a/include/asm-i386/tsc.h b/include/asm-x86/tsc.h
index a4d806610b7f..a4d806610b7f 100644
--- a/include/asm-i386/tsc.h
+++ b/include/asm-x86/tsc.h
diff --git a/include/asm-x86/types.h b/include/asm-x86/types.h
new file mode 100644
index 000000000000..a777a9b83974
--- /dev/null
+++ b/include/asm-x86/types.h
@@ -0,0 +1,13 @@
1#ifdef __KERNEL__
2# ifdef CONFIG_X86_32
3# include "types_32.h"
4# else
5# include "types_64.h"
6# endif
7#else
8# ifdef __i386__
9# include "types_32.h"
10# else
11# include "types_64.h"
12# endif
13#endif
diff --git a/include/asm-i386/types.h b/include/asm-x86/types_32.h
index ad0a55bd782f..ad0a55bd782f 100644
--- a/include/asm-i386/types.h
+++ b/include/asm-x86/types_32.h
diff --git a/include/asm-x86_64/types.h b/include/asm-x86/types_64.h
index 2d4491aae281..2d4491aae281 100644
--- a/include/asm-x86_64/types.h
+++ b/include/asm-x86/types_64.h
diff --git a/include/asm-x86/uaccess.h b/include/asm-x86/uaccess.h
new file mode 100644
index 000000000000..9fefd2947e78
--- /dev/null
+++ b/include/asm-x86/uaccess.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "uaccess_32.h"
3#else
4# include "uaccess_64.h"
5#endif
diff --git a/include/asm-i386/uaccess.h b/include/asm-x86/uaccess_32.h
index d2a4f7be9c2c..d2a4f7be9c2c 100644
--- a/include/asm-i386/uaccess.h
+++ b/include/asm-x86/uaccess_32.h
diff --git a/include/asm-x86_64/uaccess.h b/include/asm-x86/uaccess_64.h
index f4ce8768ad44..f4ce8768ad44 100644
--- a/include/asm-x86_64/uaccess.h
+++ b/include/asm-x86/uaccess_64.h
diff --git a/include/asm-x86/ucontext.h b/include/asm-x86/ucontext.h
new file mode 100644
index 000000000000..175c8cb59731
--- /dev/null
+++ b/include/asm-x86/ucontext.h
@@ -0,0 +1,13 @@
1#ifdef __KERNEL__
2# ifdef CONFIG_X86_32
3# include "ucontext_32.h"
4# else
5# include "ucontext_64.h"
6# endif
7#else
8# ifdef __i386__
9# include "ucontext_32.h"
10# else
11# include "ucontext_64.h"
12# endif
13#endif
diff --git a/include/asm-i386/ucontext.h b/include/asm-x86/ucontext_32.h
index b0db36925f55..b0db36925f55 100644
--- a/include/asm-i386/ucontext.h
+++ b/include/asm-x86/ucontext_32.h
diff --git a/include/asm-x86_64/ucontext.h b/include/asm-x86/ucontext_64.h
index 159a3da9e112..159a3da9e112 100644
--- a/include/asm-x86_64/ucontext.h
+++ b/include/asm-x86/ucontext_64.h
diff --git a/include/asm-x86/unaligned.h b/include/asm-x86/unaligned.h
new file mode 100644
index 000000000000..68067150fbcb
--- /dev/null
+++ b/include/asm-x86/unaligned.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "unaligned_32.h"
3#else
4# include "unaligned_64.h"
5#endif
diff --git a/include/asm-i386/unaligned.h b/include/asm-x86/unaligned_32.h
index 7acd7957621e..7acd7957621e 100644
--- a/include/asm-i386/unaligned.h
+++ b/include/asm-x86/unaligned_32.h
diff --git a/include/asm-x86_64/unaligned.h b/include/asm-x86/unaligned_64.h
index d4bf78dc6f39..d4bf78dc6f39 100644
--- a/include/asm-x86_64/unaligned.h
+++ b/include/asm-x86/unaligned_64.h
diff --git a/include/asm-x86/unistd.h b/include/asm-x86/unistd.h
new file mode 100644
index 000000000000..2a58ed3e51d8
--- /dev/null
+++ b/include/asm-x86/unistd.h
@@ -0,0 +1,13 @@
1#ifdef __KERNEL__
2# ifdef CONFIG_X86_32
3# include "unistd_32.h"
4# else
5# include "unistd_64.h"
6# endif
7#else
8# ifdef __i386__
9# include "unistd_32.h"
10# else
11# include "unistd_64.h"
12# endif
13#endif
diff --git a/include/asm-i386/unistd.h b/include/asm-x86/unistd_32.h
index 9b15545eb9b5..9b15545eb9b5 100644
--- a/include/asm-i386/unistd.h
+++ b/include/asm-x86/unistd_32.h
diff --git a/include/asm-x86_64/unistd.h b/include/asm-x86/unistd_64.h
index fc4e73f5f1fa..fc4e73f5f1fa 100644
--- a/include/asm-x86_64/unistd.h
+++ b/include/asm-x86/unistd_64.h
diff --git a/include/asm-x86/unwind.h b/include/asm-x86/unwind.h
new file mode 100644
index 000000000000..7e4d7ad55208
--- /dev/null
+++ b/include/asm-x86/unwind.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "unwind_32.h"
3#else
4# include "unwind_64.h"
5#endif
diff --git a/include/asm-i386/unwind.h b/include/asm-x86/unwind_32.h
index 43c70c3de2f9..43c70c3de2f9 100644
--- a/include/asm-i386/unwind.h
+++ b/include/asm-x86/unwind_32.h
diff --git a/include/asm-x86_64/unwind.h b/include/asm-x86/unwind_64.h
index 02710f6a4560..02710f6a4560 100644
--- a/include/asm-x86_64/unwind.h
+++ b/include/asm-x86/unwind_64.h
diff --git a/include/asm-x86/user.h b/include/asm-x86/user.h
new file mode 100644
index 000000000000..484715abe74a
--- /dev/null
+++ b/include/asm-x86/user.h
@@ -0,0 +1,13 @@
1#ifdef __KERNEL__
2# ifdef CONFIG_X86_32
3# include "user_32.h"
4# else
5# include "user_64.h"
6# endif
7#else
8# ifdef __i386__
9# include "user_32.h"
10# else
11# include "user_64.h"
12# endif
13#endif
diff --git a/include/asm-x86_64/user32.h b/include/asm-x86/user32.h
index f769872debea..f769872debea 100644
--- a/include/asm-x86_64/user32.h
+++ b/include/asm-x86/user32.h
diff --git a/include/asm-i386/user.h b/include/asm-x86/user_32.h
index 0e85d2a5e33a..0e85d2a5e33a 100644
--- a/include/asm-i386/user.h
+++ b/include/asm-x86/user_32.h
diff --git a/include/asm-x86_64/user.h b/include/asm-x86/user_64.h
index 12785c649ac5..12785c649ac5 100644
--- a/include/asm-x86_64/user.h
+++ b/include/asm-x86/user_64.h
diff --git a/include/asm-i386/vga.h b/include/asm-x86/vga.h
index 0ecf68ac03aa..0ecf68ac03aa 100644
--- a/include/asm-i386/vga.h
+++ b/include/asm-x86/vga.h
diff --git a/include/asm-x86_64/vgtod.h b/include/asm-x86/vgtod.h
index 3301f0929342..3301f0929342 100644
--- a/include/asm-x86_64/vgtod.h
+++ b/include/asm-x86/vgtod.h
diff --git a/include/asm-i386/vic.h b/include/asm-x86/vic.h
index 53100f353612..53100f353612 100644
--- a/include/asm-i386/vic.h
+++ b/include/asm-x86/vic.h
diff --git a/include/asm-i386/vm86.h b/include/asm-x86/vm86.h
index a5edf517b992..a5edf517b992 100644
--- a/include/asm-i386/vm86.h
+++ b/include/asm-x86/vm86.h
diff --git a/include/asm-i386/vmi.h b/include/asm-x86/vmi.h
index eb8bd892c01e..eb8bd892c01e 100644
--- a/include/asm-i386/vmi.h
+++ b/include/asm-x86/vmi.h
diff --git a/include/asm-i386/vmi_time.h b/include/asm-x86/vmi_time.h
index 478188130328..478188130328 100644
--- a/include/asm-i386/vmi_time.h
+++ b/include/asm-x86/vmi_time.h
diff --git a/include/asm-i386/voyager.h b/include/asm-x86/voyager.h
index 91a9932937ab..91a9932937ab 100644
--- a/include/asm-i386/voyager.h
+++ b/include/asm-x86/voyager.h
diff --git a/include/asm-x86_64/vsyscall.h b/include/asm-x86/vsyscall.h
index 3b8ceb4af2cf..3b8ceb4af2cf 100644
--- a/include/asm-x86_64/vsyscall.h
+++ b/include/asm-x86/vsyscall.h
diff --git a/include/asm-x86_64/vsyscall32.h b/include/asm-x86/vsyscall32.h
index c631c082f8f7..c631c082f8f7 100644
--- a/include/asm-x86_64/vsyscall32.h
+++ b/include/asm-x86/vsyscall32.h
diff --git a/include/asm-i386/xen/hypercall.h b/include/asm-x86/xen/hypercall.h
index bc0ee7d961ca..bc0ee7d961ca 100644
--- a/include/asm-i386/xen/hypercall.h
+++ b/include/asm-x86/xen/hypercall.h
diff --git a/include/asm-i386/xen/hypervisor.h b/include/asm-x86/xen/hypervisor.h
index 8e15dd28c91f..8e15dd28c91f 100644
--- a/include/asm-i386/xen/hypervisor.h
+++ b/include/asm-x86/xen/hypervisor.h
diff --git a/include/asm-i386/xen/interface.h b/include/asm-x86/xen/interface.h
index 165c3968e138..165c3968e138 100644
--- a/include/asm-i386/xen/interface.h
+++ b/include/asm-x86/xen/interface.h
diff --git a/include/asm-x86/xor.h b/include/asm-x86/xor.h
new file mode 100644
index 000000000000..11b3bb86e17b
--- /dev/null
+++ b/include/asm-x86/xor.h
@@ -0,0 +1,5 @@
1#ifdef CONFIG_X86_32
2# include "xor_32.h"
3#else
4# include "xor_64.h"
5#endif
diff --git a/include/asm-i386/xor.h b/include/asm-x86/xor_32.h
index 23c86cef3b25..23c86cef3b25 100644
--- a/include/asm-i386/xor.h
+++ b/include/asm-x86/xor_32.h
diff --git a/include/asm-x86_64/xor.h b/include/asm-x86/xor_64.h
index f942fcc21831..f942fcc21831 100644
--- a/include/asm-x86_64/xor.h
+++ b/include/asm-x86/xor_64.h
diff --git a/include/asm-x86_64/Kbuild b/include/asm-x86_64/Kbuild
deleted file mode 100644
index 75a2deffca68..000000000000
--- a/include/asm-x86_64/Kbuild
+++ /dev/null
@@ -1,21 +0,0 @@
1include include/asm-generic/Kbuild.asm
2
3ALTARCH := i386
4ARCHDEF := defined __x86_64__
5ALTARCHDEF := defined __i386__
6
7header-y += boot.h
8header-y += bootsetup.h
9header-y += debugreg.h
10header-y += ldt.h
11header-y += msr-index.h
12header-y += prctl.h
13header-y += ptrace-abi.h
14header-y += sigcontext32.h
15header-y += ucontext.h
16header-y += vsyscall32.h
17
18unifdef-y += mce.h
19unifdef-y += msr.h
20unifdef-y += mtrr.h
21unifdef-y += vsyscall.h
diff --git a/include/asm-x86_64/boot.h b/include/asm-x86_64/boot.h
deleted file mode 100644
index 3c46cea8db7f..000000000000
--- a/include/asm-x86_64/boot.h
+++ /dev/null
@@ -1 +0,0 @@
1#include <asm-i386/boot.h>
diff --git a/include/asm-x86_64/bootparam.h b/include/asm-x86_64/bootparam.h
deleted file mode 100644
index aa82e5238d82..000000000000
--- a/include/asm-x86_64/bootparam.h
+++ /dev/null
@@ -1 +0,0 @@
1#include <asm-i386/bootparam.h>
diff --git a/include/asm-x86_64/cpu.h b/include/asm-x86_64/cpu.h
deleted file mode 100644
index 8eea076525a4..000000000000
--- a/include/asm-x86_64/cpu.h
+++ /dev/null
@@ -1 +0,0 @@
1#include <asm-i386/cpu.h>
diff --git a/include/asm-x86_64/cpufeature.h b/include/asm-x86_64/cpufeature.h
deleted file mode 100644
index 8baefc3beb2e..000000000000
--- a/include/asm-x86_64/cpufeature.h
+++ /dev/null
@@ -1,30 +0,0 @@
1/*
2 * cpufeature.h
3 *
4 * Defines x86 CPU feature bits
5 */
6
7#ifndef __ASM_X8664_CPUFEATURE_H
8#define __ASM_X8664_CPUFEATURE_H
9
10#include <asm-i386/cpufeature.h>
11
12#undef cpu_has_vme
13#define cpu_has_vme 0
14
15#undef cpu_has_pae
16#define cpu_has_pae ___BUG___
17
18#undef cpu_has_mp
19#define cpu_has_mp 1 /* XXX */
20
21#undef cpu_has_k6_mtrr
22#define cpu_has_k6_mtrr 0
23
24#undef cpu_has_cyrix_arr
25#define cpu_has_cyrix_arr 0
26
27#undef cpu_has_centaur_mcr
28#define cpu_has_centaur_mcr 0
29
30#endif /* __ASM_X8664_CPUFEATURE_H */
diff --git a/include/asm-x86_64/emergency-restart.h b/include/asm-x86_64/emergency-restart.h
deleted file mode 100644
index 680c39563345..000000000000
--- a/include/asm-x86_64/emergency-restart.h
+++ /dev/null
@@ -1,6 +0,0 @@
1#ifndef _ASM_EMERGENCY_RESTART_H
2#define _ASM_EMERGENCY_RESTART_H
3
4extern void machine_emergency_restart(void);
5
6#endif /* _ASM_EMERGENCY_RESTART_H */
diff --git a/include/asm-x86_64/fcntl.h b/include/asm-x86_64/fcntl.h
deleted file mode 100644
index 46ab12db5739..000000000000
--- a/include/asm-x86_64/fcntl.h
+++ /dev/null
@@ -1 +0,0 @@
1#include <asm-generic/fcntl.h>
diff --git a/include/asm-x86_64/hpet.h b/include/asm-x86_64/hpet.h
deleted file mode 100644
index 79bb950f82c5..000000000000
--- a/include/asm-x86_64/hpet.h
+++ /dev/null
@@ -1,18 +0,0 @@
1#ifndef _ASM_X8664_HPET_H
2#define _ASM_X8664_HPET_H 1
3
4#include <asm-i386/hpet.h>
5
6#define HPET_TICK_RATE (HZ * 100000UL)
7
8extern int hpet_rtc_timer_init(void);
9extern int hpet_arch_init(void);
10extern int hpet_timer_stop_set_go(unsigned long tick);
11extern int hpet_reenable(void);
12extern unsigned int hpet_calibrate_tsc(void);
13
14extern int hpet_use_timer;
15extern unsigned long hpet_period;
16extern unsigned long hpet_tick;
17
18#endif
diff --git a/include/asm-x86_64/hypertransport.h b/include/asm-x86_64/hypertransport.h
deleted file mode 100644
index 5cbf9fa5e0b5..000000000000
--- a/include/asm-x86_64/hypertransport.h
+++ /dev/null
@@ -1 +0,0 @@
1#include <asm-i386/hypertransport.h>
diff --git a/include/asm-x86_64/ide.h b/include/asm-x86_64/ide.h
deleted file mode 100644
index 4cef0ef61878..000000000000
--- a/include/asm-x86_64/ide.h
+++ /dev/null
@@ -1 +0,0 @@
1#include <asm-i386/ide.h>
diff --git a/include/asm-x86_64/ioctl.h b/include/asm-x86_64/ioctl.h
deleted file mode 100644
index b279fe06dfe5..000000000000
--- a/include/asm-x86_64/ioctl.h
+++ /dev/null
@@ -1 +0,0 @@
1#include <asm-generic/ioctl.h>
diff --git a/include/asm-x86_64/ist.h b/include/asm-x86_64/ist.h
deleted file mode 100644
index 338857ecbc68..000000000000
--- a/include/asm-x86_64/ist.h
+++ /dev/null
@@ -1 +0,0 @@
1#include <asm-i386/ist.h>
diff --git a/include/asm-x86_64/msidef.h b/include/asm-x86_64/msidef.h
deleted file mode 100644
index 083ad5827e48..000000000000
--- a/include/asm-x86_64/msidef.h
+++ /dev/null
@@ -1 +0,0 @@
1#include <asm-i386/msidef.h>
diff --git a/include/asm-x86_64/msr-index.h b/include/asm-x86_64/msr-index.h
deleted file mode 100644
index d77a63f1ddf2..000000000000
--- a/include/asm-x86_64/msr-index.h
+++ /dev/null
@@ -1 +0,0 @@
1#include <asm-i386/msr-index.h>
diff --git a/include/asm-x86_64/node.h b/include/asm-x86_64/node.h
deleted file mode 100644
index 0ee6f88db048..000000000000
--- a/include/asm-x86_64/node.h
+++ /dev/null
@@ -1 +0,0 @@
1#include <asm-i386/node.h>
diff --git a/include/asm-x86_64/poll.h b/include/asm-x86_64/poll.h
deleted file mode 100644
index c98509d3149e..000000000000
--- a/include/asm-x86_64/poll.h
+++ /dev/null
@@ -1 +0,0 @@
1#include <asm-generic/poll.h>
diff --git a/include/asm-x86_64/processor-flags.h b/include/asm-x86_64/processor-flags.h
deleted file mode 100644
index ec99a57b2c6a..000000000000
--- a/include/asm-x86_64/processor-flags.h
+++ /dev/null
@@ -1 +0,0 @@
1#include <asm-i386/processor-flags.h>
diff --git a/include/asm-x86_64/socket.h b/include/asm-x86_64/socket.h
deleted file mode 100644
index 90af60cf3c0e..000000000000
--- a/include/asm-x86_64/socket.h
+++ /dev/null
@@ -1,55 +0,0 @@
1#ifndef _ASM_SOCKET_H
2#define _ASM_SOCKET_H
3
4#include <asm/sockios.h>
5
6/* For setsockopt(2) */
7#define SOL_SOCKET 1
8
9#define SO_DEBUG 1
10#define SO_REUSEADDR 2
11#define SO_TYPE 3
12#define SO_ERROR 4
13#define SO_DONTROUTE 5
14#define SO_BROADCAST 6
15#define SO_SNDBUF 7
16#define SO_RCVBUF 8
17#define SO_SNDBUFFORCE 32
18#define SO_RCVBUFFORCE 33
19#define SO_KEEPALIVE 9
20#define SO_OOBINLINE 10
21#define SO_NO_CHECK 11
22#define SO_PRIORITY 12
23#define SO_LINGER 13
24#define SO_BSDCOMPAT 14
25/* To add :#define SO_REUSEPORT 15 */
26#define SO_PASSCRED 16
27#define SO_PEERCRED 17
28#define SO_RCVLOWAT 18
29#define SO_SNDLOWAT 19
30#define SO_RCVTIMEO 20
31#define SO_SNDTIMEO 21
32
33/* Security levels - as per NRL IPv6 - don't actually do anything */
34#define SO_SECURITY_AUTHENTICATION 22
35#define SO_SECURITY_ENCRYPTION_TRANSPORT 23
36#define SO_SECURITY_ENCRYPTION_NETWORK 24
37
38#define SO_BINDTODEVICE 25
39
40/* Socket filtering */
41#define SO_ATTACH_FILTER 26
42#define SO_DETACH_FILTER 27
43
44#define SO_PEERNAME 28
45#define SO_TIMESTAMP 29
46#define SCM_TIMESTAMP SO_TIMESTAMP
47
48#define SO_ACCEPTCONN 30
49
50#define SO_PEERSEC 31
51#define SO_PASSSEC 34
52#define SO_TIMESTAMPNS 35
53#define SCM_TIMESTAMPNS SO_TIMESTAMPNS
54
55#endif /* _ASM_SOCKET_H */
diff --git a/include/asm-x86_64/spinlock_types.h b/include/asm-x86_64/spinlock_types.h
deleted file mode 100644
index 4da9345c1500..000000000000
--- a/include/asm-x86_64/spinlock_types.h
+++ /dev/null
@@ -1,20 +0,0 @@
1#ifndef __ASM_SPINLOCK_TYPES_H
2#define __ASM_SPINLOCK_TYPES_H
3
4#ifndef __LINUX_SPINLOCK_TYPES_H
5# error "please don't include this file directly"
6#endif
7
8typedef struct {
9 unsigned int slock;
10} raw_spinlock_t;
11
12#define __RAW_SPIN_LOCK_UNLOCKED { 1 }
13
14typedef struct {
15 unsigned int lock;
16} raw_rwlock_t;
17
18#define __RAW_RW_LOCK_UNLOCKED { RW_LOCK_BIAS }
19
20#endif
diff --git a/include/asm-x86_64/therm_throt.h b/include/asm-x86_64/therm_throt.h
deleted file mode 100644
index 5aac059007ba..000000000000
--- a/include/asm-x86_64/therm_throt.h
+++ /dev/null
@@ -1 +0,0 @@
1#include <asm-i386/therm_throt.h>
diff --git a/include/asm-x86_64/tsc.h b/include/asm-x86_64/tsc.h
deleted file mode 100644
index d66ba6ef25f6..000000000000
--- a/include/asm-x86_64/tsc.h
+++ /dev/null
@@ -1 +0,0 @@
1#include <asm-i386/tsc.h>
diff --git a/include/asm-x86_64/vga.h b/include/asm-x86_64/vga.h
deleted file mode 100644
index 0ecf68ac03aa..000000000000
--- a/include/asm-x86_64/vga.h
+++ /dev/null
@@ -1,20 +0,0 @@
1/*
2 * Access to VGA videoram
3 *
4 * (c) 1998 Martin Mares <mj@ucw.cz>
5 */
6
7#ifndef _LINUX_ASM_VGA_H_
8#define _LINUX_ASM_VGA_H_
9
10/*
11 * On the PC, we can just recalculate addresses and then
12 * access the videoram directly without any black magic.
13 */
14
15#define VGA_MAP_MEM(x,s) (unsigned long)phys_to_virt(x)
16
17#define vga_readb(x) (*(x))
18#define vga_writeb(x,y) (*(y) = (x))
19
20#endif
diff --git a/include/linux/bio.h b/include/linux/bio.h
index 1ddef34f43c3..089a8bc55dd4 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -64,7 +64,7 @@ struct bio_vec {
64 64
65struct bio_set; 65struct bio_set;
66struct bio; 66struct bio;
67typedef int (bio_end_io_t) (struct bio *, unsigned int, int); 67typedef void (bio_end_io_t) (struct bio *, int);
68typedef void (bio_destructor_t) (struct bio *); 68typedef void (bio_destructor_t) (struct bio *);
69 69
70/* 70/*
@@ -226,7 +226,7 @@ struct bio {
226#define BIO_SEG_BOUNDARY(q, b1, b2) \ 226#define BIO_SEG_BOUNDARY(q, b1, b2) \
227 BIOVEC_SEG_BOUNDARY((q), __BVEC_END((b1)), __BVEC_START((b2))) 227 BIOVEC_SEG_BOUNDARY((q), __BVEC_END((b1)), __BVEC_START((b2)))
228 228
229#define bio_io_error(bio, bytes) bio_endio((bio), (bytes), -EIO) 229#define bio_io_error(bio) bio_endio((bio), -EIO)
230 230
231/* 231/*
232 * drivers should not use the __ version unless they _really_ want to 232 * drivers should not use the __ version unless they _really_ want to
@@ -286,7 +286,7 @@ extern struct bio *bio_alloc_bioset(gfp_t, int, struct bio_set *);
286extern void bio_put(struct bio *); 286extern void bio_put(struct bio *);
287extern void bio_free(struct bio *, struct bio_set *); 287extern void bio_free(struct bio *, struct bio_set *);
288 288
289extern void bio_endio(struct bio *, unsigned int, int); 289extern void bio_endio(struct bio *, int);
290struct request_queue; 290struct request_queue;
291extern int bio_phys_segments(struct request_queue *, struct bio *); 291extern int bio_phys_segments(struct request_queue *, struct bio *);
292extern int bio_hw_segments(struct request_queue *, struct bio *); 292extern int bio_hw_segments(struct request_queue *, struct bio *);
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index b126c6f68e27..95be0ac57e76 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1,6 +1,8 @@
1#ifndef _LINUX_BLKDEV_H 1#ifndef _LINUX_BLKDEV_H
2#define _LINUX_BLKDEV_H 2#define _LINUX_BLKDEV_H
3 3
4#ifdef CONFIG_BLOCK
5
4#include <linux/sched.h> 6#include <linux/sched.h>
5#include <linux/major.h> 7#include <linux/major.h>
6#include <linux/genhd.h> 8#include <linux/genhd.h>
@@ -32,8 +34,6 @@
32) 34)
33#endif 35#endif
34 36
35#ifdef CONFIG_BLOCK
36
37struct scsi_ioctl_command; 37struct scsi_ioctl_command;
38 38
39struct request_queue; 39struct request_queue;
@@ -471,7 +471,6 @@ struct request_queue
471 int orderr, ordcolor; 471 int orderr, ordcolor;
472 struct request pre_flush_rq, bar_rq, post_flush_rq; 472 struct request pre_flush_rq, bar_rq, post_flush_rq;
473 struct request *orig_bar_rq; 473 struct request *orig_bar_rq;
474 unsigned int bi_size;
475 474
476 struct mutex sysfs_lock; 475 struct mutex sysfs_lock;
477 476
@@ -637,10 +636,23 @@ static inline void blk_queue_bounce(struct request_queue *q, struct bio **bio)
637} 636}
638#endif /* CONFIG_MMU */ 637#endif /* CONFIG_MMU */
639 638
640#define rq_for_each_bio(_bio, rq) \ 639struct req_iterator {
640 int i;
641 struct bio *bio;
642};
643
644/* This should not be used directly - use rq_for_each_segment */
645#define __rq_for_each_bio(_bio, rq) \
641 if ((rq->bio)) \ 646 if ((rq->bio)) \
642 for (_bio = (rq)->bio; _bio; _bio = _bio->bi_next) 647 for (_bio = (rq)->bio; _bio; _bio = _bio->bi_next)
643 648
649#define rq_for_each_segment(bvl, _rq, _iter) \
650 __rq_for_each_bio(_iter.bio, _rq) \
651 bio_for_each_segment(bvl, _iter.bio, _iter.i)
652
653#define rq_iter_last(rq, _iter) \
654 (_iter.bio->bi_next == NULL && _iter.i == _iter.bio->bi_vcnt-1)
655
644extern int blk_register_queue(struct gendisk *disk); 656extern int blk_register_queue(struct gendisk *disk);
645extern void blk_unregister_queue(struct gendisk *disk); 657extern void blk_unregister_queue(struct gendisk *disk);
646extern void register_disk(struct gendisk *dev); 658extern void register_disk(struct gendisk *dev);
@@ -662,8 +674,8 @@ extern int sg_scsi_ioctl(struct file *, struct request_queue *,
662/* 674/*
663 * Temporary export, until SCSI gets fixed up. 675 * Temporary export, until SCSI gets fixed up.
664 */ 676 */
665extern int ll_back_merge_fn(struct request_queue *, struct request *, 677extern int blk_rq_append_bio(struct request_queue *q, struct request *rq,
666 struct bio *); 678 struct bio *bio);
667 679
668/* 680/*
669 * A queue has just exitted congestion. Note this in the global counter of 681 * A queue has just exitted congestion. Note this in the global counter of
@@ -810,7 +822,6 @@ static inline struct request *blk_map_queue_find_tag(struct blk_queue_tag *bqt,
810 return bqt->tag_index[tag]; 822 return bqt->tag_index[tag];
811} 823}
812 824
813extern void blk_rq_bio_prep(struct request_queue *, struct request *, struct bio *);
814extern int blkdev_issue_flush(struct block_device *, sector_t *); 825extern int blkdev_issue_flush(struct block_device *, sector_t *);
815 826
816#define MAX_PHYS_SEGMENTS 128 827#define MAX_PHYS_SEGMENTS 128
diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
index 7b5d56b82b59..2e105a12fe29 100644
--- a/include/linux/blktrace_api.h
+++ b/include/linux/blktrace_api.h
@@ -142,10 +142,14 @@ struct blk_user_trace_setup {
142 u32 pid; 142 u32 pid;
143}; 143};
144 144
145#ifdef __KERNEL__
145#if defined(CONFIG_BLK_DEV_IO_TRACE) 146#if defined(CONFIG_BLK_DEV_IO_TRACE)
146extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *); 147extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
147extern void blk_trace_shutdown(struct request_queue *); 148extern void blk_trace_shutdown(struct request_queue *);
148extern void __blk_add_trace(struct blk_trace *, sector_t, int, int, u32, int, int, void *); 149extern void __blk_add_trace(struct blk_trace *, sector_t, int, int, u32, int, int, void *);
150extern int do_blk_trace_setup(struct request_queue *q,
151 struct block_device *bdev, struct blk_user_trace_setup *buts);
152
149 153
150/** 154/**
151 * blk_add_trace_rq - Add a trace for a request oriented action 155 * blk_add_trace_rq - Add a trace for a request oriented action
@@ -286,6 +290,12 @@ static inline void blk_add_trace_remap(struct request_queue *q, struct bio *bio,
286#define blk_add_trace_generic(q, rq, rw, what) do { } while (0) 290#define blk_add_trace_generic(q, rq, rw, what) do { } while (0)
287#define blk_add_trace_pdu_int(q, what, bio, pdu) do { } while (0) 291#define blk_add_trace_pdu_int(q, what, bio, pdu) do { } while (0)
288#define blk_add_trace_remap(q, bio, dev, f, t) do {} while (0) 292#define blk_add_trace_remap(q, bio, dev, f, t) do {} while (0)
293static inline int do_blk_trace_setup(struct request_queue *q,
294 struct block_device *bdev,
295 struct blk_user_trace_setup *buts)
296{
297 return 0;
298}
289#endif /* CONFIG_BLK_DEV_IO_TRACE */ 299#endif /* CONFIG_BLK_DEV_IO_TRACE */
290 300#endif /* __KERNEL__ */
291#endif 301#endif
diff --git a/include/linux/i2c-id.h b/include/linux/i2c-id.h
index b69014865714..a271b67a8e2d 100644
--- a/include/linux/i2c-id.h
+++ b/include/linux/i2c-id.h
@@ -119,6 +119,7 @@
119#define I2C_DRIVERID_WM8750 90 /* Wolfson WM8750 audio codec */ 119#define I2C_DRIVERID_WM8750 90 /* Wolfson WM8750 audio codec */
120#define I2C_DRIVERID_WM8753 91 /* Wolfson WM8753 audio codec */ 120#define I2C_DRIVERID_WM8753 91 /* Wolfson WM8753 audio codec */
121#define I2C_DRIVERID_LM4857 92 /* LM4857 Audio Amplifier */ 121#define I2C_DRIVERID_LM4857 92 /* LM4857 Audio Amplifier */
122#define I2C_DRIVERID_VP27SMPX 93 /* Panasonic VP27s tuner internal MPX */
122 123
123#define I2C_DRIVERID_I2CDEV 900 124#define I2C_DRIVERID_I2CDEV 900
124#define I2C_DRIVERID_ARP 902 /* SMBus ARP Client */ 125#define I2C_DRIVERID_ARP 902 /* SMBus ARP Client */
@@ -196,6 +197,7 @@
196#define I2C_HW_B_EM28XX 0x01001f /* em28xx video capture cards */ 197#define I2C_HW_B_EM28XX 0x01001f /* em28xx video capture cards */
197#define I2C_HW_B_CX2341X 0x010020 /* Conexant CX2341X MPEG encoder cards */ 198#define I2C_HW_B_CX2341X 0x010020 /* Conexant CX2341X MPEG encoder cards */
198#define I2C_HW_B_INTELFB 0x010021 /* intel framebuffer driver */ 199#define I2C_HW_B_INTELFB 0x010021 /* intel framebuffer driver */
200#define I2C_HW_B_CX23885 0x010022 /* conexant 23885 based tv cards (bus1) */
199 201
200/* --- PCF 8584 based algorithms */ 202/* --- PCF 8584 based algorithms */
201#define I2C_HW_P_LP 0x020000 /* Parallel port interface */ 203#define I2C_HW_P_LP 0x020000 /* Parallel port interface */
diff --git a/include/linux/ivtv.h b/include/linux/ivtv.h
new file mode 100644
index 000000000000..794b8daa9378
--- /dev/null
+++ b/include/linux/ivtv.h
@@ -0,0 +1,72 @@
1/*
2 Public ivtv API header
3 Copyright (C) 2003-2004 Kevin Thayer <nufan_wfk at yahoo.com>
4 Copyright (C) 2004-2007 Hans Verkuil <hverkuil@xs4all.nl>
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#ifndef __LINUX_IVTV_H__
22#define __LINUX_IVTV_H__
23
24#ifdef __KERNEL__
25#include <linux/compiler.h> /* need __user */
26#else
27#define __user
28#endif
29#include <linux/types.h>
30
31/* ivtv knows several distinct output modes: MPEG streaming,
32 YUV streaming, YUV updates through user DMA and the passthrough
33 mode.
34
35 In order to clearly tell the driver that we are in user DMA
36 YUV mode you need to call IVTV_IOC_DMA_FRAME with y_source == NULL
37 first (althrough if you don't then the first time
38 DMA_FRAME is called the mode switch is done automatically).
39
40 When you close the file handle the user DMA mode is exited again.
41
42 While in one mode, you cannot use another mode (EBUSY is returned).
43
44 All this means that if you want to change the YUV interlacing
45 for the user DMA YUV mode you first need to do call IVTV_IOC_DMA_FRAME
46 with y_source == NULL before you can set the correct format using
47 VIDIOC_S_FMT.
48
49 Eventually all this should be replaced with a proper V4L2 API,
50 but for now we have to do it this way. */
51
52struct ivtv_dma_frame {
53 enum v4l2_buf_type type; /* V4L2_BUF_TYPE_VIDEO_OUTPUT */
54 __u32 pixelformat; /* 0 == same as destination */
55 void __user *y_source; /* if NULL and type == V4L2_BUF_TYPE_VIDEO_OUTPUT,
56 then just switch to user DMA YUV output mode */
57 void __user *uv_source; /* Unused for RGB pixelformats */
58 struct v4l2_rect src;
59 struct v4l2_rect dst;
60 __u32 src_width;
61 __u32 src_height;
62};
63
64#define IVTV_IOC_DMA_FRAME _IOW ('V', BASE_VIDIOC_PRIVATE+0, struct ivtv_dma_frame)
65
66/* These are the VBI types as they appear in the embedded VBI private packets. */
67#define IVTV_SLICED_TYPE_TELETEXT_B (1)
68#define IVTV_SLICED_TYPE_CAPTION_525 (4)
69#define IVTV_SLICED_TYPE_WSS_625 (5)
70#define IVTV_SLICED_TYPE_VPS (7)
71
72#endif /* _LINUX_IVTV_H */
diff --git a/include/linux/ivtvfb.h b/include/linux/ivtvfb.h
new file mode 100644
index 000000000000..e980ba62ddcc
--- /dev/null
+++ b/include/linux/ivtvfb.h
@@ -0,0 +1,42 @@
1/*
2 On Screen Display cx23415 Framebuffer driver
3
4 Copyright (C) 2006, 2007 Ian Armstrong <ian@iarmst.demon.co.uk>
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#ifndef __LINUX_IVTVFB_H__
22#define __LINUX_IVTVFB_H__
23
24#ifdef __KERNEL__
25#include <linux/compiler.h> /* need __user */
26#else
27#define __user
28#endif
29#include <linux/types.h>
30
31/* Framebuffer external API */
32
33struct ivtvfb_dma_frame {
34 void __user *source;
35 unsigned long dest_offset;
36 int count;
37};
38
39#define IVTVFB_IOC_DMA_FRAME _IOW('V', BASE_VIDIOC_PRIVATE+0, struct ivtvfb_dma_frame)
40#define FBIO_WAITFORVSYNC _IOW('F', 0x20, u_int32_t)
41
42#endif
diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h
index badf702fcff4..0d508ac17d64 100644
--- a/include/linux/mmc/card.h
+++ b/include/linux/mmc/card.h
@@ -55,7 +55,28 @@ struct sd_switch_caps {
55 unsigned int hs_max_dtr; 55 unsigned int hs_max_dtr;
56}; 56};
57 57
58struct sdio_cccr {
59 unsigned int sdio_vsn;
60 unsigned int sd_vsn;
61 unsigned int multi_block:1,
62 low_speed:1,
63 wide_bus:1,
64 high_power:1,
65 high_speed:1;
66};
67
68struct sdio_cis {
69 unsigned short vendor;
70 unsigned short device;
71 unsigned short blksize;
72 unsigned int max_dtr;
73};
74
58struct mmc_host; 75struct mmc_host;
76struct sdio_func;
77struct sdio_func_tuple;
78
79#define SDIO_MAX_FUNCS 7
59 80
60/* 81/*
61 * MMC device 82 * MMC device
@@ -67,11 +88,13 @@ struct mmc_card {
67 unsigned int type; /* card type */ 88 unsigned int type; /* card type */
68#define MMC_TYPE_MMC 0 /* MMC card */ 89#define MMC_TYPE_MMC 0 /* MMC card */
69#define MMC_TYPE_SD 1 /* SD card */ 90#define MMC_TYPE_SD 1 /* SD card */
91#define MMC_TYPE_SDIO 2 /* SDIO card */
70 unsigned int state; /* (our) card state */ 92 unsigned int state; /* (our) card state */
71#define MMC_STATE_PRESENT (1<<0) /* present in sysfs */ 93#define MMC_STATE_PRESENT (1<<0) /* present in sysfs */
72#define MMC_STATE_READONLY (1<<1) /* card is read-only */ 94#define MMC_STATE_READONLY (1<<1) /* card is read-only */
73#define MMC_STATE_HIGHSPEED (1<<2) /* card is in high speed mode */ 95#define MMC_STATE_HIGHSPEED (1<<2) /* card is in high speed mode */
74#define MMC_STATE_BLOCKADDR (1<<3) /* card uses block-addressing */ 96#define MMC_STATE_BLOCKADDR (1<<3) /* card uses block-addressing */
97
75 u32 raw_cid[4]; /* raw card CID */ 98 u32 raw_cid[4]; /* raw card CID */
76 u32 raw_csd[4]; /* raw card CSD */ 99 u32 raw_csd[4]; /* raw card CSD */
77 u32 raw_scr[2]; /* raw card SCR */ 100 u32 raw_scr[2]; /* raw card SCR */
@@ -80,10 +103,19 @@ struct mmc_card {
80 struct mmc_ext_csd ext_csd; /* mmc v4 extended card specific */ 103 struct mmc_ext_csd ext_csd; /* mmc v4 extended card specific */
81 struct sd_scr scr; /* extra SD information */ 104 struct sd_scr scr; /* extra SD information */
82 struct sd_switch_caps sw_caps; /* switch (CMD6) caps */ 105 struct sd_switch_caps sw_caps; /* switch (CMD6) caps */
106
107 unsigned int sdio_funcs; /* number of SDIO functions */
108 struct sdio_cccr cccr; /* common card info */
109 struct sdio_cis cis; /* common tuple info */
110 struct sdio_func *sdio_func[SDIO_MAX_FUNCS]; /* SDIO functions (devices) */
111 unsigned num_info; /* number of info strings */
112 const char **info; /* info strings */
113 struct sdio_func_tuple *tuples; /* unknown common tuples */
83}; 114};
84 115
85#define mmc_card_mmc(c) ((c)->type == MMC_TYPE_MMC) 116#define mmc_card_mmc(c) ((c)->type == MMC_TYPE_MMC)
86#define mmc_card_sd(c) ((c)->type == MMC_TYPE_SD) 117#define mmc_card_sd(c) ((c)->type == MMC_TYPE_SD)
118#define mmc_card_sdio(c) ((c)->type == MMC_TYPE_SDIO)
87 119
88#define mmc_card_present(c) ((c)->state & MMC_STATE_PRESENT) 120#define mmc_card_present(c) ((c)->state & MMC_STATE_PRESENT)
89#define mmc_card_readonly(c) ((c)->state & MMC_STATE_READONLY) 121#define mmc_card_readonly(c) ((c)->state & MMC_STATE_READONLY)
diff --git a/include/linux/mmc/core.h b/include/linux/mmc/core.h
index 63a80ea61124..d0c3abed74c2 100644
--- a/include/linux/mmc/core.h
+++ b/include/linux/mmc/core.h
@@ -25,14 +25,20 @@ struct mmc_command {
25#define MMC_RSP_CRC (1 << 2) /* expect valid crc */ 25#define MMC_RSP_CRC (1 << 2) /* expect valid crc */
26#define MMC_RSP_BUSY (1 << 3) /* card may send busy */ 26#define MMC_RSP_BUSY (1 << 3) /* card may send busy */
27#define MMC_RSP_OPCODE (1 << 4) /* response contains opcode */ 27#define MMC_RSP_OPCODE (1 << 4) /* response contains opcode */
28#define MMC_CMD_MASK (3 << 5) /* command type */ 28
29#define MMC_CMD_MASK (3 << 5) /* non-SPI command type */
29#define MMC_CMD_AC (0 << 5) 30#define MMC_CMD_AC (0 << 5)
30#define MMC_CMD_ADTC (1 << 5) 31#define MMC_CMD_ADTC (1 << 5)
31#define MMC_CMD_BC (2 << 5) 32#define MMC_CMD_BC (2 << 5)
32#define MMC_CMD_BCR (3 << 5) 33#define MMC_CMD_BCR (3 << 5)
33 34
35#define MMC_RSP_SPI_S1 (1 << 7) /* one status byte */
36#define MMC_RSP_SPI_S2 (1 << 8) /* second byte */
37#define MMC_RSP_SPI_B4 (1 << 9) /* four data bytes */
38#define MMC_RSP_SPI_BUSY (1 << 10) /* card may send busy */
39
34/* 40/*
35 * These are the response types, and correspond to valid bit 41 * These are the native response types, and correspond to valid bit
36 * patterns of the above flags. One additional valid pattern 42 * patterns of the above flags. One additional valid pattern
37 * is all zeros, which means we don't expect a response. 43 * is all zeros, which means we don't expect a response.
38 */ 44 */
@@ -41,12 +47,30 @@ struct mmc_command {
41#define MMC_RSP_R1B (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE|MMC_RSP_BUSY) 47#define MMC_RSP_R1B (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE|MMC_RSP_BUSY)
42#define MMC_RSP_R2 (MMC_RSP_PRESENT|MMC_RSP_136|MMC_RSP_CRC) 48#define MMC_RSP_R2 (MMC_RSP_PRESENT|MMC_RSP_136|MMC_RSP_CRC)
43#define MMC_RSP_R3 (MMC_RSP_PRESENT) 49#define MMC_RSP_R3 (MMC_RSP_PRESENT)
50#define MMC_RSP_R4 (MMC_RSP_PRESENT)
51#define MMC_RSP_R5 (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
44#define MMC_RSP_R6 (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE) 52#define MMC_RSP_R6 (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
45#define MMC_RSP_R7 (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE) 53#define MMC_RSP_R7 (MMC_RSP_PRESENT|MMC_RSP_CRC|MMC_RSP_OPCODE)
46 54
47#define mmc_resp_type(cmd) ((cmd)->flags & (MMC_RSP_PRESENT|MMC_RSP_136|MMC_RSP_CRC|MMC_RSP_BUSY|MMC_RSP_OPCODE)) 55#define mmc_resp_type(cmd) ((cmd)->flags & (MMC_RSP_PRESENT|MMC_RSP_136|MMC_RSP_CRC|MMC_RSP_BUSY|MMC_RSP_OPCODE))
48 56
49/* 57/*
58 * These are the SPI response types for MMC, SD, and SDIO cards.
59 * Commands return R1, with maybe more info. Zero is an error type;
60 * callers must always provide the appropriate MMC_RSP_SPI_Rx flags.
61 */
62#define MMC_RSP_SPI_R1 (MMC_RSP_SPI_S1)
63#define MMC_RSP_SPI_R1B (MMC_RSP_SPI_S1|MMC_RSP_SPI_BUSY)
64#define MMC_RSP_SPI_R2 (MMC_RSP_SPI_S1|MMC_RSP_SPI_S2)
65#define MMC_RSP_SPI_R3 (MMC_RSP_SPI_S1|MMC_RSP_SPI_B4)
66#define MMC_RSP_SPI_R4 (MMC_RSP_SPI_S1|MMC_RSP_SPI_B4)
67#define MMC_RSP_SPI_R5 (MMC_RSP_SPI_S1|MMC_RSP_SPI_S2)
68#define MMC_RSP_SPI_R7 (MMC_RSP_SPI_S1|MMC_RSP_SPI_B4)
69
70#define mmc_spi_resp_type(cmd) ((cmd)->flags & \
71 (MMC_RSP_SPI_S1|MMC_RSP_SPI_BUSY|MMC_RSP_SPI_S2|MMC_RSP_SPI_B4))
72
73/*
50 * These are the command types. 74 * These are the command types.
51 */ 75 */
52#define mmc_cmd_type(cmd) ((cmd)->flags & MMC_CMD_MASK) 76#define mmc_cmd_type(cmd) ((cmd)->flags & MMC_CMD_MASK)
@@ -54,12 +78,19 @@ struct mmc_command {
54 unsigned int retries; /* max number of retries */ 78 unsigned int retries; /* max number of retries */
55 unsigned int error; /* command error */ 79 unsigned int error; /* command error */
56 80
57#define MMC_ERR_NONE 0 81/*
58#define MMC_ERR_TIMEOUT 1 82 * Standard errno values are used for errors, but some have specific
59#define MMC_ERR_BADCRC 2 83 * meaning in the MMC layer:
60#define MMC_ERR_FIFO 3 84 *
61#define MMC_ERR_FAILED 4 85 * ETIMEDOUT Card took too long to respond
62#define MMC_ERR_INVALID 5 86 * EILSEQ Basic format problem with the received or sent data
87 * (e.g. CRC check failed, incorrect opcode in response
88 * or bad end bit)
89 * EINVAL Request cannot be performed because of restrictions
90 * in hardware and/or the driver
91 * ENOMEDIUM Host can determine that the slot is empty and is
92 * actively failing requests
93 */
63 94
64 struct mmc_data *data; /* data segment associated with cmd */ 95 struct mmc_data *data; /* data segment associated with cmd */
65 struct mmc_request *mrq; /* associated request */ 96 struct mmc_request *mrq; /* associated request */
@@ -76,7 +107,6 @@ struct mmc_data {
76#define MMC_DATA_WRITE (1 << 8) 107#define MMC_DATA_WRITE (1 << 8)
77#define MMC_DATA_READ (1 << 9) 108#define MMC_DATA_READ (1 << 9)
78#define MMC_DATA_STREAM (1 << 10) 109#define MMC_DATA_STREAM (1 << 10)
79#define MMC_DATA_MULTI (1 << 11)
80 110
81 unsigned int bytes_xfered; 111 unsigned int bytes_xfered;
82 112
@@ -104,9 +134,20 @@ extern int mmc_wait_for_cmd(struct mmc_host *, struct mmc_command *, int);
104extern int mmc_wait_for_app_cmd(struct mmc_host *, struct mmc_card *, 134extern int mmc_wait_for_app_cmd(struct mmc_host *, struct mmc_card *,
105 struct mmc_command *, int); 135 struct mmc_command *, int);
106 136
107extern void mmc_set_data_timeout(struct mmc_data *, const struct mmc_card *, int); 137extern void mmc_set_data_timeout(struct mmc_data *, const struct mmc_card *);
108 138
109extern void mmc_claim_host(struct mmc_host *host); 139extern int __mmc_claim_host(struct mmc_host *host, atomic_t *abort);
110extern void mmc_release_host(struct mmc_host *host); 140extern void mmc_release_host(struct mmc_host *host);
111 141
142/**
143 * mmc_claim_host - exclusively claim a host
144 * @host: mmc host to claim
145 *
146 * Claim a host for a set of operations.
147 */
148static inline void mmc_claim_host(struct mmc_host *host)
149{
150 __mmc_claim_host(host, NULL);
151}
152
112#endif 153#endif
diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h
index b1350dfd3e91..125eee1407ff 100644
--- a/include/linux/mmc/host.h
+++ b/include/linux/mmc/host.h
@@ -10,6 +10,8 @@
10#ifndef LINUX_MMC_HOST_H 10#ifndef LINUX_MMC_HOST_H
11#define LINUX_MMC_HOST_H 11#define LINUX_MMC_HOST_H
12 12
13#include <linux/leds.h>
14
13#include <linux/mmc/core.h> 15#include <linux/mmc/core.h>
14 16
15struct mmc_ios { 17struct mmc_ios {
@@ -51,6 +53,7 @@ struct mmc_host_ops {
51 void (*request)(struct mmc_host *host, struct mmc_request *req); 53 void (*request)(struct mmc_host *host, struct mmc_request *req);
52 void (*set_ios)(struct mmc_host *host, struct mmc_ios *ios); 54 void (*set_ios)(struct mmc_host *host, struct mmc_ios *ios);
53 int (*get_ro)(struct mmc_host *host); 55 int (*get_ro)(struct mmc_host *host);
56 void (*enable_sdio_irq)(struct mmc_host *host, int enable);
54}; 57};
55 58
56struct mmc_card; 59struct mmc_card;
@@ -87,9 +90,10 @@ struct mmc_host {
87 90
88#define MMC_CAP_4_BIT_DATA (1 << 0) /* Can the host do 4 bit transfers */ 91#define MMC_CAP_4_BIT_DATA (1 << 0) /* Can the host do 4 bit transfers */
89#define MMC_CAP_MULTIWRITE (1 << 1) /* Can accurately report bytes sent to card on error */ 92#define MMC_CAP_MULTIWRITE (1 << 1) /* Can accurately report bytes sent to card on error */
90#define MMC_CAP_BYTEBLOCK (1 << 2) /* Can do non-log2 block sizes */ 93#define MMC_CAP_MMC_HIGHSPEED (1 << 2) /* Can do MMC high-speed timing */
91#define MMC_CAP_MMC_HIGHSPEED (1 << 3) /* Can do MMC high-speed timing */ 94#define MMC_CAP_SD_HIGHSPEED (1 << 3) /* Can do SD high-speed timing */
92#define MMC_CAP_SD_HIGHSPEED (1 << 4) /* Can do SD high-speed timing */ 95#define MMC_CAP_SDIO_IRQ (1 << 4) /* Can signal pending SDIO IRQs */
96#define MMC_CAP_SPI (1 << 5) /* Talks only SPI protocols */
93 97
94 /* host specific block data */ 98 /* host specific block data */
95 unsigned int max_seg_size; /* see blk_queue_max_segment_size */ 99 unsigned int max_seg_size; /* see blk_queue_max_segment_size */
@@ -106,6 +110,14 @@ struct mmc_host {
106 struct mmc_ios ios; /* current io bus settings */ 110 struct mmc_ios ios; /* current io bus settings */
107 u32 ocr; /* the current OCR setting */ 111 u32 ocr; /* the current OCR setting */
108 112
113 /* group bitfields together to minimize padding */
114 unsigned int use_spi_crc:1;
115 unsigned int claimed:1; /* host exclusively claimed */
116 unsigned int bus_dead:1; /* bus has been released */
117#ifdef CONFIG_MMC_DEBUG
118 unsigned int removed:1; /* host is being removed */
119#endif
120
109 unsigned int mode; /* current card mode of host */ 121 unsigned int mode; /* current card mode of host */
110#define MMC_MODE_MMC 0 122#define MMC_MODE_MMC 0
111#define MMC_MODE_SD 1 123#define MMC_MODE_SD 1
@@ -113,16 +125,19 @@ struct mmc_host {
113 struct mmc_card *card; /* device attached to this host */ 125 struct mmc_card *card; /* device attached to this host */
114 126
115 wait_queue_head_t wq; 127 wait_queue_head_t wq;
116 unsigned int claimed:1; /* host exclusively claimed */
117 128
118 struct delayed_work detect; 129 struct delayed_work detect;
119#ifdef CONFIG_MMC_DEBUG
120 unsigned int removed:1; /* host is being removed */
121#endif
122 130
123 const struct mmc_bus_ops *bus_ops; /* current bus driver */ 131 const struct mmc_bus_ops *bus_ops; /* current bus driver */
124 unsigned int bus_refs; /* reference counter */ 132 unsigned int bus_refs; /* reference counter */
125 unsigned int bus_dead:1; /* bus has been released */ 133
134 unsigned int sdio_irqs;
135 struct task_struct *sdio_irq_thread;
136 atomic_t sdio_irq_thread_abort;
137
138#ifdef CONFIG_LEDS_TRIGGERS
139 struct led_trigger *led; /* activity led */
140#endif
126 141
127 unsigned long private[0] ____cacheline_aligned; 142 unsigned long private[0] ____cacheline_aligned;
128}; 143};
@@ -137,6 +152,8 @@ static inline void *mmc_priv(struct mmc_host *host)
137 return (void *)host->private; 152 return (void *)host->private;
138} 153}
139 154
155#define mmc_host_is_spi(host) ((host)->caps & MMC_CAP_SPI)
156
140#define mmc_dev(x) ((x)->parent) 157#define mmc_dev(x) ((x)->parent)
141#define mmc_classdev(x) (&(x)->class_dev) 158#define mmc_classdev(x) (&(x)->class_dev)
142#define mmc_hostname(x) ((x)->class_dev.bus_id) 159#define mmc_hostname(x) ((x)->class_dev.bus_id)
@@ -147,5 +164,11 @@ extern int mmc_resume_host(struct mmc_host *);
147extern void mmc_detect_change(struct mmc_host *, unsigned long delay); 164extern void mmc_detect_change(struct mmc_host *, unsigned long delay);
148extern void mmc_request_done(struct mmc_host *, struct mmc_request *); 165extern void mmc_request_done(struct mmc_host *, struct mmc_request *);
149 166
167static inline void mmc_signal_sdio_irq(struct mmc_host *host)
168{
169 host->ops->enable_sdio_irq(host, 0);
170 wake_up_process(host->sdio_irq_thread);
171}
172
150#endif 173#endif
151 174
diff --git a/include/linux/mmc/mmc.h b/include/linux/mmc/mmc.h
index e3ed9b95040e..4236fbf0b6fb 100644
--- a/include/linux/mmc/mmc.h
+++ b/include/linux/mmc/mmc.h
@@ -27,7 +27,7 @@
27 27
28/* Standard MMC commands (4.1) type argument response */ 28/* Standard MMC commands (4.1) type argument response */
29 /* class 1 */ 29 /* class 1 */
30#define MMC_GO_IDLE_STATE 0 /* bc */ 30#define MMC_GO_IDLE_STATE 0 /* bc */
31#define MMC_SEND_OP_COND 1 /* bcr [31:0] OCR R3 */ 31#define MMC_SEND_OP_COND 1 /* bcr [31:0] OCR R3 */
32#define MMC_ALL_SEND_CID 2 /* bcr R2 */ 32#define MMC_ALL_SEND_CID 2 /* bcr R2 */
33#define MMC_SET_RELATIVE_ADDR 3 /* ac [31:16] RCA R1 */ 33#define MMC_SET_RELATIVE_ADDR 3 /* ac [31:16] RCA R1 */
@@ -39,8 +39,10 @@
39#define MMC_SEND_CID 10 /* ac [31:16] RCA R2 */ 39#define MMC_SEND_CID 10 /* ac [31:16] RCA R2 */
40#define MMC_READ_DAT_UNTIL_STOP 11 /* adtc [31:0] dadr R1 */ 40#define MMC_READ_DAT_UNTIL_STOP 11 /* adtc [31:0] dadr R1 */
41#define MMC_STOP_TRANSMISSION 12 /* ac R1b */ 41#define MMC_STOP_TRANSMISSION 12 /* ac R1b */
42#define MMC_SEND_STATUS 13 /* ac [31:16] RCA R1 */ 42#define MMC_SEND_STATUS 13 /* ac [31:16] RCA R1 */
43#define MMC_GO_INACTIVE_STATE 15 /* ac [31:16] RCA */ 43#define MMC_GO_INACTIVE_STATE 15 /* ac [31:16] RCA */
44#define MMC_SPI_READ_OCR 58 /* spi spi_R3 */
45#define MMC_SPI_CRC_ON_OFF 59 /* spi [0:0] flag spi_R1 */
44 46
45 /* class 2 */ 47 /* class 2 */
46#define MMC_SET_BLOCKLEN 16 /* ac [31:0] block len R1 */ 48#define MMC_SET_BLOCKLEN 16 /* ac [31:0] block len R1 */
@@ -90,15 +92,15 @@
90 */ 92 */
91 93
92/* 94/*
93 MMC status in R1 95 MMC status in R1, for native mode (SPI bits are different)
94 Type 96 Type
95 e : error bit 97 e : error bit
96 s : status bit 98 s : status bit
97 r : detected and set for the actual command response 99 r : detected and set for the actual command response
98 x : detected and set during command execution. the host must poll 100 x : detected and set during command execution. the host must poll
99 the card by sending status command in order to read these bits. 101 the card by sending status command in order to read these bits.
100 Clear condition 102 Clear condition
101 a : according to the card state 103 a : according to the card state
102 b : always related to the previous command. Reception of 104 b : always related to the previous command. Reception of
103 a valid command will clear it (with a delay of one command) 105 a valid command will clear it (with a delay of one command)
104 c : clear by read 106 c : clear by read
@@ -124,10 +126,33 @@
124#define R1_CARD_ECC_DISABLED (1 << 14) /* sx, a */ 126#define R1_CARD_ECC_DISABLED (1 << 14) /* sx, a */
125#define R1_ERASE_RESET (1 << 13) /* sr, c */ 127#define R1_ERASE_RESET (1 << 13) /* sr, c */
126#define R1_STATUS(x) (x & 0xFFFFE000) 128#define R1_STATUS(x) (x & 0xFFFFE000)
127#define R1_CURRENT_STATE(x) ((x & 0x00001E00) >> 9) /* sx, b (4 bits) */ 129#define R1_CURRENT_STATE(x) ((x & 0x00001E00) >> 9) /* sx, b (4 bits) */
128#define R1_READY_FOR_DATA (1 << 8) /* sx, a */ 130#define R1_READY_FOR_DATA (1 << 8) /* sx, a */
129#define R1_APP_CMD (1 << 5) /* sr, c */ 131#define R1_APP_CMD (1 << 5) /* sr, c */
130 132
133/*
134 * MMC/SD in SPI mode reports R1 status always, and R2 for SEND_STATUS
135 * R1 is the low order byte; R2 is the next highest byte, when present.
136 */
137#define R1_SPI_IDLE (1 << 0)
138#define R1_SPI_ERASE_RESET (1 << 1)
139#define R1_SPI_ILLEGAL_COMMAND (1 << 2)
140#define R1_SPI_COM_CRC (1 << 3)
141#define R1_SPI_ERASE_SEQ (1 << 4)
142#define R1_SPI_ADDRESS (1 << 5)
143#define R1_SPI_PARAMETER (1 << 6)
144/* R1 bit 7 is always zero */
145#define R2_SPI_CARD_LOCKED (1 << 8)
146#define R2_SPI_WP_ERASE_SKIP (1 << 9) /* or lock/unlock fail */
147#define R2_SPI_LOCK_UNLOCK_FAIL R2_SPI_WP_ERASE_SKIP
148#define R2_SPI_ERROR (1 << 10)
149#define R2_SPI_CC_ERROR (1 << 11)
150#define R2_SPI_CARD_ECC_ERROR (1 << 12)
151#define R2_SPI_WP_VIOLATION (1 << 13)
152#define R2_SPI_ERASE_PARAM (1 << 14)
153#define R2_SPI_OUT_OF_RANGE (1 << 15) /* or CSD overwrite */
154#define R2_SPI_CSD_OVERWRITE R2_SPI_OUT_OF_RANGE
155
131/* These are unpacked versions of the actual responses */ 156/* These are unpacked versions of the actual responses */
132 157
133struct _mmc_csd { 158struct _mmc_csd {
@@ -182,6 +207,7 @@ struct _mmc_csd {
182 */ 207 */
183#define CCC_BASIC (1<<0) /* (0) Basic protocol functions */ 208#define CCC_BASIC (1<<0) /* (0) Basic protocol functions */
184 /* (CMD0,1,2,3,4,7,9,10,12,13,15) */ 209 /* (CMD0,1,2,3,4,7,9,10,12,13,15) */
210 /* (and for SPI, CMD58,59) */
185#define CCC_STREAM_READ (1<<1) /* (1) Stream read commands */ 211#define CCC_STREAM_READ (1<<1) /* (1) Stream read commands */
186 /* (CMD11) */ 212 /* (CMD11) */
187#define CCC_BLOCK_READ (1<<2) /* (2) Block read commands */ 213#define CCC_BLOCK_READ (1<<2) /* (2) Block read commands */
@@ -227,6 +253,7 @@ struct _mmc_csd {
227#define EXT_CSD_BUS_WIDTH 183 /* R/W */ 253#define EXT_CSD_BUS_WIDTH 183 /* R/W */
228#define EXT_CSD_HS_TIMING 185 /* R/W */ 254#define EXT_CSD_HS_TIMING 185 /* R/W */
229#define EXT_CSD_CARD_TYPE 196 /* RO */ 255#define EXT_CSD_CARD_TYPE 196 /* RO */
256#define EXT_CSD_REV 192 /* RO */
230#define EXT_CSD_SEC_CNT 212 /* RO, 4 bytes */ 257#define EXT_CSD_SEC_CNT 212 /* RO, 4 bytes */
231 258
232/* 259/*
diff --git a/include/linux/mmc/sdio.h b/include/linux/mmc/sdio.h
new file mode 100644
index 000000000000..47ba464f5170
--- /dev/null
+++ b/include/linux/mmc/sdio.h
@@ -0,0 +1,159 @@
1/*
2 * include/linux/mmc/sdio.h
3 *
4 * Copyright 2006-2007 Pierre Ossman
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 (at
9 * your option) any later version.
10 */
11
12#ifndef MMC_SDIO_H
13#define MMC_SDIO_H
14
15/* SDIO commands type argument response */
16#define SD_IO_SEND_OP_COND 5 /* bcr [23:0] OCR R4 */
17#define SD_IO_RW_DIRECT 52 /* ac [31:0] See below R5 */
18#define SD_IO_RW_EXTENDED 53 /* adtc [31:0] See below R5 */
19
20/*
21 * SD_IO_RW_DIRECT argument format:
22 *
23 * [31] R/W flag
24 * [30:28] Function number
25 * [27] RAW flag
26 * [25:9] Register address
27 * [7:0] Data
28 */
29
30/*
31 * SD_IO_RW_EXTENDED argument format:
32 *
33 * [31] R/W flag
34 * [30:28] Function number
35 * [27] Block mode
36 * [26] Increment address
37 * [25:9] Register address
38 * [8:0] Byte/block count
39 */
40
41/*
42 SDIO status in R5
43 Type
44 e : error bit
45 s : status bit
46 r : detected and set for the actual command response
47 x : detected and set during command execution. the host must poll
48 the card by sending status command in order to read these bits.
49 Clear condition
50 a : according to the card state
51 b : always related to the previous command. Reception of
52 a valid command will clear it (with a delay of one command)
53 c : clear by read
54 */
55
56#define R5_COM_CRC_ERROR (1 << 15) /* er, b */
57#define R5_ILLEGAL_COMMAND (1 << 14) /* er, b */
58#define R5_ERROR (1 << 11) /* erx, c */
59#define R5_FUNCTION_NUMBER (1 << 9) /* er, c */
60#define R5_OUT_OF_RANGE (1 << 8) /* er, c */
61#define R5_STATUS(x) (x & 0xCB00)
62#define R5_IO_CURRENT_STATE(x) ((x & 0x3000) >> 12) /* s, b */
63
64/*
65 * Card Common Control Registers (CCCR)
66 */
67
68#define SDIO_CCCR_CCCR 0x00
69
70#define SDIO_CCCR_REV_1_00 0 /* CCCR/FBR Version 1.00 */
71#define SDIO_CCCR_REV_1_10 1 /* CCCR/FBR Version 1.10 */
72#define SDIO_CCCR_REV_1_20 2 /* CCCR/FBR Version 1.20 */
73
74#define SDIO_SDIO_REV_1_00 0 /* SDIO Spec Version 1.00 */
75#define SDIO_SDIO_REV_1_10 1 /* SDIO Spec Version 1.10 */
76#define SDIO_SDIO_REV_1_20 2 /* SDIO Spec Version 1.20 */
77#define SDIO_SDIO_REV_2_00 3 /* SDIO Spec Version 2.00 */
78
79#define SDIO_CCCR_SD 0x01
80
81#define SDIO_SD_REV_1_01 0 /* SD Physical Spec Version 1.01 */
82#define SDIO_SD_REV_1_10 1 /* SD Physical Spec Version 1.10 */
83#define SDIO_SD_REV_2_00 2 /* SD Physical Spec Version 2.00 */
84
85#define SDIO_CCCR_IOEx 0x02
86#define SDIO_CCCR_IORx 0x03
87
88#define SDIO_CCCR_IENx 0x04 /* Function/Master Interrupt Enable */
89#define SDIO_CCCR_INTx 0x05 /* Function Interrupt Pending */
90
91#define SDIO_CCCR_ABORT 0x06 /* function abort/card reset */
92
93#define SDIO_CCCR_IF 0x07 /* bus interface controls */
94
95#define SDIO_BUS_WIDTH_1BIT 0x00
96#define SDIO_BUS_WIDTH_4BIT 0x02
97
98#define SDIO_BUS_CD_DISABLE 0x80 /* disable pull-up on DAT3 (pin 1) */
99
100#define SDIO_CCCR_CAPS 0x08
101
102#define SDIO_CCCR_CAP_SDC 0x01 /* can do CMD52 while data transfer */
103#define SDIO_CCCR_CAP_SMB 0x02 /* can do multi-block xfers (CMD53) */
104#define SDIO_CCCR_CAP_SRW 0x04 /* supports read-wait protocol */
105#define SDIO_CCCR_CAP_SBS 0x08 /* supports suspend/resume */
106#define SDIO_CCCR_CAP_S4MI 0x10 /* interrupt during 4-bit CMD53 */
107#define SDIO_CCCR_CAP_E4MI 0x20 /* enable ints during 4-bit CMD53 */
108#define SDIO_CCCR_CAP_LSC 0x40 /* low speed card */
109#define SDIO_CCCR_CAP_4BLS 0x80 /* 4 bit low speed card */
110
111#define SDIO_CCCR_CIS 0x09 /* common CIS pointer (3 bytes) */
112
113/* Following 4 regs are valid only if SBS is set */
114#define SDIO_CCCR_SUSPEND 0x0c
115#define SDIO_CCCR_SELx 0x0d
116#define SDIO_CCCR_EXECx 0x0e
117#define SDIO_CCCR_READYx 0x0f
118
119#define SDIO_CCCR_BLKSIZE 0x10
120
121#define SDIO_CCCR_POWER 0x12
122
123#define SDIO_POWER_SMPC 0x01 /* Supports Master Power Control */
124#define SDIO_POWER_EMPC 0x02 /* Enable Master Power Control */
125
126#define SDIO_CCCR_SPEED 0x13
127
128#define SDIO_SPEED_SHS 0x01 /* Supports High-Speed mode */
129#define SDIO_SPEED_EHS 0x02 /* Enable High-Speed mode */
130
131/*
132 * Function Basic Registers (FBR)
133 */
134
135#define SDIO_FBR_BASE(f) ((f) * 0x100) /* base of function f's FBRs */
136
137#define SDIO_FBR_STD_IF 0x00
138
139#define SDIO_FBR_SUPPORTS_CSA 0x40 /* supports Code Storage Area */
140#define SDIO_FBR_ENABLE_CSA 0x80 /* enable Code Storage Area */
141
142#define SDIO_FBR_STD_IF_EXT 0x01
143
144#define SDIO_FBR_POWER 0x02
145
146#define SDIO_FBR_POWER_SPS 0x01 /* Supports Power Selection */
147#define SDIO_FBR_POWER_EPS 0x02 /* Enable (low) Power Selection */
148
149#define SDIO_FBR_CIS 0x09 /* CIS pointer (3 bytes) */
150
151
152#define SDIO_FBR_CSA 0x0C /* CSA pointer (3 bytes) */
153
154#define SDIO_FBR_CSA_DATA 0x0F
155
156#define SDIO_FBR_BLKSIZE 0x10 /* block size (2 bytes) */
157
158#endif
159
diff --git a/include/linux/mmc/sdio_func.h b/include/linux/mmc/sdio_func.h
new file mode 100644
index 000000000000..b050f4d7b41f
--- /dev/null
+++ b/include/linux/mmc/sdio_func.h
@@ -0,0 +1,153 @@
1/*
2 * include/linux/mmc/sdio_func.h
3 *
4 * Copyright 2007 Pierre Ossman
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 (at
9 * your option) any later version.
10 */
11
12#ifndef MMC_SDIO_FUNC_H
13#define MMC_SDIO_FUNC_H
14
15#include <linux/device.h>
16#include <linux/mod_devicetable.h>
17
18struct mmc_card;
19struct sdio_func;
20
21typedef void (sdio_irq_handler_t)(struct sdio_func *);
22
23/*
24 * SDIO function CIS tuple (unknown to the core)
25 */
26struct sdio_func_tuple {
27 struct sdio_func_tuple *next;
28 unsigned char code;
29 unsigned char size;
30 unsigned char data[0];
31};
32
33/*
34 * SDIO function devices
35 */
36struct sdio_func {
37 struct mmc_card *card; /* the card this device belongs to */
38 struct device dev; /* the device */
39 sdio_irq_handler_t *irq_handler; /* IRQ callback */
40 unsigned int num; /* function number */
41
42 unsigned char class; /* standard interface class */
43 unsigned short vendor; /* vendor id */
44 unsigned short device; /* device id */
45
46 unsigned max_blksize; /* maximum block size */
47 unsigned cur_blksize; /* current block size */
48
49 unsigned int state; /* function state */
50#define SDIO_STATE_PRESENT (1<<0) /* present in sysfs */
51
52 u8 tmpbuf[4]; /* DMA:able scratch buffer */
53
54 unsigned num_info; /* number of info strings */
55 const char **info; /* info strings */
56
57 struct sdio_func_tuple *tuples;
58};
59
60#define sdio_func_present(f) ((f)->state & SDIO_STATE_PRESENT)
61
62#define sdio_func_set_present(f) ((f)->state |= SDIO_STATE_PRESENT)
63
64#define sdio_func_id(f) ((f)->dev.bus_id)
65
66#define sdio_get_drvdata(f) dev_get_drvdata(&(f)->dev)
67#define sdio_set_drvdata(f,d) dev_set_drvdata(&(f)->dev, d)
68
69/*
70 * SDIO function device driver
71 */
72struct sdio_driver {
73 char *name;
74 const struct sdio_device_id *id_table;
75
76 int (*probe)(struct sdio_func *, const struct sdio_device_id *);
77 void (*remove)(struct sdio_func *);
78
79 struct device_driver drv;
80};
81
82/**
83 * SDIO_DEVICE - macro used to describe a specific SDIO device
84 * @vend: the 16 bit manufacturer code
85 * @dev: the 16 bit function id
86 *
87 * This macro is used to create a struct sdio_device_id that matches a
88 * specific device. The class field will be set to SDIO_ANY_ID.
89 */
90#define SDIO_DEVICE(vend,dev) \
91 .class = SDIO_ANY_ID, \
92 .vendor = (vend), .device = (dev)
93
94/**
95 * SDIO_DEVICE_CLASS - macro used to describe a specific SDIO device class
96 * @dev_class: the 8 bit standard interface code
97 *
98 * This macro is used to create a struct sdio_device_id that matches a
99 * specific standard SDIO function type. The vendor and device fields will
100 * be set to SDIO_ANY_ID.
101 */
102#define SDIO_DEVICE_CLASS(dev_class) \
103 .class = (dev_class), \
104 .vendor = SDIO_ANY_ID, .device = SDIO_ANY_ID
105
106extern int sdio_register_driver(struct sdio_driver *);
107extern void sdio_unregister_driver(struct sdio_driver *);
108
109/*
110 * SDIO I/O operations
111 */
112extern void sdio_claim_host(struct sdio_func *func);
113extern void sdio_release_host(struct sdio_func *func);
114
115extern int sdio_enable_func(struct sdio_func *func);
116extern int sdio_disable_func(struct sdio_func *func);
117
118extern int sdio_set_block_size(struct sdio_func *func, unsigned blksz);
119
120extern int sdio_claim_irq(struct sdio_func *func, sdio_irq_handler_t *handler);
121extern int sdio_release_irq(struct sdio_func *func);
122
123extern unsigned char sdio_readb(struct sdio_func *func,
124 unsigned int addr, int *err_ret);
125extern unsigned short sdio_readw(struct sdio_func *func,
126 unsigned int addr, int *err_ret);
127extern unsigned long sdio_readl(struct sdio_func *func,
128 unsigned int addr, int *err_ret);
129
130extern int sdio_memcpy_fromio(struct sdio_func *func, void *dst,
131 unsigned int addr, int count);
132extern int sdio_readsb(struct sdio_func *func, void *dst,
133 unsigned int addr, int count);
134
135extern void sdio_writeb(struct sdio_func *func, unsigned char b,
136 unsigned int addr, int *err_ret);
137extern void sdio_writew(struct sdio_func *func, unsigned short b,
138 unsigned int addr, int *err_ret);
139extern void sdio_writel(struct sdio_func *func, unsigned long b,
140 unsigned int addr, int *err_ret);
141
142extern int sdio_memcpy_toio(struct sdio_func *func, unsigned int addr,
143 void *src, int count);
144extern int sdio_writesb(struct sdio_func *func, unsigned int addr,
145 void *src, int count);
146
147extern unsigned char sdio_f0_readb(struct sdio_func *func,
148 unsigned int addr, int *err_ret);
149extern void sdio_f0_writeb(struct sdio_func *func, unsigned char b,
150 unsigned int addr, int *err_ret);
151
152#endif
153
diff --git a/include/linux/mmc/sdio_ids.h b/include/linux/mmc/sdio_ids.h
new file mode 100644
index 000000000000..09306d47ff5e
--- /dev/null
+++ b/include/linux/mmc/sdio_ids.h
@@ -0,0 +1,23 @@
1/*
2 * SDIO Classes, Interface Types, Manufacturer IDs, etc.
3 */
4
5#ifndef MMC_SDIO_IDS_H
6#define MMC_SDIO_IDS_H
7
8/*
9 * Standard SDIO Function Interfaces
10 */
11
12#define SDIO_CLASS_NONE 0x00 /* Not a SDIO standard interface */
13#define SDIO_CLASS_UART 0x01 /* standard UART interface */
14#define SDIO_CLASS_BT_A 0x02 /* Type-A BlueTooth std interface */
15#define SDIO_CLASS_BT_B 0x03 /* Type-B BlueTooth std interface */
16#define SDIO_CLASS_GPS 0x04 /* GPS standard interface */
17#define SDIO_CLASS_CAMERA 0x05 /* Camera standard interface */
18#define SDIO_CLASS_PHS 0x06 /* PHS standard interface */
19#define SDIO_CLASS_WLAN 0x07 /* WLAN interface */
20#define SDIO_CLASS_ATA 0x08 /* Embedded SDIO-ATA std interface */
21
22
23#endif
diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
index 4dc5fa8be781..e47e5951058b 100644
--- a/include/linux/mod_devicetable.h
+++ b/include/linux/mod_devicetable.h
@@ -340,4 +340,15 @@ struct parisc_device_id {
340#define PA_HVERSION_ANY_ID 0xffff 340#define PA_HVERSION_ANY_ID 0xffff
341#define PA_SVERSION_ANY_ID 0xffffffff 341#define PA_SVERSION_ANY_ID 0xffffffff
342 342
343/* SDIO */
344
345#define SDIO_ANY_ID (~0)
346
347struct sdio_device_id {
348 __u8 class; /* Standard interface or SDIO_ANY_ID */
349 __u16 vendor; /* Vendor or SDIO_ANY_ID */
350 __u16 device; /* Device ID or SDIO_ANY_ID */
351 kernel_ulong_t driver_data; /* Data private to the driver */
352};
353
343#endif /* LINUX_MOD_DEVICETABLE_H */ 354#endif /* LINUX_MOD_DEVICETABLE_H */
diff --git a/include/linux/pci_ids.h b/include/linux/pci_ids.h
index 55f307ffbf96..cfee06bca2d3 100644
--- a/include/linux/pci_ids.h
+++ b/include/linux/pci_ids.h
@@ -1471,6 +1471,8 @@
1471#define PCI_DEVICE_ID_RICOH_RL5C476 0x0476 1471#define PCI_DEVICE_ID_RICOH_RL5C476 0x0476
1472#define PCI_DEVICE_ID_RICOH_RL5C478 0x0478 1472#define PCI_DEVICE_ID_RICOH_RL5C478 0x0478
1473#define PCI_DEVICE_ID_RICOH_R5C822 0x0822 1473#define PCI_DEVICE_ID_RICOH_R5C822 0x0822
1474#define PCI_DEVICE_ID_RICOH_R5C832 0x0832
1475#define PCI_DEVICE_ID_RICOH_R5C843 0x0843
1474 1476
1475#define PCI_VENDOR_ID_DLINK 0x1186 1477#define PCI_VENDOR_ID_DLINK 0x1186
1476#define PCI_DEVICE_ID_DLINK_DGE510T 0x4c00 1478#define PCI_DEVICE_ID_DLINK_DGE510T 0x4c00
@@ -1736,6 +1738,11 @@
1736 1738
1737#define PCI_VENDOR_ID_RADISYS 0x1331 1739#define PCI_VENDOR_ID_RADISYS 0x1331
1738 1740
1741#define PCI_VENDOR_ID_MICRO_MEMORY 0x1332
1742#define PCI_DEVICE_ID_MICRO_MEMORY_5415CN 0x5415
1743#define PCI_DEVICE_ID_MICRO_MEMORY_5425CN 0x5425
1744#define PCI_DEVICE_ID_MICRO_MEMORY_6155 0x6155
1745
1739#define PCI_VENDOR_ID_DOMEX 0x134a 1746#define PCI_VENDOR_ID_DOMEX 0x134a
1740#define PCI_DEVICE_ID_DOMEX_DMX3191D 0x0001 1747#define PCI_DEVICE_ID_DOMEX_DMX3191D 0x0001
1741 1748
diff --git a/include/linux/spi/mmc_spi.h b/include/linux/spi/mmc_spi.h
new file mode 100644
index 000000000000..e9bbe3ebd721
--- /dev/null
+++ b/include/linux/spi/mmc_spi.h
@@ -0,0 +1,33 @@
1#ifndef __LINUX_SPI_MMC_SPI_H
2#define __LINUX_SPI_MMC_SPI_H
3
4struct device;
5struct mmc_host;
6
7/* Put this in platform_data of a device being used to manage an MMC/SD
8 * card slot. (Modeled after PXA mmc glue; see that for usage examples.)
9 *
10 * REVISIT This is not a spi-specific notion. Any card slot should be
11 * able to handle it. If the MMC core doesn't adopt this kind of notion,
12 * switch the "struct device *" parameters over to "struct spi_device *".
13 */
14struct mmc_spi_platform_data {
15 /* driver activation and (optional) card detect irq hookup */
16 int (*init)(struct device *,
17 irqreturn_t (*)(int, void *),
18 void *);
19 void (*exit)(struct device *, void *);
20
21 /* sense switch on sd cards */
22 int (*get_ro)(struct device *);
23
24 /* how long to debounce card detect, in msecs */
25 u16 detect_delay;
26
27 /* power management */
28 u16 powerup_msecs; /* delay of up to 250 msec */
29 u32 ocr_mask; /* available voltages */
30 void (*setpower)(struct device *, unsigned int maskval);
31};
32
33#endif /* __LINUX_SPI_MMC_SPI_H */
diff --git a/include/linux/swap.h b/include/linux/swap.h
index 665f85f2a3af..edf681a7fd8f 100644
--- a/include/linux/swap.h
+++ b/include/linux/swap.h
@@ -221,7 +221,7 @@ extern void swap_unplug_io_fn(struct backing_dev_info *, struct page *);
221/* linux/mm/page_io.c */ 221/* linux/mm/page_io.c */
222extern int swap_readpage(struct file *, struct page *); 222extern int swap_readpage(struct file *, struct page *);
223extern int swap_writepage(struct page *page, struct writeback_control *wbc); 223extern int swap_writepage(struct page *page, struct writeback_control *wbc);
224extern int end_swap_bio_read(struct bio *bio, unsigned int bytes_done, int err); 224extern void end_swap_bio_read(struct bio *bio, int err);
225 225
226/* linux/mm/swap_state.c */ 226/* linux/mm/swap_state.c */
227extern struct address_space swapper_space; 227extern struct address_space swapper_space;
diff --git a/include/linux/umem.h b/include/linux/umem.h
deleted file mode 100644
index f36ebfc32bf6..000000000000
--- a/include/linux/umem.h
+++ /dev/null
@@ -1,138 +0,0 @@
1
2/*
3 * This file contains defines for the
4 * Micro Memory MM5415
5 * family PCI Memory Module with Battery Backup.
6 *
7 * Copyright Micro Memory INC 2001. All rights reserved.
8 * Release under the terms of the GNU GENERAL PUBLIC LICENSE version 2.
9 * See the file COPYING.
10 */
11
12#ifndef _DRIVERS_BLOCK_MM_H
13#define _DRIVERS_BLOCK_MM_H
14
15
16#define IRQ_TIMEOUT (1 * HZ)
17
18/* CSR register definition */
19#define MEMCTRLSTATUS_MAGIC 0x00
20#define MM_MAGIC_VALUE (unsigned char)0x59
21
22#define MEMCTRLSTATUS_BATTERY 0x04
23#define BATTERY_1_DISABLED 0x01
24#define BATTERY_1_FAILURE 0x02
25#define BATTERY_2_DISABLED 0x04
26#define BATTERY_2_FAILURE 0x08
27
28#define MEMCTRLSTATUS_MEMORY 0x07
29#define MEM_128_MB 0xfe
30#define MEM_256_MB 0xfc
31#define MEM_512_MB 0xf8
32#define MEM_1_GB 0xf0
33#define MEM_2_GB 0xe0
34
35#define MEMCTRLCMD_LEDCTRL 0x08
36#define LED_REMOVE 2
37#define LED_FAULT 4
38#define LED_POWER 6
39#define LED_FLIP 255
40#define LED_OFF 0x00
41#define LED_ON 0x01
42#define LED_FLASH_3_5 0x02
43#define LED_FLASH_7_0 0x03
44#define LED_POWER_ON 0x00
45#define LED_POWER_OFF 0x01
46#define USER_BIT1 0x01
47#define USER_BIT2 0x02
48
49#define MEMORY_INITIALIZED USER_BIT1
50
51#define MEMCTRLCMD_ERRCTRL 0x0C
52#define EDC_NONE_DEFAULT 0x00
53#define EDC_NONE 0x01
54#define EDC_STORE_READ 0x02
55#define EDC_STORE_CORRECT 0x03
56
57#define MEMCTRLCMD_ERRCNT 0x0D
58#define MEMCTRLCMD_ERRSTATUS 0x0E
59
60#define ERROR_DATA_LOG 0x20
61#define ERROR_ADDR_LOG 0x28
62#define ERROR_COUNT 0x3D
63#define ERROR_SYNDROME 0x3E
64#define ERROR_CHECK 0x3F
65
66#define DMA_PCI_ADDR 0x40
67#define DMA_LOCAL_ADDR 0x48
68#define DMA_TRANSFER_SIZE 0x50
69#define DMA_DESCRIPTOR_ADDR 0x58
70#define DMA_SEMAPHORE_ADDR 0x60
71#define DMA_STATUS_CTRL 0x68
72#define DMASCR_GO 0x00001
73#define DMASCR_TRANSFER_READ 0x00002
74#define DMASCR_CHAIN_EN 0x00004
75#define DMASCR_SEM_EN 0x00010
76#define DMASCR_DMA_COMP_EN 0x00020
77#define DMASCR_CHAIN_COMP_EN 0x00040
78#define DMASCR_ERR_INT_EN 0x00080
79#define DMASCR_PARITY_INT_EN 0x00100
80#define DMASCR_ANY_ERR 0x00800
81#define DMASCR_MBE_ERR 0x01000
82#define DMASCR_PARITY_ERR_REP 0x02000
83#define DMASCR_PARITY_ERR_DET 0x04000
84#define DMASCR_SYSTEM_ERR_SIG 0x08000
85#define DMASCR_TARGET_ABT 0x10000
86#define DMASCR_MASTER_ABT 0x20000
87#define DMASCR_DMA_COMPLETE 0x40000
88#define DMASCR_CHAIN_COMPLETE 0x80000
89
90/*
913.SOME PCs HAVE HOST BRIDGES WHICH APPARENTLY DO NOT CORRECTLY HANDLE
92READ-LINE (0xE) OR READ-MULTIPLE (0xC) PCI COMMAND CODES DURING DMA
93TRANSFERS. IN OTHER SYSTEMS THESE COMMAND CODES WILL CAUSE THE HOST BRIDGE
94TO ALLOW LONGER BURSTS DURING DMA READ OPERATIONS. THE UPPER FOUR BITS
95(31..28) OF THE DMA CSR HAVE BEEN MADE PROGRAMMABLE, SO THAT EITHER A 0x6,
96AN 0xE OR A 0xC CAN BE WRITTEN TO THEM TO SET THE COMMAND CODE USED DURING
97DMA READ OPERATIONS.
98*/
99#define DMASCR_READ 0x60000000
100#define DMASCR_READLINE 0xE0000000
101#define DMASCR_READMULTI 0xC0000000
102
103
104#define DMASCR_ERROR_MASK (DMASCR_MASTER_ABT | DMASCR_TARGET_ABT | DMASCR_SYSTEM_ERR_SIG | DMASCR_PARITY_ERR_DET | DMASCR_MBE_ERR | DMASCR_ANY_ERR)
105#define DMASCR_HARD_ERROR (DMASCR_MASTER_ABT | DMASCR_TARGET_ABT | DMASCR_SYSTEM_ERR_SIG | DMASCR_PARITY_ERR_DET | DMASCR_MBE_ERR)
106
107#define WINDOWMAP_WINNUM 0x7B
108
109#define DMA_READ_FROM_HOST 0
110#define DMA_WRITE_TO_HOST 1
111
112struct mm_dma_desc {
113 __le64 pci_addr;
114 __le64 local_addr;
115 __le32 transfer_size;
116 u32 zero1;
117 __le64 next_desc_addr;
118 __le64 sem_addr;
119 __le32 control_bits;
120 u32 zero2;
121
122 dma_addr_t data_dma_handle;
123
124 /* Copy of the bits */
125 __le64 sem_control_bits;
126} __attribute__((aligned(8)));
127
128#define PCI_VENDOR_ID_MICRO_MEMORY 0x1332
129#define PCI_DEVICE_ID_MICRO_MEMORY_5415CN 0x5415
130#define PCI_DEVICE_ID_MICRO_MEMORY_5425CN 0x5425
131#define PCI_DEVICE_ID_MICRO_MEMORY_6155 0x6155
132
133/* bits for card->flags */
134#define UM_FLAG_DMA_IN_REGS 1
135#define UM_FLAG_NO_BYTE_STATUS 2
136#define UM_FLAG_NO_BATTREG 4
137#define UM_FLAG_NO_BATT 8
138#endif
diff --git a/include/linux/videodev2.h b/include/linux/videodev2.h
index ae9b24c12f6a..1f503e94eff1 100644
--- a/include/linux/videodev2.h
+++ b/include/linux/videodev2.h
@@ -271,6 +271,7 @@ struct v4l2_pix_format
271 271
272/* Pixel format FOURCC depth Description */ 272/* Pixel format FOURCC depth Description */
273#define V4L2_PIX_FMT_RGB332 v4l2_fourcc('R','G','B','1') /* 8 RGB-3-3-2 */ 273#define V4L2_PIX_FMT_RGB332 v4l2_fourcc('R','G','B','1') /* 8 RGB-3-3-2 */
274#define V4L2_PIX_FMT_RGB444 v4l2_fourcc('R','4','4','4') /* 16 xxxxrrrr ggggbbbb */
274#define V4L2_PIX_FMT_RGB555 v4l2_fourcc('R','G','B','O') /* 16 RGB-5-5-5 */ 275#define V4L2_PIX_FMT_RGB555 v4l2_fourcc('R','G','B','O') /* 16 RGB-5-5-5 */
275#define V4L2_PIX_FMT_RGB565 v4l2_fourcc('R','G','B','P') /* 16 RGB-5-6-5 */ 276#define V4L2_PIX_FMT_RGB565 v4l2_fourcc('R','G','B','P') /* 16 RGB-5-6-5 */
276#define V4L2_PIX_FMT_RGB555X v4l2_fourcc('R','G','B','Q') /* 16 RGB-5-5-5 BE */ 277#define V4L2_PIX_FMT_RGB555X v4l2_fourcc('R','G','B','Q') /* 16 RGB-5-5-5 BE */
@@ -280,6 +281,7 @@ struct v4l2_pix_format
280#define V4L2_PIX_FMT_BGR32 v4l2_fourcc('B','G','R','4') /* 32 BGR-8-8-8-8 */ 281#define V4L2_PIX_FMT_BGR32 v4l2_fourcc('B','G','R','4') /* 32 BGR-8-8-8-8 */
281#define V4L2_PIX_FMT_RGB32 v4l2_fourcc('R','G','B','4') /* 32 RGB-8-8-8-8 */ 282#define V4L2_PIX_FMT_RGB32 v4l2_fourcc('R','G','B','4') /* 32 RGB-8-8-8-8 */
282#define V4L2_PIX_FMT_GREY v4l2_fourcc('G','R','E','Y') /* 8 Greyscale */ 283#define V4L2_PIX_FMT_GREY v4l2_fourcc('G','R','E','Y') /* 8 Greyscale */
284#define V4L2_PIX_FMT_PAL8 v4l2_fourcc('P','A','L','8') /* 8 8-bit palette */
283#define V4L2_PIX_FMT_YVU410 v4l2_fourcc('Y','V','U','9') /* 9 YVU 4:1:0 */ 285#define V4L2_PIX_FMT_YVU410 v4l2_fourcc('Y','V','U','9') /* 9 YVU 4:1:0 */
284#define V4L2_PIX_FMT_YVU420 v4l2_fourcc('Y','V','1','2') /* 12 YVU 4:2:0 */ 286#define V4L2_PIX_FMT_YVU420 v4l2_fourcc('Y','V','1','2') /* 12 YVU 4:2:0 */
285#define V4L2_PIX_FMT_YUYV v4l2_fourcc('Y','U','Y','V') /* 16 YUV 4:2:2 */ 287#define V4L2_PIX_FMT_YUYV v4l2_fourcc('Y','U','Y','V') /* 16 YUV 4:2:2 */
@@ -287,6 +289,10 @@ struct v4l2_pix_format
287#define V4L2_PIX_FMT_YUV422P v4l2_fourcc('4','2','2','P') /* 16 YVU422 planar */ 289#define V4L2_PIX_FMT_YUV422P v4l2_fourcc('4','2','2','P') /* 16 YVU422 planar */
288#define V4L2_PIX_FMT_YUV411P v4l2_fourcc('4','1','1','P') /* 16 YVU411 planar */ 290#define V4L2_PIX_FMT_YUV411P v4l2_fourcc('4','1','1','P') /* 16 YVU411 planar */
289#define V4L2_PIX_FMT_Y41P v4l2_fourcc('Y','4','1','P') /* 12 YUV 4:1:1 */ 291#define V4L2_PIX_FMT_Y41P v4l2_fourcc('Y','4','1','P') /* 12 YUV 4:1:1 */
292#define V4L2_PIX_FMT_YUV444 v4l2_fourcc('Y','4','4','4') /* 16 xxxxyyyy uuuuvvvv */
293#define V4L2_PIX_FMT_YUV555 v4l2_fourcc('Y','U','V','O') /* 16 YUV-5-5-5 */
294#define V4L2_PIX_FMT_YUV565 v4l2_fourcc('Y','U','V','P') /* 16 YUV-5-6-5 */
295#define V4L2_PIX_FMT_YUV32 v4l2_fourcc('Y','U','V','4') /* 32 YUV-8-8-8-8 */
290 296
291/* two planes -- one Y, one Cr + Cb interleaved */ 297/* two planes -- one Y, one Cr + Cb interleaved */
292#define V4L2_PIX_FMT_NV12 v4l2_fourcc('N','V','1','2') /* 12 Y/CbCr 4:2:0 */ 298#define V4L2_PIX_FMT_NV12 v4l2_fourcc('N','V','1','2') /* 12 Y/CbCr 4:2:0 */
@@ -298,7 +304,6 @@ struct v4l2_pix_format
298#define V4L2_PIX_FMT_YYUV v4l2_fourcc('Y','Y','U','V') /* 16 YUV 4:2:2 */ 304#define V4L2_PIX_FMT_YYUV v4l2_fourcc('Y','Y','U','V') /* 16 YUV 4:2:2 */
299#define V4L2_PIX_FMT_HI240 v4l2_fourcc('H','I','2','4') /* 8 8-bit color */ 305#define V4L2_PIX_FMT_HI240 v4l2_fourcc('H','I','2','4') /* 8 8-bit color */
300#define V4L2_PIX_FMT_HM12 v4l2_fourcc('H','M','1','2') /* 8 YUV 4:2:0 16x16 macroblocks */ 306#define V4L2_PIX_FMT_HM12 v4l2_fourcc('H','M','1','2') /* 8 YUV 4:2:0 16x16 macroblocks */
301#define V4L2_PIX_FMT_RGB444 v4l2_fourcc('R','4','4','4') /* 16 xxxxrrrr ggggbbbb */
302 307
303/* see http://www.siliconimaging.com/RGB%20Bayer.htm */ 308/* see http://www.siliconimaging.com/RGB%20Bayer.htm */
304#define V4L2_PIX_FMT_SBGGR8 v4l2_fourcc('B','A','8','1') /* 8 BGBG.. GRGR.. */ 309#define V4L2_PIX_FMT_SBGGR8 v4l2_fourcc('B','A','8','1') /* 8 BGBG.. GRGR.. */
diff --git a/include/linux/writeback.h b/include/linux/writeback.h
index b4af6bcb7b7a..c7c3337c3a88 100644
--- a/include/linux/writeback.h
+++ b/include/linux/writeback.h
@@ -5,6 +5,7 @@
5#define WRITEBACK_H 5#define WRITEBACK_H
6 6
7#include <linux/sched.h> 7#include <linux/sched.h>
8#include <linux/fs.h>
8 9
9struct backing_dev_info; 10struct backing_dev_info;
10 11
diff --git a/include/media/cx2341x.h b/include/media/cx2341x.h
index 38c12fed7535..af8071d7620d 100644
--- a/include/media/cx2341x.h
+++ b/include/media/cx2341x.h
@@ -91,7 +91,7 @@ int cx2341x_update(void *priv, cx2341x_mbox_func func,
91int cx2341x_ctrl_query(struct cx2341x_mpeg_params *params, 91int cx2341x_ctrl_query(struct cx2341x_mpeg_params *params,
92 struct v4l2_queryctrl *qctrl); 92 struct v4l2_queryctrl *qctrl);
93const char **cx2341x_ctrl_get_menu(u32 id); 93const char **cx2341x_ctrl_get_menu(u32 id);
94int cx2341x_ext_ctrls(struct cx2341x_mpeg_params *params, 94int cx2341x_ext_ctrls(struct cx2341x_mpeg_params *params, int busy,
95 struct v4l2_ext_controls *ctrls, unsigned int cmd); 95 struct v4l2_ext_controls *ctrls, unsigned int cmd);
96void cx2341x_fill_defaults(struct cx2341x_mpeg_params *p); 96void cx2341x_fill_defaults(struct cx2341x_mpeg_params *p);
97void cx2341x_log_status(struct cx2341x_mpeg_params *p, const char *prefix); 97void cx2341x_log_status(struct cx2341x_mpeg_params *p, const char *prefix);
diff --git a/include/media/ir-common.h b/include/media/ir-common.h
index 9807a7c15830..7a785fa77212 100644
--- a/include/media/ir-common.h
+++ b/include/media/ir-common.h
@@ -140,6 +140,7 @@ extern IR_KEYTAB_TYPE ir_codes_budget_ci_old[IR_KEYTAB_SIZE];
140extern IR_KEYTAB_TYPE ir_codes_asus_pc39[IR_KEYTAB_SIZE]; 140extern IR_KEYTAB_TYPE ir_codes_asus_pc39[IR_KEYTAB_SIZE];
141extern IR_KEYTAB_TYPE ir_codes_encore_enltv[IR_KEYTAB_SIZE]; 141extern IR_KEYTAB_TYPE ir_codes_encore_enltv[IR_KEYTAB_SIZE];
142extern IR_KEYTAB_TYPE ir_codes_tt_1500[IR_KEYTAB_SIZE]; 142extern IR_KEYTAB_TYPE ir_codes_tt_1500[IR_KEYTAB_SIZE];
143extern IR_KEYTAB_TYPE ir_codes_fusionhdtv_mce[IR_KEYTAB_SIZE];
143 144
144#endif 145#endif
145 146
diff --git a/include/media/ivtv.h b/include/media/ivtv.h
deleted file mode 100644
index 412b48ea8eda..000000000000
--- a/include/media/ivtv.h
+++ /dev/null
@@ -1,65 +0,0 @@
1/*
2 Public ivtv API header
3 Copyright (C) 2003-2004 Kevin Thayer <nufan_wfk at yahoo.com>
4 Copyright (C) 2004-2007 Hans Verkuil <hverkuil@xs4all.nl>
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#ifndef _LINUX_IVTV_H
22#define _LINUX_IVTV_H
23
24/* ivtv knows several distinct output modes: MPEG streaming,
25 YUV streaming, YUV updates through user DMA and the passthrough
26 mode.
27
28 In order to clearly tell the driver that we are in user DMA
29 YUV mode you need to call IVTV_IOC_DMA_FRAME with y_source == NULL
30 first (althrough if you don't then the first time
31 DMA_FRAME is called the mode switch is done automatically).
32
33 When you close the file handle the user DMA mode is exited again.
34
35 While in one mode, you cannot use another mode (EBUSY is returned).
36
37 All this means that if you want to change the YUV interlacing
38 for the user DMA YUV mode you first need to do call IVTV_IOC_DMA_FRAME
39 with y_source == NULL before you can set the correct format using
40 VIDIOC_S_FMT.
41
42 Eventually all this should be replaced with a proper V4L2 API,
43 but for now we have to do it this way. */
44
45struct ivtv_dma_frame {
46 enum v4l2_buf_type type; /* V4L2_BUF_TYPE_VIDEO_OUTPUT */
47 __u32 pixelformat; /* 0 == same as destination */
48 void __user *y_source; /* if NULL and type == V4L2_BUF_TYPE_VIDEO_OUTPUT,
49 then just switch to user DMA YUV output mode */
50 void __user *uv_source; /* Unused for RGB pixelformats */
51 struct v4l2_rect src;
52 struct v4l2_rect dst;
53 __u32 src_width;
54 __u32 src_height;
55};
56
57#define IVTV_IOC_DMA_FRAME _IOW ('V', BASE_VIDIOC_PRIVATE+0, struct ivtv_dma_frame)
58
59/* These are the VBI types as they appear in the embedded VBI private packets. */
60#define IVTV_SLICED_TYPE_TELETEXT_B (1)
61#define IVTV_SLICED_TYPE_CAPTION_525 (4)
62#define IVTV_SLICED_TYPE_WSS_625 (5)
63#define IVTV_SLICED_TYPE_VPS (7)
64
65#endif /* _LINUX_IVTV_H */
diff --git a/include/media/saa7146.h b/include/media/saa7146.h
index 67703249b245..cd3ff2c29d5e 100644
--- a/include/media/saa7146.h
+++ b/include/media/saa7146.h
@@ -146,7 +146,6 @@ struct saa7146_dev
146 146
147/* from saa7146_i2c.c */ 147/* from saa7146_i2c.c */
148int saa7146_i2c_adapter_prepare(struct saa7146_dev *dev, struct i2c_adapter *i2c_adapter, u32 bitrate); 148int saa7146_i2c_adapter_prepare(struct saa7146_dev *dev, struct i2c_adapter *i2c_adapter, u32 bitrate);
149int saa7146_i2c_transfer(struct saa7146_dev *saa, const struct i2c_msg *msgs, int num, int retries);
150 149
151/* from saa7146_core.c */ 150/* from saa7146_core.c */
152extern struct list_head saa7146_devices; 151extern struct list_head saa7146_devices;
diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
index cce20ed5cf6c..e49f7e156061 100644
--- a/include/media/saa7146_vv.h
+++ b/include/media/saa7146_vv.h
@@ -4,7 +4,7 @@
4#include <linux/videodev.h> 4#include <linux/videodev.h>
5#include <media/v4l2-common.h> 5#include <media/v4l2-common.h>
6#include <media/saa7146.h> 6#include <media/saa7146.h>
7#include <media/video-buf.h> 7#include <media/videobuf-dma-sg.h>
8 8
9#define MAX_SAA7146_CAPTURE_BUFFERS 32 /* arbitrary */ 9#define MAX_SAA7146_CAPTURE_BUFFERS 32 /* arbitrary */
10#define BUFFER_TIMEOUT (HZ/2) /* 0.5 seconds */ 10#define BUFFER_TIMEOUT (HZ/2) /* 0.5 seconds */
diff --git a/include/media/tuner-types.h b/include/media/tuner-types.h
index e5ad3fcfe984..b201371416a0 100644
--- a/include/media/tuner-types.h
+++ b/include/media/tuner-types.h
@@ -79,6 +79,10 @@ struct tuner_params {
79 /* Select 18% (or according to datasheet 0%) L standard PLL gating, 79 /* Select 18% (or according to datasheet 0%) L standard PLL gating,
80 vs the driver default of 36%. */ 80 vs the driver default of 36%. */
81 unsigned int default_pll_gating_18:1; 81 unsigned int default_pll_gating_18:1;
82 /* IF to use in radio mode. Tuners with a separate radio IF filter
83 seem to use 10.7, while those without use 33.3 for PAL/SECAM tuners
84 and 41.3 for NTSC tuners. 0 = 10.7, 1 = 33.3, 2 = 41.3 */
85 unsigned int radio_if:2;
82 /* Default tda9887 TOP value in dB for the low band. Default is 0. 86 /* Default tda9887 TOP value in dB for the low band. Default is 0.
83 Range: -16:+15 */ 87 Range: -16:+15 */
84 signed int default_top_low:5; 88 signed int default_top_low:5;
diff --git a/include/media/tuner.h b/include/media/tuner.h
index 160381c72e4b..c03dceb92605 100644
--- a/include/media/tuner.h
+++ b/include/media/tuner.h
@@ -146,6 +146,7 @@ extern int tuner_debug;
146#define TDA9887_AUTOMUTE (1<<18) 146#define TDA9887_AUTOMUTE (1<<18)
147#define TDA9887_GATING_18 (1<<19) 147#define TDA9887_GATING_18 (1<<19)
148#define TDA9887_GAIN_NORMAL (1<<20) 148#define TDA9887_GAIN_NORMAL (1<<20)
149#define TDA9887_RIF_41_3 (1<<21) /* radio IF1 41.3 vs 33.3 */
149 150
150#ifdef __KERNEL__ 151#ifdef __KERNEL__
151 152
diff --git a/include/media/v4l2-chip-ident.h b/include/media/v4l2-chip-ident.h
index 09d16c4f00f7..8ae42c41dd08 100644
--- a/include/media/v4l2-chip-ident.h
+++ b/include/media/v4l2-chip-ident.h
@@ -65,6 +65,9 @@ enum {
65 V4L2_IDENT_CX23415 = 415, 65 V4L2_IDENT_CX23415 = 415,
66 V4L2_IDENT_CX23416 = 416, 66 V4L2_IDENT_CX23416 = 416,
67 67
68 /* module vp27smpx: just ident 2700 */
69 V4L2_IDENT_VP27SMPX = 2700,
70
68 /* module wm8739: just ident 8739 */ 71 /* module wm8739: just ident 8739 */
69 V4L2_IDENT_WM8739 = 8739, 72 V4L2_IDENT_WM8739 = 8739,
70 73
diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
index 17f8f3a2f0a3..e75d5e6c4cea 100644
--- a/include/media/v4l2-dev.h
+++ b/include/media/v4l2-dev.h
@@ -23,8 +23,6 @@
23#include <linux/videodev2.h> 23#include <linux/videodev2.h>
24#endif 24#endif
25 25
26#include <linux/fs.h>
27
28#define VIDEO_MAJOR 81 26#define VIDEO_MAJOR 81
29/* Minor device allocation */ 27/* Minor device allocation */
30#define MINOR_VFL_TYPE_GRABBER_MIN 0 28#define MINOR_VFL_TYPE_GRABBER_MIN 0
@@ -88,8 +86,11 @@ struct video_device
88 /* device ops */ 86 /* device ops */
89 const struct file_operations *fops; 87 const struct file_operations *fops;
90 88
89 /* sysfs */
90 struct device class_dev; /* v4l device */
91 struct device *dev; /* device parent */
92
91 /* device info */ 93 /* device info */
92 struct device *dev;
93 char name[32]; 94 char name[32];
94 int type; /* v4l1 */ 95 int type; /* v4l1 */
95 int type2; /* v4l2 */ 96 int type2; /* v4l2 */
@@ -334,7 +335,6 @@ void *priv;
334 /* for videodev.c intenal usage -- please don't touch */ 335 /* for videodev.c intenal usage -- please don't touch */
335 int users; /* video_exclusive_{open|close} ... */ 336 int users; /* video_exclusive_{open|close} ... */
336 struct mutex lock; /* ... helper function uses these */ 337 struct mutex lock; /* ... helper function uses these */
337 struct class_device class_dev; /* sysfs */
338}; 338};
339 339
340/* Class-dev to video-device */ 340/* Class-dev to video-device */
@@ -362,18 +362,18 @@ extern int video_usercopy(struct inode *inode, struct file *file,
362 362
363static inline int __must_check 363static inline int __must_check
364video_device_create_file(struct video_device *vfd, 364video_device_create_file(struct video_device *vfd,
365 struct class_device_attribute *attr) 365 struct device_attribute *attr)
366{ 366{
367 int ret = class_device_create_file(&vfd->class_dev, attr); 367 int ret = device_create_file(&vfd->class_dev, attr);
368 if (ret < 0) 368 if (ret < 0)
369 printk(KERN_WARNING "%s error: %d\n", __FUNCTION__, ret); 369 printk(KERN_WARNING "%s error: %d\n", __FUNCTION__, ret);
370 return ret; 370 return ret;
371} 371}
372static inline void 372static inline void
373video_device_remove_file(struct video_device *vfd, 373video_device_remove_file(struct video_device *vfd,
374 struct class_device_attribute *attr) 374 struct device_attribute *attr)
375{ 375{
376 class_device_remove_file(&vfd->class_dev, attr); 376 device_remove_file(&vfd->class_dev, attr);
377} 377}
378 378
379#endif /* CONFIG_VIDEO_V4L1_COMPAT */ 379#endif /* CONFIG_VIDEO_V4L1_COMPAT */
diff --git a/include/media/v4l2-int-device.h b/include/media/v4l2-int-device.h
new file mode 100644
index 000000000000..066ebfc4f983
--- /dev/null
+++ b/include/media/v4l2-int-device.h
@@ -0,0 +1,278 @@
1/*
2 * include/media/v4l2-int-device.h
3 *
4 * V4L2 internal ioctl interface.
5 *
6 * Copyright (C) 2007 Nokia Corporation.
7 *
8 * Contact: Sakari Ailus <sakari.ailus@nokia.com>
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * version 2 as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
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., 51 Franklin St, Fifth Floor, Boston, MA
22 * 02110-1301 USA
23 */
24
25#ifndef V4L2_INT_DEVICE_H
26#define V4L2_INT_DEVICE_H
27
28#include <linux/module.h>
29#include <media/v4l2-common.h>
30
31#define V4L2NAMESIZE 32
32
33/*
34 *
35 * The internal V4L2 device interface core.
36 *
37 */
38
39enum v4l2_int_type {
40 v4l2_int_type_master = 1,
41 v4l2_int_type_slave
42};
43
44struct v4l2_int_device;
45
46struct v4l2_int_master {
47 int (*attach)(struct v4l2_int_device *master,
48 struct v4l2_int_device *slave);
49 void (*detach)(struct v4l2_int_device *master);
50};
51
52typedef int (v4l2_int_ioctl_func)(struct v4l2_int_device *);
53typedef int (v4l2_int_ioctl_func_0)(struct v4l2_int_device *);
54typedef int (v4l2_int_ioctl_func_1)(struct v4l2_int_device *, void *);
55
56struct v4l2_int_ioctl_desc {
57 int num;
58 v4l2_int_ioctl_func *func;
59};
60
61struct v4l2_int_slave {
62 /* Don't touch master. */
63 struct v4l2_int_device *master;
64
65 char attach_to[V4L2NAMESIZE];
66
67 int num_ioctls;
68 struct v4l2_int_ioctl_desc *ioctls;
69};
70
71struct v4l2_int_device {
72 /* Don't touch head. */
73 struct list_head head;
74
75 struct module *module;
76
77 char name[V4L2NAMESIZE];
78
79 enum v4l2_int_type type;
80 union {
81 struct v4l2_int_master *master;
82 struct v4l2_int_slave *slave;
83 } u;
84
85 void *priv;
86};
87
88int v4l2_int_device_register(struct v4l2_int_device *d);
89void v4l2_int_device_unregister(struct v4l2_int_device *d);
90
91int v4l2_int_ioctl_0(struct v4l2_int_device *d, int cmd);
92int v4l2_int_ioctl_1(struct v4l2_int_device *d, int cmd, void *arg);
93
94/*
95 *
96 * Types and definitions for IOCTL commands.
97 *
98 */
99
100/* Slave interface type. */
101enum v4l2_if_type {
102 /*
103 * Parallel 8-, 10- or 12-bit interface, used by for example
104 * on certain image sensors.
105 */
106 V4L2_IF_TYPE_BT656,
107};
108
109enum v4l2_if_type_bt656_mode {
110 /*
111 * Modes without Bt synchronisation codes. Separate
112 * synchronisation signal lines are used.
113 */
114 V4L2_IF_TYPE_BT656_MODE_NOBT_8BIT,
115 V4L2_IF_TYPE_BT656_MODE_NOBT_10BIT,
116 V4L2_IF_TYPE_BT656_MODE_NOBT_12BIT,
117 /*
118 * Use Bt synchronisation codes. The vertical and horizontal
119 * synchronisation is done based on synchronisation codes.
120 */
121 V4L2_IF_TYPE_BT656_MODE_BT_8BIT,
122 V4L2_IF_TYPE_BT656_MODE_BT_10BIT,
123};
124
125struct v4l2_if_type_bt656 {
126 /*
127 * 0: Frame begins when vsync is high.
128 * 1: Frame begins when vsync changes from low to high.
129 */
130 unsigned frame_start_on_rising_vs:1;
131 /* Use Bt synchronisation codes for sync correction. */
132 unsigned bt_sync_correct:1;
133 /* Swap every two adjacent image data elements. */
134 unsigned swap:1;
135 /* Inverted latch clock polarity from slave. */
136 unsigned latch_clk_inv:1;
137 /* Hs polarity. 0 is active high, 1 active low. */
138 unsigned nobt_hs_inv:1;
139 /* Vs polarity. 0 is active high, 1 active low. */
140 unsigned nobt_vs_inv:1;
141 enum v4l2_if_type_bt656_mode mode;
142 /* Minimum accepted bus clock for slave (in Hz). */
143 u32 clock_min;
144 /* Maximum accepted bus clock for slave. */
145 u32 clock_max;
146 /*
147 * Current wish of the slave. May only change in response to
148 * ioctls that affect image capture.
149 */
150 u32 clock_curr;
151};
152
153struct v4l2_ifparm {
154 enum v4l2_if_type if_type;
155 union {
156 struct v4l2_if_type_bt656 bt656;
157 } u;
158};
159
160/* IOCTL command numbers. */
161enum v4l2_int_ioctl_num {
162 /*
163 *
164 * "Proper" V4L ioctls, as in struct video_device.
165 *
166 */
167 vidioc_int_enum_fmt_cap_num = 1,
168 vidioc_int_g_fmt_cap_num,
169 vidioc_int_s_fmt_cap_num,
170 vidioc_int_try_fmt_cap_num,
171 vidioc_int_queryctrl_num,
172 vidioc_int_g_ctrl_num,
173 vidioc_int_s_ctrl_num,
174 vidioc_int_g_parm_num,
175 vidioc_int_s_parm_num,
176
177 /*
178 *
179 * Strictly internal ioctls.
180 *
181 */
182 /* Initialise the device when slave attaches to the master. */
183 vidioc_int_dev_init_num = 1000,
184 /* Delinitialise the device at slave detach. */
185 vidioc_int_dev_exit_num,
186 /* Set device power state: 0 is off, non-zero is on. */
187 vidioc_int_s_power_num,
188 /* Get slave interface parameters. */
189 vidioc_int_g_ifparm_num,
190 /* Does the slave need to be reset after VIDIOC_DQBUF? */
191 vidioc_int_g_needs_reset_num,
192
193 /*
194 *
195 * VIDIOC_INT_* ioctls.
196 *
197 */
198 /* VIDIOC_INT_RESET */
199 vidioc_int_reset_num,
200 /* VIDIOC_INT_INIT */
201 vidioc_int_init_num,
202 /* VIDIOC_INT_G_CHIP_IDENT */
203 vidioc_int_g_chip_ident_num,
204
205 /*
206 *
207 * Start of private ioctls.
208 *
209 */
210 vidioc_int_priv_start_num = 2000,
211};
212
213/*
214 *
215 * IOCTL wrapper functions for better type checking.
216 *
217 */
218
219#define V4L2_INT_WRAPPER_0(name) \
220 static inline int vidioc_int_##name(struct v4l2_int_device *d) \
221 { \
222 return v4l2_int_ioctl_0(d, vidioc_int_##name##_num); \
223 } \
224 \
225 static inline struct v4l2_int_ioctl_desc \
226 vidioc_int_##name##_cb(int (*func) \
227 (struct v4l2_int_device *)) \
228 { \
229 struct v4l2_int_ioctl_desc desc; \
230 \
231 desc.num = vidioc_int_##name##_num; \
232 desc.func = (v4l2_int_ioctl_func *)func; \
233 \
234 return desc; \
235 }
236
237#define V4L2_INT_WRAPPER_1(name, arg_type, asterisk) \
238 static inline int vidioc_int_##name(struct v4l2_int_device *d, \
239 arg_type asterisk arg) \
240 { \
241 return v4l2_int_ioctl_1(d, vidioc_int_##name##_num, \
242 (void *)(unsigned long)arg); \
243 } \
244 \
245 static inline struct v4l2_int_ioctl_desc \
246 vidioc_int_##name##_cb(int (*func) \
247 (struct v4l2_int_device *, \
248 arg_type asterisk)) \
249 { \
250 struct v4l2_int_ioctl_desc desc; \
251 \
252 desc.num = vidioc_int_##name##_num; \
253 desc.func = (v4l2_int_ioctl_func *)func; \
254 \
255 return desc; \
256 }
257
258V4L2_INT_WRAPPER_1(enum_fmt_cap, struct v4l2_fmtdesc, *);
259V4L2_INT_WRAPPER_1(g_fmt_cap, struct v4l2_format, *);
260V4L2_INT_WRAPPER_1(s_fmt_cap, struct v4l2_format, *);
261V4L2_INT_WRAPPER_1(try_fmt_cap, struct v4l2_format, *);
262V4L2_INT_WRAPPER_1(queryctrl, struct v4l2_queryctrl, *);
263V4L2_INT_WRAPPER_1(g_ctrl, struct v4l2_control, *);
264V4L2_INT_WRAPPER_1(s_ctrl, struct v4l2_control, *);
265V4L2_INT_WRAPPER_1(g_parm, struct v4l2_streamparm, *);
266V4L2_INT_WRAPPER_1(s_parm, struct v4l2_streamparm, *);
267
268V4L2_INT_WRAPPER_0(dev_init);
269V4L2_INT_WRAPPER_0(dev_exit);
270V4L2_INT_WRAPPER_1(s_power, int, );
271V4L2_INT_WRAPPER_1(g_ifparm, struct v4l2_ifparm, *);
272V4L2_INT_WRAPPER_1(g_needs_reset, void, *);
273
274V4L2_INT_WRAPPER_0(reset);
275V4L2_INT_WRAPPER_0(init);
276V4L2_INT_WRAPPER_1(g_chip_ident, int, *);
277
278#endif
diff --git a/include/media/video-buf.h b/include/media/video-buf.h
deleted file mode 100644
index d6f079476db3..000000000000
--- a/include/media/video-buf.h
+++ /dev/null
@@ -1,289 +0,0 @@
1/*
2 *
3 * generic helper functions for video4linux capture buffers, to handle
4 * memory management and PCI DMA.
5 * Right now, bttv, saa7134, saa7146 and cx88 use it.
6 *
7 * The functions expect the hardware being able to scatter gatter
8 * (i.e. the buffers are not linear in physical memory, but fragmented
9 * into PAGE_SIZE chunks). They also assume the driver does not need
10 * to touch the video data.
11 *
12 * device specific map/unmap/sync stuff now are mapped as file operations
13 * to allow its usage by USB and virtual devices.
14 *
15 * (c) 2001,02 Gerd Knorr <kraxel@bytesex.org>
16 * (c) 2006 Mauro Carvalho Chehab, <mchehab@infradead.org>
17 * (c) 2006 Ted Walther and John Sokol
18 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
23 */
24
25#include <linux/videodev2.h>
26#include <linux/poll.h>
27
28#define UNSET (-1U)
29
30/* --------------------------------------------------------------------- */
31
32/*
33 * Return a scatterlist for some page-aligned vmalloc()'ed memory
34 * block (NULL on errors). Memory for the scatterlist is allocated
35 * using kmalloc. The caller must free the memory.
36 */
37struct scatterlist* videobuf_vmalloc_to_sg(unsigned char *virt, int nr_pages);
38
39/*
40 * Return a scatterlist for a an array of userpages (NULL on errors).
41 * Memory for the scatterlist is allocated using kmalloc. The caller
42 * must free the memory.
43 */
44struct scatterlist* videobuf_pages_to_sg(struct page **pages, int nr_pages,
45 int offset);
46
47struct videobuf_buffer;
48struct videobuf_queue;
49
50/* --------------------------------------------------------------------- */
51
52/*
53 * A small set of helper functions to manage buffers (both userland
54 * and kernel) for DMA.
55 *
56 * videobuf_dma_init_*()
57 * creates a buffer. The userland version takes a userspace
58 * pointer + length. The kernel version just wants the size and
59 * does memory allocation too using vmalloc_32().
60 *
61 * videobuf_dma_*()
62 * see Documentation/DMA-mapping.txt, these functions to
63 * basically the same. The map function does also build a
64 * scatterlist for the buffer (and unmap frees it ...)
65 *
66 * videobuf_dma_free()
67 * no comment ...
68 *
69 */
70
71struct videobuf_dmabuf {
72 u32 magic;
73
74 /* for userland buffer */
75 int offset;
76 struct page **pages;
77
78 /* for kernel buffers */
79 void *vmalloc;
80
81 /* Stores the userspace pointer to vmalloc area */
82 void *varea;
83
84 /* for overlay buffers (pci-pci dma) */
85 dma_addr_t bus_addr;
86
87 /* common */
88 struct scatterlist *sglist;
89 int sglen;
90 int nr_pages;
91 int direction;
92};
93
94void videobuf_dma_init(struct videobuf_dmabuf *dma);
95int videobuf_dma_init_user(struct videobuf_dmabuf *dma, int direction,
96 unsigned long data, unsigned long size);
97int videobuf_dma_init_kernel(struct videobuf_dmabuf *dma, int direction,
98 int nr_pages);
99int videobuf_dma_init_overlay(struct videobuf_dmabuf *dma, int direction,
100 dma_addr_t addr, int nr_pages);
101int videobuf_dma_free(struct videobuf_dmabuf *dma);
102
103int videobuf_dma_map(struct videobuf_queue* q,struct videobuf_dmabuf *dma);
104int videobuf_dma_sync(struct videobuf_queue* q,struct videobuf_dmabuf *dma);
105int videobuf_dma_unmap(struct videobuf_queue* q,struct videobuf_dmabuf *dma);
106
107 /*FIXME: these variants are used only on *-alsa code, where videobuf is
108 * used without queue
109 */
110int videobuf_pci_dma_map(struct pci_dev *pci,struct videobuf_dmabuf *dma);
111int videobuf_pci_dma_unmap(struct pci_dev *pci,struct videobuf_dmabuf *dma);
112
113/* --------------------------------------------------------------------- */
114
115/*
116 * A small set of helper functions to manage video4linux buffers.
117 *
118 * struct videobuf_buffer holds the data structures used by the helper
119 * functions, additionally some commonly used fields for v4l buffers
120 * (width, height, lists, waitqueue) are in there. That struct should
121 * be used as first element in the drivers buffer struct.
122 *
123 * about the mmap helpers (videobuf_mmap_*):
124 *
125 * The mmaper function allows to map any subset of contingous buffers.
126 * This includes one mmap() call for all buffers (which the original
127 * video4linux API uses) as well as one mmap() for every single buffer
128 * (which v4l2 uses).
129 *
130 * If there is a valid mapping for a buffer, buffer->baddr/bsize holds
131 * userspace address + size which can be feeded into the
132 * videobuf_dma_init_user function listed above.
133 *
134 */
135
136struct videobuf_mapping {
137 unsigned int count;
138 unsigned long start;
139 unsigned long end;
140 struct videobuf_queue *q;
141};
142
143enum videobuf_state {
144 STATE_NEEDS_INIT = 0,
145 STATE_PREPARED = 1,
146 STATE_QUEUED = 2,
147 STATE_ACTIVE = 3,
148 STATE_DONE = 4,
149 STATE_ERROR = 5,
150 STATE_IDLE = 6,
151};
152
153struct videobuf_buffer {
154 unsigned int i;
155 u32 magic;
156
157 /* info about the buffer */
158 unsigned int width;
159 unsigned int height;
160 unsigned int bytesperline; /* use only if != 0 */
161 unsigned long size;
162 unsigned int input;
163 enum v4l2_field field;
164 enum videobuf_state state;
165 struct videobuf_dmabuf dma;
166 struct list_head stream; /* QBUF/DQBUF list */
167
168 /* for mmap'ed buffers */
169 enum v4l2_memory memory;
170 size_t boff; /* buffer offset (mmap + overlay) */
171 size_t bsize; /* buffer size */
172 unsigned long baddr; /* buffer addr (userland ptr!) */
173 struct videobuf_mapping *map;
174
175 /* touched by irq handler */
176 struct list_head queue;
177 wait_queue_head_t done;
178 unsigned int field_count;
179 struct timeval ts;
180};
181
182typedef int (vb_map_sg_t)(void *dev,struct scatterlist *sglist,int nr_pages,
183 int direction);
184
185
186struct videobuf_queue_ops {
187 int (*buf_setup)(struct videobuf_queue *q,
188 unsigned int *count, unsigned int *size);
189 int (*buf_prepare)(struct videobuf_queue *q,
190 struct videobuf_buffer *vb,
191 enum v4l2_field field);
192 void (*buf_queue)(struct videobuf_queue *q,
193 struct videobuf_buffer *vb);
194 void (*buf_release)(struct videobuf_queue *q,
195 struct videobuf_buffer *vb);
196
197 /* Helper operations - device dependent.
198 * If null, videobuf_init defaults all to PCI handling
199 */
200
201 vb_map_sg_t *vb_map_sg;
202 vb_map_sg_t *vb_dma_sync_sg;
203 vb_map_sg_t *vb_unmap_sg;
204};
205
206struct videobuf_queue {
207 struct mutex lock;
208 spinlock_t *irqlock;
209 void *dev; /* on pci, points to struct pci_dev */
210
211 enum v4l2_buf_type type;
212 unsigned int inputs; /* for V4L2_BUF_FLAG_INPUT */
213 unsigned int msize;
214 enum v4l2_field field;
215 enum v4l2_field last; /* for field=V4L2_FIELD_ALTERNATE */
216 struct videobuf_buffer *bufs[VIDEO_MAX_FRAME];
217 struct videobuf_queue_ops *ops;
218
219 /* capture via mmap() + ioctl(QBUF/DQBUF) */
220 unsigned int streaming;
221 struct list_head stream;
222
223 /* capture via read() */
224 unsigned int reading;
225 unsigned int read_off;
226 struct videobuf_buffer *read_buf;
227
228 /* driver private data */
229 void *priv_data;
230};
231
232void* videobuf_alloc(unsigned int size);
233int videobuf_waiton(struct videobuf_buffer *vb, int non_blocking, int intr);
234int videobuf_iolock(struct videobuf_queue* q, struct videobuf_buffer *vb,
235 struct v4l2_framebuffer *fbuf);
236
237/* Maps fops to PCI stuff */
238void videobuf_queue_pci(struct videobuf_queue* q);
239
240void videobuf_queue_init(struct videobuf_queue *q,
241 struct videobuf_queue_ops *ops,
242 void *dev,
243 spinlock_t *irqlock,
244 enum v4l2_buf_type type,
245 enum v4l2_field field,
246 unsigned int msize,
247 void *priv);
248int videobuf_queue_is_busy(struct videobuf_queue *q);
249void videobuf_queue_cancel(struct videobuf_queue *q);
250
251enum v4l2_field videobuf_next_field(struct videobuf_queue *q);
252void videobuf_status(struct v4l2_buffer *b, struct videobuf_buffer *vb,
253 enum v4l2_buf_type type);
254int videobuf_reqbufs(struct videobuf_queue *q,
255 struct v4l2_requestbuffers *req);
256int videobuf_querybuf(struct videobuf_queue *q, struct v4l2_buffer *b);
257int videobuf_qbuf(struct videobuf_queue *q,
258 struct v4l2_buffer *b);
259int videobuf_dqbuf(struct videobuf_queue *q,
260 struct v4l2_buffer *b, int nonblocking);
261int videobuf_streamon(struct videobuf_queue *q);
262int videobuf_streamoff(struct videobuf_queue *q);
263
264int videobuf_read_start(struct videobuf_queue *q);
265void videobuf_read_stop(struct videobuf_queue *q);
266ssize_t videobuf_read_stream(struct videobuf_queue *q,
267 char __user *data, size_t count, loff_t *ppos,
268 int vbihack, int nonblocking);
269ssize_t videobuf_read_one(struct videobuf_queue *q,
270 char __user *data, size_t count, loff_t *ppos,
271 int nonblocking);
272unsigned int videobuf_poll_stream(struct file *file,
273 struct videobuf_queue *q,
274 poll_table *wait);
275
276int videobuf_mmap_setup(struct videobuf_queue *q,
277 unsigned int bcount, unsigned int bsize,
278 enum v4l2_memory memory);
279int videobuf_mmap_free(struct videobuf_queue *q);
280int videobuf_mmap_mapper(struct videobuf_queue *q,
281 struct vm_area_struct *vma);
282
283/* --------------------------------------------------------------------- */
284
285/*
286 * Local variables:
287 * c-basic-offset: 8
288 * End:
289 */
diff --git a/include/media/videobuf-core.h b/include/media/videobuf-core.h
new file mode 100644
index 000000000000..9fa09fb800a1
--- /dev/null
+++ b/include/media/videobuf-core.h
@@ -0,0 +1,236 @@
1/*
2 * generic helper functions for handling video4linux capture buffers
3 *
4 * (c) 2007 Mauro Carvalho Chehab, <mchehab@infradead.org>
5 *
6 * Highly based on video-buf written originally by:
7 * (c) 2001,02 Gerd Knorr <kraxel@bytesex.org>
8 * (c) 2006 Mauro Carvalho Chehab, <mchehab@infradead.org>
9 * (c) 2006 Ted Walther and John Sokol
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2
14 */
15
16#include <linux/poll.h>
17#ifdef CONFIG_VIDEO_V4L1_COMPAT
18#include <linux/videodev.h>
19#endif
20#include <linux/videodev2.h>
21
22#define UNSET (-1U)
23
24
25struct videobuf_buffer;
26struct videobuf_queue;
27
28/* --------------------------------------------------------------------- */
29
30/*
31 * A small set of helper functions to manage video4linux buffers.
32 *
33 * struct videobuf_buffer holds the data structures used by the helper
34 * functions, additionally some commonly used fields for v4l buffers
35 * (width, height, lists, waitqueue) are in there. That struct should
36 * be used as first element in the drivers buffer struct.
37 *
38 * about the mmap helpers (videobuf_mmap_*):
39 *
40 * The mmaper function allows to map any subset of contingous buffers.
41 * This includes one mmap() call for all buffers (which the original
42 * video4linux API uses) as well as one mmap() for every single buffer
43 * (which v4l2 uses).
44 *
45 * If there is a valid mapping for a buffer, buffer->baddr/bsize holds
46 * userspace address + size which can be feeded into the
47 * videobuf_dma_init_user function listed above.
48 *
49 */
50
51struct videobuf_mapping {
52 unsigned int count;
53 unsigned long start;
54 unsigned long end;
55 struct videobuf_queue *q;
56};
57
58enum videobuf_state {
59 STATE_NEEDS_INIT = 0,
60 STATE_PREPARED = 1,
61 STATE_QUEUED = 2,
62 STATE_ACTIVE = 3,
63 STATE_DONE = 4,
64 STATE_ERROR = 5,
65 STATE_IDLE = 6,
66};
67
68struct videobuf_buffer {
69 unsigned int i;
70 u32 magic;
71
72 /* info about the buffer */
73 unsigned int width;
74 unsigned int height;
75 unsigned int bytesperline; /* use only if != 0 */
76 unsigned long size;
77 unsigned int input;
78 enum v4l2_field field;
79 enum videobuf_state state;
80 struct list_head stream; /* QBUF/DQBUF list */
81
82 /* touched by irq handler */
83 struct list_head queue;
84 wait_queue_head_t done;
85 unsigned int field_count;
86 struct timeval ts;
87
88 /* Memory type */
89 enum v4l2_memory memory;
90
91 /* buffer size */
92 size_t bsize;
93
94 /* buffer offset (mmap + overlay) */
95 size_t boff;
96
97 /* buffer addr (userland ptr!) */
98 unsigned long baddr;
99
100 /* for mmap'ed buffers */
101 struct videobuf_mapping *map;
102
103 /* Private pointer to allow specific methods to store their data */
104 int privsize;
105 void *priv;
106};
107
108struct videobuf_queue_ops {
109 int (*buf_setup)(struct videobuf_queue *q,
110 unsigned int *count, unsigned int *size);
111 int (*buf_prepare)(struct videobuf_queue *q,
112 struct videobuf_buffer *vb,
113 enum v4l2_field field);
114 void (*buf_queue)(struct videobuf_queue *q,
115 struct videobuf_buffer *vb);
116 void (*buf_release)(struct videobuf_queue *q,
117 struct videobuf_buffer *vb);
118};
119
120#define MAGIC_QTYPE_OPS 0x12261003
121
122/* Helper operations - device type dependent */
123struct videobuf_qtype_ops {
124 u32 magic;
125
126 void* (*alloc) (size_t size);
127 int (*iolock) (struct videobuf_queue* q,
128 struct videobuf_buffer *vb,
129 struct v4l2_framebuffer *fbuf);
130 int (*mmap) (struct videobuf_queue *q,
131 unsigned int *count,
132 unsigned int *size,
133 enum v4l2_memory memory);
134 int (*sync) (struct videobuf_queue* q,
135 struct videobuf_buffer *buf);
136 int (*copy_to_user) (struct videobuf_queue *q,
137 char __user *data,
138 size_t count,
139 int nonblocking);
140 int (*copy_stream) (struct videobuf_queue *q,
141 char __user *data,
142 size_t count,
143 size_t pos,
144 int vbihack,
145 int nonblocking);
146 int (*mmap_free) (struct videobuf_queue *q);
147 int (*mmap_mapper) (struct videobuf_queue *q,
148 struct vm_area_struct *vma);
149};
150
151struct videobuf_queue {
152 struct mutex lock;
153 spinlock_t *irqlock;
154 void *dev; /* on pci, points to struct pci_dev */
155
156 enum v4l2_buf_type type;
157 unsigned int inputs; /* for V4L2_BUF_FLAG_INPUT */
158 unsigned int msize;
159 enum v4l2_field field;
160 enum v4l2_field last; /* for field=V4L2_FIELD_ALTERNATE */
161 struct videobuf_buffer *bufs[VIDEO_MAX_FRAME];
162 struct videobuf_queue_ops *ops;
163 struct videobuf_qtype_ops *int_ops;
164
165 /* capture via mmap() + ioctl(QBUF/DQBUF) */
166 unsigned int streaming;
167 struct list_head stream;
168
169 /* capture via read() */
170 unsigned int reading;
171 unsigned int read_off;
172 struct videobuf_buffer *read_buf;
173
174 /* driver private data */
175 void *priv_data;
176};
177
178int videobuf_waiton(struct videobuf_buffer *vb, int non_blocking, int intr);
179int videobuf_iolock(struct videobuf_queue* q, struct videobuf_buffer *vb,
180 struct v4l2_framebuffer *fbuf);
181
182void *videobuf_alloc(struct videobuf_queue* q);
183
184void videobuf_queue_core_init(struct videobuf_queue *q,
185 struct videobuf_queue_ops *ops,
186 void *dev,
187 spinlock_t *irqlock,
188 enum v4l2_buf_type type,
189 enum v4l2_field field,
190 unsigned int msize,
191 void *priv,
192 struct videobuf_qtype_ops *int_ops);
193int videobuf_queue_is_busy(struct videobuf_queue *q);
194void videobuf_queue_cancel(struct videobuf_queue *q);
195
196enum v4l2_field videobuf_next_field(struct videobuf_queue *q);
197int videobuf_reqbufs(struct videobuf_queue *q,
198 struct v4l2_requestbuffers *req);
199int videobuf_querybuf(struct videobuf_queue *q, struct v4l2_buffer *b);
200int videobuf_qbuf(struct videobuf_queue *q,
201 struct v4l2_buffer *b);
202int videobuf_dqbuf(struct videobuf_queue *q,
203 struct v4l2_buffer *b, int nonblocking);
204#ifdef CONFIG_VIDEO_V4L1_COMPAT
205int videobuf_cgmbuf(struct videobuf_queue *q,
206 struct video_mbuf *mbuf, int count);
207#endif
208int videobuf_streamon(struct videobuf_queue *q);
209int videobuf_streamoff(struct videobuf_queue *q);
210
211int videobuf_read_start(struct videobuf_queue *q);
212void videobuf_read_stop(struct videobuf_queue *q);
213ssize_t videobuf_read_stream(struct videobuf_queue *q,
214 char __user *data, size_t count, loff_t *ppos,
215 int vbihack, int nonblocking);
216ssize_t videobuf_read_one(struct videobuf_queue *q,
217 char __user *data, size_t count, loff_t *ppos,
218 int nonblocking);
219unsigned int videobuf_poll_stream(struct file *file,
220 struct videobuf_queue *q,
221 poll_table *wait);
222
223int videobuf_mmap_setup(struct videobuf_queue *q,
224 unsigned int bcount, unsigned int bsize,
225 enum v4l2_memory memory);
226int videobuf_mmap_free(struct videobuf_queue *q);
227int videobuf_mmap_mapper(struct videobuf_queue *q,
228 struct vm_area_struct *vma);
229
230/* --------------------------------------------------------------------- */
231
232/*
233 * Local variables:
234 * c-basic-offset: 8
235 * End:
236 */
diff --git a/include/media/videobuf-dma-sg.h b/include/media/videobuf-dma-sg.h
new file mode 100644
index 000000000000..38105031db23
--- /dev/null
+++ b/include/media/videobuf-dma-sg.h
@@ -0,0 +1,122 @@
1/*
2 * helper functions for PCI DMA video4linux capture buffers
3 *
4 * The functions expect the hardware being able to scatter gatter
5 * (i.e. the buffers are not linear in physical memory, but fragmented
6 * into PAGE_SIZE chunks). They also assume the driver does not need
7 * to touch the video data.
8 *
9 * (c) 2007 Mauro Carvalho Chehab, <mchehab@infradead.org>
10 *
11 * Highly based on video-buf written originally by:
12 * (c) 2001,02 Gerd Knorr <kraxel@bytesex.org>
13 * (c) 2006 Mauro Carvalho Chehab, <mchehab@infradead.org>
14 * (c) 2006 Ted Walther and John Sokol
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
19 */
20
21#include <media/videobuf-core.h>
22
23/* --------------------------------------------------------------------- */
24
25/*
26 * Return a scatterlist for some page-aligned vmalloc()'ed memory
27 * block (NULL on errors). Memory for the scatterlist is allocated
28 * using kmalloc. The caller must free the memory.
29 */
30struct scatterlist* videobuf_vmalloc_to_sg(unsigned char *virt, int nr_pages);
31
32/*
33 * Return a scatterlist for a an array of userpages (NULL on errors).
34 * Memory for the scatterlist is allocated using kmalloc. The caller
35 * must free the memory.
36 */
37struct scatterlist* videobuf_pages_to_sg(struct page **pages, int nr_pages,
38 int offset);
39
40/* --------------------------------------------------------------------- */
41
42/*
43 * A small set of helper functions to manage buffers (both userland
44 * and kernel) for DMA.
45 *
46 * videobuf_dma_init_*()
47 * creates a buffer. The userland version takes a userspace
48 * pointer + length. The kernel version just wants the size and
49 * does memory allocation too using vmalloc_32().
50 *
51 * videobuf_dma_*()
52 * see Documentation/DMA-mapping.txt, these functions to
53 * basically the same. The map function does also build a
54 * scatterlist for the buffer (and unmap frees it ...)
55 *
56 * videobuf_dma_free()
57 * no comment ...
58 *
59 */
60
61struct videobuf_dmabuf {
62 u32 magic;
63
64 /* for userland buffer */
65 int offset;
66 struct page **pages;
67
68 /* for kernel buffers */
69 void *vmalloc;
70
71 /* Stores the userspace pointer to vmalloc area */
72 void *varea;
73
74 /* for overlay buffers (pci-pci dma) */
75 dma_addr_t bus_addr;
76
77 /* common */
78 struct scatterlist *sglist;
79 int sglen;
80 int nr_pages;
81 int direction;
82};
83
84struct videbuf_pci_sg_memory
85{
86 u32 magic;
87
88 /* for mmap'ed buffers */
89 struct videobuf_dmabuf dma;
90};
91
92void videobuf_dma_init(struct videobuf_dmabuf *dma);
93int videobuf_dma_init_user(struct videobuf_dmabuf *dma, int direction,
94 unsigned long data, unsigned long size);
95int videobuf_dma_init_kernel(struct videobuf_dmabuf *dma, int direction,
96 int nr_pages);
97int videobuf_dma_init_overlay(struct videobuf_dmabuf *dma, int direction,
98 dma_addr_t addr, int nr_pages);
99int videobuf_dma_free(struct videobuf_dmabuf *dma);
100
101int videobuf_dma_map(struct videobuf_queue* q,struct videobuf_dmabuf *dma);
102int videobuf_dma_sync(struct videobuf_queue* q,struct videobuf_dmabuf *dma);
103int videobuf_dma_unmap(struct videobuf_queue* q,struct videobuf_dmabuf *dma);
104struct videobuf_dmabuf *videobuf_to_dma (struct videobuf_buffer *buf);
105
106void *videobuf_pci_alloc (size_t size);
107
108void videobuf_queue_pci_init(struct videobuf_queue* q,
109 struct videobuf_queue_ops *ops,
110 void *dev,
111 spinlock_t *irqlock,
112 enum v4l2_buf_type type,
113 enum v4l2_field field,
114 unsigned int msize,
115 void *priv);
116
117 /*FIXME: these variants are used only on *-alsa code, where videobuf is
118 * used without queue
119 */
120int videobuf_pci_dma_map(struct pci_dev *pci,struct videobuf_dmabuf *dma);
121int videobuf_pci_dma_unmap(struct pci_dev *pci,struct videobuf_dmabuf *dma);
122
diff --git a/include/media/video-buf-dvb.h b/include/media/videobuf-dvb.h
index 8233cafdeef6..8233cafdeef6 100644
--- a/include/media/video-buf-dvb.h
+++ b/include/media/videobuf-dvb.h
diff --git a/include/media/videobuf-vmalloc.h b/include/media/videobuf-vmalloc.h
new file mode 100644
index 000000000000..26a8958d23d1
--- /dev/null
+++ b/include/media/videobuf-vmalloc.h
@@ -0,0 +1,41 @@
1/*
2 * helper functions for vmalloc capture buffers
3 *
4 * The functions expect the hardware being able to scatter gatter
5 * (i.e. the buffers are not linear in physical memory, but fragmented
6 * into PAGE_SIZE chunks). They also assume the driver does not need
7 * to touch the video data.
8 *
9 * (c) 2007 Mauro Carvalho Chehab, <mchehab@infradead.org>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2
14 */
15
16#include <media/videobuf-core.h>
17
18/* --------------------------------------------------------------------- */
19
20struct videbuf_vmalloc_memory
21{
22 u32 magic;
23
24 void *vmalloc;
25
26 /* remap_vmalloc_range seems to need to run after mmap() on some cases */
27 struct vm_area_struct *vma;
28};
29
30void videobuf_queue_vmalloc_init(struct videobuf_queue* q,
31 struct videobuf_queue_ops *ops,
32 void *dev,
33 spinlock_t *irqlock,
34 enum v4l2_buf_type type,
35 enum v4l2_field field,
36 unsigned int msize,
37 void *priv);
38
39void *videobuf_to_vmalloc (struct videobuf_buffer *buf);
40
41void videobuf_vmalloc_free (struct videobuf_buffer *buf);
diff --git a/kernel/sched.c b/kernel/sched.c
index 6107a0cd6325..6c10fa796ca0 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -61,6 +61,7 @@
61#include <linux/delayacct.h> 61#include <linux/delayacct.h>
62#include <linux/reciprocal_div.h> 62#include <linux/reciprocal_div.h>
63#include <linux/unistd.h> 63#include <linux/unistd.h>
64#include <linux/pagemap.h>
64 65
65#include <asm/tlb.h> 66#include <asm/tlb.h>
66 67
diff --git a/mm/bounce.c b/mm/bounce.c
index 179fe38a2416..3b549bf31f7d 100644
--- a/mm/bounce.c
+++ b/mm/bounce.c
@@ -140,26 +140,19 @@ static void bounce_end_io(struct bio *bio, mempool_t *pool, int err)
140 mempool_free(bvec->bv_page, pool); 140 mempool_free(bvec->bv_page, pool);
141 } 141 }
142 142
143 bio_endio(bio_orig, bio_orig->bi_size, err); 143 bio_endio(bio_orig, err);
144 bio_put(bio); 144 bio_put(bio);
145} 145}
146 146
147static int bounce_end_io_write(struct bio *bio, unsigned int bytes_done, int err) 147static void bounce_end_io_write(struct bio *bio, int err)
148{ 148{
149 if (bio->bi_size)
150 return 1;
151
152 bounce_end_io(bio, page_pool, err); 149 bounce_end_io(bio, page_pool, err);
153 return 0;
154} 150}
155 151
156static int bounce_end_io_write_isa(struct bio *bio, unsigned int bytes_done, int err) 152static void bounce_end_io_write_isa(struct bio *bio, int err)
157{ 153{
158 if (bio->bi_size)
159 return 1;
160 154
161 bounce_end_io(bio, isa_page_pool, err); 155 bounce_end_io(bio, isa_page_pool, err);
162 return 0;
163} 156}
164 157
165static void __bounce_end_io_read(struct bio *bio, mempool_t *pool, int err) 158static void __bounce_end_io_read(struct bio *bio, mempool_t *pool, int err)
@@ -172,22 +165,14 @@ static void __bounce_end_io_read(struct bio *bio, mempool_t *pool, int err)
172 bounce_end_io(bio, pool, err); 165 bounce_end_io(bio, pool, err);
173} 166}
174 167
175static int bounce_end_io_read(struct bio *bio, unsigned int bytes_done, int err) 168static void bounce_end_io_read(struct bio *bio, int err)
176{ 169{
177 if (bio->bi_size)
178 return 1;
179
180 __bounce_end_io_read(bio, page_pool, err); 170 __bounce_end_io_read(bio, page_pool, err);
181 return 0;
182} 171}
183 172
184static int bounce_end_io_read_isa(struct bio *bio, unsigned int bytes_done, int err) 173static void bounce_end_io_read_isa(struct bio *bio, int err)
185{ 174{
186 if (bio->bi_size)
187 return 1;
188
189 __bounce_end_io_read(bio, isa_page_pool, err); 175 __bounce_end_io_read(bio, isa_page_pool, err);
190 return 0;
191} 176}
192 177
193static void __blk_queue_bounce(struct request_queue *q, struct bio **bio_orig, 178static void __blk_queue_bounce(struct request_queue *q, struct bio **bio_orig,
diff --git a/mm/page_io.c b/mm/page_io.c
index dbffec0d78c9..3b97f6850273 100644
--- a/mm/page_io.c
+++ b/mm/page_io.c
@@ -44,14 +44,11 @@ static struct bio *get_swap_bio(gfp_t gfp_flags, pgoff_t index,
44 return bio; 44 return bio;
45} 45}
46 46
47static int end_swap_bio_write(struct bio *bio, unsigned int bytes_done, int err) 47static void end_swap_bio_write(struct bio *bio, int err)
48{ 48{
49 const int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); 49 const int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags);
50 struct page *page = bio->bi_io_vec[0].bv_page; 50 struct page *page = bio->bi_io_vec[0].bv_page;
51 51
52 if (bio->bi_size)
53 return 1;
54
55 if (!uptodate) { 52 if (!uptodate) {
56 SetPageError(page); 53 SetPageError(page);
57 /* 54 /*
@@ -71,17 +68,13 @@ static int end_swap_bio_write(struct bio *bio, unsigned int bytes_done, int err)
71 } 68 }
72 end_page_writeback(page); 69 end_page_writeback(page);
73 bio_put(bio); 70 bio_put(bio);
74 return 0;
75} 71}
76 72
77int end_swap_bio_read(struct bio *bio, unsigned int bytes_done, int err) 73void end_swap_bio_read(struct bio *bio, int err)
78{ 74{
79 const int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); 75 const int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags);
80 struct page *page = bio->bi_io_vec[0].bv_page; 76 struct page *page = bio->bi_io_vec[0].bv_page;
81 77
82 if (bio->bi_size)
83 return 1;
84
85 if (!uptodate) { 78 if (!uptodate) {
86 SetPageError(page); 79 SetPageError(page);
87 ClearPageUptodate(page); 80 ClearPageUptodate(page);
@@ -94,7 +87,6 @@ int end_swap_bio_read(struct bio *bio, unsigned int bytes_done, int err)
94 } 87 }
95 unlock_page(page); 88 unlock_page(page);
96 bio_put(bio); 89 bio_put(bio);
97 return 0;
98} 90}
99 91
100/* 92/*
diff --git a/mm/readahead.c b/mm/readahead.c
index 39bf45d43320..be20c9d699d3 100644
--- a/mm/readahead.c
+++ b/mm/readahead.c
@@ -15,6 +15,7 @@
15#include <linux/backing-dev.h> 15#include <linux/backing-dev.h>
16#include <linux/task_io_accounting_ops.h> 16#include <linux/task_io_accounting_ops.h>
17#include <linux/pagevec.h> 17#include <linux/pagevec.h>
18#include <linux/pagemap.h>
18 19
19void default_unplug_io_fn(struct backing_dev_info *bdi, struct page *page) 20void default_unplug_io_fn(struct backing_dev_info *bdi, struct page *page)
20{ 21{
diff --git a/scripts/checkstack.pl b/scripts/checkstack.pl
index f7844f6aa487..663158627155 100755
--- a/scripts/checkstack.pl
+++ b/scripts/checkstack.pl
@@ -12,6 +12,7 @@
12# sh64 port by Paul Mundt 12# sh64 port by Paul Mundt
13# Random bits by Matt Mackall <mpm@selenic.com> 13# Random bits by Matt Mackall <mpm@selenic.com>
14# M68k port by Geert Uytterhoeven and Andreas Schwab 14# M68k port by Geert Uytterhoeven and Andreas Schwab
15# AVR32 port by Haavard Skinnemoen <hskinnemoen@atmel.com>
15# 16#
16# Usage: 17# Usage:
17# objdump -d vmlinux | stackcheck.pl [arch] 18# objdump -d vmlinux | stackcheck.pl [arch]
@@ -37,6 +38,10 @@ my (@stack, $re, $x, $xs);
37 if ($arch eq 'arm') { 38 if ($arch eq 'arm') {
38 #c0008ffc: e24dd064 sub sp, sp, #100 ; 0x64 39 #c0008ffc: e24dd064 sub sp, sp, #100 ; 0x64
39 $re = qr/.*sub.*sp, sp, #(([0-9]{2}|[3-9])[0-9]{2})/o; 40 $re = qr/.*sub.*sp, sp, #(([0-9]{2}|[3-9])[0-9]{2})/o;
41 } elsif ($arch eq 'avr32') {
42 #8000008a: 20 1d sub sp,4
43 #80000ca8: fa cd 05 b0 sub sp,sp,1456
44 $re = qr/^.*sub.*sp.*,([0-9]{1,8})/o;
40 } elsif ($arch =~ /^i[3456]86$/) { 45 } elsif ($arch =~ /^i[3456]86$/) {
41 #c0105234: 81 ec ac 05 00 00 sub $0x5ac,%esp 46 #c0105234: 81 ec ac 05 00 00 sub $0x5ac,%esp
42 $re = qr/^.*[as][du][db] \$(0x$x{1,8}),\%esp$/o; 47 $re = qr/^.*[as][du][db] \$(0x$x{1,8}),\%esp$/o;
diff --git a/scripts/checksyscalls.sh b/scripts/checksyscalls.sh
index 0dcc01ce45a6..366f8c7f62bf 100755
--- a/scripts/checksyscalls.sh
+++ b/scripts/checksyscalls.sh
@@ -119,5 +119,5 @@ sed -n -e '/^\#define/ { s/[^_]*__NR_\([^[:space:]]*\).*/\
119\#endif/p }' $1 119\#endif/p }' $1
120} 120}
121 121
122(ignore_list && syscall_list ${srctree}/include/asm-i386/unistd.h) | \ 122(ignore_list && syscall_list ${srctree}/include/asm-x86/unistd_32.h) | \
123$* -E -x c - > /dev/null 123$* -E -x c - > /dev/null
diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
index 8a09021d8c59..1e5d4d693195 100644
--- a/scripts/mod/file2alias.c
+++ b/scripts/mod/file2alias.c
@@ -484,6 +484,22 @@ static int do_parisc_entry(const char *filename, struct parisc_device_id *id,
484 return 1; 484 return 1;
485} 485}
486 486
487/* Looks like: sdio:cNvNdN. */
488static int do_sdio_entry(const char *filename,
489 struct sdio_device_id *id, char *alias)
490{
491 id->class = TO_NATIVE(id->class);
492 id->vendor = TO_NATIVE(id->vendor);
493 id->device = TO_NATIVE(id->device);
494
495 strcpy(alias, "sdio:");
496 ADD(alias, "c", id->class != (__u8)SDIO_ANY_ID, id->class);
497 ADD(alias, "v", id->vendor != (__u16)SDIO_ANY_ID, id->vendor);
498 ADD(alias, "d", id->device != (__u16)SDIO_ANY_ID, id->device);
499
500 return 1;
501}
502
487/* Ignore any prefix, eg. v850 prepends _ */ 503/* Ignore any prefix, eg. v850 prepends _ */
488static inline int sym_is(const char *symbol, const char *name) 504static inline int sym_is(const char *symbol, const char *name)
489{ 505{
@@ -599,6 +615,10 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
599 do_table(symval, sym->st_size, 615 do_table(symval, sym->st_size,
600 sizeof(struct parisc_device_id), "parisc", 616 sizeof(struct parisc_device_id), "parisc",
601 do_parisc_entry, mod); 617 do_parisc_entry, mod);
618 else if (sym_is(symname, "__mod_sdio_device_table"))
619 do_table(symval, sym->st_size,
620 sizeof(struct sdio_device_id), "sdio",
621 do_sdio_entry, mod);
602} 622}
603 623
604/* Now add out buffered information to the generated C source */ 624/* Now add out buffered information to the generated C source */
diff --git a/scripts/namespace.pl b/scripts/namespace.pl
index f34373853ef8..c6e88c652c2f 100755
--- a/scripts/namespace.pl
+++ b/scripts/namespace.pl
@@ -105,7 +105,7 @@ sub linux_objects
105 if (/.*\.o$/ && 105 if (/.*\.o$/ &&
106 ! ( 106 ! (
107 m:/built-in.o$: 107 m:/built-in.o$:
108 || m:arch/i386/kernel/vsyscall-syms.o$: 108 || m:arch/x86/kernel/vsyscall-syms.o$:
109 || m:arch/ia64/ia32/ia32.o$: 109 || m:arch/ia64/ia32/ia32.o$:
110 || m:arch/ia64/kernel/gate-syms.o$: 110 || m:arch/ia64/kernel/gate-syms.o$:
111 || m:arch/ia64/lib/__divdi3.o$: 111 || m:arch/ia64/lib/__divdi3.o$:
@@ -328,9 +328,9 @@ sub list_multiply_defined
328 } 328 }
329 # Special case for i386 entry code 329 # Special case for i386 entry code
330 if ($#{$def{$name}} == 1 && $name =~ /^__kernel_/ && 330 if ($#{$def{$name}} == 1 && $name =~ /^__kernel_/ &&
331 $def{$name}[0] eq "arch/i386/kernel/vsyscall-int80.o" && 331 $def{$name}[0] eq "arch/x86/kernel/vsyscall-int80_32.o" &&
332 $def{$name}[1] eq "arch/i386/kernel/vsyscall-sysenter.o") { 332 $def{$name}[1] eq "arch/x86/kernel/vsyscall-sysenter_32.o") {
333 &drop_def("arch/i386/kernel/vsyscall-sysenter.o", $name); 333 &drop_def("arch/x86/kernel/vsyscall-sysenter_32.o", $name);
334 next; 334 next;
335 } 335 }
336 printf "$name is multiply defined in :-\n"; 336 printf "$name is multiply defined in :-\n";